Skip to:
Content
Pages
Categories
Search
Top
Bottom

Search Results for 'bp_core_fetch_avatar'

Viewing 25 results - 51 through 75 (of 304 total)
  • Author
    Search Results
  • #252860
    Henry Wright
    Moderator

    Hi @etavio

    Your custom plugin is most likely filtering get_avatar to display your custom images. BuddyPress actually bypasses that filter through the use of bp_core_fetch_avatar().

    Ref: https://github.com/buddypress/BuddyPress/blob/master/src/bp-core/bp-core-avatars.php#L192

    You will need to use a different filter.

    #251396
    danbp
    Moderator

    Hi,

    default avatar is ‘gravatar’ ‘s mytery man. To use your own avatar, you have to deactivate gravatar in addition to constant. Try this in bp-custom.php

    add_filter('bp_core_fetch_avatar_no_grav', '__return_true');
    define ( 'BP_AVATAR_DEFAULT_THUMB', 'YOURIMAGEURL' );
    #250977
    tkuron
    Participant

    I managed to fix the issue.

    Apparently BuddyPress does not change the avatar url when get_avatar_data() -function is called. I managed to fix the issue by adding following piece of script to my plugin’s source code:

    <?php
    add_filter("get_avatar_data", function($args, $id_or_email){
    	$bp_avatar_url = bp_core_fetch_avatar([
    			"html" => false,
    			"item_id" => $id,
    			"type" => "full",
    			"width" => $args["size"],
    			"height" => $args["size"]
    	]);
    	
    	$bp_avatar_url = htmlspecialchars_decode($bp_avatar_url);
    	$args["url"] = $bp_avatar_url;
    			
    	return $args;
    }, 10, 2);
    ?>
    #250975
    Henry Wright
    Moderator

    If it’s a BuddyPress page then I guess the bp_core_fetch_avatar() function should display the local avatar if no Grav exists. Are you saying this doesn’t happen?

    #250971
    Henry Wright
    Moderator

    You could disable Gravatar?

    add_filter( 'bp_core_fetch_avatar_no_grav', '__return_true' );

    #249994
    Florent
    Participant

    Hello,

    I would like to add the class ‘thumbnail’ to the group avatar with this filter but for some reason it returns an error saying “Illegal string offset ‘class’ “. What could be the reason ?

    function.php :

    // Add class to Group avatar image
      function bp_add_class_thumbnail_group_avatar( $avatar ) {
      $avatar['class'] .= ' thumbnail';
      return $avatar;
    	}
    	
    add_filter( 'bp_get_group_avatar', 'bp_add_class_thumbnail_group_avatar' );
     

    The original class is set by the function bp_core_fetch_avatar inside bp_get_group_avatar but it is not clear for me how to address this sub-function.

    If somebody have an idea,
    Thank you

    	function bp_get_group_avatar( $args = '' ) {
    		global $groups_template;
    
    		// Bail if avatars are turned off.
    		if ( bp_disable_group_avatar_uploads() || ! buddypress()->avatar->show_avatars ) {
    			return false;
    		}
    
    		// Parse the arguments
    		$r = bp_parse_args( $args, array(
    			'type'   => 'full',
    			'width'  => false,
    			'height' => false,
    			'class'  => 'avatar',
    			'id'     => false,
    			'alt'    => sprintf( __( 'Group logo of %s', 'buddypress' ), $groups_template->group->name )
    		) );
    
    		// Fetch the avatar from the folder
    		$avatar = bp_core_fetch_avatar( array(
    			'item_id'    => $groups_template->group->id,
    			'title'      => $groups_template->group->name,
    			'avatar_dir' => 'group-avatars',
    			'object'     => 'group',
    			'type'       => $r['type'],
    			'alt'        => $r['alt'],
    			'css_id'     => $r['id'],
    			'class'      => $r['class'],
    			'width'      => $r['width'],
    			'height'     => $r['height']
    		) );
    
    		// If No avatar found, provide some backwards compatibility
    		if ( empty( $avatar ) ) {
    			$avatar = '<img src="' . esc_url( $groups_template->group->avatar_thumb ) . '" class="avatar" alt="' . esc_attr( $groups_template->group->name ) . '" />';
    		}
    
    		/**
    		 * Filters the group avatar while in the groups loop.
    		 *
    		 * @since 1.0.0
    		 *
    		 * @param string $avatar HTML image element holding the group avatar.
    		 * @param array  $r      Array of parsed arguments for the group avatar.
    		 */
    		return apply_filters( 'bp_get_group_avatar', $avatar, $r );
    	}
    #249815
    Florent
    Participant

    Topic close as result is already formated :
    http://hookr.io/functions/bp_core_fetch_avatar/

    Usage

    $string = bp_core_fetch_avatar( $args );

    Parameters

    $args
    ( array|string ) optional – { An array of arguments. All arguments are technically optional; some will, if not provided, be auto-detected by bp_core_fetch_avatar(). This auto-detection is described more below, when discussing specific arguments.

    Returns

    string Formatted HTML element, or raw avatar URL based on $html arg.

    #249814
    Florent
    Participant

    Hello,

    I use this function to display the user avatar but for some reason the image is not displayed.

    function author_avatar_shortocode_handler($atts) {
    	
    	return "<img src='". bp_core_fetch_avatar ( array( 'item_id' => $atts, 'type' => 'full' ) ). "' >";
    }

    Firebug show that image URL starts with // as in :

    src='<img src="//www.gravatar.com/avatar/cfb543ca40e1d2c06d297f83bac37bfd?s=150&r=g&d=monsterid" class="avatar user-Array-avatar avatar-150 photo" width="150" height="150" alt="Photo du profil" />'

    Do you have an idea how to remove this ?

    Thank you,

    #247239
    Henry Wright
    Moderator

    bp_core_default_avatar_user will fire only if you have disabled Gravatar via the bp_core_fetch_avatar_no_grav hook.

    #247233
    jimme595
    Participant

    Wordpress: 4.3.1
    BP: 2.4.0

    Hi, I have a slightly unusual setup that I’m trying to get working.

    I run a site for kids and as such I have created profile images that they can choose from which are stored as user-meta in wp. I also have my own user profiles basaed on the wp author.php located at /profiles/(nickname). I want to integrate buddypress in to my site as it uses Learndash and this integrates with bp to give an activity feed to the LMS.

    So the two things I would like to achieve are to change the user profile links on bp features such as the activity feed and online members widget etc from the buddypress profiles to links to my profiles at /profiles/. Secondly I need to change the avatar images that come up in activity feed and member widges from the buddypress ones to my custom meta.

    I’ve been working away on this all day and can’t quite get it. I’ve placed teh following code in my bp-custom.php and had some success but it is not yet working. If someone could take a look and help me out or point me in the right direction i’d really appreciate it!

    Here is the first code to try and get the profile links to redirect:

    function _bp_core_get_user_domain($domain) {
    		$url = get_home_url();
    		$user_id = bp_get_member_user_id();
    		$link = bp_core_get_username( $user_id ); 
            $domain = '' . $url . '/profiles/' . $link . '';
            return $domain;
        }
    add_filter('bp_core_get_user_domain', '_bp_core_get_user_domain', 10, 4);

    And here is the second to try and change the profile pics:

    function my_default_avatar_url() {
    	$url = get_site_url();
    	$user_id = bp_get_member_user_id();
    	$profile_image = get_the_author_meta( my_avatar, $user_id );
    	if (empty($profile_image)) {
    	$profile_image = '' . $url . '/wp-content/uploads/avatars/avatar.png';
    }
        $image = '<img src="' . $profile_image . '" width="50px" height="50px" />';
    	return $image;
    }
    
    add_filter( 'bp_core_default_avatar_user', 'my_default_avatar_url' );
    add_filter( 'bp_core_fetch_avatar', 'my_default_avatar_url');

    Thanks!

    #247012
    r-a-y
    Keymaster

    We do not store avatar data in the database.

    We do a look up at the files level instead.

    If you want to show an avatar based on a custom avatar stored in the database, you’ll need to use the 'bp_core_fetch_avatar' filter to override how BuddyPress shows avatars:
    https://buddypress.trac.wordpress.org/browser/tags/2.4.0/src/bp-core/bp-core-avatars.php?marks=531-546,660-664#L531

    If you just want to display a user avatar, use the bp_core_fetch_avatar() function:

    echo bp_core_fetch_avatar( array(
        'item_id' => USER_ID_TO_GRAB_AVATAR_FOR
    ) );
    #246176
    silversurfer.wf
    Participant

    OK, for some reason that did not cut and paste correctly. The add_filter line looks like this.

    add_filter( 'bp_core_fetch_avatar_no_grav','__return_true' );

    #246175
    silversurfer.wf
    Participant

    The following code…

    <?php

    // Use this file to customize Buddy Press

    // This section changes the default avatar to the picture of a box
    // the picture is uploaded into WordPress
    add_filter( 'bp_core_fetch_avatar_no_grav','__return_true' );
    define ( ‘BP_AVATAR_DEFAULT’, ‘http://www.truesouthernmen.com/wp-content/uploads/2015/10/0307152159-02-300×225.jpg&#8217; );
    define ( ‘BP_AVATAR_DEFAULT_THUMB’, ‘http://www.truesouthernmen.com/wp-content/uploads/2015/10/0307152159-02-300×225.jpg&#8217; );

    ?>

    Returns this error when loading the page…..

    Fatal error: Can’t use function return value in write context in /home/cody7670/public_html/wp-content/plugins/bp-custom.php on line 8

    #246171
    Brajesh Singh
    Participant

    For that purpose, please put the following line too in your bp-custom.php

    
    add_filter( 'bp_core_fetch_avatar_no_grav', '__return_true' );
    
    

    That forces BuddyPress to avoid using gravatar and use local avatars for default(when no avatar is uploaded).

    Hope that helps

    danbp
    Moderator

    BuddyPress use Gravatar by default, like WordPress.
    If your user uploaded custom avatars, you may use bp_core_fetch_avatar in place of wp’s get_avatar

    http://oik-plugins.eu/buddypress-a2z/oik_api/bp_core_fetch_avatar/

    More about avatars here and search for “avatar”
    http://hookr.io/plugins/buddypress/#index=a

    #245627
    LaurieDugdale
    Participant

    Found the code below on these forums works perfectly.

    function my_cache_avatar_url() {
    	update_user_meta( bp_displayed_user_id(), 'modemloopers_awesome_avatar_url', bp_core_fetch_avatar( 'html=false&item_id=' . bp_displayed_user_id() ) );
    }
    add_action( 'xprofile_screen_change_avatar', 'my_cache_avatar_url' );
    

    I’ve tried to make it work for an xprofile field by doing the code below with no such luck. Any ideas?

    
    function my_cache_xprofile_website() {
    	update_user_meta( bp_displayed_user_id(), 'modemloopers_awesome_website_url', bp_profile_field_data('field=Website&item_id=' . bp_displayed_user_id() ) );
    }
    add_action( 'xprofile_updated_profile ', 'my_cache_xprofile_website' );
    
    #244571
    alpha2
    Participant

    Yes it is. But rather than using a plugin (for this project i am nearly at 53 active plugins…too much) maybe its better to use a function.
    i use this thread to ask you another question, some users (registered before i applied this plugin) named their account with a period: john.doe . Actually it’s not a big deal because buddypress (or wordpress natively) transform this dot into hyphen in each link.

    On one specific page template, I have special function i created with the help of a dev to display all users by a custom taxonomy (ranks)

    Only mater is that every hyperlink that link to account like john.doe are display like this http://www.website.com/members/john.doe and not http://www.website.com/members/john-doe

    I search into the code and found this:

    <div><?php $user = get_user_by('id', $gold ); ?><a href="<?php echo site_url();?>/members/<?php echo $user->user_login;?>/buddyblog/"><?php echo bp_core_fetch_avatar( array( 'item_id' => $gold, 'type' => 'full' ) ); ?></a><a href="<?php echo site_url();?>/members/<?php echo $user->user_login;?>/buddyblog/"><?php echo $user->user_login; ?></a>Performances: <?php echo count_user_posts( $gold ); ?></div>

    I must change how is display the username.

    Thank you for your time and your help!

    #244091
    shanebp
    Moderator

    This is not a gravatar:
    http://chocobento.x10.mx/wp/wp-content/uploads/avatars/1/63d3ab039b099fd772971c5498789561-bpfull.jpg

    You can disable gravatars by adding this to your theme/functions.php
    add_filter('bp_core_fetch_avatar_no_grav', '__return_true');

    #243539
    fatihaslann
    Participant

    I place this code in function.PHP

    function my_cache_avatar_url() {
    	update_user_meta( bp_displayed_user_id(), 'modemloopers_awesome_avatar_url', bp_core_fetch_avatar( 'html=false&item_id=' . bp_displayed_user_id() ) );
    }
    add_action( 'xprofile_screen_change_avatar', 'my_cache_avatar_url' );

    But my web site show white screen

    #243527
    fatihaslann
    Participant

    Where should I place on which page this code?

    function my_cache_avatar_url() {
    	update_user_meta( bp_displayed_user_id(), 'modemloopers_awesome_avatar_url', bp_core_fetch_avatar( 'html=false&item_id=' . bp_displayed_user_id() ) );
    }
    add_action( 'xprofile_screen_change_avatar', 'my_cache_avatar_url' );
    #242474
    Henry Wright
    Moderator

    You can disable Gravatar like this:

    function no_grav() {
        return true;
    }
    add_filter( 'bp_core_fetch_avatar_no_grav', 'no_grav' );
    #242191
    Garrett Hyder
    Participant

    Hi @shanebp,

    Sorry for the confusion, I’ve created a bp_group_list_managers that’s a merge of bp_group_list_admins and bp_group_list_mods to provide a single consolidated listing.

    function bp_group_list_managers($group=false) {
        global $groups_template;
        if(empty($group)) {
            $group =& $groups_template->group;
        }
    
        // fetch group admins if 'populate_extras' flag is false
        if (empty($group->args['populate_extras']) || true) {
            $query = new BP_Group_Member_Query(array(
                'group_id'   => $group->id,
                'group_role' => 'admin',
                'type'       => 'alphabetical',
            ));
    
            if (!empty($query->results)) {
                $group->admins = $query->results;
            }
        }
    
        // fetch group mods if 'populate_extras' flag is false
        if (empty($group->args['populate_extras']) || true) {
            $query = new BP_Group_Member_Query(array(
                'group_id'   => $group->id,
                'group_role' => 'mod',
                'type'       => 'alphabetical',
            ));
    
            if (!empty($query->results)) {
                $group->mods = $query->results;
            }
        }
    
        $admins = (array)$group->admins;
        $mods = (array)$group->mods;
    
        usort($admins, 'bp_group_member_sort');
        usort($mods, 'bp_group_member_sort');
    
        $group->managers = array_merge($admins, $mods);
    
        if (!empty($group->managers)) { ?>
            <ul id="group-managers">
                <?php foreach((array)$group->managers as $manager) { ?>
                    <li>
                        <a href="<?php echo bp_core_get_user_domain($manager->user_id, $manager->user_nicename, $manager->user_login); ?>"><?php echo bp_core_fetch_avatar(array('item_id' => $manager->user_id, 'email' => $manager->user_email, 'alt' => sprintf( __( 'Profile picture of %s', 'buddypress' ), bp_core_get_user_displayname($manager->user_id)))) ?></a>
                    </li>
                <?php } ?>
            </ul>
    <?php } else { ?>
        <span class="activity"><?php _e( 'No Managers', 'buddypress' ) ?></span>
    <?php }
    }

    As you can see I set the type here to alphabetical and was first confused why it did nothing then I realized the BP_Group_Member_Query’s were never even called as I guess populate_extras was set so not empty. This meant that the $group->admins and $group->mods came from the global $group_template->group which wasn’t ordered. I’m curious how to make that global $group_template->group admin/mod lists could be alphabetically ordered by default.

    For now I just amended my method to simply force the BP_Group_Member_Query’s to be used instead which has allowed for the alphabetical ordering.

    Hope that clears things up.

    Thanks

    #240990
    shanebp
    Moderator

    That’s a tricky one. And I don’t have a solution.

    It’s probably a timing issue. The hook fires before the dir is updated.
    Or maybe bp_core_fetch_avatar is cached.

    Which version of BP are you using?
    The issue may be related to the new approach to avatar uploads using the BP_Attachments class.

    kokoko
    Participant

    Hi,

    I have one problem with fetching avatars using bp_core_fetch_avatar() function and xprofile_avatar_uploaded action. I keep my avatars as user meta. What I want to do is to update that meta every time new avatar is uploaded from back end. I wrote this functions:

    function update_avatar_admin(){
    	update_user_meta(bp_displayed_user_id(),'profile_photo',bp_core_fetch_avatar( array( 'item_id' => bp_displayed_user_id(), 'html' => false ) ));
    }
    add_action('xprofile_avatar_uploaded', 'update_avatar_admin', 99);

    The thing is it always gets previous avatar and not the one uploaded.

    #240216
    shanebp
    Moderator

    The sql call isn’t returning the user ID.

    Change the sql to:
    $usernames = $wpdb->get_results("SELECT ID, user_nicename FROM $wpdb->users ORDER BY ID DESC LIMIT 5");

    Then make this change:
    $recentusers .= '<li>' . bp_core_fetch_avatar( array( 'item_id' => $username->ID, 'type' => 'full') ) . '<a href="' . bp_core_get_user_domain($username->ID) .'">' . $username->user_nicename . '</a></li>';

Viewing 25 results - 51 through 75 (of 304 total)
Skip to toolbar