Skip to:
Content

BuddyPress.org

Changeset 11792


Ignore:
Timestamp:
01/04/2018 04:05:39 PM (3 years ago)
Author:
djpaul
Message:

Groups: add support to query for members from multiple groups.

Fixes #7573

Props r-a-y, dcavins

Location:
trunk/src/bp-groups
Files:
2 edited

Legend:

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

    r11764 r11792  
    642642 *
    643643 * @since 1.0.0
     644 * @since 3.0.0 $group_id now supports multiple values. Only works if legacy query is not
     645 *              in use.
    644646 *
    645647 * @param array $args {
    646648 *     An array of optional arguments.
    647  *     @type int      $group_id     ID of the group whose members are being queried.
    648  *                                  Default: current group ID.
    649  *     @type int      $page         Page of results to be queried. Default: 1.
    650  *     @type int      $per_page     Number of items to return per page of results.
    651  *                                  Default: 20.
    652  *     @type int      $max          Optional. Max number of items to return.
    653  *     @type array    $exclude      Optional. Array of user IDs to exclude.
    654  *     @type bool|int $value        True (or 1) to exclude admins and mods from results.
    655  *                                  Default: 1.
    656  *     @type bool|int $value        True (or 1) to exclude banned users from results.
    657  *                                  Default: 1.
    658  *     @type array    $group_role   Optional. Array of group roles to include.
    659  *     @type string   $search_terms Optional. Filter results by a search string.
    660  *     @type string   $type         Optional. Sort the order of results. 'last_joined',
    661  *                                  'first_joined', or any of the $type params available
    662  *                                  in {@link BP_User_Query}. Default: 'last_joined'.
     649 *     @type int|array|string $group_id            ID of the group to limit results to. Also accepts multiple values
     650 *                                                 either as an array or as a comma-delimited string.
     651 *     @type int              $page                Page of results to be queried. Default: 1.
     652 *     @type int              $per_page            Number of items to return per page of results. Default: 20.
     653 *     @type int              $max                 Optional. Max number of items to return.
     654 *     @type array            $exclude             Optional. Array of user IDs to exclude.
     655 *     @type bool|int         $exclude_admins_mods True (or 1) to exclude admins and mods from results. Default: 1.
     656 *     @type bool|int         $exclude_banned      True (or 1) to exclude banned users from results. Default: 1.
     657 *     @type array            $group_role          Optional. Array of group roles to include.
     658 *     @type string           $search_terms        Optional. Filter results by a search string.
     659 *     @type string           $type                Optional. Sort the order of results. 'last_joined', 'first_joined', or
     660 *                                                 any of the $type params available in {@link BP_User_Query}. Default:
     661 *                                                 'last_joined'.
    663662 * }
    664663 * @return false|array Multi-d array of 'members' list and 'count'.
  • trunk/src/bp-groups/classes/class-bp-group-member-query.php

    r11256 r11792  
    2525 *
    2626 * @since 1.8.0
     27 * @since 3.0.0 $group_id now supports multiple values.
    2728 *
    2829 * @param array $args  {
     
    3031 *     {@link BP_User_Query}, with the following additions:
    3132 *
    32  *     @type int    $group_id     ID of the group to limit results to.
    33  *     @type array  $group_role   Array of group roles to match ('member',
    34  *                                'mod', 'admin', 'banned').
    35  *                                Default: array( 'member' ).
    36  *     @type bool   $is_confirmed Whether to limit to confirmed members.
    37  *                                Default: true.
    38  *     @type string $type         Sort order. Accepts any value supported by
    39  *                                {@link BP_User_Query}, in addition to 'last_joined'
    40  *                                and 'first_joined'. Default: 'last_joined'.
     33 *     @type int|array|string $group_id     ID of the group to limit results to. Also accepts multiple values
     34 *                                          either as an array or as a comma-delimited string.
     35 *     @type array            $group_role   Array of group roles to match ('member', 'mod', 'admin', 'banned').
     36 *                                          Default: array( 'member' ).
     37 *     @type bool             $is_confirmed Whether to limit to confirmed members. Default: true.
     38 *     @type string           $type         Sort order. Accepts any value supported by {@link BP_User_Query}, in
     39 *                                          addition to 'last_joined' and 'first_joined'. Default: 'last_joined'.
    4140 * }
    4241 */
     
    138137
    139138        // Group id.
    140         $sql['where'][] = $wpdb->prepare( "group_id = %d", $this->query_vars['group_id'] );
     139        $group_ids = wp_parse_id_list( $this->query_vars['group_id'] );
     140        $group_ids = implode( ',', $group_ids );
     141        $sql['where'][] = "group_id IN ({$group_ids})";
    141142
    142143        // If is_confirmed.
Note: See TracChangeset for help on using the changeset viewer.