0

I am trying to override a plugin's built in avatar with the default WP avatar. The plugin's filter is this:

add_filter( "idea_push_change_user_image", "idea_push_change_user_image_callback", 10, 1 );

function idea_push_change_user_image_callback( $userId ) 
{
  return "https://cdn.britannica.com/55/174255-004-9A4971E9.jpg";
}

I tried replacing that with 'get_avatar' but it ends up with a broken jpg image

add_filter( "idea_push_change_user_image", "idea_push_change_user_image_callback", 10, 1 );

function idea_push_change_user_image_callback( $userId ) 
{
  return get_avatar( get_the_author_meta( 'ID' ), 32 );
}

Any ideas how to fix, thanks

UPDATE:

Thanks for answers, this has helped. Turns out I needed to pull another plugins (Ultimate Member) avatar not the default:

add_filter( "idea_push_change_user_image", "idea_push_change_user_image_callback", 10, 1 );

function idea_push_change_user_image_callback( $userId )
{
  return um_get_user_avatar_url();
}

What's weird is it's only working/visible to the logged in user, not visible to anyone else.

  • The return value of get_avatar is an img tag, not just the url, which as it seems the plugin needs. Try get_avatar_url instead – Jeffrey von Grumbkow Sep 18 '18 at 11:44
1

Replace the below line your code

return get_avatar( get_the_author_meta( 'ID' ), 32 ); 

to

return get_avatar_url( get_the_author_meta( 'ID' ) ); 

Hope this helps.

|improve this answer|||||
  • get_the_author_meta( 'ID' ) is probably unnecessary when $userId is one of the parameters being passed to the function. – Otto Sep 18 '18 at 14:26
0

This code fixed it. Had to get the UM avatar:

add_filter( "idea_push_change_user_image", 
  "idea_push_change_user_image_callback", 10, 1 ); 
function 
  idea_push_change_user_image_callback( $userId ) 
{ return um_get_user_avatar_url($userId ); }
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.