Skip to:
Content
Pages
Categories
Search
Top
Bottom

Search Results for 'bp_core_fetch_avatar'

Viewing 25 results - 76 through 100 (of 246 total)
  • Author
    Search Results
  • #236638
    shanebp
    Moderator
    <?php $user_id = get_current_user_id(); ?>
    <a href="<?php echo bp_core_get_user_domain( $user_id ); ?>"><?php echo bp_core_fetch_avatar( array( 'item_id' => $user_id ) ); ?></a>
    #235984
    shanebp
    Moderator

    Your request is more properly asked of the plugin creator.
    You could try this:
    Open birds-author-box\public\frontend.php and replace this:

               if (get_the_author_meta('image', get_query_var('author')))
                {
                    $content.= '<img class="birds_box_avatar" src="' . get_the_author_meta('image', get_query_var('author')) . '">';
                }
                else
                {
                    $blank = plugin_dir_url(__FILE__) . 'img/blank.png';
                    $content.= '<img class="birds_box_avatar" src="' . $blank . '">';
                }

    with this:

    $avatar_args = array( 
       'item_id' =>  get_the_author_meta('ID', get_query_var('author')),
       'type' => 'thumb',
       'html' => false
    );
    
    $content.= '<img class="birds_box_avatar" src="' . bp_core_fetch_avatar( $avatar_args ) . '">';
    #235469
    tipsy
    Participant

    thank you @danbp I will start right away!

    Here is were I am now (not working):

    
    <?php
    if ($entry[1] == xprofile_get_field_data(2, $user_id));  {
         echo bp_core_fetch_avatar($user_id);
    }  
    ?>
    
    #235466
    danbp
    Participant
    #203190
    danbp
    Participant

    @reinforcez,

    the link given by @drakedoc was started over 4 years. Many solutions are given in this thread, and the last one was published a year ago.

    That solution works for 1.9 and above !

    /* Skip the Gravatar check when using a default BP avatar */ 	
    add_filter( 'bp_core_fetch_avatar_no_grav', '__return_true' );

    By the way you have also to modify the global WP setting of avatars to “mystery man” or “nothing”.

    Another solution to avoid gravatars slowing down a big site (at least > 500 members), is to use a specific cache plugin like Nix Gravatar Cache. Complete list here.

    #197233
    Henry Wright
    Moderator

    Hi @tightflks

    You can use get_avatar() instead of the BuddyPress function bp_core_fetch_avatar(). See: https://codex.wordpress.org/Function_Reference/get_avatar

    #187695
    Henry Wright
    Moderator

    There might actually be more things you’d need to do. For example, the bp_get_message_thread_avatar() function uses bp_core_fetch_avatar() so you would need to filter that using bp_get_message_thread_avatar etc.

    Unless someone else knows of an easier way, it seems as though it’ll be a big task of going through everything. You’d also need to be comfortable with PHP.

    Alternatively, you could try disabling avatars by adding this to your bp-custom.php file

    define( 'BP_SHOW_AVATARS', false );

    Note: I’ve not tested that, I’m just going on what I see at the beginning of the bp_core_fetch_avatar() function. i.e:

    // If avatars are disabled for the root site, obey that request and bail
    if ( ! buddypress()->avatar->show_avatars )
       return;
    #187692
    Martin Waller
    Participant

    Okay, so searching that GitHub repo there is only one file under the bp-themes/bp-legacy/buddypress folders which mentions bp_core_fetch_avatar() (but lots within the core BuddyPress code. So I just need to replace the reference in that one file and add it to by child theme under a BuddyPress folder and it should work?

    #187685
    Martin Waller
    Participant

    Thanks @henrywright

    I’m not entirely sure that my front-end template actually references bp_core_fetch_avatar() as it is not a BuddyPress theme but rather a regular WordPress theme (Responsive Pro).

    Martin

    #187684
    Henry Wright
    Moderator

    Actually scratch that last post – it’s now displaying the avatars as the WordPress avatars in the back-end but not the front end

    In that case, I think we’ve just crossed that bridge hehe. i.e the next step will be to replace all instances of bp_core_fetch_avatar() in your front-end templates with get_avatar()

    #187679
    Henry Wright
    Moderator

    Humm.. not helpful then. In that case we might have to try doing it manually. Perhaps try disabling the filter which replaces the WP avatars with BP avatars. For example, add this to your theme’s functions.php file:

    remove_filter( 'get_avatar', 'bp_core_fetch_avatar_filter', 10, 5 );

    I think you can disable the Gravatar fallback as well with this:

    add_filter( 'bp_core_fetch_avatar_no_grav', '__return_true' );

    If that doesn’t work, you may need to replace all occurrences of bp_core_fetch_avatar() with get_avatar() in your templates. But cross that bridge when you come to it.

    Ref: https://codex.wordpress.org/Function_Reference/get_avatar

    #187149
    adamt19
    Participant

    This worked for me

    
    function no_photos() { 
    	global $wpdb;
    
    	$nophotoids = array();
    	
    	$ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->prefix}users" );
    
    	foreach( $ids as $id ) { 
    
    		$avatar_check = false;
       
    		if ( preg_match('/mystery-man.jpg/', bp_core_fetch_avatar( array( 'item_id' => $id, 'no_grav' => true, 'html'=> false ) ) ) )			
    		  $avatar_check = true; 
    
    		if( ! $avatar_check ) { 
    			$nophotoids[] = $id;
    		}
    	}
    		
    	$nophotoids = implode(",", $nophotoids);
    		
    	echo 'no photo ids: ' . $nophotoids;
    	
    		
    }
    #184752
    shanebp
    Moderator

    untested:

    
    function no_photos() { 
    	global $wpdb;
    
    	$emails = array();
    	
    	$ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->prefix}users" );
    
    	foreach( $ids as $id ) { 
    
    		$avatar_check = false;
       
    		if ( bp_core_fetch_avatar( array( 'item_id' => $id, 'no_grav' => true, 'html'=> false ) ) != bp_core_avatar_default() )
    			$avatar_check = true; 
    
    		if( ! $avatar_check ) { 
    			$email = $wpdb->get_var( "SELECT user_email FROM {$wpdb->prefix}users WHERE ID = $id" );
    			$emails[] = $email;
    		}
    	}
    		
    	$emails = implode(",", $emails);
    		
    	return $emails;
    		
    }
    rodhewitt
    Participant

    Hello im looking for same solution , im looking for days, all solutions uses too many CPU resources because avatars are not stored in database

    I found this code add to functions.php but its not working for me

    ________________________________________________________________________________________________

    //Hide members without avatars
    add_action( ‘bp_core_delete_existing_avatar’, ‘log_avatar_deleted’ );
    add_action( ‘xprofile_avatar_uploaded’, ‘log_avatar_uploaded’ );

    //on new avatar upload, record it to user meta
    function log_avatar_uploaded(){
    update_user_meta(bp_loggedin_user_id(), ‘has_avatar’, 1);
    }

    //on delete avatar, delete it from user meta
    function log_avatar_deleted($args){
    if($args[‘object’]!=’user’)
    return;
    //we are sure it was user avatar delete
    //remove the log from user meta
    delete_user_meta(bp_loggedin_user_id(), ‘has_avatar’);
    }

    function modify_loop_and_pag($qs, $object=false) {
    global $wpdb;
    $include = ”;

    if( $object != ‘members’ )//hide for members only
    return $qs;

    $subscribers = $wpdb->get_results(“SELECT user_id FROM {$wpdb->usermeta } WHERE meta_key=’has_avatar'” , ARRAY_N );
    foreach($subscribers as $subscriber){
    $include = $include . “,” . $subscriber[0];
    }

    $args = wp_parse_args( $qs );

    //check if we are listing friends?, do not apply in this case

    if( !empty( $args[‘include’] ) ) {
    $args[‘include’] = $args[‘include’] . ‘,’ . $include;
    }
    else {
    $args[‘include’] = $include;
    }

    $qs = build_query($args);

    return $qs;

    }
    add_action( ‘bp_ajax_querystring’ , ‘modify_loop_and_pag’, 25, 2 );

    function current_user_has_avatar($id) {
    global $bp;
    if ( bp_core_fetch_avatar( array( ‘item_id’ => $id, ‘no_grav’ => true,’html’=> false ) ) != bp_core_avatar_default( ‘local’ ) ) {
    return true;
    }
    return false;
    }

    // ATTENTION
    // This code should be deleted after first site load with the code
    //
    function init_avatar_meta(){
    global $wpdb;
    $ids=$wpdb->get_col(“SELECT ID FROM $wpdb->users”);//we don’t need to check for meta value anyway
    foreach( $ids as $id ){
    if( current_user_has_avatar($id) ){
    update_user_meta( $id, ‘has_avatar’, 1 );
    } else {
    delete_user_meta( $id, ‘has_avatar’ );
    }
    }
    }
    add_action(‘init’, ‘init_avatar_meta’);

    #183465
    shanebp
    Moderator

    $defaults aren’t being passed by the filter.

    Try:

    add_filter('bp_member_avatar', 'mm_hide_name_in_alt_text', 1);
    function mm_hide_name_in_alt_text( $var ) {
      var_dump( $var ); 
      return $var;
    }

    Then you should be able to tell what is being passed to the filter and adjust it accordingly.
    You could also use the filters in bp_core_fetch_avatar()

    #179965
    wp_kouhai
    Participant

    I have found and corrected the issue.

    function buddypress_redirect_if_no_avatar($redirect_url,$request_url,$user) {
    
      $avatar = bp_core_fetch_avatar( array( 'item_id' => $user->ID, 'no_grav' => true, 'html'=>false) );
    
      $pos = strpos($avatar, 'mystery-man');
      if ($pos === false) { return "/";}
      else {
        $redirect_url = bp_core_get_user_domain($user->ID)."/profile/change-avatar/";
        return $redirect_url;
      }
    
    }
    
    add_filter("login_redirect","buddypress_redirect_if_no_avatar",100,3);
    #179514

    In reply to: 3rd Sized Avatar

    Henry Wright
    Moderator

    So, with the code I suggested in place. You can output the 3 sized avatars on your site like this:

    Thumb size:

    $type = 'thumb';
    $width = 200;
    $height = 200;
    $user_fullname = bp_get_loggedin_user_fullname();
    $user_id = bp_loggedin_user_id();
    
    echo bp_core_fetch_avatar( array( 'alt' => $user_fullname, 'class' => 'avatar', 'width' => $width, 'height' => $height, 'item_id' => $user_id, 'type' => $type, 'title' => $user_fullname ) );

    Full size:

    $type = 'full';
    $width = 500;
    $height = 500;
    $user_fullname = bp_get_loggedin_user_fullname();
    $user_id = bp_loggedin_user_id();
    
    echo bp_core_fetch_avatar( array( 'alt' => $user_fullname, 'class' => 'avatar', 'width' => $width, 'height' => $height, 'item_id' => $user_id, 'type' => $type, 'title' => $user_fullname ) );

    Tiny thumb size:

    $width = 20;
    $height = 20;
    $user_fullname = bp_get_loggedin_user_fullname();
    $user_id = bp_loggedin_user_id();
    
    echo bp_core_fetch_avatar( array( 'alt' => $user_fullname, 'class' => 'avatar', 'width' => $width, 'height' => $height, 'item_id' => $user_id, 'title' => $user_fullname ) );

    Note: It isn’t recommended to change core files in this way because you’ll lose the changes you made on each upgrade. But it’s what you asked for so… 🙂

    #179509

    In reply to: 3rd Sized Avatar

    darqpony
    Participant

    Yes! that! Since I know so little about php coding, I didn’t know WHAT to do instead of the choice it gave me or where to look.

    1. I understand about the upgrade will overwrite thing. If I put this bit of code in my bpcustom.php file, will it override the original “$avatar_size = ( ‘full’ == $type ) ? ‘-bpfull’ : ‘-bpthumb;” or do I have to somehow negate that first in the bpcustom file?

    2. I have this in the bp_core_fetch_avatar:

    function bp_core_fetch_avatar( $args = '' ) {
    
    	// If avatars are disabled for the root site, obey that request and bail
    	if ( ! buddypress()->avatar->show_avatars )
    		return;
    
    	global $current_blog;
    
    	$bp = buddypress();
    
    	// Set a few default variables
    	$def_object = 'user';
    	$def_type   = 'thumb';
    	$def_class  = 'avatar';
    
    	// Set the default variables array
    	$params = wp_parse_args( $args, array(
    		'item_id'    => false,
    		'object'     => $def_object, // user/group/blog/custom type (if you use filters)
    		'type'       => $def_type,   // tinythumb, thumb or full
    		'avatar_dir' => false,       // Specify a custom avatar directory for your object
    		'width'      => false,       // Custom width (int)
    		'height'     => false,       // Custom height (int)
    		'class'      => $def_class,  // Custom <img> class (string)
    		'css_id'     => false,       // Custom <img> ID (string)
    		'alt'        => '',    	     // Custom <img> alt (string)
    		'email'      => false,       // Pass the user email (for gravatar) to prevent querying the DB for it
    		'no_grav'    => false,       // If there is no avatar found, return false instead of a grav?
    		'html'       => true,        // Wrap the return img URL in <img />
    		'title'      => ''           // Custom <img> title (string)
    	) );
    	extract( $params, EXTR_SKIP );
    

    Where do I ‘pass’ thumb or full to it? Or is it already there in this original since I haven’t changed anything yet?

    3. If I change the bp_core_fetch_avatar, do I have to somehow change the first 1.’s solution?

    4. Should I post this on the other site you found my question on? LOL (Hey, I gave it two days before trying a different site! But got the same guy answering… go figure… LOL)

    … and yes, it did use the tinythumb type and it did make the thumb sized avatar fuzzy. I have an avatar for that size. I want it to use it! LOL I want to use ALL my avatars!

    #179497

    In reply to: 3rd Sized Avatar

    Henry Wright
    Moderator

    You’d change $avatar_size = ( ‘full’ == $type ) ? ‘-bpfull’ : ‘-bpthumb; to:

    if ($type == 'full' ) {
        $avatar_size = '-bpfull';
    } elseif ($type == 'thumb' ) {
        $avatar_size = '-bpthumb';
    } else {
        $avatar_size = '-bptinythumb';
    }

    But that approach wouldn’t be recommended because when you upgrade buddypress your changes will be lost.

    The tiny thumb will be the default avatar size. If you wanted to use the thumb or full versions then you’d need to pass thumb or full to bp_core_fetch_avatar

    #179475

    In reply to: 3rd Sized Avatar

    darqpony
    Participant

    Yes, I already have the different various sizes of avatar. I have the Tinythumb, Thumb, and Full sizes. And I can change them to whatever width and height I’d like them to be. I could make miiiiyyyons of them if I so chose. Thumb1, Thumb2, Thumb3, etc. . . . Not the issue. I’m stuck in the calling of them to my themes widget. I can call only two of those sizes. If I change $avatar_size = ( ‘full’ == $type ) ? ‘-bpfull’ : ‘-bpthumb’; to add ‘-bptinythumb’, it defaults back to the default of full and bpfull or bpthumb. I can’t get it to USE bptinythumb in the theme. Or in actuality, to USE more than two, hence I need it to SEE the third size avatar.

    🙂

    And thanks so much for taking a look at this guys.

    PS: And I’m gonna check to see what bp_core_fetch_avatar does… maybe rewriting it will get me what I want. Maybe you guys know already how I should rewrite it? *Hint hint* LOL

    #179470

    In reply to: 3rd Sized Avatar

    Henry Wright
    Moderator

    Hi @darqpony

    1. Thumbs

    define ( 'BP_AVATAR_THUMB_WIDTH', 20 );
    define ( 'BP_AVATAR_THUMB_HEIGHT', 20 );

    2. Full

    define ( 'BP_AVATAR_FULL_WIDTH', 150 );
    define ( 'BP_AVATAR_FULL_HEIGHT', 150 );

    3. Original

    define ( 'BP_AVATAR_ORIGINAL_MAX_WIDTH', 300 );

    4. File size

    define ( 'BP_AVATAR_ORIGINAL_MAX_FILESIZE', $max_in_kb );

    Now, you can use bp_core_fetch_avatar to output either the thumb or the full size avatar. This doesn’t cover the original. You could write your own version of bp_core_fetch_avatar which will output the original as well. That’s if the original is saved. You’ll have to check that it is. I’m sure it will be but have never needed to use it so you might want to make sure.

    #179201
    modemlooper
    Moderator

    add this to your bp-custom.php file

    add_filter('bp_core_fetch_avatar_no_grav', '__return_true');

    #178036
    Henry Wright
    Moderator

    Hi

    Try:

    echo bp_core_fetch_avatar( array( 
        'alt' => 'Profile picture of ' . bp_get_loggedin_user_fullname(),
        'class' => 'avatar', 
        'width' => 50, 
        'height' => 50, 
        'item_id' => bp_loggedin_user_id(), 
        'type' => 'full', 
        'title'=> bp_get_loggedin_user_fullname()
    ) );
    #176486
    Henry
    Member

    Not saying this is the problem because I have very limited PHP knowledge but maybe that’s where echo bp_core_fetch_avatar( array(… is getting it’s Avatar from.

    I can’t seem to duplicate the problem. It actually works for me.

    Can you try using Twenty Thirteen? If that works then that shows something has been introduced (perhaps in your theme or maybe a plugin) which is conflicting with the function.

    #176483
    Shmoo
    Participant

    No not really, the only places where I’ve changed the avatar sizes is inside BP page templates like this,

    
    <?php bp_the_thread_message_sender_avatar( 'type=thumb&width=64&height=64' ); ?>
    ....
    <?php bp_loggedin_user_avatar( 'type=thumb&height=64&width=64' ); ?>
    ....
    <?php bp_member_avatar( 'height=192&width=192' ); ?>
    ....
    <?php bp_displayed_user_avatar('type=full&height=192&width=192'); ?>
    

    I’m using functions.php to add custom codes, but no avatar related code inside that.

    I did a search at bp_core_fetch_avatar and found this at bp-core-tamplet.php

    
    /**
     * Output a post author's avatar.
     *
     * Not currently used in BuddyPress.
     *
     * @todo Deprecate.
     */
    function bp_post_author_avatar() {
    	global $post;
    
    	if ( function_exists( 'bp_core_fetch_avatar' ) )
    		echo apply_filters( 'bp_post_author_avatar', bp_core_fetch_avatar( array( 'item_id' => $post->post_author, 'type' => 'thumb', 'alt' => sprintf( __( 'Avatar of %s', 'buddypress' ), bp_core_get_user_displayname( $post->post_author ) ) ) ) );
    	else if ( function_exists('get_avatar') )
    		get_avatar();
    }
    

    This is the first time I can track bp_core_fetch_avatar as a function combined with an array() and look there is no width and height inside that array only thumb and alt.

    Not saying this is the problem because I have very limited PHP knowledge but maybe that’s where echo bp_core_fetch_avatar( array(… is getting it’s Avatar from.

Viewing 25 results - 76 through 100 (of 246 total)
Skip to toolbar