Skip to:
Content
Pages
Categories
Search
Top
Bottom

Search Results for 'bp_core_fetch_avatar'

Viewing 25 results - 101 through 125 (of 258 total)
  • Author
    Search Results
  • 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.

    #174707
    mattg123
    Participant

    @pjbursnall , I wouldn’t say that it is pretty easy here

    <?php global $current_user;
    		get_currentuserinfo();
    		$display = $current_user->display_name;
    		$login = $current_user->user_login;
    		$userid = $current_user->ID;
                    $home = get_home_url();
    ?>

    add that above your custom drop-down then its pretty simple just echo out the username, url etc <li class="li-fourth"><a href="<?php echo $home . '/members/' . $login . '/activity/mentions'; ?>">Mentions</a></li>

    EDIT –

    Oh the other bit you’d have to google for is the avatar but here
    <?php echo bp_core_fetch_avatar( array('item_id' => $userid, 'type' => 'full', 'width' => 100,'height' => 100));?>
    You’ll want to adjust the width/height accordingly

    #170843
    aleciri83
    Participant

    add_filter('bp_core_fetch_avatar_no_grav', '__return_true');

    #170656
    Hugo Ashmore
    Participant

    to get the authors BP account url you could try:

    bp_core_get_user_domain( get_the_author_meta( ‘ID’ )

    In the same vein you should be able to grab the BP avatar:

    bp_core_fetch_avatar( array(‘item_id’ => get_the_author_meta( ‘ID’ )

    #170090
    Hugo Ashmore
    Participant

    Please do not advise the editing of core files this is poor practise and never recommended.

    You describe the default args there, the correct means of changing those is when using bp_core_fetch_avatar() to pass it an array of values.

    In templates adjust the various avatar calls using similar principle

    mathieu.urstein
    Participant

    @modemlooper

    thank you the problem was the quotes 😉

    modemlooper
    Moderator
    <?php
    $userid = bp_loggedin_user_id();
    $avatarurl = bp_core_fetch_avatar( array( ‘item_id’ => $userid, ‘html’ => false ) );
    echo $avatarurl;
    ?>

    rewrite the quote marks, if you cut and paste it can have funky formatting. If you want to display the avatar instead of getting link:

    <?php
    $userid = bp_loggedin_user_id();
    echo bp_core_fetch_avatar( array( ‘item_id’ => $userid) );
    ?>
    mathieu.urstein
    Participant

    thank you @modemlooper

    I did :

    $userid = bp_loggedin_user_id();
    $avatarurl = bp_core_fetch_avatar( array( ‘item_id’ => $userid, ‘html’ => false ) );

    But the problem is still the same,
    what did I do wrong?

    Thanks.

    modemlooper
    Moderator

    $id = //pass the id of a user
    bp_core_fetch_avatar( array( ‘item_id’ => $id, ‘html’ => false ) );

    If you are not on a user page then you must tell it what id of the avatar to get.

    bp_displayed_user_id
    bp_loggedin_user_id

    #166817
    mattg123
    Participant

    @applegateian, henries code should work, but as you’ve experienced it won’t change the current size of the avatars. I also believe bp has thumbnail avatars and “full” the smaller “thumbnail” the ones wordpress uses is 50px and the larger(which can be grabbed with bp_core_fetch_avatar) are 150px by 150px.

    bp_core_fetch_avatar( array(
        'item_id' => $userid,
        'type'     => 'full',
        'width'    => 150,
        'height'  => 150
    ));

    That will display the “full” avatar.

    #166754
    Henry
    Member

    BuddyPress seems to attempt to filter get_avatar() – see bp_core_fetch_avatar_filter(). I did bring this issue up a while ago at WordPress Trac but the call was closed.

    https://core.trac.wordpress.org/ticket/24596

    Wonder if anyone thinks it’s worthy of a BP Trac ticket?

    #166723
    applegateian
    Participant

    Ah ok thanks, this code doesn’t seem to return anything, can you help me with the error?

     <a href="/community/members/<?php echo get_the_author_meta('user_login') ?>"> <?php echo bp_core_fetch_avatar ( get_the_author_meta('user_email'), $size = '192' ); ?>
    </a>
    #166683
    mattg123
    Participant

    You’re using wordpress’s get_avatar, bp_core_fetch_avatar is what you’re looking for

    #165607
    funmi omoba
    Participant

    @megainfo, @shanebp, please what am I missing.

    I put the below code in my functions.php

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

    and this in my header.php

    <?php
    global $bp;
    if( !bp_get_user_has_avatar()) :
    ?>
            <div class="no-pic">
                <strong>Alert !</strong> You have no profile Pic, Clik here to add one now.
                <button class="close" data-dismiss="alert">×</button>
                </div>
    <?php
    endif;

    It work but the alert is not closing when i try to close it

Viewing 25 results - 101 through 125 (of 258 total)
Skip to toolbar