Return WP avatar inside a function

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.

Answers 2

  • 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.


  • 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 ); }
    

Related Questions