Last active
August 29, 2015 14:02
-
-
Save shanebp/848d9c4e763fb0a51f2f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
re: http://buddypress.org/support/topic/show-only-members-with-avatars-on-member-loop/ | |
untested, but cleaned up... | |
/********* SEARCH MEMBERS BASED ON PROFILE FIELDS *********/ | |
function gd_custom_ids( $field_name, $field_value = '' ) { | |
if ( empty( $field_name ) ) | |
return ''; | |
global $wpdb; | |
$field_id = xprofile_get_field_id_from_name( $field_name ); | |
if ( !empty( $field_id ) ) | |
$query = "SELECT user_id FROM " . $wpdb->prefix . "bp_xprofile_data WHERE field_id = " . $field_id; | |
else | |
return ''; | |
$custom_ids = $wpdb->get_col( $query ); | |
$user_ids_loop = array(); | |
foreach ($custom_ids as $custom_id){ | |
if(gd_check_avatar($custom_id)){ | |
$user_ids_loop[] = $custom_id; | |
} | |
} | |
if ( !empty( $user_ids_loop ) ) { | |
// convert the array to a csv string | |
$custom_ids_str = 'include=' . implode(",", $user_ids_loop); | |
return $custom_ids_str; | |
} | |
else | |
return ''; | |
} | |
/********* CHECK IF MEMBER HAVE AVATARS *********/ | |
function gd_check_avatar($user_id){ | |
// Check for avatar. | |
$avatarchk = false; | |
$userfbavatar = get_user_meta($user_id, 'facebook_uid', true); | |
if (!empty( $userfbavatar ) ) | |
{ | |
$avatarchk = true; | |
//echo "DEBUG: user has a FB photo<br/>"; | |
} | |
elseif (bp_core_fetch_avatar( array( 'item_id' => $user_id, 'no_grav' => true,'html'=> false ) ) != bp_core_avatar_default() ) | |
{ | |
$avatarchk = true; | |
//echo "DEBUG: user has a photo<br/>"; | |
} | |
return $avatarchk; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment