Search Results for 'bp_core_fetch_avatar'
-
AuthorSearch Results
-
May 30, 2014 at 5:50 pm #183495rodhewittParticipant
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’);May 30, 2014 at 12:37 am #183465In reply to: How to properly filter bp_member_avatar
shanebpModerator$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()March 18, 2014 at 2:35 pm #179965In reply to: Detecting if User Uploaded an Avatar
wp_kouhaiParticipantI 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);
March 9, 2014 at 7:25 pm #179514In reply to: 3rd Sized Avatar
Henry WrightModeratorSo, 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… 🙂
March 9, 2014 at 3:04 pm #179509In reply to: 3rd Sized Avatar
darqponyParticipantYes! 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!
March 9, 2014 at 6:49 am #179497In reply to: 3rd Sized Avatar
Henry WrightModeratorYou’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
orfull
to bp_core_fetch_avatarMarch 8, 2014 at 6:35 pm #179475In reply to: 3rd Sized Avatar
darqponyParticipantYes, 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
March 8, 2014 at 12:39 pm #179470In reply to: 3rd Sized Avatar
Henry WrightModeratorHi @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 ofbp_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.March 3, 2014 at 2:04 am #179201In reply to: remove all gravatar calls
modemlooperModeratoradd this to your bp-custom.php file
add_filter('bp_core_fetch_avatar_no_grav', '__return_true');
February 6, 2014 at 6:45 pm #178036In reply to: How to access Buddypress avatar not on profile page
Henry WrightModeratorHi
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() ) );
January 6, 2014 at 3:33 pm #176486In reply to: avatar width doesn't apply
HenryMemberNot 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.
January 6, 2014 at 1:31 pm #176483In reply to: avatar width doesn't apply
ShmooParticipantNo 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.
November 24, 2013 at 12:42 am #174707In reply to: Buddypress on Mobile / Hide admin access
mattg123Participant@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 accordinglySeptember 4, 2013 at 3:28 pm #170843In reply to: How to disable Gravatar completely?
aleciri83Participantadd_filter('bp_core_fetch_avatar_no_grav', '__return_true');
August 30, 2013 at 9:17 am #170656In reply to: Post author Profile link
Hugo AshmoreParticipantto 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’ )
August 20, 2013 at 7:35 am #170090In reply to: Always use full size Avatar
Hugo AshmoreParticipantPlease 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
July 9, 2013 at 10:31 am #167801mathieu.ursteinParticipantthank you the problem was the quotes 😉
July 9, 2013 at 2:32 am #167789modemlooperModerator<?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) ); ?>
July 9, 2013 at 1:26 am #167787mathieu.ursteinParticipantthank 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.
July 8, 2013 at 11:28 pm #167778modemlooperModerator$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_idJune 25, 2013 at 5:23 am #166817In reply to: Getting the large avatar
mattg123Participant@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.
June 24, 2013 at 4:36 pm #166754In reply to: Getting the large avatar
HenryMemberBuddyPress 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?
June 24, 2013 at 10:36 am #166723In reply to: Getting the large avatar
applegateianParticipantAh 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>
June 23, 2013 at 11:38 pm #166683In reply to: Getting the large avatar
mattg123ParticipantYou’re using wordpress’s
get_avatar
,bp_core_fetch_avatar
is what you’re looking forJune 8, 2013 at 7:54 pm #165607In reply to: How to check if member has avatar ?
funmi omobaParticipant@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
-
AuthorSearch Results