Skip to:
Content

BuddyPress.org

Changeset 12663


Ignore:
Timestamp:
06/10/2020 02:09:59 AM (4 years ago)
Author:
boonebgorges
Message:

Add xprofile_query parameter to bp_has_members().

And related functions/classes.

Fixes #8309.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-members/bp-members-functions.php

    r12657 r12663  
    7979 *
    8080 * @since 1.2.0
     81 * @since 7.0.0 Added `xprofile_query` parameter.
    8182 *
    8283 * @param array|string $args {
     
    9798 *     @type int          $page                Page of results. Default: 1.
    9899 *     @type bool         $populate_extras     Fetch optional extras. Default: true.
     100 *     @type array        $xprofile_query      Filter results by xprofile data. Requires the xprofile
     101 *                                             component. See {@see BP_XProfile_Query} for details.
    99102 *     @type string|bool  $count_total         How to do total user count. Default: 'count_query'.
    100103 * }
     
    118121        'page'                => 1,            // The page to return if limiting per page.
    119122        'populate_extras'     => true,         // Fetch the last active, where the user is a friend, total friend count, latest update.
     123        'xprofile_query'      => false,
    120124        'count_total'         => 'count_query' // What kind of total user count to do, if any. 'count_query', 'sql_calc_found_rows', or false.
    121125    ), 'core_get_users' );
  • trunk/src/bp-members/bp-members-template.php

    r12647 r12663  
    283283 *
    284284 * @since 1.2.0
     285 * @since 7.0.0 Added `xprofile_query` parameter.
    285286 *
    286287 * @global object $members_template {@link BP_Members_Template}
     
    326327 *     @type mixed                 $meta_value          When used with meta_key, limits results by the a matching
    327328 *                                                      usermeta value. Default: false.
     329 *     @type array                 $xprofile_query      Filter results by xprofile data. Requires the xprofile
     330 *                                                      component. See {@see BP_XProfile_Query} for details.
    328331 *     @type bool                  $populate_extras     Whether to fetch optional data, such as friend counts.
    329332 *                                                      Default: true.
     
    379382        'meta_value'          => false,    // Only return users where the usermeta value matches. Requires meta_key.
    380383
     384        'xprofile_query'      => false,
    381385        'populate_extras'     => true      // Fetch usermeta? Friend count, last active etc.
    382386    ), 'has_members' );
     
    412416        $r['member_type'],
    413417        $r['member_type__in'],
    414         $r['member_type__not_in']
     418        $r['member_type__not_in'],
     419        $r['xprofile_query']
    415420    );
    416421
  • trunk/src/bp-members/classes/class-bp-core-members-template.php

    r10711 r12663  
    111111     *
    112112     * @since 1.5.0
     113     * @since 7.0.0 Added $xprofile_query parameter.
    113114     *
    114115     * @see BP_User_Query for an in-depth description of parameters.
     
    131132     * @param array|string $member_type__not_in Array or comma-separated string of member types to exclude
    132133     *                                          from results.
    133      */
    134     function __construct( $type, $page_number, $per_page, $max, $user_id, $search_terms, $include, $populate_extras, $exclude, $meta_key, $meta_value, $page_arg = 'upage', $member_type = '', $member_type__in = '', $member_type__not_in = '' ) {
     134 *     @param array        $xprofile_query      Filter results by xprofile data. Requires the xprofile
     135 *                                              component. See {@see BP_XProfile_Query} for details.
     136     */
     137    function __construct( $type, $page_number, $per_page, $max, $user_id, $search_terms, $include, $populate_extras, $exclude, $meta_key, $meta_value, $page_arg = 'upage', $member_type = '', $member_type__in = '', $member_type__not_in = '', $xprofile_query = false ) {
    135138
    136139        $this->pag_arg  = sanitize_key( $page_arg );
     
    139142        $this->type     = $type;
    140143
    141         if ( !empty( $_REQUEST['letter'] ) )
     144        if ( ! empty( $_REQUEST['letter'] ) ) {
    142145            $this->members = BP_Core_User::get_users_by_letter( $_REQUEST['letter'], $this->pag_num, $this->pag_page, $populate_extras, $exclude );
    143         else
    144             $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, 'member_type' => $member_type, 'member_type__in' => $member_type__in, 'member_type__not_in' => $member_type__not_in ) );
     146        } else {
     147            $this->members = bp_core_get_users(
     148                array(
     149                    'type'                => $this->type,
     150                    'per_page'            => $this->pag_num,
     151                    'page'                => $this->pag_page,
     152                    'user_id'             => $user_id,
     153                    'include'             => $include,
     154                    'search_terms'        => $search_terms,
     155                    'populate_extras'     => $populate_extras,
     156                    'exclude'             => $exclude,
     157                    'meta_key'            => $meta_key,
     158                    'meta_value'          => $meta_value,
     159                    'member_type'         => $member_type,
     160                    'member_type__in'     => $member_type__in,
     161                    'member_type__not_in' => $member_type__not_in,
     162                    'xprofile_query'      => $xprofile_query,
     163                )
     164            );
     165        }
    145166
    146167        if ( !$max || $max >= (int) $this->members['total'] )
  • trunk/tests/phpunit/testcases/members/template.php

    r12459 r12663  
    185185        $GLOBALS['members_template'] = $old_members_template;
    186186    }
     187
     188    /**
     189     * @group bp_has_members
     190     * @ticket BP8309
     191     */
     192    public function test_bp_has_members_xprofile_query() {
     193        $group_id = self::factory()->xprofile_group->create();
     194        $field_id = self::factory()->xprofile_field->create( array(
     195            'field_group_id' => $group_id,
     196            'type'           => 'textbox',
     197        ) );
     198        $users = self::factory()->user->create_many( 2 );
     199
     200        xprofile_set_field_data( $field_id, $users[0], 'foo' );
     201        xprofile_set_field_data( $field_id, $users[1], 'bar' );
     202
     203        global $members_template;
     204        $old_members_template = $members_template;
     205
     206        $args = array(
     207            'xprofile_query' => array(
     208                array(
     209                    'field' => $field_id,
     210                    'value' => 'foo',
     211                ),
     212            ),
     213        );
     214
     215        bp_has_members( $args );
     216
     217        $members    = is_array( $members_template->members ) ? array_values( $members_template->members ) : array();
     218        $member_ids = wp_list_pluck( $members, 'ID' );
     219        $this->assertEqualSets( array( $users[0] ), $member_ids );
     220
     221        $GLOBALS['members_template'] = $old_members_template;
     222    }
     223
    187224
    188225    /**
Note: See TracChangeset for help on using the changeset viewer.