Skip to:
Content
Pages
Categories
Search
Top
Bottom

Search Results for 'bp_core_fetch_avatar'

Viewing 25 results - 226 through 250 (of 304 total)
  • Author
    Search Results
  • #107606

    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

    #107109
    Virtuali
    Participant

    Wait… do you mean a subnav? Like for instance, under profile, the subtabs are “Edit Profile, and Change Cignature?”

    Could be done, wrap the bp_core_new_subnav_item call in a function which is hooked on xprofile_setup_nav action;

    `/* Add the subnav items */
    bp_core_new_subnav_item( array( ‘name’ => __( ‘My Friends’, ‘buddypress’ ), ‘slug’ => ‘my-friends’, ‘parent_url’ => $friends_link, ‘parent_slug’ => $bp->friends->slug, ‘screen_function’ => ‘friends_screen_my_friends’, ‘position’ => 10, ‘item_css_id’ => ‘friends-my-friends’ ) );
    bp_core_new_subnav_item( array( ‘name’ => sprintf( __( ‘Requests (%d)‘, ‘buddypress’ ), bp_friend_get_total_requests_count() ), ‘slug’ => ‘requests’, ‘parent_url’ => $friends_link, ‘parent_slug’ => $bp->friends->slug, ‘screen_function’ => ‘friends_screen_requests’, ‘position’ => 20, ‘user_has_access’ => bp_is_my_profile() ) );

    if ( $bp->current_component == $bp->friends->slug ) {
    if ( bp_is_my_profile() ) {
    $bp->bp_options_title = __( ‘My Friends’, ‘buddypress’ );
    } else {
    $bp->bp_options_avatar = bp_core_fetch_avatar( array( ‘item_id’ => $bp->displayed_user->id, ‘type’ => ‘thumb’ ) );
    $bp->bp_options_title = $bp->displayed_user->fullname;
    }`

    There ya go, 2 in one! ;)

    #106871
    r-a-y
    Keymaster

    That’s the WP version of grabbing the avatar.

    You can also try the BuddyPress way:
    `echo bp_core_fetch_avatar( array( ‘item_id’ => $id, ‘width’ => $width, ‘height’ => $height ) );`

    A list of full parameters can be found by looking at the source:
    https://trac.buddypress.org/browser/tags/1.2.8/bp-core/bp-core-avatars.php#L50

    Cam
    Participant

    @boonebgorges

    I am a complete newbie when it comes to this. I tried to utilize the funciton you created above and it results in an error: Unexpected return.

    I imagine I am missing something obvious but here is my code:
    `function my_blog_avatar_1( $old_avatar ) {
    bp_core_fetch_avatar( array( ‘item_id’ => ‘1’, ‘type’ => $type, ‘alt’ => $alt, ‘width’ => $width, ‘height’ => $height, ‘class’ => $class ) ) // Do some stuff to get the avatar you want, then
    return $new_avatar;
    }
    add_filter( ‘bp_get_blog_avatar_1?, ‘my_blog_avatar_1’ );`

    Thanks in advance for your help.

    #106174

    In reply to: Recent Post plugin

    r-a-y
    Keymaster

    Pass the user id as the “item_id” parameter in bp_core_fetch_avatar().

    This function is located in /bp-core/bp-core-avatars.php.

    #20071
    G2Gmin
    Participant

    Warning: Missing argument 5 for bp_core_fetch_avatar_filter() in /home2/gtwogmin/public_html/wp-content/plugins/buddypress/bp-core/bp-core-avatars.php on line 479

    David Bisset
    Participant

    @grimbog

    Was there any progress on this? I was interested in the same thing, whether if it’s code or an actual plugin.

    Thanks!

    #101581
    Boone Gorges
    Keymaster

    You will have te create a custom function, either in your theme’s functions.php or in plugins/bp-custom.php, that filters the output of that function and replaces it with the avatar of your choice. Eg, if your blog_id is 5,
    ‘function my_blog_avatar( $old_avatar ) {
    // Do some stuff to get the avatar you want, then
    return $new_avatar;
    }
    add_filter( ‘bp_get_blog_avatar_5’, ‘my_blog_avatar’ );`

    The ‘do some stuff’ part will depend highly on your setup. If by ‘the associated group’ you mean that you are using bp-groupblog, then you will likely have to do some direct queries of the groupmeta database table to find the group that is associated with a particular blog (I don’t think that the plugin stores that info in a place that is easily accessible by blog_id). Then you will use some permutation of bp_core_fetch_avatar() to pull up the avatar for that group_id.

    Good luck!

    #101490
    scabadaska
    Member

    Hi @BuddyPresser,

    I would like to add to Javier’s @arques post above. His method does work but it’s missing the initial sign-up screen where gravatar is being pulled. I also rewrote his path a bit. This should do the trick for killing all Gravatar calls. If someone has more time than I it would be great to have this in plugin form. Here is the code:

    `
    function bp_remove_gravatar ($image, $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir) {

    $default = get_stylesheet_directory_uri() .’/_inc/images/bp_default_avatar.jpg’;

    if( $image && strpos( $image, “gravatar.com” ) ){

    return ‘avatar‘;
    } else {
    return $image;

    }

    }
    add_filter(‘bp_core_fetch_avatar’, ‘bp_remove_gravatar’, 1, 9 );

    function remove_gravatar ($avatar, $id_or_email, $size, $default, $alt) {

    $default = get_stylesheet_directory_uri() .’/_inc/images/bp_default_avatar.jpg’;
    return “{$alt}“;
    }

    add_filter(‘get_avatar’, ‘remove_gravatar’, 1, 5);

    function bp_remove_signup_gravatar ($image) {

    $default = get_stylesheet_directory_uri() .’/_inc/images/bp_default_avatar.jpg’;

    if( $image && strpos( $image, “gravatar.com” ) ){

    return ‘avatar‘;
    } else {
    return $image;
    }

    }
    add_filter(‘bp_get_signup_avatar’, ‘bp_remove_signup_gravatar’, 1, 1 );
    `

    The image that I am referencing doesn’t have to be a JPG. The size is 150×150. You may have to adjust the file name and/or path to your liking.

    Thanks @arques for the initial code!

    #98097
    r-a-y
    Keymaster

    If you need to stay on BP 1.2.4, you could probably just copy the part of the bp_core_fetch_avatar() function that adds support for the ‘html’ parameter… but I’d strongly suggest upgrading when you have the chance.

    See the codex article on upgrading:
    https://codex.buddypress.org/buddypress-site-administration/upgrading-buddypress/

    #98083
    r-a-y
    Keymaster

    Try this:
    `bp_core_fetch_avatar( ‘html=false’ );`

    Be sure to check out the full parameters for the function in bp-core-avatars.php.

    #16595
    powers1
    Member

    How can I retrieve the URL to a user or group’s avatar/gravatar *without* the `IMG` HTML tag? For our site layout we’re looking to use the avatar as a background image of a DIV – so we need just the URL, none of the `IMG` stuff. For instance, I’m using the `bp_group_avatar` function to return an `IMG` tag and using a regex to match the `SRC` attribute – but this is ugly and hackish. Is there a better way?

    Using Buddypress 1.2.4.1

    **Edit**

    Looking at the `bp_core_fetch_avatar` – I’m seeing hard-coded `IMG` tag – so I’m thinking no, this isn’t possible :(

    #97733
    Javier Arques
    Participant

    Hi @BuddyPresser !
    I have found out another way get it not editing core files. Put this filter into your functions.php file:

    `function bp_remove_gravatar ($image, $params, $item_id, $avatar_dir, $css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir) {

    $default = ‘http://yoursite.net/wp-content/plugins/buddypress/bp-core/images/mystery-man.jpg’;

    if( $image && strpos( $image, “gravatar.com” ) ){

    return ‘avatar‘;
    }else
    return $image;

    }
    add_filter(‘bp_core_fetch_avatar’, ‘bp_remove_gravatar’, 1, 9 );

    function remove_gravatar ($avatar, $id_or_email, $size, $default, $alt) {

    $default = ‘http://yoursite.net/wp-content/plugins/buddypress/bp-core/images/mystery-man.jpg’;
    return “{$alt}“;
    }

    add_filter(‘get_avatar’, ‘remove_gravatar’, 1, 5);
    `

    It worked for me

    #97121
    Boone Gorges
    Keymaster

    Cool, I’m glad the first part worked!

    Here’s a thrown-together-in-five-minutes filter to replace missing avatars with BP’s default mystery man. This probably won’t differentiate between user and group avatars, which you’ll have to sniff out of the $params array (in sort of the same way that I do with width and height). The basic idea is: if bp_core_fetch_avatar is not outputting any HTML, swap out the boolean false with the default mystery man.

    `function bbg_no_avatar( $html, $params ) {
    if ( !$html ) {
    if ( $params )
    $height = ‘ height=”‘ . $params . ‘”‘;

    if ( $params )
    $height = ‘ width=”‘ . $params . ‘”‘;

    $default_image_url = WP_PLUGIN_URL . ‘/buddypress/bp-core/images/mystery-man.jpg’;
    $html = ‘‘;
    }

    return $html;
    }
    add_action( ‘bp_core_fetch_avatar’, ‘bbg_no_avatar’, 10, 2 );`

    #97104
    mistercyril
    Participant

    Hello Boone,

    So step 1 WORKS!
    Hooray ;-) This was pretty simple, i’m sorry I couldn’t find it on my own.

    As far as step 2 is concerned
    You are right, previous users who had the mistery man icon don’t have an avatar anymore.
    I took a look at the ‘bp_core_fetch_avatar’ section but i’m not quite sure how to write the filter you mentioned.
    Could I abuse of your help and ask for an example? Would really be great.

    Thank you,
    C.

    #96997
    Boone Gorges
    Keymaster

    At the moment, there is no easy way to turn off Gravatar. I agree that there should be an easy way, as there can be performance concerns, as @mistercyril. (Though I find “I’m starting to think I’m the only one concerned with performance” unnecessarily confrontational.) I’ve had issues with it in the past myself.

    I’ve just opened a ticket to make disabling Gravatar easier: https://trac.buddypress.org/ticket/2697 Until it’s been implemented, here’s the general core-hack strategy for disabling Gravatar altogether:
    1) In bp-core/bp-core-avatars.php, find where the $defaults for bp_core_fetch_avatar() are set. Change
    `’no_grav’ => false,`
    to
    `’no_grav’ => true,`

    2) There will likely be some instances where the Mystery Man doesn’t kick in properly (group avatars, existing users). Write a filter for `’bp_core_fetch_avatar’` that sets the avatar to some default value when no avatar is returned.

    Lawrence
    Participant

    Hey guys,

    Just letting everyone know I’ve finally made progress on this: I now have custom avatars for Buddypress – the code needs tidying up, but its pretty much there. If all else fails then it reverts to the mysteryman. At the moment I’m trying to see if I can set a male/female setting, so when users sign up it can auto-generate dependent on their gender.

    Should note it filters bp_core_fetch_avatar, so if someone uses a gravatar then it’ll show accordingly.

    Anyone interested in this as a plugin? The theory is that I’m going to do various different graphics/styles so people can ultimately choose or design their own avatars “parts”. Might need someone look over my code though – its rough at best. I could also see this as quite a nice official implementation in the core as I’m sure designers would like to extend the avatar system.

    Some screenshots:
    http://www.obscuresounds.com/output.png
    http://www.obscuresounds.com/avatar-screenshot.jpg

    Lawrence
    Participant

    Hey guys, I’m working on a plugin that is an adaptation of ravatar (which was built for for WordPress 2.5). I realise its been out of development for a while, but I’ve done some code changes and have it working on the latest 3.x WordPress – I wanted to use my own random (wavatar) type system where I design different head graphics and have them alternate colour/background etc. as I grew tired of the wavetar effect and wanted my own graphic.

    Wondering if people are interested in this as a public release?

    UPDATE 04/02/2013: Firstly just want to apologise for the delay – ended up getting side-tracked with a large site/project. However I just thought I’d mention that I will endeavour to get this up and will create a new topic when this happens. All the code is there on my development machine… I just wish I had more time to add in a proper backend for it!

    caplain
    Member

    Thanks. I figured it out while waiting, even though your response was immediate ;)

    $group = new BP_Groups_Group( 1, true );
    $avatar = bp_core_fetch_avatar(
    array(
    ‘item_id’ => 1,
    ‘object’ => ‘group’,
    ‘type’ => ‘full’,
    ‘avatar_dir’ => ‘group-avatars’,
    ‘alt’ => ‘Group Avatar’,
    ‘css_id’ => 0,
    ‘class’ => ‘avatar’,
    ‘width’ => false,
    ‘height’ => false
    )
    );

    echo $avatar . “
    “;
    echo ‘slug.’/”>’.$group->name.’
    ‘.$group->description;

    Boone Gorges
    Keymaster

    Try this:
    `$group = new BP_Groups_Group( $group_id );`

    $group will then be an object containing the group name and a few other pieces of info. You’ll need to use bp_core_fetch_avatar() to get the avatar.

    omosha
    Participant

    Yeah, I’m still getting the error message
    ‘Warning: Missing argument 5 for bp_core_fetch_avatar_filter() in /home/integral/public_html/wp-content/plugins/buddypress/bp-core/bp-core-avatars.php on line 479’

    and I’ve removed step 3 from https://codex.buddypress.org/getting-started/install-buddypress-on-a-secondary-blog/

    Have you ever run into this or have any idea how to fix?

    Thanks again for checking it out

    omosha
    Participant

    Thank you so much, Mercime! I’ve got most of it all installed with the exception of a few hiccups.

    I had a difficult time with the avatars even before this modification. I’m getting this error code
    ‘/home/integral/public_html/wp-content/plugins/buddypress/bp-core/bp-core-avatars.php on line 479’
    When I go into bp-core-avatars.php on line 479 I see this as the definition:
    ‘function bp_core_fetch_avatar_filter( $avatar, $user, $size, $default, $alt ) {

    // If passed an object, assume $user->user_id
    if ( is_object( $user ) )
    $id = $user->user_id;

    // If passed a number, assume it was a $user_id
    else if ( is_numeric( $user ) )
    $id = $user;

    // If passed a string and that string returns a user, get the $id
    else if ( is_string( $user ) && ( $user_by_email = get_user_by_email( $user ) ) )
    $id = $user_by_email->ID;

    // If somehow $id hasn’t been assigned, return the result of get_avatar
    if ( empty( $id ) )
    return !empty( $avatar ) ? $avatar : $default;

    // Let BuddyPress handle the fetching of the avatar
    $bp_avatar = bp_core_fetch_avatar( array( ‘item_id’ => $id, ‘width’ => $size, ‘height’ => $size, ‘alt’ => $alt ) );

    // If BuddyPress found an avatar, use it. If not, use the result of get_avatar
    return ( !$bp_avatar ) ? $avatar : $bp_avatar;
    }’

    I’ve tried installing a bp-custom.php file within the plugin directory so that it would not be deleted when updating Buddypress but it produces an error everywhere on the site.
    Here is what I tried to add as the bp-custom.php file for reference:
    ‘define( ‘BP_AVATAR_UPLOAD_PATH’, ‘/var/www/wp-content/blogs.dir/1/files’ );
    define( ‘BP_AVATAR_URL’, ‘hxxp://integralbeings.com/files’ );’

    As I look at the code, I’m wondering if this is because there is no hxxp://integralbeings.com/files directory. Do I need to add this or is the path incorrect? Also, I’ve not seen hxxp before, is this a typo?

    Thanks for the support on this, it’s rather minor in the grand scheme of things, but I’m wondering if it will become a bigger problem as the community grows.

    Cheers,
    -Brant

    #92253
    defunct
    Participant

    Thank you both for your help, so I’m hoping I can return the favor. Modemlooper, here is how I adjusted the My Friends tab, but it has sub nav code for you, maybe it will help. Credit for this from @jeffsayre

    `function my_friends_setup_nav() {
    global $bp;

    /* Add ‘Friends’ to the main navigation */
    if( bp_friend_get_total_requests_count($disp_user) > 0 && bp_is_my_profile()) {
    bp_core_new_nav_item( array( ‘name’ => sprintf( __( ‘Friends (%d) (%d)‘, ‘buddypress’ ), friends_get_total_friend_count(), bp_friend_get_total_requests_count() ), ‘slug’ => $bp->friends->slug, ‘position’ => 60, ‘screen_function’ => ‘friends_screen_my_friends’, ‘default_subnav_slug’ => ‘my-friends’, ‘item_css_id’ => $bp->friends->id ) );
    } else {
    bp_core_new_nav_item( array( ‘name’ => sprintf( __( ‘Friends (%d)‘, ‘buddypress’ ), friends_get_total_friend_count() ), ‘slug’ => $bp->friends->slug, ‘position’ => 60, ‘screen_function’ => ‘friends_screen_my_friends’, ‘default_subnav_slug’ => ‘my-friends’, ‘item_css_id’ => $bp->friends->id ) );
    }

    $friends_link = $bp->loggedin_user->domain . $bp->friends->slug . ‘/’;

    /* Add the subnav items to the friends nav item */
    bp_core_new_subnav_item( array( ‘name’ => __( ‘My Friends’, ‘buddypress’ ), ‘slug’ => ‘my-friends’, ‘parent_url’ => $friends_link, ‘parent_slug’ => $bp->friends->slug, ‘screen_function’ => ‘friends_screen_my_friends’, ‘position’ => 10, ‘item_css_id’ => ‘friends-my-friends’ ) );
    bp_core_new_subnav_item( array( ‘name’ => sprintf( __( ‘Requests (%d)‘, ‘buddypress’ ), bp_friend_get_total_requests_count() ), ‘slug’ => ‘requests’, ‘parent_url’ => $friends_link, ‘parent_slug’ => $bp->friends->slug, ‘screen_function’ => ‘friends_screen_requests’, ‘position’ => 20, ‘user_has_access’ => bp_is_my_profile() ) );

    if ( $bp->current_component == $bp->friends->slug ) {
    if ( bp_is_my_profile() ) {
    $bp->bp_options_title = __( ‘My Friends’, ‘buddypress’ );
    } else {
    $bp->bp_options_avatar = bp_core_fetch_avatar( array( ‘item_id’ => $bp->displayed_user->id, ‘type’ => ‘thumb’ ) );
    $bp->bp_options_title = $bp->displayed_user->fullname;
    }
    }

    do_action( ‘friends_setup_nav’ );
    }

    add_action( ‘bp_setup_nav’, ‘my_friends_setup_nav’, 11 );`

    #14895
    KV
    Participant

    HI!
    I recently installed BuddyPress plugin in my wordpress project but I got this message
    Warning: Missing argument 5 for bp_core_fetch_avatar_filter() in C:xampphtdocssouthparkwp-contentpluginsbuddypressbp-corebp-core-avatars.php on line 479.
    What does this mean? And how can I solve it?

    #90139

    In reply to: group default avatar

    r-a-y
    Keymaster

    Since you’re using the filter I posted, I would manually setup a group loop. Then in this loop, I would use the bp_core_fetch_avatar() function with the “html” parameter set to false (view the full function and parameter list in /bp-core/bp-core-avatars.php).

    Doing this will return the URL of the avatar, then you can manually define the width and height in an IMG tag.

Viewing 25 results - 226 through 250 (of 304 total)
Skip to toolbar