Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/18/2014 09:44:25 PM (10 years ago)
Author:
boonebgorges
Message:

Refactor bp_group_has_members() stack to use array-style parameters

See #3797, #921

File:
1 edited

Legend:

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

    r7903 r7930  
    363363
    364364/**
    365  * Fetch the members of a group
     365 * Fetch the members of a group.
    366366 *
    367367 * Since BuddyPress 1.8, a procedural wrapper for BP_Group_Member_Query.
     
    371371 * returning true.
    372372 *
     373 * @param array $args {
     374 *     An array of optional arguments.
     375 *     @type int $group_id ID of the group whose members are being queried.
     376 *           Default: current group ID.
     377 *     @type int $page Page of results to be queried. Default: 1.
     378 *     @type int $per_page Number of items to return per page of results.
     379 *           Default: 20.
     380 *     @type int $max Optional. Max number of items to return.
     381 *     @type array $exclude Optional. Array of user IDs to exclude.
     382 *     @type bool|int True (or 1) to exclude admins and mods from results.
     383 *           Default: 1.
     384 *     @type bool|int True (or 1) to exclude banned users from results.
     385 *           Default: 1.
     386 *     @type array $group_role Optional. Array of group roles to include.
     387 * }
    373388 * @param int $group_id
    374389 * @param int $limit Maximum members to return
     
    379394 * @return array Multi-d array of 'members' list and 'count'
    380395 */
    381 function groups_get_group_members( $group_id, $limit = false, $page = false, $exclude_admins_mods = true, $exclude_banned = true, $exclude = false, $group_role = false ) {
     396function groups_get_group_members( $args = array() ) {
     397
     398    // Backward compatibility with old method of passing arguments
     399    if ( ! is_array( $args ) || func_num_args() > 1 ) {
     400        _deprecated_argument( __METHOD__, '2.0.0', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) );
     401
     402        $old_args_keys = array(
     403            0 => 'group_id',
     404            1 => 'per_page',
     405            2 => 'page',
     406            3 => 'exclude_admins_mods',
     407            4 => 'exclude_banned',
     408            5 => 'exclude',
     409            6 => 'group_role',
     410        );
     411
     412        $func_args = func_get_args();
     413        $args      = bp_core_parse_args_array( $old_args_keys, $func_args );
     414    }
     415
     416    $r = wp_parse_args( $args, array(
     417        'group_id'            => bp_get_current_group_id(),
     418        'per_page'            => false,
     419        'page'                => false,
     420        'exclude_admins_mods' => true,
     421        'exclude_banned'      => true,
     422        'exclude'             => false,
     423        'group_role'          => array(),
     424    ) );
    382425
    383426    // For legacy users. Use of BP_Groups_Member::get_all_for_group()
     
    386429    $func_args = func_get_args();
    387430    if ( apply_filters( 'bp_use_legacy_group_member_query', false, __FUNCTION__, $func_args ) ) {
    388         $retval = BP_Groups_Member::get_all_for_group( $group_id, $limit, $page, $exclude_admins_mods, $exclude_banned, $exclude );
     431        $retval = BP_Groups_Member::get_all_for_group( $r['group_id'], $r['per_page'], $r['page'], $r['exclude_admins_mods'], $r['exclude_banned'], $r['exclude'] );
    389432    } else {
    390433
    391434        // exclude_admins_mods and exclude_banned are legacy arguments.
    392435        // Convert to group_role
    393         if ( empty( $group_role ) ) {
    394             $group_role = array( 'member' );
    395 
    396             if ( ! $exclude_admins_mods ) {
    397                 $group_role[] = 'mod';
    398                 $group_role[] = 'admin';
     436        if ( empty( $r['group_role'] ) ) {
     437            $r['group_role'] = array( 'member' );
     438
     439            if ( ! $r['exclude_admins_mods'] ) {
     440                $r['group_role'][] = 'mod';
     441                $r['group_role'][] = 'admin';
    399442            }
    400443
    401             if ( ! $exclude_banned ) {
    402                 $group_role[] = 'banned';
     444            if ( ! $r['exclude_banned'] ) {
     445                $r['group_role'][] = 'banned';
    403446            }
    404447        }
     
    406449        // Perform the group member query (extends BP_User_Query)
    407450        $members = new BP_Group_Member_Query( array(
    408             'group_id'       => $group_id,
    409             'per_page'       => $limit,
    410             'page'           => $page,
    411             'group_role'     => $group_role,
    412             'exclude'        => $exclude,
     451            'group_id'       => $r['group_id'],
     452            'per_page'       => $r['per_page'],
     453            'page'           => $r['page'],
     454            'group_role'     => $r['group_role'],
     455            'exclude'        => $r['exclude'],
    413456            'type'           => 'last_modified',
    414457        ) );
Note: See TracChangeset for help on using the changeset viewer.