Skip to:
Content
Pages
Categories
Search
Top
Bottom

Get E-mail addresses of users without Photos?

  • Avatar of adamt19
    adamt19
    Participant

    @adamt19

    We’d like to encourage users who have not uploaded a custom profile photo.. to do so.

    I see threads related to bp_has_members calls, for displaying only users with photos in a member loop, but this isn’t really what we’re after, and I didn’t want to distract with my question on those threads.

    I’m looking for a SQL-only solution that returns e-mail addresses of users WITHOUT a custom photo, separated by commas for a mailing list. I can imagine this would also be very useful for other site administrators trying to increase engagement.

    Obviously if a user is using the default gravatar, their e-mail should not be included.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Avatar of shanebp
    shanebp
    Moderator

    @shanebp

    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;
    		
    }
    Avatar of adamt19
    adamt19
    Participant

    @adamt19

    @shanebp thanks but unfortunately this doesn’t return anything. We do have hundreds of users with the default gravatar/grey buddy image. These are the people I’m trying to isolate. Returning just the IDs of these people is fine.

    Any other ideas of how to modify the snippet to return those users?

    Avatar of adamt19
    adamt19
    Participant

    @adamt19

    Is any config changes needed for this to work (eg disable gravatar service, or something)?

    Avatar of adamt19
    adamt19
    Participant

    @adamt19

    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;
    	
    		
    }
    Avatar of shanebp
    shanebp
    Moderator

    @shanebp

    Nice.

    fwiw… The ‘wp’ approach would be to get rid of the global and use:

    $ids = get_users( array( 'fields' => array( 'ID' ) ) );

    and access via: $id->ID

Viewing 5 replies - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.