Support » Plugin: Avatar Manager » Trying to get the avatar url

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Catalin Dogaru

    (@cdog)

    Hey,

    You can retrieve the avatar for a user who provided a user ID or email address by using the WordPress built-in get_avatar() function.

    <?php echo get_avatar( $id_or_email, $size, $default, $alt, $args ); ?>

    You can also retrieve the avatar URL by calling the get_avatar_url() function. However, this was added in WordPress 4.2.0 and it’s not yet handled by Avatar Manager, returning only the Gravatar (this will change with the next release).

    Please let me know if this helps (providing the right parameters, get_avatar() should return an img element for the user’s avatar or false on failure).

    Best,
    Cătălin

    Thanks for the answer, then I guess I have to wait until the plugin can handle what I need.

    Plugin Author Catalin Dogaru

    (@cdog)

    Can you provide a link or a code sample? If you need an img element with the avatar, the get_avatar() function should be what you are looking for. If you only need the avatar url, please wait for the next release when the plugin will also support get_avatar_url().

    Cătălin Dogaru: When will the next release be? I’m in need of using get_avatar_url() atm. Can I get a code sample to do it on my own before the release? Or is it a tricky solution?

    Plugin Author Catalin Dogaru

    (@cdog)

    Hey Droapd,

    On it, sorry for delay. I would like to update the code on the dev branch. I’ll let you know when I have something.

    Best,
    Cătălin

    Checking in on this. It looks like in last post in this thread you mentioned that this functionality would be coming in a new release. That was 7 months ago and I noticed that the last update was 2 months ago.

    Is this functionality here yet? I couldnt get it to work.

    Guys, maybe this will be helpful: I wanted rectangle avatar – not square – so I did a bit of digging.

    User avatars from this plugin (well, their attachement ids) are stored in option called “avatar_manager_custom_avatar”. That means it’s quite easy to get it and then do whatever you need to do. Some examples:

    $attachement_id = get_user_meta(get_current_user_id(), 'avatar_manager_custom_avatar', true);
    echo wp_get_attachment_url($attachement_id); // will give you avatar url (full size)

    if you would like specific size you could do something like:

    $attachement_id = get_user_meta(get_current_user_id(), 'avatar_manager_custom_avatar', true);
    $image = wp_get_attachment_image( $attachement_id, 'people-avatar', false );
    echo $image;

    or

    $attachement_id = get_user_meta(get_current_user_id(), 'avatar_manager_custom_avatar', true);
    $thumb_url_array = wp_get_attachment_image_src($attachement_id, 'thumbnail-size', true);
    $thumb_url = $thumb_url_array[0];
    echo $thumb_url;

    Hope that helps! 👍🏻

    Lukas

    Thanks a lot Lukas. I think that’s exactly what we were all looking for 🙂

    Plugin Author Catalin Dogaru

    (@cdog)

    Hey,

    @austin Gil: I missed it when I bundled the release, I’m sorry for this.

    @lukas Juhas: Thank you for sharing, this is definitely a good approach for this issue.

    Also, you can use this function to return the image src:

    avatar_manager_generate_avatar_url( $attachment_id, $size );

    Both methods (this and the one provided by Lukas), however, don’t generate a new size if it doesn’t exist and doesn’t count the avatar rating neither (so it doesn’t default to Gravatar). For this I’m going to add support to get_avatar_url which will generate image sizes on demand, same as is get_avatar now. Again, sorry for delaying this.

    Thanks,
    Cătălin

    Hey, no worries Catalin. Thanks for the great plugin!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Trying to get the avatar url’ is closed to new replies.