Skip to:
Content

BuddyPress.org

Ticket #3205: 3205-2.patch

File 3205-2.patch, 6.6 KB (added by boonebgorges, 13 years ago)
  • bp-core/bp-core-classes.php

    class BP_Core_User { 
    109109
    110110        /** Static Functions ******************************************************/
    111111
    112         function get_users( $type, $limit = 0, $page = 1, $user_id = 0, $include = false, $search_terms = false, $populate_extras = true, $exclude = false ) {
     112        function get_users( $type, $limit = 0, $page = 1, $user_id = 0, $include = false, $search_terms = false, $populate_extras = true, $exclude = false, $meta_key = false, $meta_value = false ) {
    113113                global $wpdb, $bp;
    114114
    115115                $sql = array();
    class BP_Core_User { 
    124124
    125125                if ( 'alphabetical' == $type )
    126126                        $sql['select_alpha'] = ", pd.value as fullname";
     127               
     128                if ( $meta_key ) {
     129                        $sql['select_meta'] = ", umm.meta_key";
     130                       
     131                        if ( $meta_value )
     132                                $sql['select_meta'] .= ", umm.meta_value";
     133                }
    127134
    128135                $sql['from'] = "FROM " . CUSTOM_USER_TABLE . " u LEFT JOIN " . CUSTOM_USER_META_TABLE . " um ON um.user_id = u.ID";
    129136
    130137                if ( $search_terms && bp_is_active( 'xprofile' ) || 'alphabetical' == $type )
    131138                        $sql['join_profiledata'] = "LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id";
     139                       
     140                if ( $meta_key )
     141                        $sql['join_meta']       = "LEFT JOIN {$wpdb->usermeta} umm ON umm.user_id = u.ID";
    132142
    133143                $sql['where'] = 'WHERE ' . bp_core_get_status_sql( 'u.' );
    134144
    class BP_Core_User { 
    174184                        $search_terms             = like_escape( $wpdb->escape( $search_terms ) );
    175185                        $sql['where_searchterms'] = "AND pd.value LIKE '%%$search_terms%%'";
    176186                }
     187               
     188                if ( $meta_key ) {
     189                        $sql['where_meta']      = $wpdb->prepare( " AND umm.meta_key = %s", $meta_key );
     190                       
     191                        // If a meta value is provided, match it
     192                        if ( $meta_value ) {
     193                                $sql['where_meta'] .= $wpdb->prepare( " AND umm.meta_value = %s", $meta_value );
     194                        }
     195                }
    177196
    178197                switch ( $type ) {
    179198                        case 'active': case 'online': default:
  • bp-members/bp-members-functions.php

    function bp_core_get_users( $args = '' ) { 
    6060                'user_id'         => false,    // Pass a user_id to limit to only friend connections for this user
    6161                'exclude'         => false,    // Users to exclude from results
    6262                'search_terms'    => false,    // Limit to users that match these search terms
     63                'meta_key'        => false,    // Limit to users who have this piece of usermeta
     64                'meta_value'      => false,    // With meta_key, limit to users where usermeta matches this value
    6365
    6466                'include'         => false,    // Pass comma separated list of user_ids to limit to only these users
    6567                'per_page'        => 20,       // The number of results to return per page
    function bp_core_get_users( $args = '' ) { 
    7072        $params = wp_parse_args( $args, $defaults );
    7173        extract( $params, EXTR_SKIP );
    7274
    73         return apply_filters( 'bp_core_get_users', BP_Core_User::get_users( $type, $per_page, $page, $user_id, $include, $search_terms, $populate_extras, $exclude ), $params );
     75        return apply_filters( 'bp_core_get_users', BP_Core_User::get_users( $type, $per_page, $page, $user_id, $include, $search_terms, $populate_extras, $exclude, $meta_key, $meta_value ), $params );
    7476}
    7577
    7678/**
  • bp-members/bp-members-template.php

    class BP_Core_Members_Template { 
    139139        var $pag_links;
    140140        var $total_member_count;
    141141
    142         function bp_core_members_template( $type, $page_number, $per_page, $max, $user_id, $search_terms, $include, $populate_extras, $exclude ) {
    143                 $this->__construct( $type, $page_number, $per_page, $max, $user_id, $search_terms, $include, $populate_extras, $exclude );
     142        function bp_core_members_template( $type, $page_number, $per_page, $max, $user_id, $search_terms, $include, $populate_extras, $exclude, $meta_key, $meta_value ) {
     143                $this->__construct( $type, $page_number, $per_page, $max, $user_id, $search_terms, $include, $populate_extras, $exclude, $meta_key, $meta_value );
    144144        }
    145145
    146         function __construct( $type, $page_number, $per_page, $max, $user_id, $search_terms, $include, $populate_extras, $exclude ) {
     146        function __construct( $type, $page_number, $per_page, $max, $user_id, $search_terms, $include, $populate_extras, $exclude, $meta_key, $meta_value ) {
    147147                global $bp;
    148148               
    149149                $this->pag_page  = !empty( $_REQUEST['upage'] ) ? intval( $_REQUEST['upage'] ) : (int)$page_number;
    class BP_Core_Members_Template { 
    155155                else if ( false !== $include )
    156156                        $this->members = BP_Core_User::get_specific_users( $include, $this->pag_num, $this->pag_page, $populate_extras );
    157157                else
    158                         $this->members = bp_core_get_users( array( 'type' => $this->type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'include' => $include, 'search_terms' => $search_terms, 'populate_extras' => $populate_extras, 'exclude' => $exclude ) );
     158                        $this->members = bp_core_get_users( array( 'type' => $this->type, 'per_page' => $this->pag_num, 'page' => $this->pag_page, 'user_id' => $user_id, 'include' => $include, 'search_terms' => $search_terms, 'populate_extras' => $populate_extras, 'exclude' => $exclude, 'meta_key' => $meta_key, 'meta_value' => $meta_value ) );
    159159
    160160                if ( !$max || $max >= (int)$this->members['total'] )
    161161                        $this->total_member_count = (int)$this->members['total'];
    function bp_has_members( $args = '' ) { 
    267267
    268268                'user_id'         => $user_id,      // Pass a user_id to only show friends of this user
    269269                'search_terms'    => $search_terms, // Pass search_terms to filter users by their profile data
     270               
     271                'meta_key'        => false,         // Only return users with this usermeta
     272                'meta_value'      => false,         // Only return users where the usermeta value matches. Requires meta_key
    270273
    271274                'populate_extras' => true           // Fetch usermeta? Friend count, last active etc.
    272275        );
    function bp_has_members( $args = '' ) { 
    290293        if ( empty( $include ) && bp_is_friends_component() && bp_is_current_action( 'requests' ) )
    291294                return false;
    292295
    293         $members_template = new BP_Core_Members_Template( $type, $page, $per_page, $max, $user_id, $search_terms, $include, (bool)$populate_extras, $exclude );
     296        $members_template = new BP_Core_Members_Template( $type, $page, $per_page, $max, $user_id, $search_terms, $include, (bool)$populate_extras, $exclude, $meta_key, $meta_value );
    294297        return apply_filters( 'bp_has_members', $members_template->has_members(), $members_template );
    295298}
    296299