Skip to:
Content

BuddyPress.org

Changeset 14076


Ignore:
Timestamp:
11/03/2024 10:01:19 PM (5 months ago)
Author:
espellcaste
Message:

WPCS - Part I: miscellaneous fixes for some of the files of the groups component.

See #9173
See #9174

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

Legend:

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

    r14070 r14076  
    2121 * @since 1.5.0
    2222 *
    23  * @return bool True if set, False if empty.
     23 * @return bool
    2424 */
    2525function bp_groups_has_directory() {
    2626    $bp = buddypress();
    2727
    28     return (bool) !empty( $bp->pages->groups->id );
     28    return ! empty( $bp->pages->groups->id );
    2929}
    3030
     
    4545function groups_get_group( $group_id ) {
    4646    /*
    47      * Backward compatibilty.
     47     * Backward compatibility.
    4848     * Old-style arguments take the form of an array or a query string.
    4949     */
     
    9191    }
    9292
    93     $group = groups_get_group( array( 'group_id' => (int) $group_id ) );
     93    $group = groups_get_group( (int) $group_id );
    9494
    9595    if ( empty( $group->id ) ) {
     
    200200    // Pass an existing group ID.
    201201    if ( ! empty( $group_id ) ) {
    202         $group = groups_get_group( $group_id );
    203         $name  = ! empty( $name ) ? $name : $group->name;
    204         $slug  = ! empty( $slug ) ? $slug : $group->slug;
    205         $creator_id  = ! empty( $creator_id ) ? $creator_id : $group->creator_id;
    206         $description = ! empty( $description ) ? $description : $group->description;
    207         $status = ! is_null( $status ) ? $status : $group->status;
    208         $parent_id = ! is_null( $parent_id ) ? $parent_id : $group->parent_id;
     202        $group        = groups_get_group( $group_id );
     203        $name         = ! empty( $name ) ? $name : $group->name;
     204        $slug         = ! empty( $slug ) ? $slug : $group->slug;
     205        $creator_id   = ! empty( $creator_id ) ? $creator_id : $group->creator_id;
     206        $description  = ! empty( $description ) ? $description : $group->description;
     207        $status       = ! is_null( $status ) ? $status : $group->status;
     208        $parent_id    = ! is_null( $parent_id ) ? $parent_id : $group->parent_id;
    209209        $enable_forum = ! is_null( $enable_forum ) ? $enable_forum : $group->enable_forum;
    210210        $date_created = ! is_null( $date_created ) ? $date_created : $group->date_created;
     
    215215        }
    216216
    217     // Create a new group.
     217        // Create a new group.
    218218    } else {
    219219        // Instantiate new group object.
    220         $group = new BP_Groups_Group;
     220        $group = new BP_Groups_Group();
    221221
    222222        // Check for null values, reset to sensible defaults.
    223         $status = ! is_null( $status ) ? $status : 'public';
    224         $parent_id = ! is_null( $parent_id ) ? $parent_id : 0;
     223        $status       = ! is_null( $status ) ? $status : 'public';
     224        $parent_id    = ! is_null( $parent_id ) ? $parent_id : 0;
    225225        $enable_forum = ! is_null( $enable_forum ) ? $enable_forum : 0;
    226226        $date_created = ! is_null( $date_created ) ? $date_created : bp_core_current_time();
     
    259259    // If this is a new group, set up the creator as the first member and admin.
    260260    if ( empty( $group_id ) ) {
    261         $member                = new BP_Groups_Member;
     261        $member                = new BP_Groups_Member();
    262262        $member->group_id      = $group->id;
    263263        $member->user_id       = $group->creator_id;
     
    536536    $slug = sanitize_title( $slug );
    537537
    538     if ( 'wp' == substr( $slug, 0, 2 ) )
     538    if ( 'wp' == substr( $slug, 0, 2 ) ) {
    539539        $slug = substr( $slug, 2, strlen( $slug ) - 2 );
    540 
    541     if ( in_array( $slug, (array) $bp->groups->forbidden_names ) )
     540    }
     541
     542    if ( in_array( $slug, (array) $bp->groups->forbidden_names ) ) {
    542543        $slug = $slug . '-' . rand();
     544    }
    543545
    544546    if ( BP_Groups_Group::check_slug( $slug ) ) {
    545547        do {
    546548            $slug = $slug . '-' . rand();
    547         }
    548         while ( BP_Groups_Group::check_slug( $slug ) );
     549        } while ( BP_Groups_Group::check_slug( $slug ) );
    549550    }
    550551
     
    682683    // Check if the user has an outstanding request. If so, delete it.
    683684    if ( groups_check_for_membership_request( $user_id, $group_id ) ) {
    684         groups_delete_membership_request( null, $user_id, $group_id );
     685        groups_delete_membership_request( 0, $user_id, $group_id );
    685686    }
    686687
     
    737738 * @param int|string|BP_Groups_Group $group The Group ID, the Group Slug or the Group object.
    738739 *                                          Default: the current group's ID.
    739  * @return bool False on failure.
    740740 */
    741741function groups_update_last_activity( $group = 0 ) {
     
    744744
    745745    if ( empty( $group->id ) ) {
    746         return false;
     746        return;
    747747    }
    748748
     
    868868
    869869        // Perform the group member query (extends BP_User_Query).
    870         $members = new BP_Group_Member_Query( array(
    871             'group_id'       => $r['group_id'],
    872             'per_page'       => $r['per_page'],
    873             'page'           => $r['page'],
    874             'group_role'     => $r['group_role'],
    875             'exclude'        => $r['exclude'],
    876             'search_terms'   => $r['search_terms'],
    877             'type'           => $r['type'],
    878         ) );
     870        $members = new BP_Group_Member_Query(
     871            array(
     872                'group_id'     => $r['group_id'],
     873                'per_page'     => $r['per_page'],
     874                'page'         => $r['page'],
     875                'group_role'   => $r['group_role'],
     876                'exclude'      => $r['exclude'],
     877                'search_terms' => $r['search_terms'],
     878                'type'         => $r['type'],
     879            )
     880        );
    879881
    880882        // Structure the return value as expected by the template functions.
     
    959961    );
    960962
    961     $groups = BP_Groups_Group::get( array(
    962         'type'               => $r['type'],
    963         'user_id'            => $r['user_id'],
    964         'include'            => $r['include'],
    965         'exclude'            => $r['exclude'],
    966         'slug'               => $r['slug'],
    967         'parent_id'          => $r['parent_id'],
    968         'search_terms'       => $r['search_terms'],
    969         'search_columns'     => $r['search_columns'],
    970         'group_type'         => $r['group_type'],
    971         'group_type__in'     => $r['group_type__in'],
    972         'group_type__not_in' => $r['group_type__not_in'],
    973         'meta_query'         => $r['meta_query'],
    974         'date_query'         => $r['date_query'],
    975         'show_hidden'        => $r['show_hidden'],
    976         'status'             => $r['status'],
    977         'per_page'           => $r['per_page'],
    978         'page'               => $r['page'],
    979         'update_meta_cache'  => $r['update_meta_cache'],
    980         'update_admin_cache' => $r['update_admin_cache'],
    981         'order'              => $r['order'],
    982         'orderby'            => $r['orderby'],
    983         'fields'             => $r['fields'],
    984     ) );
     963    $groups = BP_Groups_Group::get(
     964        array(
     965            'type'               => $r['type'],
     966            'user_id'            => $r['user_id'],
     967            'include'            => $r['include'],
     968            'exclude'            => $r['exclude'],
     969            'slug'               => $r['slug'],
     970            'parent_id'          => $r['parent_id'],
     971            'search_terms'       => $r['search_terms'],
     972            'search_columns'     => $r['search_columns'],
     973            'group_type'         => $r['group_type'],
     974            'group_type__in'     => $r['group_type__in'],
     975            'group_type__not_in' => $r['group_type__not_in'],
     976            'meta_query'         => $r['meta_query'],
     977            'date_query'         => $r['date_query'],
     978            'show_hidden'        => $r['show_hidden'],
     979            'status'             => $r['status'],
     980            'per_page'           => $r['per_page'],
     981            'page'               => $r['page'],
     982            'update_meta_cache'  => $r['update_meta_cache'],
     983            'update_admin_cache' => $r['update_admin_cache'],
     984            'order'              => $r['order'],
     985            'orderby'            => $r['orderby'],
     986            'fields'             => $r['fields'],
     987        )
     988    );
    985989
    986990    /**
     
    10561060 * @since 2.6.0
    10571061 *
    1058  * @param int $user_id ID of the user.
    1059  * @param array $args {
     1062 * @param int       $user_id ID of the user.
     1063 * @param array     $args {
    10601064 *     Array of optional args.
    1061  *     @param bool|null   $is_confirmed Whether to return only confirmed memberships. Pass `null` to disable this
    1062  *                                      filter. Default: true.
    1063  *     @param bool|null   $is_banned    Whether to return only banned memberships. Pass `null` to disable this filter.
    1064  *                                      Default: false.
    1065  *     @param bool|null   $is_admin     Whether to return only admin memberships. Pass `null` to disable this filter.
    1066  *                                      Default: false.
    1067  *     @param bool|null   $is_mod       Whether to return only mod memberships. Pass `null` to disable this filter.
    1068  *                                      Default: false.
    1069  *     @param bool|null   $invite_sent  Whether to return only memberships with 'invite_sent'. Pass `null` to disable
    1070  *                                      this filter. Default: false.
    1071  *     @param string      $orderby      Field to order by. Accepts 'id' (membership ID), 'group_id', 'date_modified'.
    1072  *                                      Default: 'group_id'.
    1073  *     @param string      $order        Sort order. Accepts 'ASC' or 'DESC'. Default: 'ASC'.
     1065 *     @param bool|null $is_confirmed Whether to return only confirmed memberships. Pass `null` to disable this
     1066 *                                    filter. Default: true.
     1067 *     @param bool|null $is_banned    Whether to return only banned memberships. Pass `null` to disable this filter.
     1068 *                                    Default: false.
     1069 *     @param bool|null $is_admin     Whether to return only admin memberships. Pass `null` to disable this filter.
     1070 *                                    Default: false.
     1071 *     @param bool|null $is_mod       Whether to return only mod memberships. Pass `null` to disable this filter.
     1072 *                                    Default: false.
     1073 *     @param bool|null $invite_sent  Whether to return only memberships with 'invite_sent'. Pass `null` to disable
     1074 *                                    this filter. Default: false.
     1075 *     @param string    $orderby      Field to order by. Accepts 'id' (membership ID), 'group_id', 'date_modified'.
     1076 *                                    Default: 'group_id'.
     1077 *     @param string    $order        Sort order. Accepts 'ASC' or 'DESC'. Default: 'ASC'.
    10741078 * }
    10751079 * @return array Array of matching group memberships, keyed by group ID.
     
    11121116    $invitation_ids = array();
    11131117    if ( true !== $r['is_confirmed'] || false !== $r['invite_sent'] ) {
    1114         $invitation_ids = groups_get_invites( array(
    1115             'user_id'     => $user_id,
    1116             'invite_sent' => 'all',
    1117             'type'        => 'all',
    1118             'fields'      => 'ids'
    1119         ) );
     1118        $invitation_ids = groups_get_invites(
     1119            array(
     1120                'user_id'     => $user_id,
     1121                'invite_sent' => 'all',
     1122                'type'        => 'all',
     1123                'fields'      => 'ids',
     1124            )
     1125        );
    11201126
    11211127        // Prime the invitations cache.
    11221128        $uncached_invitation_ids = bp_get_non_cached_ids( $invitation_ids, 'bp_groups_invitations_as_memberships' );
    11231129        if ( $uncached_invitation_ids ) {
    1124             $uncached_invitations = groups_get_invites( array(
    1125                 'id'          => $uncached_invitation_ids,
    1126                 'invite_sent' => 'all',
    1127                 'type'        => 'all'
    1128             ) );
     1130            $uncached_invitations = groups_get_invites(
     1131                array(
     1132                    'id'          => $uncached_invitation_ids,
     1133                    'invite_sent' => 'all',
     1134                    'type'        => 'all',
     1135                )
     1136            );
    11291137            foreach ( $uncached_invitations as $uncached_invitation ) {
    11301138                // Reshape the result as a membership db entry.
    1131                 $invitation = new StdClass;
     1139                $invitation                = new StdClass();
    11321140                $invitation->id            = $uncached_invitation->id;
    11331141                $invitation->group_id      = $uncached_invitation->item_id;
     
    12441252function groups_total_groups_for_user( $user_id = 0 ) {
    12451253
    1246     if ( empty( $user_id ) )
     1254    if ( empty( $user_id ) ) {
    12471255        $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id();
     1256    }
    12481257
    12491258    $count = wp_cache_get( 'bp_total_groups_for_user_' . $user_id, 'bp' );
     
    13301339     * @param array $value Array of parts related to the groups avatar upload directory.
    13311340     */
    1332     return apply_filters( 'groups_avatar_upload_dir', array(
    1333         'path'    => $path,
    1334         'url'     => $newurl,
    1335         'subdir'  => $newsubdir,
    1336         'basedir' => $newbdir,
    1337         'baseurl' => $newburl,
    1338         'error'   => false
    1339     ) );
     1341    return apply_filters(
     1342        'groups_avatar_upload_dir',
     1343        array(
     1344            'path'    => $path,
     1345            'url'     => $newurl,
     1346            'subdir'  => $newsubdir,
     1347            'basedir' => $newbdir,
     1348            'baseurl' => $newburl,
     1349            'error'   => false,
     1350        )
     1351    );
    13401352}
    13411353
     
    13511363function bp_groups_get_group_roles() {
    13521364    return array(
    1353         'admin' => (object) array(
     1365        'admin'  => (object) array(
    13541366            'id'           => 'admin',
    13551367            'name'         => __( 'Administrator', 'buddypress' ),
     
    13601372            'is_mod'       => false,
    13611373        ),
    1362         'mod' => (object) array(
     1374        'mod'    => (object) array(
    13631375            'id'           => 'mod',
    13641376            'name'         => __( 'Moderator', 'buddypress' ),
     
    14011413    $is_admin = false;
    14021414
    1403     $user_groups = bp_get_user_groups( $user_id, array(
    1404         'is_admin' => true,
    1405     ) );
     1415    $user_groups = bp_get_user_groups(
     1416        $user_id,
     1417        array(
     1418            'is_admin' => true,
     1419        )
     1420    );
    14061421
    14071422    if ( isset( $user_groups[ $group_id ] ) ) {
     
    14241439    $is_mod = false;
    14251440
    1426     $user_groups = bp_get_user_groups( $user_id, array(
    1427         'is_mod' => true,
    1428     ) );
     1441    $user_groups = bp_get_user_groups(
     1442        $user_id,
     1443        array(
     1444            'is_mod' => true,
     1445        )
     1446    );
    14291447
    14301448    if ( isset( $user_groups[ $group_id ] ) ) {
     
    14471465    $is_member = false;
    14481466
    1449     $user_groups = bp_get_user_groups( $user_id, array(
    1450         'is_admin' => null,
    1451         'is_mod' => null,
    1452     ) );
     1467    $user_groups = bp_get_user_groups(
     1468        $user_id,
     1469        array(
     1470            'is_admin' => null,
     1471            'is_mod'   => null,
     1472        )
     1473    );
    14531474
    14541475    if ( isset( $user_groups[ $group_id ] ) ) {
     
    14711492    $is_banned = false;
    14721493
    1473     $user_groups = bp_get_user_groups( $user_id, array(
    1474         'is_confirmed' => null,
    1475         'is_banned' => true,
    1476     ) );
     1494    $user_groups = bp_get_user_groups(
     1495        $user_id,
     1496        array(
     1497            'is_confirmed' => null,
     1498            'is_banned'    => true,
     1499        )
     1500    );
    14771501
    14781502    if ( isset( $user_groups[ $group_id ] ) ) {
     
    15141538    }
    15151539
    1516     $args = array(
    1517         'user_id'     => $user_id,
    1518         'item_id'     => $group_id,
     1540    $args          = array(
     1541        'user_id' => $user_id,
     1542        'item_id' => $group_id,
    15191543    );
    15201544    $invites_class = new BP_Groups_Invitation_Manager();
     
    16071631 * @return array Array of group IDs.
    16081632 */
    1609  function groups_get_invited_to_group_ids( $user_id = 0 ) {
     1633function groups_get_invited_to_group_ids( $user_id = 0 ) {
    16101634    if ( empty( $user_id ) ) {
    16111635        $user_id = bp_loggedin_user_id();
    16121636    }
    16131637
    1614     $group_ids = groups_get_invites( array(
    1615         'user_id'     => $user_id,
    1616         'invite_sent' => 'sent',
    1617         'fields'      => 'item_ids'
    1618     ) );
     1638    $group_ids = groups_get_invites(
     1639        array(
     1640            'user_id'     => $user_id,
     1641            'invite_sent' => 'sent',
     1642            'fields'      => 'item_ids',
     1643        )
     1644    );
    16191645
    16201646    return array_unique( $group_ids );
     
    16971723
    16981724    $invites_class = new BP_Groups_Invitation_Manager();
    1699     $success       = $invites_class->delete( array(
    1700         'user_id'    => $user_id,
    1701         'item_id'    => $group_id,
    1702         'inviter_id' => $inviter_id,
    1703     ) );
     1725    $success       = $invites_class->delete(
     1726        array(
     1727            'user_id'    => $user_id,
     1728            'item_id'    => $group_id,
     1729            'inviter_id' => $inviter_id,
     1730        )
     1731    );
    17041732
    17051733    if ( $success ) {
     
    17331761function groups_accept_invite( $user_id, $group_id ) {
    17341762    $invites_class = new BP_Groups_Invitation_Manager();
    1735     $args = array(
     1763    $args          = array(
    17361764        'user_id'     => $user_id,
    17371765        'item_id'     => $group_id,
     
    17601788
    17611789    $invites_class = new BP_Groups_Invitation_Manager();
    1762     $success       = $invites_class->delete( array(
    1763         'user_id'    => $user_id,
    1764         'item_id'    => $group_id,
    1765         'inviter_id' => $inviter_id,
    1766     ) );
     1790    $success       = $invites_class->delete(
     1791        array(
     1792            'user_id'    => $user_id,
     1793            'item_id'    => $group_id,
     1794            'inviter_id' => $inviter_id,
     1795        )
     1796    );
    17671797
    17681798    /**
     
    17991829
    18001830    $invites_class = new BP_Groups_Invitation_Manager();
    1801     $success       = $invites_class->delete( array(
    1802         'user_id'    => $user_id,
    1803         'item_id'    => $group_id,
    1804         'inviter_id' => $inviter_id,
    1805     ) );
     1831    $success       = $invites_class->delete(
     1832        array(
     1833            'user_id'    => $user_id,
     1834            'item_id'    => $group_id,
     1835            'inviter_id' => $inviter_id,
     1836        )
     1837    );
    18061838
    18071839    /**
     
    19732005 * @return int|bool ID of the first found membership if found, otherwise false.
    19742006 */
    1975  function groups_check_has_invite_from_user( $user_id, $group_id, $inviter_id = false, $type = 'sent' ) {
     2007function groups_check_has_invite_from_user( $user_id, $group_id, $inviter_id = false, $type = 'sent' ) {
    19762008    if ( empty( $user_id ) || empty( $group_id ) ) {
    19772009        return false;
     
    23372369
    23382370    $invites_class = new BP_Groups_Invitation_Manager();
    2339     $request_id = $invites_class->add_request( $inv_args );
     2371    $request_id    = $invites_class->add_request( $inv_args );
    23402372
    23412373    // If a new request was created, send the emails.
     
    23892421
    23902422    $invites_class = new BP_Groups_Invitation_Manager();
    2391     $args = array(
     2423    $args          = array(
    23922424        'user_id' => $user_id,
    23932425        'item_id' => $group_id,
     
    24132445function groups_reject_membership_request( $membership_id, $user_id = 0, $group_id = 0 ) {
    24142446
    2415     if ( ! empty( $membership_id ) ){
     2447    if ( ! empty( $membership_id ) ) {
    24162448        /* translators: 1: the name of the method. 2: the name of the file. */
    24172449        _deprecated_argument( __METHOD__, '5.0.0', sprintf( esc_html__( 'Argument `membership_id` passed to %1$s is deprecated. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) );
     
    24482480 *                           requested. Provide this value along with $user_id to
    24492481 *                           override $membership_id.
    2450  * @return false|BP_Groups_Member True on success, false on failure.
     2482 * @return int|false Number of records deleted. False if the user is not a member of the group.
    24512483 */
    24522484function groups_delete_membership_request( $membership_id, $user_id = 0, $group_id = 0 ) {
    2453     if ( ! empty( $membership_id ) ){
     2485    if ( ! empty( $membership_id ) ) {
    24542486        /* translators: 1: the name of the method. 2: the name of the file. */
    24552487        _deprecated_argument( __METHOD__, '5.0.0', sprintf( esc_html__( 'Argument `membership_id` passed to %1$s is deprecated. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) );
     
    24612493
    24622494    $invites_class = new BP_Groups_Invitation_Manager();
    2463     $success       = $invites_class->delete_requests( array(
    2464         'user_id' => $user_id,
    2465         'item_id' => $group_id
    2466     ) );
    2467 
    2468     return $success;
     2495
     2496    return $invites_class->delete_requests(
     2497        array(
     2498            'user_id' => $user_id,
     2499            'item_id' => $group_id,
     2500        )
     2501    );
    24692502}
    24702503
     
    24992532    }
    25002533
    2501     $args = array(
     2534    $args          = array(
    25022535        'user_id' => $user_id,
    25032536        'item_id' => $group_id,
     
    25082541}
    25092542
    2510  /**
    2511   * Get an array of group IDs to which a user has requested membership.
    2512   *
    2513   * @since 5.0.0
    2514   *
    2515   * @param int $user_id The user ID.
    2516   *
    2517   * @return array Array of group IDs.
    2518   */
    2519  function groups_get_membership_requested_group_ids( $user_id = 0 ) {
     2543/**
     2544 * Get an array of group IDs to which a user has requested membership.
     2545 *
     2546 * @since 5.0.0
     2547 *
     2548 * @param int $user_id The user ID.
     2549 *
     2550 * @return array Array of group IDs.
     2551 */
     2552function groups_get_membership_requested_group_ids( $user_id = 0 ) {
    25202553    if ( ! $user_id ) {
    25212554        $user_id = bp_loggedin_user_id();
    25222555    }
    25232556
    2524     $group_ids     = groups_get_requests( array(
    2525         'user_id' => $user_id,
    2526         'fields'  => 'item_ids'
    2527     ) );
     2557    $group_ids = groups_get_requests(
     2558        array(
     2559            'user_id' => $user_id,
     2560            'fields'  => 'item_ids',
     2561        )
     2562    );
    25282563
    25292564    return $group_ids;
    25302565}
    25312566
    2532  /**
    2533   * Get an array of group IDs to which a user has requested membership.
    2534   *
    2535   * @since 5.0.0
    2536   *
    2537   * @param int $user_id The user ID.
    2538   *
    2539   * @return array Array of group IDs.
    2540   */
    2541  function groups_get_membership_requested_user_ids( $group_id = 0 ) {
     2567/**
     2568 * Get an array of group IDs to which a user has requested membership.
     2569 *
     2570 * @since 5.0.0
     2571 *
     2572 * @param int $group_id The group ID.
     2573 *
     2574 * @return array Array of group IDs.
     2575 */
     2576function groups_get_membership_requested_user_ids( $group_id = 0 ) {
    25422577    if ( ! $group_id ) {
    25432578        $group_id = bp_get_current_group_id();
    25442579    }
    25452580
    2546     $requests = groups_get_requests( array(
    2547         'item_id' => $group_id,
    2548         'fields'  => 'user_ids'
    2549     ) );
     2581    $requests = groups_get_requests(
     2582        array(
     2583            'item_id' => $group_id,
     2584            'fields'  => 'user_ids',
     2585        )
     2586    );
    25502587
    25512588    return $requests;
     
    27202757    do_action( 'groups_remove_data_for_user', $user_id );
    27212758}
    2722 add_action( 'wpmu_delete_user',  'groups_remove_data_for_user' );
     2759add_action( 'wpmu_delete_user', 'groups_remove_data_for_user' );
    27232760add_action( 'bp_make_spam_user', 'groups_remove_data_for_user' );
    27242761
     
    27492786    // Get child groups and set the parent to the deleted parent's parent.
    27502787    $grandparent_group_id = $group->parent_id;
    2751     $child_args = array(
     2788    $child_args           = array(
    27522789        'parent_id'         => $group->id,
    27532790        'show_hidden'       => true,
     
    27552792        'update_meta_cache' => false,
    27562793    );
    2757     $children = groups_get_groups( $child_args );
    2758     $children = $children['groups'];
     2794    $children             = groups_get_groups( $child_args );
     2795    $children             = $children['groups'];
    27592796
    27602797    foreach ( $children as $cgroup ) {
     
    27832820     * @return string The unique Group taxonomy slug.
    27842821     */
    2785     function bp_get_group_type_tax_name() {
    2786         /**
    2787         * Filters the slug of the Group type taxonomy.
    2788         *
    2789         * @since 7.0.0
    2790         *
    2791         * @param string $value Group type taxonomy slug.
    2792         */
    2793         return apply_filters( 'bp_get_group_type_tax_name', 'bp_group_type' );
    2794     }
     2822function bp_get_group_type_tax_name() {
     2823    /**
     2824    * Filters the slug of the Group type taxonomy.
     2825    *
     2826    * @since 7.0.0
     2827    *
     2828    * @param string $value Group type taxonomy slug.
     2829    */
     2830    return apply_filters( 'bp_get_group_type_tax_name', 'bp_group_type' );
     2831}
    27952832
    27962833/**
     
    30493086    // Make sure the relevant labels have been filled in.
    30503087    $default_name = isset( $r['labels']['name'] ) ? $r['labels']['name'] : ucfirst( $r['name'] );
    3051     $r['labels'] = array_merge( array(
    3052         'name'          => $default_name,
    3053         'singular_name' => $default_name,
    3054     ), $r['labels'] );
     3088    $r['labels']  = array_merge(
     3089        array(
     3090            'name'          => $default_name,
     3091            'singular_name' => $default_name,
     3092        ),
     3093        $r['labels']
     3094    );
    30553095
    30563096    // Directory slug.
     
    30603100            $directory_slug = $r['has_directory'];
    30613101
    3062         // Otherwise fall back on group type.
     3102            // Otherwise fall back on group type.
    30633103        } else {
    30643104            $directory_slug = $group_type;
     
    33483388 * @since 2.6.0
    33493389 *
    3350  * @param int            $group_id   ID of the user.
    3351  * @param string         $group_type Group type.
     3390 * @param int    $group_id   ID of the user.
     3391 * @param string $group_type Group type.
    33523392 * @return bool|WP_Error $deleted    True on success. False or WP_Error on failure.
    33533393 */
     
    34363476 * @since 2.6.0
    34373477 *
    3438  * @param  int   $group_id ID of the group.
    3439  * @return array|null $value    See {@see bp_groups_set_group_type()}.
     3478 * @param int $group_id ID of the group.
    34403479 */
    34413480function bp_remove_group_type_on_group_delete( $group_id = 0 ) {
     
    34693508    }
    34703509
    3471     $memberships = BP_Groups_Member::get_user_memberships( $user->ID, array(
    3472         'type'     => 'membership',
    3473         'page'     => $page,
    3474         'per_page' => $number,
    3475     ) );
     3510    $memberships = BP_Groups_Member::get_user_memberships(
     3511        $user->ID,
     3512        array(
     3513            'type'     => 'membership',
     3514            'page'     => $page,
     3515            'per_page' => $number,
     3516        )
     3517    );
    34763518
    34773519    foreach ( $memberships as $membership ) {
     
    35583600    }
    35593601
    3560     $requests = groups_get_requests( array(
    3561         'user_id'  => $user->ID,
    3562         'page'     => $page,
    3563         'per_page' => $number,
    3564     ) );
     3602    $requests = groups_get_requests(
     3603        array(
     3604            'user_id'  => $user->ID,
     3605            'page'     => $page,
     3606            'per_page' => $number,
     3607        )
     3608    );
    35653609
    35663610    foreach ( $requests as $request ) {
     
    36243668    }
    36253669
    3626     $invitations = groups_get_invites( array(
    3627         'inviter_id'  => $user->ID,
    3628         'page'        => $page,
    3629         'per_page'    => $number,
    3630     ) );
     3670    $invitations = groups_get_invites(
     3671        array(
     3672            'inviter_id' => $user->ID,
     3673            'page'       => $page,
     3674            'per_page'   => $number,
     3675        )
     3676    );
    36313677
    36323678    foreach ( $invitations as $invitation ) {
     
    36943740    }
    36953741
    3696     $invitations = groups_get_invites( array(
    3697         'user_id'  => $user->ID,
    3698         'page'     => $page,
    3699         'per_page' => $number,
    3700     ) );
     3742    $invitations = groups_get_invites(
     3743        array(
     3744            'user_id'  => $user->ID,
     3745            'page'     => $page,
     3746            'per_page' => $number,
     3747        )
     3748    );
    37013749
    37023750    foreach ( $invitations as $invitation ) {
     
    37563804
    37573805    $processed = array();
    3758     $values = array();
     3806    $values    = array();
    37593807    foreach ( $records as $record ) {
    3760         $values[] = $wpdb->prepare(
    3761             "(%d, %d, %s, %s, %d, %d, %s, %s, %s, %d, %d)",
     3808        $values[]    = $wpdb->prepare(
     3809            '(%d, %d, %s, %s, %d, %d, %s, %s, %s, %d, %d)',
    37623810            (int) $record->user_id,
    37633811            (int) $record->inviter_id,
     
    37763824
    37773825    $table_name = BP_Invitation_Manager::get_table_name();
    3778     $query = "INSERT INTO {$table_name} (user_id, inviter_id, invitee_email, class, item_id, secondary_item_id, type, content, date_modified, invite_sent, accepted) VALUES ";
    3779     $query .= implode(', ', $values );
    3780     $query .= ';';
     3826    $query      = "INSERT INTO {$table_name} (user_id, inviter_id, invitee_email, class, item_id, secondary_item_id, type, content, date_modified, invite_sent, accepted) VALUES ";
     3827    $query     .= implode( ', ', $values );
     3828    $query     .= ';';
    37813829    $wpdb->query( $query );
    37823830
     
    38283876
    38293877    foreach ( array_keys( $registered_group_extensions ) as $group_extension_class ) {
    3830         $extension = new $group_extension_class;
     3878        $extension = new $group_extension_class();
    38313879
    38323880        add_action( 'bp_actions', array( $extension, '_register' ), 8 );
     
    38613909 *
    38623910 * @param bool $defer True to defer, false otherwise.
    3863  * @param int $group_id The group's ID.
     3911 * @param int  $group_id The group's ID.
    38643912 */
    38653913function bp_groups_defer_group_members_count( $defer = true, $group_id = 0 ) {
     
    38743922    }
    38753923
    3876     if  ( $group_id ) {
     3924    if ( $group_id ) {
    38773925        bp_groups_update_group_members_count( 0, (int) $group_id );
    38783926    }
     
    41604208 * @since 12.0.0
    41614209 *
    4162  * @param array $chunks   An array of BP URL default slugs.
     4210 * @param array  $chunks   An array of BP URL default slugs.
    41634211 * @param string $context Whether to get chunks for the 'read', 'create' or 'manage' contexts.
    41644212 * @return array An associative array containing group's customized path chunks.
     
    41984246            if ( is_numeric( $chunk ) ) {
    41994247                $path_chunks[ $key_action_variables ][] = $chunk;
    4200             } else {
    4201                 if ( isset( $group_screens[ $chunk ]['rewrite_id'] ) ) {
     4248            } elseif ( isset( $group_screens[ $chunk ]['rewrite_id'] ) ) {
    42024249                    $item_action_variable_rewrite_id        = $group_screens[ $chunk ]['rewrite_id'];
    42034250                    $path_chunks[ $key_action_variables ][] = bp_rewrites_get_slug( 'groups', $item_action_variable_rewrite_id, $chunk );
    4204                 } else {
    4205                     $path_chunks[ $key_action_variables ][] = $chunk;
    4206                 }
     4251            } else {
     4252                $path_chunks[ $key_action_variables ][] = $chunk;
    42074253            }
    42084254        }
  • trunk/src/bp-groups/classes/class-bp-group-extension.php

    r13878 r14076  
    1111defined( 'ABSPATH' ) || exit;
    1212
    13 if ( ! class_exists( 'BP_Group_Extension', false ) ) :
     13if ( class_exists( 'BP_Group_Extension', false ) ) {
     14    return;
     15}
     16
    1417/**
    1518 * API for creating group extensions without having to hardcode the content into
     
    767770
    768771        foreach ( $screens as $context => &$screen ) {
    769             $screen['enabled']     = true;
    770             $screen['name']        = $this->name;
    771             $screen['slug']        = $this->slug;
    772 
    773             $screen['screen_callback']      = $this->get_screen_callback( $context, 'screen'      );
     772            $screen['enabled'] = true;
     773            $screen['name']    = $this->name;
     774            $screen['slug']    = $this->slug;
     775
     776            $screen['screen_callback']      = $this->get_screen_callback( $context, 'screen' );
    774777            $screen['screen_save_callback'] = $this->get_screen_callback( $context, 'screen_save' );
    775778        }
     
    887890                    $this->params['show_tab'] = 'anyone';
    888891                }
    889 
    890892            } else {
    891893                /*
     
    927929
    928930        switch ( $access_condition ) {
    929             case 'admin' :
     931            case 'admin':
    930932                $meets_condition = groups_is_user_admin( bp_loggedin_user_id(), $this->group_id );
    931933                break;
    932934
    933             case 'mod' :
     935            case 'mod':
    934936                $meets_condition = groups_is_user_mod( bp_loggedin_user_id(), $this->group_id );
    935937                break;
    936938
    937             case 'member' :
     939            case 'member':
    938940                $meets_condition = groups_is_user_member( bp_loggedin_user_id(), $this->group_id );
    939941                break;
    940942
    941             case 'loggedin' :
     943            case 'loggedin':
    942944                $meets_condition = is_user_logged_in();
    943945                break;
    944946
    945             case 'noone' :
     947            case 'noone':
    946948                $meets_condition = false;
    947949                break;
    948950
    949             case 'anyone' :
    950             default :
     951            case 'anyone':
     952            default:
    951953                $meets_condition = true;
    952954                break;
     
    10351037            // When we are viewing the extension display page, set the title and options title.
    10361038            if ( bp_is_current_action( $this->slug ) ) {
    1037                 add_filter( 'bp_group_user_has_access',   array( $this, 'group_access_protection' ), 10, 2 );
     1039                add_filter( 'bp_group_user_has_access', array( $this, 'group_access_protection' ), 10, 2 );
    10381040
    10391041                $extension_name = $this->name;
    10401042                add_action(
    10411043                    'bp_template_content_header',
    1042                     function() use ( $extension_name ) {
     1044                    function () use ( $extension_name ) {
    10431045                        echo esc_attr( $extension_name );
    10441046                    }
     
    10461048                add_action(
    10471049                    'bp_template_title',
    1048                     function() use ( $extension_name ) {
     1050                    function () use ( $extension_name ) {
    10491051                        echo esc_attr( $extension_name );
    10501052                    }
     
    12921294                $this->edit_screen_template = '/groups/single/home';
    12931295            } else {
    1294                 add_action( 'bp_template_content_header', function () {
    1295                     echo '<ul class="content-header-nav">';
    1296                     bp_group_admin_tabs();
    1297                     echo '</ul>';
    1298                 } );
     1296                add_action(
     1297                    'bp_template_content_header',
     1298                    function () {
     1299                        echo '<ul class="content-header-nav">';
     1300                        bp_group_admin_tabs();
     1301                        echo '</ul>';
     1302                    }
     1303                );
    12991304                add_action( 'bp_template_content', array( &$this, 'call_edit_screen' ) );
    13001305                $this->edit_screen_template = '/groups/single/plugins';
     
    13801385             * @param string $value URL to redirect to.
    13811386             */
    1382             $redirect_to = apply_filters( 'bp_group_extension_edit_screen_save_redirect', bp_get_requested_url( ) );
     1387            $redirect_to = apply_filters( 'bp_group_extension_edit_screen_save_redirect', bp_get_requested_url() );
    13831388
    13841389            bp_core_redirect( $redirect_to );
     
    13901395     * Load the template that houses the Edit screen.
    13911396     *
    1392      * Separated out into a callback so that it can run after all other
     1397     * Separated out into a callback so that it can run after all others
    13931398     * Group Extensions have had a chance to register their navigation, to
    13941399     * avoid missing tabs.
     
    14011406     */
    14021407    public function call_edit_screen_template_loader() {
    1403         bp_core_load_template( $this->edit_screen_template );
     1408        bp_core_load_template( (array) $this->edit_screen_template );
    14041409    }
    14051410
     
    17731778
    17741779        switch ( $key ) {
    1775             case 'enable_create_step' :
     1780            case 'enable_create_step':
    17761781                $this->screens['create']['enabled'] = $value;
    17771782                break;
    17781783
    1779             case 'enable_edit_item' :
     1784            case 'enable_edit_item':
    17801785                $this->screens['edit']['enabled'] = $value;
    17811786                break;
    17821787
    1783             case 'enable_admin_item' :
     1788            case 'enable_admin_item':
    17841789                $this->screens['admin']['enabled'] = $value;
    17851790                break;
    17861791
    1787             case 'create_step_position' :
     1792            case 'create_step_position':
    17881793                $this->screens['create']['position'] = $value;
    17891794                break;
    17901795
    17911796            // Note: 'admin' becomes 'edit' to distinguish from Dashboard 'admin'.
    1792             case 'admin_name' :
     1797            case 'admin_name':
    17931798                $this->screens['edit']['name'] = $value;
    17941799                break;
    17951800
    1796             case 'admin_slug' :
     1801            case 'admin_slug':
    17971802                $this->screens['edit']['slug'] = $value;
    17981803                break;
    17991804
    1800             case 'create_name' :
     1805            case 'create_name':
    18011806                $this->screens['create']['name'] = $value;
    18021807                break;
    18031808
    1804             case 'create_slug' :
     1809            case 'create_slug':
    18051810                $this->screens['create']['slug'] = $value;
    18061811                break;
    18071812
    1808             case 'admin_metabox_context' :
     1813            case 'admin_metabox_context':
    18091814                $this->screens['admin']['metabox_context'] = $value;
    18101815                break;
    18111816
    1812             case 'admin_metabox_priority' :
     1817            case 'admin_metabox_priority':
    18131818                $this->screens['admin']['metabox_priority'] = $value;
    18141819                break;
    18151820
    1816             default :
     1821            default:
    18171822                $this->data[ $key ] = $value;
    18181823                break;
     
    18871892
    18881893            switch ( $property ) {
    1889                 case 'enable_create_step' :
     1894                case 'enable_create_step':
    18901895                    $lpc['screens']['create']['enabled'] = (bool) $value;
    18911896                    break;
    18921897
    1893                 case 'enable_edit_item' :
     1898                case 'enable_edit_item':
    18941899                    $lpc['screens']['edit']['enabled'] = (bool) $value;
    18951900                    break;
    18961901
    1897                 case 'enable_admin_item' :
     1902                case 'enable_admin_item':
    18981903                    $lpc['screens']['admin']['enabled'] = (bool) $value;
    18991904                    break;
    19001905
    1901                 case 'create_step_position' :
     1906                case 'create_step_position':
    19021907                    $lpc['screens']['create']['position'] = $value;
    19031908                    break;
    19041909
    19051910                // Note: 'admin' becomes 'edit' to distinguish from Dashboard 'admin'.
    1906                 case 'admin_name' :
     1911                case 'admin_name':
    19071912                    $lpc['screens']['edit']['name'] = $value;
    19081913                    break;
    19091914
    1910                 case 'admin_slug' :
     1915                case 'admin_slug':
    19111916                    $lpc['screens']['edit']['slug'] = $value;
    19121917                    break;
    19131918
    1914                 case 'create_name' :
     1919                case 'create_name':
    19151920                    $lpc['screens']['create']['name'] = $value;
    19161921                    break;
    19171922
    1918                 case 'create_slug' :
     1923                case 'create_slug':
    19191924                    $lpc['screens']['create']['slug'] = $value;
    19201925                    break;
    19211926
    1922                 case 'admin_metabox_context' :
     1927                case 'admin_metabox_context':
    19231928                    $lpc['screens']['admin']['metabox_context'] = $value;
    19241929                    break;
    19251930
    1926                 case 'admin_metabox_priority' :
     1931                case 'admin_metabox_priority':
    19271932                    $lpc['screens']['admin']['metabox_priority'] = $value;
    19281933                    break;
    19291934
    1930                 default :
     1935                default:
    19311936                    $lpc[ $property ] = $value;
    19321937                    break;
     
    19601965        foreach ( $properties as $property ) {
    19611966            switch ( $property ) {
    1962                 case 'enable_create_step' :
     1967                case 'enable_create_step':
    19631968                    $lp['enable_create_step'] = $params['screens']['create']['enabled'];
    19641969                    break;
    19651970
    1966                 case 'enable_edit_item' :
     1971                case 'enable_edit_item':
    19671972                    $lp['enable_edit_item'] = $params['screens']['edit']['enabled'];
    19681973                    break;
    19691974
    1970                 case 'enable_admin_item' :
     1975                case 'enable_admin_item':
    19711976                    $lp['enable_admin_item'] = $params['screens']['admin']['enabled'];
    19721977                    break;
    19731978
    1974                 case 'create_step_position' :
     1979                case 'create_step_position':
    19751980                    $lp['create_step_position'] = $params['screens']['create']['position'];
    19761981                    break;
    19771982
    19781983                // Note: 'admin' becomes 'edit' to distinguish from Dashboard 'admin'.
    1979                 case 'admin_name' :
     1984                case 'admin_name':
    19801985                    $lp['admin_name'] = $params['screens']['edit']['name'];
    19811986                    break;
    19821987
    1983                 case 'admin_slug' :
     1988                case 'admin_slug':
    19841989                    $lp['admin_slug'] = $params['screens']['edit']['slug'];
    19851990                    break;
    19861991
    1987                 case 'create_name' :
     1992                case 'create_name':
    19881993                    $lp['create_name'] = $params['screens']['create']['name'];
    19891994                    break;
    19901995
    1991                 case 'create_slug' :
     1996                case 'create_slug':
    19921997                    $lp['create_slug'] = $params['screens']['create']['slug'];
    19931998                    break;
    19941999
    1995                 case 'admin_metabox_context' :
     2000                case 'admin_metabox_context':
    19962001                    $lp['admin_metabox_context'] = $params['screens']['admin']['metabox_context'];
    19972002                    break;
    19982003
    1999                 case 'admin_metabox_priority' :
     2004                case 'admin_metabox_priority':
    20002005                    $lp['admin_metabox_priority'] = $params['screens']['admin']['metabox_priority'];
    20012006                    break;
    20022007
    2003                 default :
     2008                default:
    20042009                    // All other items get moved over.
    20052010                    $lp[ $property ] = $params[ $property ];
     
    20072012                    // Also reapply to the object, for backpat.
    20082013                    $this->{$property} = $params[ $property ];
    2009 
    20102014                    break;
    20112015            }
     
    20132017    }
    20142018}
    2015 endif; // End class_exists check.
  • trunk/src/bp-groups/classes/class-bp-group-member-query.php

    r13372 r14076  
    4646     *
    4747     * @since 1.8.1
    48      * @var null|array Null if not yet defined, otherwise an array of ints.
     48     * @var null|array Null if not yet defined, otherwise an array of integers.
    4949     */
    5050    protected $group_member_ids;
     
    101101    public function do_wp_user_query() {
    102102        if ( ! $this->query_vars_raw['count'] ) {
    103             return parent::do_wp_user_query();
     103            parent::do_wp_user_query();
    104104        }
    105105
     
    109109         * @since 10.3.0
    110110         *
    111          * @param array         $value      Array of arguments for the user query.
     111         * @param array         $arguments  Array of arguments for the user query.
    112112         * @param BP_User_Query $user_query Current BP_User_Query instance.
    113113         */
     
    122122                    // Overrides
    123123                    'blog_id'     => 0,    // BP does not require blog roles.
    124                     'count_total' => false // We already have a count.
     124                    'count_total' => false, // We already have a count.
    125125
    126126                ),
     
    145145     * @since 1.8.0
    146146     *
    147      * @param array $include Existing group IDs in the $include parameter,
    148      *                       as calculated in BP_User_Query.
     147     * @param array $include_ids Existing group IDs in the `$include_ids` parameter,
     148     *                           as calculated in BP_User_Query.
    149149     * @return array
    150150     */
    151     public function get_include_ids( $include = array() ) {
     151    public function get_include_ids( $include_ids = array() ) {
    152152        // The following args are specific to group member queries, and
    153153        // are not present in the query_vars of a normal BP_User_Query.
     
    176176        }
    177177
    178         if ( ! empty( $include ) ) {
    179             $group_member_ids = array_intersect( $include, $group_member_ids );
     178        if ( ! empty( $include_ids ) ) {
     179            $group_member_ids = array_intersect( $include_ids, $group_member_ids );
    180180        }
    181181
     
    187187     *
    188188     * @since 1.8.0
     189     *
     190     * @global wpdb $wpdb WordPress database abstraction object.
    189191     *
    190192     * @return array $ids User IDs of relevant group member ids.
     
    208210
    209211        // Group id.
    210         $group_ids = wp_parse_id_list( $this->query_vars['group_id'] );
    211         $group_ids = implode( ',', $group_ids );
     212        $group_ids      = wp_parse_id_list( $this->query_vars['group_id'] );
     213        $group_ids      = implode( ',', $group_ids );
    212214        $sql['where'][] = "group_id IN ({$group_ids})";
    213215
    214216        // If is_confirmed.
    215         $is_confirmed = ! empty( $this->query_vars['is_confirmed'] ) ? 1 : 0;
    216         $sql['where'][] = $wpdb->prepare( "is_confirmed = %d", $is_confirmed );
     217        $is_confirmed   = ! empty( $this->query_vars['is_confirmed'] ) ? 1 : 0;
     218        $sql['where'][] = $wpdb->prepare( 'is_confirmed = %d', $is_confirmed );
    217219
    218220        // If invite_sent.
    219221        if ( ! is_null( $this->query_vars['invite_sent'] ) ) {
    220             $invite_sent = ! empty( $this->query_vars['invite_sent'] ) ? 1 : 0;
    221             $sql['where'][] = $wpdb->prepare( "invite_sent = %d", $invite_sent );
     222            $invite_sent    = ! empty( $this->query_vars['invite_sent'] ) ? 1 : 0;
     223            $sql['where'][] = $wpdb->prepare( 'invite_sent = %d', $invite_sent );
    222224        }
    223225
     
    228230            // Empty: inviter_id = 0. (pass false, 0, or empty array).
    229231            if ( empty( $inviter_id ) ) {
    230                 $sql['where'][] = "inviter_id = 0";
    231 
    232             // The string 'any' matches any non-zero value (inviter_id != 0).
     232                $sql['where'][] = 'inviter_id = 0';
     233
     234                // The string 'any' matches any non-zero value (inviter_id != 0).
    233235            } elseif ( 'any' === $inviter_id ) {
    234                 $sql['where'][] = "inviter_id != 0";
    235 
    236             // Assume that a list of inviter IDs has been passed.
     236                $sql['where'][] = 'inviter_id != 0';
     237
     238                // Assume that a list of inviter IDs has been passed.
    237239            } else {
    238240                // Parse and sanitize.
     
    240242                if ( ! empty( $inviter_ids ) ) {
    241243                    $inviter_ids_sql = implode( ',', $inviter_ids );
    242                     $sql['where'][] = "inviter_id IN ({$inviter_ids_sql})";
     244                    $sql['where'][]  = "inviter_id IN ({$inviter_ids_sql})";
    243245                }
    244246            }
     
    248250        // is_admin = 1, mods have is_mod = 1, banned have is_banned =
    249251        // 1, and members have all three set to 0.
    250         $roles = !empty( $this->query_vars['group_role'] ) ? $this->query_vars['group_role'] : array();
     252        $roles = ! empty( $this->query_vars['group_role'] ) ? $this->query_vars['group_role'] : array();
    251253        if ( is_string( $roles ) ) {
    252254            $roles = explode( ',', $roles );
     
    277279            }
    278280
    279         // When querying for a set of roles *not* containing 'member',
    280         // simply construct a list of is_* = 1 clauses.
     281            // When querying for a set of roles *not* containing 'member',
     282            // simply construct a list of is_* = 1 clauses.
    281283        } else {
    282284            $role_columns = array();
     
    300302        // 'first_joined', the order will be overridden in
    301303        // BP_Group_Member_Query::set_orderby().
    302         $sql['orderby'] = "ORDER BY date_modified";
     304        $sql['orderby'] = 'ORDER BY date_modified';
    303305        $sql['order']   = 'first_joined' === $this->query_vars['type'] ? 'ASC' : 'DESC';
    304306
     
    327329                    $invite_args['type'] = 'request';
    328330
    329                 /*
    330                 * The string 'any' matches any non-zero value (inviter_id != 0).
    331                 * These are invitations, not requests.
    332                 */
     331                    /*
     332                    * The string 'any' matches any non-zero value (inviter_id != 0).
     333                    * These are invitations, not requests.
     334                    */
    333335                } elseif ( 'any' === $inviter_id ) {
    334336                    $invite_args['type'] = 'invite';
    335337
    336                 // Assume that a list of inviter IDs has been passed.
     338                    // Assume that a list of inviter IDs has been passed.
    337339                } else {
    338340                    $invite_args['type'] = 'invite';
     
    407409
    408410            // The first param in the FIELD() clause is the sort column id.
    409             $gm_ids = array_merge( array( 'u.id' ), wp_parse_id_list( $gm_ids ) );
     411            $gm_ids     = array_merge( array( 'u.id' ), wp_parse_id_list( $gm_ids ) );
    410412            $gm_ids_sql = implode( ',', $gm_ids );
    411413
    412             $query->uid_clauses['orderby'] = "ORDER BY FIELD(" . $gm_ids_sql . ")";
     414            $query->uid_clauses['orderby'] = 'ORDER BY FIELD(' . $gm_ids_sql . ')';
    413415        }
    414416
     
    422424     *
    423425     * Additional data fetched:
    424      *      - is_banned
    425      *      - date_modified
     426     *  - is_banned
     427     *  - date_modified
    426428     *
    427429     * @since 1.8.0
     430     *
     431     * @global wpdb $wpdb WordPress database abstraction object.
    428432     *
    429433     * @param BP_User_Query $query        BP_User_Query object. Because we're
    430434     *                                    filtering the current object, we use
    431      *                                    $this inside of the method instead.
     435     *                                    $this inside the method instead.
    432436     * @param string        $user_ids_sql Sanitized, comma-separated string of
    433437     *                                    the user ids returned by the main query.
     
    457461
    458462        // Add accurate invitation info from the invitations table.
    459         $invites = groups_get_invites( array(
    460             'user_id' => $user_ids_sql,
    461             'item_id' => $this->query_vars['group_id'],
    462             'type'    => 'all',
    463         ) );
     463        $invites = groups_get_invites(
     464            array(
     465                'user_id' => $user_ids_sql,
     466                'item_id' => $this->query_vars['group_id'],
     467                'type'    => 'all',
     468            )
     469        );
    464470        foreach ( $invites as $invite ) {
    465471            if ( isset( $this->results[ $invite->user_id ] ) ) {
     
    504510     * @since 2.1.0
    505511     *
     512     * @global wpdb $wpdb WordPress database abstraction object.
     513     *
    506514     * @param BP_User_Query $query  BP_User_Query object.
    507515     * @param array         $gm_ids array of group member ids.
     
    532540            'user_id IN (' . implode( ',', wp_parse_id_list( $gm_ids ) ) . ')',
    533541            'item_id = ' . absint( $query->query_vars['group_id'] ),
    534             $wpdb->prepare( "component = %s", buddypress()->groups->id ),
     542            $wpdb->prepare( 'component = %s', buddypress()->groups->id ),
    535543        );
    536544
     
    552560    public function populate_extras() {
    553561        if ( ! $this->query_vars_raw['count'] ) {
    554             return parent::populate_extras();
     562            parent::populate_extras();
    555563        }
    556564
  • trunk/src/bp-groups/classes/class-bp-groups-member.php

    r13890 r14076  
    148148
    149149        // User and group are not empty, and ID is.
    150         if ( !empty( $user_id ) && !empty( $group_id ) && empty( $id ) ) {
     150        if ( ! empty( $user_id ) && ! empty( $group_id ) && empty( $id ) ) {
    151151            $this->user_id  = $user_id;
    152152            $this->group_id = $group_id;
    153153
    154             if ( !empty( $populate ) ) {
     154            if ( ! empty( $populate ) ) {
    155155                $this->populate();
    156156            }
     
    158158
    159159        // ID is not empty.
    160         if ( !empty( $id ) ) {
     160        if ( ! empty( $id ) ) {
    161161            $this->id = $id;
    162162
    163             if ( !empty( $populate ) ) {
     163            if ( ! empty( $populate ) ) {
    164164                $this->populate();
    165165            }
     
    171171     *
    172172     * @since 1.6.0
     173     *
     174     * @global wpdb $wpdb WordPress database abstraction object.
    173175     */
    174176    public function populate() {
     
    177179        $bp = buddypress();
    178180
    179         if ( $this->user_id && $this->group_id && !$this->id )
     181        if ( $this->user_id && $this->group_id && ! $this->id ) {
    180182            $sql = $wpdb->prepare( "SELECT * FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d", $this->user_id, $this->group_id );
    181 
    182         if ( !empty( $this->id ) )
     183        }
     184
     185        if ( ! empty( $this->id ) ) {
    183186            $sql = $wpdb->prepare( "SELECT * FROM {$bp->groups->table_name_members} WHERE id = %d", $this->id );
    184 
    185         $member = $wpdb->get_row($sql);
    186 
    187         if ( !empty( $member ) ) {
     187        }
     188
     189        $member = $wpdb->get_row( $sql );
     190
     191        if ( ! empty( $member ) ) {
    188192            $this->id            = (int) $member->id;
    189193            $this->group_id      = (int) $member->group_id;
     
    210214     */
    211215    public function __get( $key ) {
    212         switch ( $key ) {
    213             case 'user' :
    214                 return $this->get_user_object( $this->user_id );
     216        if ( $key == 'user' ) {
     217            // @todo fix this.
     218            return $this->get_user_object( $this->user_id );
    215219        }
    216220    }
     
    226230    public function __isset( $key ) {
    227231        switch ( $key ) {
    228             case 'user' :
     232            case 'user':
    229233                return true;
    230234
    231             default :
     235            default:
    232236                return isset( $this->{$key} );
    233237        }
     
    256260     * @since 1.6.0
    257261     *
     262     * @global wpdb $wpdb WordPress database abstraction object.
     263     *
    258264     * @return bool
    259265     */
     
    263269        $bp = buddypress();
    264270
    265         $this->user_id       = apply_filters( 'groups_member_user_id_before_save',       $this->user_id,      $this->id );
    266         $this->group_id      = apply_filters( 'groups_member_group_id_before_save',      $this->group_id,      $this->id );
    267         $this->inviter_id    = apply_filters( 'groups_member_inviter_id_before_save',    $this->inviter_id,    $this->id );
    268         $this->is_admin      = apply_filters( 'groups_member_is_admin_before_save',      $this->is_admin,      $this->id );
    269         $this->is_mod        = apply_filters( 'groups_member_is_mod_before_save',        $this->is_mod,        $this->id );
    270         $this->is_banned     = apply_filters( 'groups_member_is_banned_before_save',     $this->is_banned,    $this->id );
    271         $this->user_title    = apply_filters( 'groups_member_user_title_before_save',    $this->user_title,    $this->id );
     271        $this->user_id       = apply_filters( 'groups_member_user_id_before_save', $this->user_id, $this->id );
     272        $this->group_id      = apply_filters( 'groups_member_group_id_before_save', $this->group_id, $this->id );
     273        $this->inviter_id    = apply_filters( 'groups_member_inviter_id_before_save', $this->inviter_id, $this->id );
     274        $this->is_admin      = apply_filters( 'groups_member_is_admin_before_save', $this->is_admin, $this->id );
     275        $this->is_mod        = apply_filters( 'groups_member_is_mod_before_save', $this->is_mod, $this->id );
     276        $this->is_banned     = apply_filters( 'groups_member_is_banned_before_save', $this->is_banned, $this->id );
     277        $this->user_title    = apply_filters( 'groups_member_user_title_before_save', $this->user_title, $this->id );
    272278        $this->date_modified = apply_filters( 'groups_member_date_modified_before_save', $this->date_modified, $this->id );
    273         $this->is_confirmed  = apply_filters( 'groups_member_is_confirmed_before_save',  $this->is_confirmed, $this->id );
    274         $this->comments      = apply_filters( 'groups_member_comments_before_save',      $this->comments,      $this->id );
    275         $this->invite_sent   = apply_filters( 'groups_member_invite_sent_before_save',   $this->invite_sent,  $this->id );
     279        $this->is_confirmed  = apply_filters( 'groups_member_is_confirmed_before_save', $this->is_confirmed, $this->id );
     280        $this->comments      = apply_filters( 'groups_member_comments_before_save', $this->comments, $this->id );
     281        $this->invite_sent   = apply_filters( 'groups_member_invite_sent_before_save', $this->invite_sent, $this->id );
    276282
    277283        /**
     
    291297        }
    292298
    293         if ( !empty( $this->id ) ) {
     299        if ( ! empty( $this->id ) ) {
    294300            $sql = $wpdb->prepare( "UPDATE {$bp->groups->table_name_members} SET inviter_id = %d, is_admin = %d, is_mod = %d, is_banned = %d, user_title = %s, date_modified = %s, is_confirmed = %d, comments = %s, invite_sent = %d WHERE id = %d", $this->inviter_id, $this->is_admin, $this->is_mod, $this->is_banned, $this->user_title, $this->date_modified, $this->is_confirmed, $this->comments, $this->invite_sent, $this->id );
    295301        } else {
     
    302308        }
    303309
    304         if ( !$wpdb->query( $sql ) )
     310        if ( ! $wpdb->query( $sql ) ) {
    305311            return false;
     312        }
    306313
    307314        $this->id = $wpdb->insert_id;
     
    371378     */
    372379    public function ban() {
    373         if ( !empty( $this->is_admin ) )
     380        if ( ! empty( $this->is_admin ) ) {
    374381            return false;
    375 
    376         $this->is_mod = 0;
     382        }
     383
     384        $this->is_mod    = 0;
    377385        $this->is_banned = 1;
    378386
     
    388396     */
    389397    public function unban() {
    390         if ( !empty( $this->is_admin ) )
     398        if ( ! empty( $this->is_admin ) ) {
    391399            return false;
     400        }
    392401
    393402        $this->is_banned = 0;
     
    413422     */
    414423    public function accept_request() {
    415         $this->is_confirmed = 1;
     424        $this->is_confirmed  = 1;
    416425        $this->date_modified = bp_core_current_time();
    417426    }
     
    421430     *
    422431     * @since 1.6.0
     432     *
     433     * @global wpdb $wpdb WordPress database abstraction object.
    423434     *
    424435     * @return bool
     
    439450        $sql = $wpdb->prepare( "DELETE FROM {$bp->groups->table_name_members} WHERE user_id = %d AND group_id = %d", $this->user_id, $this->group_id );
    440451
    441         if ( !$result = $wpdb->query( $sql ) )
     452        if ( ! $result = $wpdb->query( $sql ) ) {
    442453            return false;
     454        }
    443455
    444456        // Update the user's group count.
     
    473485     * Refresh the `total_member_count` for a group.
    474486     *
    475      * The request skip the current cache so that we always grab the lastest total count.
     487     * The request skip the current cache so that we always grab the latest total count.
    476488     *
    477489     * @since 1.8.0
     
    488500     *
    489501     * @since 1.6.0
     502     *
     503     * @global wpdb $wpdb WordPress database abstraction object.
    490504     *
    491505     * @param int $user_id  ID of the user.
     
    529543     *
    530544     * @since 1.6.0
     545     *
     546     * @global wpdb $wpdb WordPress database abstraction object.
    531547     *
    532548     * @param int      $user_id ID of the user.
     
    544560
    545561        $pag_sql = '';
    546         if ( !empty( $limit ) && !empty( $page ) )
    547             $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
     562        if ( ! empty( $limit ) && ! empty( $page ) ) {
     563            $pag_sql = $wpdb->prepare( ' LIMIT %d, %d', intval( ( $page - 1 ) * $limit ), intval( $limit ) );
     564        }
    548565
    549566        $bp = buddypress();
     
    551568        // If the user is logged in and viewing their own groups, we can show hidden and private groups.
    552569        if ( $user_id != bp_loggedin_user_id() ) {
    553             $group_sql = $wpdb->prepare( "SELECT DISTINCT m.group_id FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE g.status != 'hidden' AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0{$pag_sql}", $user_id );
     570            $group_sql    = $wpdb->prepare( "SELECT DISTINCT m.group_id FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE g.status != 'hidden' AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0{$pag_sql}", $user_id );
    554571            $total_groups = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE g.status != 'hidden' AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0", $user_id ) );
    555572        } else {
    556             $group_sql = $wpdb->prepare( "SELECT DISTINCT group_id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND is_confirmed = 1 AND is_banned = 0{$pag_sql}", $user_id );
     573            $group_sql    = $wpdb->prepare( "SELECT DISTINCT group_id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND is_confirmed = 1 AND is_banned = 0{$pag_sql}", $user_id );
    557574            $total_groups = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT group_id) FROM {$bp->groups->table_name_members} WHERE user_id = %d AND is_confirmed = 1 AND is_banned = 0", $user_id ) );
    558575        }
     
    560577        $groups = $wpdb->get_col( $group_sql );
    561578
    562         return array( 'groups' => $groups, 'total' => (int) $total_groups );
     579        return array(
     580            'groups' => $groups,
     581            'total'  => (int) $total_groups,
     582        );
    563583    }
    564584
     
    567587     *
    568588     * @since 1.6.0
     589     *
     590     * @global wpdb $wpdb WordPress database abstraction object.
    569591     *
    570592     * @param int         $user_id ID of the user.
     
    583605        global $wpdb;
    584606
    585         $user_id_sql = $pag_sql = $hidden_sql = $filter_sql = '';
    586 
     607        $pag_sql     = $hidden_sql = $filter_sql = '';
    587608        $user_id_sql = $wpdb->prepare( 'm.user_id = %d', $user_id );
    588609
    589         if ( !empty( $limit ) && !empty( $page ) )
    590             $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    591 
    592         if ( !empty( $filter ) ) {
     610        if ( ! empty( $limit ) && ! empty( $page ) ) {
     611            $pag_sql = $wpdb->prepare( ' LIMIT %d, %d', intval( ( $page - 1 ) * $limit ), intval( $limit ) );
     612        }
     613
     614        if ( ! empty( $filter ) ) {
    593615            $search_terms_like = '%' . bp_esc_like( $filter ) . '%';
    594             $filter_sql = $wpdb->prepare( " AND ( g.name LIKE %s OR g.description LIKE %s )", $search_terms_like, $search_terms_like );
    595         }
    596 
    597         if ( $user_id != bp_loggedin_user_id() )
     616            $filter_sql        = $wpdb->prepare( ' AND ( g.name LIKE %s OR g.description LIKE %s )', $search_terms_like, $search_terms_like );
     617        }
     618
     619        if ( $user_id != bp_loggedin_user_id() ) {
    598620            $hidden_sql = " AND g.status != 'hidden'";
     621        }
    599622
    600623        $bp = buddypress();
     
    603626        $total_groups = $wpdb->get_var( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id{$hidden_sql}{$filter_sql} AND {$user_id_sql} AND m.is_banned = 0 AND m.is_confirmed = 1 ORDER BY m.date_modified DESC" );
    604627
    605         return array( 'groups' => $paged_groups, 'total' => $total_groups );
     628        return array(
     629            'groups' => $paged_groups,
     630            'total'  => $total_groups,
     631        );
    606632    }
    607633
     
    610636     *
    611637     * @since 1.6.0
     638     *
     639     * @global wpdb $wpdb WordPress database abstraction object.
    612640     *
    613641     * @param int         $user_id ID of the user.
     
    626654        global $wpdb;
    627655
    628         $user_id_sql = $pag_sql = $hidden_sql = $filter_sql = '';
    629 
     656        $pag_sql     = $hidden_sql = $filter_sql = '';
    630657        $user_id_sql = $wpdb->prepare( 'm.user_id = %d', $user_id );
    631658
    632         if ( !empty( $limit ) && !empty( $page ) )
    633             $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    634 
    635         if ( !empty( $filter ) ) {
     659        if ( ! empty( $limit ) && ! empty( $page ) ) {
     660            $pag_sql = $wpdb->prepare( ' LIMIT %d, %d', intval( ( $page - 1 ) * $limit ), intval( $limit ) );
     661        }
     662
     663        if ( ! empty( $filter ) ) {
    636664            $search_terms_like = '%' . bp_esc_like( $filter ) . '%';
    637             $filter_sql = $wpdb->prepare( " AND ( g.name LIKE %s OR g.description LIKE %s )", $search_terms_like, $search_terms_like );
    638         }
    639 
    640         if ( $user_id != bp_loggedin_user_id() )
     665            $filter_sql        = $wpdb->prepare( ' AND ( g.name LIKE %s OR g.description LIKE %s )', $search_terms_like, $search_terms_like );
     666        }
     667
     668        if ( $user_id != bp_loggedin_user_id() ) {
    641669            $hidden_sql = " AND g.status != 'hidden'";
     670        }
    642671
    643672        $bp = buddypress();
     
    646675        $total_groups = $wpdb->get_var( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id{$hidden_sql}{$filter_sql} AND {$user_id_sql} AND m.is_confirmed = 1 AND m.is_banned = 0 AND m.is_admin = 1 ORDER BY date_modified ASC" );
    647676
    648         return array( 'groups' => $paged_groups, 'total' => $total_groups );
     677        return array(
     678            'groups' => $paged_groups,
     679            'total'  => $total_groups,
     680        );
    649681    }
    650682
     
    653685     *
    654686     * @since 1.6.0
     687     *
     688     * @global wpdb $wpdb WordPress database abstraction object.
    655689     *
    656690     * @param int         $user_id ID of the user.
     
    673707        $user_id_sql = $wpdb->prepare( 'm.user_id = %d', $user_id );
    674708
    675         if ( !empty( $limit ) && !empty( $page ) )
    676             $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    677 
    678         if ( !empty( $filter ) ) {
     709        if ( ! empty( $limit ) && ! empty( $page ) ) {
     710            $pag_sql = $wpdb->prepare( ' LIMIT %d, %d', intval( ( $page - 1 ) * $limit ), intval( $limit ) );
     711        }
     712
     713        if ( ! empty( $filter ) ) {
    679714            $search_terms_like = '%' . bp_esc_like( $filter ) . '%';
    680             $filter_sql = $wpdb->prepare( " AND ( g.name LIKE %s OR g.description LIKE %s )", $search_terms_like, $search_terms_like );
    681         }
    682 
    683         if ( $user_id != bp_loggedin_user_id() )
     715            $filter_sql        = $wpdb->prepare( ' AND ( g.name LIKE %s OR g.description LIKE %s )', $search_terms_like, $search_terms_like );
     716        }
     717
     718        if ( $user_id != bp_loggedin_user_id() ) {
    684719            $hidden_sql = " AND g.status != 'hidden'";
     720        }
    685721
    686722        $bp = buddypress();
     
    689725        $total_groups = $wpdb->get_var( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id{$hidden_sql}{$filter_sql} AND {$user_id_sql} AND m.is_confirmed = 1 AND m.is_banned = 0 AND m.is_mod = 1 ORDER BY date_modified ASC" );
    690726
    691         return array( 'groups' => $paged_groups, 'total' => $total_groups );
     727        return array(
     728            'groups' => $paged_groups,
     729            'total'  => $total_groups,
     730        );
    692731    }
    693732
     
    696735     *
    697736     * @since 2.4.0
     737     *
     738     * @global wpdb $wpdb WordPress database abstraction object.
    698739     *
    699740     * @param int         $user_id ID of the user.
     
    718759
    719760        if ( $limit && $page ) {
    720             $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit ), intval( $limit ) );
     761            $pag_sql = $wpdb->prepare( ' LIMIT %d, %d', intval( ( $page - 1 ) * $limit ), intval( $limit ) );
    721762        }
    722763
    723764        if ( $filter ) {
    724765            $search_terms_like = '%' . bp_esc_like( $filter ) . '%';
    725             $filter_sql        = $wpdb->prepare( " AND ( g.name LIKE %s OR g.description LIKE %s )", $search_terms_like, $search_terms_like );
     766            $filter_sql        = $wpdb->prepare( ' AND ( g.name LIKE %s OR g.description LIKE %s )', $search_terms_like, $search_terms_like );
    726767        }
    727768
     
    733774        $total_groups = $wpdb->get_var( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id{$hidden_sql}{$filter_sql} AND {$user_id_sql} AND m.is_banned = 1 ORDER BY date_modified ASC" );
    734775
    735         return array( 'groups' => $paged_groups, 'total' => $total_groups );
     776        return array(
     777            'groups' => $paged_groups,
     778            'total'  => $total_groups,
     779        );
    736780    }
    737781
     
    740784     *
    741785     * @since 1.6.0
     786     *
     787     * @global wpdb $wpdb WordPress database abstraction object.
    742788     *
    743789     * @param int $user_id Optional. Default: ID of the displayed user.
     
    747793        global $wpdb;
    748794
    749         if ( empty( $user_id ) )
     795        if ( empty( $user_id ) ) {
    750796            $user_id = bp_displayed_user_id();
    751 
    752         $bp = buddypress();
    753 
    754         if ( $user_id != bp_loggedin_user_id() && !bp_current_user_can( 'bp_moderate' ) ) {
     797        }
     798
     799        $bp = buddypress();
     800
     801        if ( $user_id != bp_loggedin_user_id() && ! bp_current_user_can( 'bp_moderate' ) ) {
    755802            return (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id AND g.status != 'hidden' AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0", $user_id ) );
    756         } else {
    757             return (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0", $user_id ) );
    758         }
     803        }
     804
     805        return (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(DISTINCT m.group_id) FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0", $user_id ) );
    759806    }
    760807
     
    797844     * @since 4.0.0
    798845     *
    799      * @param int $user_id ID of the user.
     846     * @global wpdb $wpdb WordPress database abstraction object.
     847     *
     848     * @param int   $user_id ID of the user.
    800849     * @param array $args {
    801850     *    Array of optional arguments.
     
    814863        $bp = buddypress();
    815864
    816         $r = array_merge( array(
    817             'page'     => 1,
    818             'per_page' => 20,
    819             'type'     => 'membership',
    820         ), $args );
     865        $r = array_merge(
     866            array(
     867                'page'     => 1,
     868                'per_page' => 20,
     869                'type'     => 'membership',
     870            ),
     871            $args
     872        );
    821873
    822874        $sql = array(
     
    828880
    829881        switch ( $r['type'] ) {
    830             case 'pending_request' :
    831                 return groups_get_requests( array(
    832                     'user_id'  => $user_id,
    833                     'page'     => $r['page'],
    834                     'per_page' => $r['per_page'],
    835                 ) );
    836             break;
    837 
    838             case 'pending_received_invitation' :
    839                 return groups_get_invites( array(
    840                     'user_id'  => $user_id,
    841                     'page'     => $r['page'],
    842                     'per_page' => $r['per_page'],
    843                 ) );
    844             break;
    845 
    846             case 'pending_sent_invitation' :
    847                 return groups_get_invites( array(
    848                     'inviter_id'  => $user_id,
    849                     'page'        => $r['page'],
    850                     'per_page'    => $r['per_page'],
    851                 ) );
    852             break;
    853 
    854             case 'membership' :
    855             default :
    856                 $sql['where'] = $wpdb->prepare( "user_id = %d AND is_confirmed = 1", $user_id );
    857             break;
     882            case 'pending_request':
     883                return groups_get_requests(
     884                    array(
     885                        'user_id'  => $user_id,
     886                        'page'     => $r['page'],
     887                        'per_page' => $r['per_page'],
     888                    )
     889                );
     890
     891            case 'pending_received_invitation':
     892                return groups_get_invites(
     893                    array(
     894                        'user_id'  => $user_id,
     895                        'page'     => $r['page'],
     896                        'per_page' => $r['per_page'],
     897                    )
     898                );
     899
     900            case 'pending_sent_invitation':
     901                return groups_get_invites(
     902                    array(
     903                        'inviter_id' => $user_id,
     904                        'page'       => $r['page'],
     905                        'per_page'   => $r['per_page'],
     906                    )
     907                );
     908
     909            case 'membership':
     910            default:
     911                $sql['where'] = $wpdb->prepare( 'user_id = %d AND is_confirmed = 1', $user_id );
     912                break;
    858913        }
    859914
    860915        if ( $r['page'] && $r['per_page'] ) {
    861             $sql['limits'] = $wpdb->prepare( "LIMIT %d, %d", ( $r['page'] - 1 ) * $r['per_page'], $r['per_page'] );
     916            $sql['limits'] = $wpdb->prepare( 'LIMIT %d, %d', ( $r['page'] - 1 ) * $r['per_page'], $r['per_page'] );
    862917        }
    863918
     
    931986     * @param int $user_id  ID of the user.
    932987     * @param int $group_id ID of the group.
    933      * @return int Number of records deleted.
     988     * @return int|false Number of records deleted. False if the user is not a member of the group.
    934989     */
    935990    public static function delete_request( $user_id, $group_id ) {
     
    941996     *
    942997     * @since 1.6.0
     998     *
     999     * @global wpdb $wpdb WordPress database abstraction object.
    9431000     *
    9441001     * @param int $user_id  ID of the user.
     
    9491006        global $wpdb;
    9501007
    951         if ( empty( $user_id ) )
     1008        if ( empty( $user_id ) ) {
    9521009            return false;
     1010        }
    9531011
    9541012        $bp = buddypress();
     
    9611019     *
    9621020     * @since 1.6.0
     1021     *
     1022     * @global wpdb $wpdb WordPress database abstraction object.
    9631023     *
    9641024     * @param int $user_id  ID of the user.
     
    9691029        global $wpdb;
    9701030
    971         if ( empty( $user_id ) )
     1031        if ( empty( $user_id ) ) {
    9721032            return false;
     1033        }
    9731034
    9741035        $bp = buddypress();
     
    9811042     *
    9821043     * @since 1.6.0
     1044     *
     1045     * @global wpdb $wpdb WordPress database abstraction object.
    9831046     *
    9841047     * @param int $user_id  ID of the user.
     
    9891052        global $wpdb;
    9901053
    991         if ( empty( $user_id ) )
     1054        if ( empty( $user_id ) ) {
    9921055            return false;
     1056        }
    9931057
    9941058        $bp = buddypress();
     
    10011065     *
    10021066     * @since 1.6.0
     1067     *
     1068     * @global wpdb $wpdb WordPress database abstraction object.
    10031069     *
    10041070     * @param int $user_id  ID of the user.
     
    10101076        global $wpdb;
    10111077
    1012         if ( empty( $user_id ) )
     1078        if ( empty( $user_id ) ) {
    10131079            return false;
     1080        }
    10141081
    10151082        $bp = buddypress();
     
    10241091     *
    10251092     * @since 1.2.6
     1093     *
     1094     * @global wpdb $wpdb WordPress database abstraction object.
    10261095     *
    10271096     * @param int $user_id  ID of the user.
     
    10321101        global $wpdb;
    10331102
    1034         if ( empty( $user_id ) )
     1103        if ( empty( $user_id ) ) {
    10351104            return false;
     1105        }
    10361106
    10371107        $bp = buddypress();
     
    10601130     * @since 1.6.0
    10611131     *
     1132     * @global wpdb $wpdb WordPress database abstraction object.
     1133     *
    10621134     * @param int $user_id      ID of the user.
    10631135     * @param int $total_groups Max number of group IDs to return. Default: 5.
     
    10721144        if ( bp_is_my_profile() ) {
    10731145            return array_map( 'intval', $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT group_id FROM {$bp->groups->table_name_members} WHERE user_id = %d AND is_confirmed = 1 AND is_banned = 0 ORDER BY rand() LIMIT %d", $user_id, $total_groups ) ) );
    1074         } else {
    1075             return array_map( 'intval', $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT m.group_id FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id AND g.status != 'hidden' AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0 ORDER BY rand() LIMIT %d", $user_id, $total_groups ) ) );
    1076         }
     1146        }
     1147
     1148        return array_map( 'intval', $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT m.group_id FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id AND g.status != 'hidden' AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0 ORDER BY rand() LIMIT %d", $user_id, $total_groups ) ) );
    10771149    }
    10781150
     
    10811153     *
    10821154     * @since 1.6.0
     1155     *
     1156     * @global wpdb $wpdb WordPress database abstraction object.
    10831157     *
    10841158     * @param int $group_id ID of the group.
     
    10981172     * @since 1.6.0
    10991173     *
    1100      * @param  int   $group_id ID of the group.
     1174     * @param  int $group_id ID of the group.
    11011175     * @return array           Info about group admins (user_id + date_modified).
    11021176     */
     
    11311205     * @since 2.7.0
    11321206     *
     1207     * @global wpdb $wpdb WordPress database abstraction object.
     1208     *
    11331209     * @param array $group_ids IDs of the groups.
    1134      * @return bool
    11351210     */
    11361211    public static function prime_group_admins_mods_cache( $group_ids ) {
     
    11401215
    11411216        if ( $uncached ) {
    1142             $bp = buddypress();
    1143             $uncached_sql = implode( ',', array_map( 'intval', $uncached ) );
     1217            $bp               = buddypress();
     1218            $uncached_sql     = implode( ',', array_map( 'intval', $uncached ) );
    11441219            $group_admin_mods = $wpdb->get_results( "SELECT user_id, group_id, date_modified, is_admin, is_mod FROM {$bp->groups->table_name_members} WHERE group_id IN ({$uncached_sql}) AND ( is_admin = 1 OR is_mod = 1 ) AND is_banned = 0" );
    11451220
     
    11471222            if ( $group_admin_mods ) {
    11481223                foreach ( $group_admin_mods as $group_admin_mod ) {
    1149                     $obj = new stdClass();
    1150                     $obj->user_id = $group_admin_mod->user_id;
     1224                    $obj                = new stdClass();
     1225                    $obj->user_id       = $group_admin_mod->user_id;
    11511226                    $obj->date_modified = $group_admin_mod->date_modified;
    11521227
     
    12091284     * @since 2.6.0
    12101285     *
     1286     * @global wpdb $wpdb WordPress database abstraction object.
     1287     *
    12111288     * @param int|string|array $membership_ids Single membership ID or comma-separated/array list of membership IDs.
    12121289     * @return array
     
    12181295
    12191296        $membership_ids = implode( ',', wp_parse_id_list( $membership_ids ) );
     1297
    12201298        return $wpdb->get_results( "SELECT * FROM {$bp->groups->table_name_members} WHERE id IN ({$membership_ids})" );
    12211299    }
     
    12351313    /**
    12361314     * Get members of a group.
     1315     *
     1316     * @global wpdb $wpdb WordPress database abstraction object.
    12371317     *
    12381318     * @deprecated 1.6.0
     
    12521332
    12531333        $pag_sql = '';
    1254         if ( !empty( $limit ) && !empty( $page ) )
    1255             $pag_sql = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
     1334        if ( ! empty( $limit ) && ! empty( $page ) ) {
     1335            $pag_sql = $wpdb->prepare( 'LIMIT %d, %d', intval( ( $page - 1 ) * $limit ), intval( $limit ) );
     1336        }
    12561337
    12571338        $exclude_admins_sql = '';
    1258         if ( !empty( $exclude_admins_mods ) )
    1259             $exclude_admins_sql = "AND is_admin = 0 AND is_mod = 0";
     1339        if ( ! empty( $exclude_admins_mods ) ) {
     1340            $exclude_admins_sql = 'AND is_admin = 0 AND is_mod = 0';
     1341        }
    12601342
    12611343        $banned_sql = '';
    1262         if ( !empty( $exclude_banned ) )
    1263             $banned_sql = " AND is_banned = 0";
     1344        if ( ! empty( $exclude_banned ) ) {
     1345            $banned_sql = ' AND is_banned = 0';
     1346        }
    12641347
    12651348        $exclude_sql = '';
    1266         if ( !empty( $exclude ) ) {
     1349        if ( ! empty( $exclude ) ) {
    12671350            $exclude     = implode( ',', wp_parse_id_list( $exclude ) );
    12681351            $exclude_sql = " AND m.user_id NOT IN ({$exclude})";
     
    13061389
    13071390        // Fetch whether or not the user is a friend.
    1308         foreach ( (array) $members as $user )
     1391        foreach ( (array) $members as $user ) {
    13091392            $user_ids[] = $user->user_id;
     1393        }
    13101394
    13111395        $user_ids = implode( ',', wp_parse_id_list( $user_ids ) );
     
    13151399            for ( $i = 0, $count = count( $members ); $i < $count; ++$i ) {
    13161400                foreach ( (array) $friend_status as $status ) {
    1317                     if ( $status->initiator_user_id == $members[$i]->user_id || $status->friend_user_id == $members[$i]->user_id ) {
    1318                         $members[$i]->is_friend = $status->is_confirmed;
     1401                    if ( $status->initiator_user_id == $members[ $i ]->user_id || $status->friend_user_id == $members[ $i ]->user_id ) {
     1402                        $members[ $i ]->is_friend = $status->is_confirmed;
    13191403                    }
    13201404                }
     
    13221406        }
    13231407
    1324         return array( 'members' => $members, 'count' => $total_member_count );
     1408        return array(
     1409            'members' => $members,
     1410            'count'   => $total_member_count,
     1411        );
    13251412    }
    13261413
     
    13291416     *
    13301417     * @since 2.6.0
     1418     *
     1419     * @global wpdb $wpdb WordPress database abstraction object.
    13311420     *
    13321421     * @param int $user_id ID of the user.
     
    13471436     *
    13481437     * @since 1.6.0
     1438     *
     1439     * @global wpdb $wpdb WordPress database abstraction object.
    13491440     *
    13501441     * @param int $group_id ID of the group.
     
    13731464     */
    13741465    public static function delete_all_for_user( $user_id ) {
    1375         $group_ids = BP_Groups_Member::get_group_ids( $user_id );
     1466        $group_ids = self::get_group_ids( $user_id );
    13761467
    13771468        foreach ( $group_ids['groups'] as $group_id ) {
     
    13791470                // If the user is a sole group admin, install a site admin as their replacement.
    13801471                if ( count( groups_get_group_admins( $group_id ) ) < 2 ) {
    1381                     $admin = get_users( array(
    1382                         'blog_id' => bp_get_root_blog_id(),
    1383                         'fields'  => 'id',
    1384                         'number'  => 1,
    1385                         'orderby' => 'ID',
    1386                         'role'    => 'administrator',
    1387                     ) );
     1472                    $admin = get_users(
     1473                        array(
     1474                            'blog_id' => bp_get_root_blog_id(),
     1475                            'fields'  => 'id',
     1476                            'number'  => 1,
     1477                            'orderby' => 'ID',
     1478                            'role'    => 'administrator',
     1479                        )
     1480                    );
    13881481
    13891482                    if ( ! empty( $admin ) ) {
     
    13961489            }
    13971490
    1398             BP_Groups_Member::delete( $user_id, $group_id );
     1491            self::delete( $user_id, $group_id );
    13991492        }
    14001493
Note: See TracChangeset for help on using the changeset viewer.