Skip to:
Content
Pages
Categories
Search
Top
Bottom

Is it possible to get only the avatar-url ?


  • seppolaatle112
    Participant

    @seppolaatle112

    Hi and hello.!

    Is there any way I can get only url to users avatars, so that I could choose to use something like <img src=”?” alt=”one of my site members…”> ?

    – In advance, thanks for your reply.!

Viewing 16 replies - 1 through 16 (of 16 total)

  • yu
    Participant

    @gerbilo

    it’s not just url, but something..

    <?php echo bp_core_get_avatar( user_id_here, 1 ) ?>

    you will get ->

    <img src="http://your.site/wp-content/blogs.dir/blog_id_here/files/avatars/user_id_here/user_avatar.jpg" alt="" class="avatar photo" width="50" height="50" />


    seppolaatle112
    Participant

    @seppolaatle112

    Thanks for the reply, but that’s not what I need… I know what I can use to get the full “<img src=”http://your.site/wp-content/blogs.dir/blog_id_here/files/avatars/user_id_here/user_avatar.jpg&#8221; alt=”” class=”avatar photo” width=”50″ height=”50″ />” , but I need something that only gives me the image-url, in this case, “http://your.site/wp-content/blogs.dir/blog_id_here/files/avatars/user_id_here/user_avatar.jpg…&#8221;

    Is there anything I can do to make Buddypress return only the image url?


    yu
    Participant

    @gerbilo

    add new function in wp-core-avatars.php ->

    function bp_core_get_avatar_url( $user, $version = 1, $width = null, $height = null, $no_tag = false ) {
    global $bp, $current_blog;

    if ( !is_int($version) )
    $version = (int) $version;

    if ( CORE_AVATAR_V2_W == false && CORE_AVATAR_V2_H == false )
    $version = 1;

    if ( !$width )
    $width = constant('CORE_AVATAR_V' . $version . '_W');

    if ( !$height )
    $height = constant('CORE_AVATAR_V' . $version . '_H');

    $avatar_file = get_usermeta( $user, "bp_core_avatar_v$version" );
    $url = $bp['root_domain'] . '/' . $avatar_file;

    if ( strlen($avatar_file) ) {
    if ( $no_tag )
    return $url;
    else
    return $url;
    } else {
    $ud = get_userdata($user);
    $grav_option = get_site_option('user-avatar-default');

    if ( $grav_option == '' ) {
    $default_grav = 'wavatar';
    } else if ( $grav_option == 'mystery' ) {
    $default_grav = site_url('wp-content/mu-plugins/bp-core/images/mystery-man.jpg');
    } else {
    $default_grav = $grav_option;
    }

    $gravatar = 'https://secure.gravatar.com/avatar/' . md5( $ud->user_email ) . '?d=' . $default_grav . '&amp;s=';
    if ( $no_tag )
    return $gravatar . constant('CORE_AVATAR_V' . $version . '_W');
    else
    return $gravatar . constant('CORE_AVATAR_V' . $version . '_W');
    }
    }

    and use bp_core_get_avatar_url(user_id_here,1)


    seppolaatle112
    Participant

    @seppolaatle112

    gerbilo, to be quite honest with you, I do not think this one will do what I need. Anyway I will try it out, and come back to you with some info on how this works.

    – Thanks for helping me out. ;)


    Burt Adsit
    Participant

    @burtadsit

    In bp-core-classes.php is BP_Core_User

    /**
    * BP_Core_User class can be used by any component. It will fetch useful
    * details for any user when provided with a user_id.
    *
    * Example:
    * $user = new BP_Core_User( $user_id );
    * $user_avatar = $user->avatar;
    * $user_email = $user->email;
    * $user_status = $user->status;
    * etc.
    *
    * @package BuddyPress Core
    */

    Lots of stuff in that class. You need a user id to instantiate one.


    yu
    Participant

    @gerbilo

    seppolaatle112, to be quite honest with you – it’ll do exactlty what you need.


    seppolaatle112
    Participant

    @seppolaatle112

    Do you know what gerbilo? You are right. That piece of code you came up with actually did exactly what I asked.

    It was me who came with too little information in the thread to get a correct answer to what I actually needed, and that’s why this would not work for me.

    Without writing much on exactly what I wanted to do, I can at least mention that I got it working now. It was actually kind of fun to take a look into the Buddypress Core-files and actually do it myself.

    – Thanks for helping me out with my issues here.! :)


    yu
    Participant

    @gerbilo

    oh.. nice to heard that you got what you want finally )) but it would be better if you paste you editions here for the next generations )


    odiggy
    Participant

    @odiggy

    Sorry to revive an old thread but I’m trying to do this as well. What’s the best method now with the latest version of BP and WP 3.0? I just want to fetch the avatar url for posting avatars in a chat box. So far I’m able to use bp_core_avatar_url() but that only fetches the uploaded directory /uploads.

    Thanks in advance


    r-a-y
    Keymaster

    @r-a-y

    Use bp_core_fetch_avatar() and pass the “html” argument as false.

    Check out bp_core_fetch_avatar() @ /bp-core/bp-core-avatars.php.


    odiggy
    Participant

    @odiggy

    Thanks for your reply!

    Using bp_core_fetch_avatar( array( ‘html’ => false ) ) but still not quite working, do I need to call the logged in user id somehow along with this?


    r-a-y
    Keymaster

    @r-a-y

    @odiggy – You could also use:
    bp_loggedin_user_avatar( 'html=false' );
    (available in /bp-core/bp-core-templatetags.php)

    Because that will automatically call the logged in user’s avatar without using the generic bp_core_fetch_avatar() and needing additional parameters.


    odiggy
    Participant

    @odiggy

    Sweet that worked! Can I buy you a beer?


    techguy
    Participant

    @crashutah

    @odiggy Try the Donate button on one of r-a-y’s plugins: https://buddypress.org/community/groups/oembed-for-buddypress/

    r-a-y, Thanks for the extra answer. I started trying to document some of the bp_core_fetch_avatar function so that I could add it to the codex: https://buddypress.org/community/groups/how-to-and-troubleshooting/forum/topic/changing-avatar-size-sometimes-creates-fuzzy-avatars/ This is a good addition.


    xavieremerson
    Member

    @xavieremerson

    hi
    here is the solution for getting the avatar image url
    bp_core_fetch_avatar(array(‘item_id’ => $other_user, ‘type’ => ‘thumb’, ‘width’ => 32, ‘height’ => 32, ‘class’ => ‘friend-avatar’,’html’=>false));

    html = false

    @r-a-y thanks a ton

Viewing 16 replies - 1 through 16 (of 16 total)
  • The topic ‘Is it possible to get only the avatar-url ?’ is closed to new replies.
Skip to toolbar