Forum Replies Created
-
hello @adamt19 Have you found any solution?
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’);