• Resolved timbergski

    (@timbergski)


    Hello,

    What is the correct function call to obtain the URL of a profile image for a given user id? I’m doing this from code outside UM. I’ve tried:

    get_avatar_url // WordPress standard function

    UM()->uploader()->get_upload_base_url() . um_user( ‘ID’ ) . “/” . um_profile( ‘profile_photo’ ) // doesn’t work when not logged in

    Many thanks

Viewing 8 replies - 1 through 8 (of 8 total)
  • @timbergski

    You will get the profile photo file name by this code:

    $image = get_usermeta( $user_id , "profile_photo", true);

    Thread Starter timbergski

    (@timbergski)

    Thanks, but that doesn’t work: it returns the contents of the wp_usermeta table for that key, which is just “profile_photo.png”.

    When I look at the URL for a user profile picture as displayed in their page, I get something along the lines of:

    <my site>/wp-content/uploads/ultimatemember/1/profile_photo-190x190.jpg?1680617169
    
    

    I was using the “UM()->uploader()->get_upload_base_url()…” variant above because that gets the right answer – but not when the user isn’t logged in.

    • This reply was modified 1 year, 7 months ago by timbergski.

    @timbergski

    You can hardcode the <my site>/wp-content/uploads/ultimatemember/ as it will not change on your site. The $user_id you must get from the context of your page.

    $image may be different depending on the extension used for the profile image not always .png with the addition of the image size being defined in your UM Settings and the current timestamp.

    Thread Starter timbergski

    (@timbergski)

    Thanks. I’d already done that ?? but thought maybe there was a function for doing it. Good to know it won’t change.

    Plugin Support andrewshu

    (@andrewshu)

    Hello @timbergski

    You could try to use this code:

    um_get_avatar( '', $user_id, 150 ); // 150 - avatar size

    Refards.

    Thread Starter timbergski

    (@timbergski)

    That’s not working for me (not exactly sure what’s happening but it definitely breaks my code). Does the size have to correspond to the size of one of the stored images?

    @timbergski

    Make the size parameter a string.

    /**
     * Get user UM avatars
     * @param  string $avatar
     * @param  string $id_or_email
     * @param  string $size
     * @param  string $avatar_class
     * @param  string $default
     * @param  string $alt
     * @hooks  filter <code>get_avatar</code>
     * @return string returns avatar in image html elements
     */
    function um_get_avatar( $avatar = '', $id_or_email='', $size = '96', $avatar_class = '', $default = '', $alt = '' ) 
    Plugin Support andrewshu

    (@andrewshu)

    Hi @timbergski

    This thread has been inactive for a while so we’re going to go ahead and mark it Resolved.

    Please feel free to re-open this thread if any other questions come up and we’d be happy to help. ??

    Regards

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Function to return URL of profile image’ is closed to new replies.