Skip to:
Content

BuddyPress.org

Changeset 3728 for trunk/bp-groups.php


Ignore:
Timestamp:
01/18/2011 12:53:31 PM (13 years ago)
Author:
johnjamesjacoby
Message:

Code normalization and whitespace clean-up. Introduce bp-core-deprecated.php. Introduce root_slug globals into components with directories, to help with WP page slugs. Fixes #2600. Optimus Props boonebgorges

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-groups.php

    r3648 r3728  
    11<?php
     2
     3// Required Files
    24require ( BP_PLUGIN_DIR . '/bp-groups/bp-groups-classes.php' );
    35require ( BP_PLUGIN_DIR . '/bp-groups/bp-groups-templatetags.php' );
     
    1416    global $bp;
    1517
     18    // Define a slug, if necessary
    1619    if ( !defined( 'BP_GROUPS_SLUG' ) )
    17         define ( 'BP_GROUPS_SLUG', $bp->pages->groups->slug );
    18 
    19     /* For internal identification */
    20     $bp->groups->id = 'groups';
    21     $bp->groups->name = $bp->pages->groups->name;
    22     $bp->groups->slug = BP_GROUPS_SLUG;
    23 
     20        define ( 'BP_GROUPS_SLUG', bp_core_component_slug_from_root_slug( $bp->pages->groups->slug ) );
     21
     22    // For internal identification
     23    $bp->groups->id        = 'groups';
     24    $bp->groups->name      = $bp->pages->groups->name;
     25
     26    // Slugs
     27    $bp->groups->slug      = BP_GROUPS_SLUG;
     28    $bp->groups->root_slug = $bp->pages->groups->slug;
     29
     30    // Tables
    2431    $bp->groups->table_name           = $bp->table_prefix . 'bp_groups';
    2532    $bp->groups->table_name_members   = $bp->table_prefix . 'bp_groups_members';
    2633    $bp->groups->table_name_groupmeta = $bp->table_prefix . 'bp_groups_groupmeta';
    2734
     35    // Notifications
    2836    $bp->groups->format_notification_function = 'groups_format_notifications';
    2937
    30     /* Register this in the active components array */
     38    // Register this in the active components array
    3139    $bp->active_components[$bp->groups->slug] = $bp->groups->id;
    3240
     
    3442
    3543    $bp->groups->group_creation_steps = apply_filters( 'groups_create_group_steps', array(
    36         'group-details' => array( 'name' => __( 'Details', 'buddypress' ), 'position' => 0 ),
     44        'group-details'  => array( 'name' => __( 'Details', 'buddypress' ), 'position' => 0 ),
    3745        'group-settings' => array( 'name' => __( 'Settings', 'buddypress' ), 'position' => 10 ),
    38         'group-avatar' => array( 'name' => __( 'Avatar', 'buddypress' ), 'position' => 20 ),
     46        'group-avatar'   => array( 'name' => __( 'Avatar', 'buddypress' ), 'position' => 20 ),
    3947    ) );
    4048
     
    4856
    4957    // The default text for the groups directory search box
    50         $bp->default_search_strings[$bp->groups->slug] = __( 'Search Groups...', 'buddypress' );
     58    $bp->default_search_strings[$bp->groups->slug] = __( 'Search Groups...', 'buddypress' );
    5159
    5260    do_action( 'groups_setup_globals' );
     
    5765    global $bp;
    5866
    59     if ( $bp->current_component == $bp->groups->slug && $group_id = BP_Groups_Group::group_exists($bp->current_action) ) {
    60 
    61         /* This is a single group page. */
     67    if ( bp_is_current_component( $bp->groups->slug ) && $group_id = BP_Groups_Group::group_exists($bp->current_action) ) {
     68
     69        // This is a single group page.
    6270        $bp->is_single_item = true;
    6371        $bp->groups->current_group = new BP_Groups_Group( $group_id );
    6472
    65         /* Using "item" not "group" for generic support in other components. */
     73        // Using "item" not "group" for generic support in other components.
    6674        if ( is_super_admin() )
    6775            $bp->is_item_admin = 1;
     
    6977            $bp->is_item_admin = groups_is_user_admin( $bp->loggedin_user->id, $bp->groups->current_group->id );
    7078
    71         /* If the user is not an admin, check if they are a moderator */
     79        // If the user is not an admin, check if they are a moderator
    7280        if ( !$bp->is_item_admin )
    7381            $bp->is_item_mod = groups_is_user_mod( $bp->loggedin_user->id, $bp->groups->current_group->id );
    7482
    75         /* Is the logged in user a member of the group? */
     83        // Is the logged in user a member of the group?
    7684        $bp->groups->current_group->is_user_member = ( is_user_logged_in() && groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) ) ? true : false;
    7785
    78         /* Should this group be visible to the logged in user? */
     86        // Should this group be visible to the logged in user?
    7987        $bp->groups->current_group->is_group_visible_to_member = ( 'public' == $bp->groups->current_group->status || $bp->groups->current_group->is_user_member ) ? true : false;
    8088    }
    8189
    82     /* Add 'Groups' to the main navigation */
    83     bp_core_new_nav_item( array( 'name' => sprintf( __( 'Groups <span>(%d)</span>', 'buddypress' ), groups_total_groups_for_user() ), 'slug' => $bp->groups->name, 'position' => 70, 'screen_function' => 'groups_screen_my_groups', 'default_subnav_slug' => 'my-groups', 'item_css_id' => $bp->groups->id ) );
    84 
    85     $groups_link = $bp->loggedin_user->domain . $bp->groups->name . '/';
    86 
    87     /* Add the subnav items to the groups nav item */
    88     bp_core_new_subnav_item( array( 'name' => __( 'My Groups', 'buddypress' ), 'slug' => 'my-groups', 'parent_url' => $groups_link, 'parent_slug' => $bp->groups->name, 'screen_function' => 'groups_screen_my_groups', 'position' => 10, 'item_css_id' => 'groups-my-groups' ) );
    89     bp_core_new_subnav_item( array( 'name' => __( 'Invites', 'buddypress' ), 'slug' => 'invites', 'parent_url' => $groups_link, 'parent_slug' => $bp->groups->name, 'screen_function' => 'groups_screen_group_invites', 'position' => 30, 'user_has_access' => bp_is_my_profile() ) );
    90 
    91     if ( $bp->current_component == $bp->groups->slug ) {
     90    // Add 'Groups' to the main navigation
     91    bp_core_new_nav_item( array( 'name' => sprintf( __( 'Groups <span>(%d)</span>', 'buddypress' ), groups_total_groups_for_user() ), 'slug' => $bp->groups->slug, 'position' => 70, 'screen_function' => 'groups_screen_my_groups', 'default_subnav_slug' => 'my-groups', 'item_css_id' => $bp->groups->id ) );
     92
     93    $groups_link = $bp->loggedin_user->domain . $bp->groups->slug . '/';
     94
     95    // Add the subnav items to the groups nav item
     96    bp_core_new_subnav_item( array( 'name' => __( 'My Groups', 'buddypress' ), 'slug' => 'my-groups', 'parent_url' => $groups_link, 'parent_slug' => $bp->groups->slug, 'screen_function' => 'groups_screen_my_groups',     'position' => 10, 'item_css_id'    => 'groups-my-groups' ) );
     97    bp_core_new_subnav_item( array( 'name' => __( 'Invites',   'buddypress' ), 'slug' => 'invites',   'parent_url' => $groups_link, 'parent_slug' => $bp->groups->slug, 'screen_function' => 'groups_screen_group_invites', 'position' => 30, 'user_has_access' => bp_is_my_profile() ) );
     98
     99    if ( bp_is_current_component( $bp->groups->slug ) ) {
    92100
    93101        if ( bp_is_my_profile() && !$bp->is_single_item ) {
     
    104112            // group navigation menu using the $bp->groups->current_group global.
    105113
    106             /* When in a single group, the first action is bumped down one because of the
    107                group name, so we need to adjust this and set the group name to current_item. */
    108             $bp->current_item = isset( $bp->current_action ) ? $bp->current_action : false;
     114            // When in a single group, the first action is bumped down one because of the
     115            // group name, so we need to adjust this and set the group name to current_item.
     116            $bp->current_item   = isset( $bp->current_action )      ? $bp->current_action      : false;
    109117            $bp->current_action = isset( $bp->action_variables[0] ) ? $bp->action_variables[0] : false;
    110             array_shift($bp->action_variables);
     118            array_shift( $bp->action_variables );
    111119
    112120            $bp->bp_options_title = $bp->groups->current_group->name;
     
    115123                $bp->bp_options_avatar = '<img src="' . esc_attr( $group->avatar_full ) . '" class="avatar" alt="' . esc_attr( $group->name ) . '" />';
    116124
    117             $group_link = $bp->root_domain . '/' . $bp->groups->slug . '/' . $bp->groups->current_group->slug . '/';
     125            $group_link = $bp->root_domain . '/' . $bp->groups->root_slug . '/' . $bp->groups->current_group->slug . '/';
    118126
    119127            // If this is a private or hidden group, does the user have access?
     
    127135            }
    128136
    129             /* Reset the existing subnav items */
    130             bp_core_reset_subnav_items($bp->groups->slug);
    131 
    132             /* Add a new default subnav item for when the groups nav is selected. */
    133             bp_core_new_nav_default( array( 'parent_slug' => $bp->groups->slug, 'screen_function' => 'groups_screen_group_home', 'subnav_slug' => 'home' ) );
    134 
    135             /* Add the "Home" subnav item, as this will always be present */
    136             bp_core_new_subnav_item( array( 'name' => __( 'Home', 'buddypress' ), 'slug' => 'home', 'parent_url' => $group_link, 'parent_slug' => $bp->groups->slug, 'screen_function' => 'groups_screen_group_home', 'position' => 10, 'item_css_id' => 'home' ) );
    137 
    138             /* If the user is a group mod or more, then show the group admin nav item */
     137            // Reset the existing subnav items
     138            bp_core_reset_subnav_items( $bp->groups->root_slug );
     139
     140            // Add a new default subnav item for when the groups nav is selected.
     141            bp_core_new_nav_default( array( 'parent_slug' => $bp->groups->root_slug, 'screen_function' => 'groups_screen_group_home', 'subnav_slug' => 'home' ) );
     142
     143            // Add the "Home" subnav item, as this will always be present
     144            bp_core_new_subnav_item( array( 'name' => __( 'Home', 'buddypress' ), 'slug' => 'home', 'parent_url' => $group_link, 'parent_slug' => $bp->groups->root_slug, 'screen_function' => 'groups_screen_group_home', 'position' => 10, 'item_css_id' => 'home' ) );
     145
     146            // If the user is a group mod or more, then show the group admin nav item
    139147            if ( $bp->is_item_mod || $bp->is_item_admin )
    140                 bp_core_new_subnav_item( array( 'name' => __( 'Admin', 'buddypress' ), 'slug' => 'admin', 'parent_url' => $group_link, 'parent_slug' => $bp->groups->slug, 'screen_function' => 'groups_screen_group_admin', 'position' => 20, 'user_has_access' => ( $bp->is_item_admin + (int)$bp->is_item_mod ), 'item_css_id' => 'admin' ) );
     148                bp_core_new_subnav_item( array( 'name' => __( 'Admin', 'buddypress' ), 'slug' => 'admin', 'parent_url' => $group_link, 'parent_slug' => $bp->groups->root_slug, 'screen_function' => 'groups_screen_group_admin', 'position' => 20, 'user_has_access' => ( $bp->is_item_admin + (int)$bp->is_item_mod ), 'item_css_id' => 'admin' ) );
    141149
    142150            // If this is a private group, and the user is not a member, show a "Request Membership" nav item.
    143151            if ( !is_super_admin() && is_user_logged_in() && !$bp->groups->current_group->is_user_member && !groups_check_for_membership_request( $bp->loggedin_user->id, $bp->groups->current_group->id ) && $bp->groups->current_group->status == 'private' )
    144                 bp_core_new_subnav_item( array( 'name' => __( 'Request Membership', 'buddypress' ), 'slug' => 'request-membership', 'parent_url' => $group_link, 'parent_slug' => $bp->groups->slug, 'screen_function' => 'groups_screen_group_request_membership', 'position' => 30 ) );
    145 
    146             if ( $bp->groups->current_group->enable_forum && function_exists('bp_forums_setup') )
    147                 bp_core_new_subnav_item( array( 'name' => __( 'Forum', 'buddypress' ), 'slug' => 'forum', 'parent_url' => $group_link, 'parent_slug' => $bp->groups->slug, 'screen_function' => 'groups_screen_group_forum', 'position' => 40, 'user_has_access' => $bp->groups->current_group->user_has_access, 'item_css_id' => 'forums' ) );
    148 
    149             bp_core_new_subnav_item( array( 'name' => sprintf( __( 'Members (%s)', 'buddypress' ), number_format( $bp->groups->current_group->total_member_count ) ), 'slug' => 'members', 'parent_url' => $group_link, 'parent_slug' => $bp->groups->slug, 'screen_function' => 'groups_screen_group_members', 'position' => 60, 'user_has_access' => $bp->groups->current_group->user_has_access, 'item_css_id' => 'members'  ) );
     152                bp_core_new_subnav_item( array( 'name' => __( 'Request Membership', 'buddypress' ), 'slug' => 'request-membership', 'parent_url' => $group_link, 'parent_slug' => $bp->groups->root_slug, 'screen_function' => 'groups_screen_group_request_membership', 'position' => 30 ) );
     153
     154            // Forums are enabled and turned on
     155            if ( $bp->groups->current_group->enable_forum && function_exists( 'bp_forums_setup' ) )
     156                bp_core_new_subnav_item( array( 'name' => __( 'Forum', 'buddypress' ), 'slug' => 'forum', 'parent_url' => $group_link, 'parent_slug' => $bp->groups->root_slug, 'screen_function' => 'groups_screen_group_forum', 'position' => 40, 'user_has_access' => $bp->groups->current_group->user_has_access, 'item_css_id' => 'forums' ) );
     157
     158            bp_core_new_subnav_item( array( 'name' => sprintf( __( 'Members (%s)', 'buddypress' ), number_format( $bp->groups->current_group->total_member_count ) ), 'slug' => 'members', 'parent_url' => $group_link, 'parent_slug' => $bp->groups->root_slug, 'screen_function' => 'groups_screen_group_members', 'position' => 60, 'user_has_access' => $bp->groups->current_group->user_has_access, 'item_css_id' => 'members'  ) );
    150159
    151160            if ( is_user_logged_in() && groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) ) {
    152161                if ( bp_is_active('friends') )
    153                     bp_core_new_subnav_item( array( 'name' => __( 'Send Invites', 'buddypress' ), 'slug' => 'send-invites', 'parent_url' => $group_link, 'parent_slug' => $bp->groups->slug, 'screen_function' => 'groups_screen_group_invite', 'item_css_id' => 'invite', 'position' => 70, 'user_has_access' => $bp->groups->current_group->user_has_access ) );
     162                    bp_core_new_subnav_item( array( 'name' => __( 'Send Invites', 'buddypress' ), 'slug' => 'send-invites', 'parent_url' => $group_link, 'parent_slug' => $bp->groups->root_slug, 'screen_function' => 'groups_screen_group_invite', 'item_css_id' => 'invite', 'position' => 70, 'user_has_access' => $bp->groups->current_group->user_has_access ) );
    154163            }
    155164        }
     
    165174function groups_directory_groups_setup() {
    166175    global $bp;
    167 
    168     if ( $bp->current_component == $bp->groups->slug && empty( $bp->current_action ) && empty( $bp->current_item ) ) {
     176   
     177    if ( bp_is_current_component( $bp->groups->slug ) && empty( $bp->current_action ) && empty( $bp->current_item ) ) {
    169178        $bp->is_directory = true;
    170179
     
    181190        return false;
    182191
    183     /* Don't show this menu to non site admins or if you're viewing your own profile */
     192    // Don't show this menu to non site admins or if you're viewing your own profile
    184193    if ( !is_super_admin() )
    185         return false;
    186     ?>
     194        return false; ?>
     195
    187196    <li id="bp-adminbar-adminoptions-menu">
    188197        <a href=""><?php _e( 'Admin Options', 'buddypress' ) ?></a>
     
    192201
    193202            <?php do_action( 'groups_adminbar_menu_items' ) ?>
     203
    194204        </ul>
    195205    </li>
     206
    196207    <?php
    197208}
    198209add_action( 'bp_adminbar_menus', 'groups_setup_adminbar_menu', 20 );
    199 
    200210
    201211/********************************************************************************
     
    210220    global $bp;
    211221
    212     if ( isset($_GET['n']) ) {
    213         // Delete group request notifications for the user
     222    // Delete group request notifications for the user
     223    if ( isset( $_GET['n'] ) ) {
    214224        bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->groups->id, 'membership_request_accepted' );
    215225        bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->groups->id, 'membership_request_rejected' );
    216         bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->groups->id, 'member_promoted_to_mod' );
    217         bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->groups->id, 'member_promoted_to_admin' );
     226        bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->groups->id, 'member_promoted_to_mod'      );
     227        bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->groups->id, 'member_promoted_to_admin'    );
    218228    }
    219229
     
    231241
    232242    if ( isset( $bp->action_variables ) && in_array( 'accept', (array)$bp->action_variables ) && is_numeric( $group_id ) ) {
    233         /* Check the nonce */
     243        // Check the nonce
    234244        if ( !check_admin_referer( 'groups_accept_invite' ) )
    235245            return false;
     
    240250            bp_core_add_message( __('Group invite accepted', 'buddypress') );
    241251
    242             /* Record this in activity streams */
     252            // Record this in activity streams
    243253            $group = new BP_Groups_Group( $group_id );
    244254
    245255            groups_record_activity( array(
    246                 'action' => apply_filters( 'groups_activity_accepted_invite_action', sprintf( __( '%1$s joined the group %2$s', 'buddypress'), bp_core_get_userlink( $bp->loggedin_user->id ), '<a href="' . bp_get_group_permalink( $group ) . '">' . esc_attr( $group->name ) . '</a>' ), $bp->loggedin_user->id, &$group ),
    247                 'type' => 'joined_group',
     256                'action'  => apply_filters( 'groups_activity_accepted_invite_action', sprintf( __( '%1$s joined the group %2$s', 'buddypress'), bp_core_get_userlink( $bp->loggedin_user->id ), '<a href="' . bp_get_group_permalink( $group ) . '">' . esc_attr( $group->name ) . '</a>' ), $bp->loggedin_user->id, &$group ),
     257                'type'    => 'joined_group',
    248258                'item_id' => $group->id
    249259            ) );
     
    253263
    254264    } elseif ( isset( $bp->action_variables ) && in_array( 'reject', (array)$bp->action_variables ) && is_numeric( $group_id ) ) {
    255         /* Check the nonce */
     265        // Check the nonce
    256266        if ( !check_admin_referer( 'groups_reject_invite' ) )
    257267            return false;
     
    277287
    278288    if ( $bp->is_single_item ) {
    279         if ( isset($_GET['n']) ) {
    280             // Delete group request notifications for the user
     289        if ( isset( $_GET['n'] ) ) {
    281290            bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->groups->id, 'membership_request_accepted' );
    282291            bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->groups->id, 'membership_request_rejected' );
    283             bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->groups->id, 'member_promoted_to_mod' );
    284             bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->groups->id, 'member_promoted_to_admin' );
     292            bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->groups->id, 'member_promoted_to_mod'      );
     293            bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->groups->id, 'member_promoted_to_admin'    );
    285294        }
    286295
     
    296305    if ( $bp->is_single_item && $bp->groups->current_group->user_has_access ) {
    297306
    298         /* Fetch the details we need */
    299         $topic_slug = isset( $bp->action_variables[1] ) ? $bp->action_variables[1] : false;
    300         $topic_id = bp_forums_get_topic_id_from_slug( $topic_slug );
    301         $forum_id = groups_get_groupmeta( $bp->groups->current_group->id, 'forum_id' );
    302 
     307        // Fetch the details we need
     308        $topic_slug     = isset( $bp->action_variables[1] ) ? $bp->action_variables[1] : false;
     309        $topic_id       = bp_forums_get_topic_id_from_slug( $topic_slug );
     310        $forum_id       = groups_get_groupmeta( $bp->groups->current_group->id, 'forum_id' );
    303311        $user_is_banned = false;
     312
    304313        if ( !is_super_admin() && groups_is_user_banned( $bp->loggedin_user->id, $bp->groups->current_group->id ) )
    305314            $user_is_banned = true;
     
    307316        if ( $topic_slug && $topic_id ) {
    308317
    309             /* Posting a reply */
     318            // Posting a reply
    310319            if ( !$user_is_banned && !isset( $bp->action_variables[2] ) && isset( $_POST['submit_reply'] ) ) {
    311                 /* Check the nonce */
     320                // Check the nonce
    312321                check_admin_referer( 'bp_forums_new_reply' );
    313322
    314                 /* Auto join this user if they are not yet a member of this group */
     323                // Auto join this user if they are not yet a member of this group
    315324                if ( $bp->groups->auto_join && !is_super_admin() && 'public' == $bp->groups->current_group->status && !groups_is_user_member( $bp->loggedin_user->id, $bp->groups->current_group->id ) )
    316325                    groups_join_group( $bp->groups->current_group->id, $bp->loggedin_user->id );
    317326
    318                                 $topic_page = isset( $_GET['topic_page'] ) ? $_GET['topic_page'] : false;
     327                $topic_page = isset( $_GET['topic_page'] ) ? $_GET['topic_page'] : false;
    319328
    320329                if ( !$post_id = groups_new_group_forum_post( $_POST['reply_text'], $topic_id, $topic_page ) )
     
    329338            }
    330339
    331             /* Sticky a topic */
     340            // Sticky a topic
    332341            else if ( isset( $bp->action_variables[2] ) && 'stick' == $bp->action_variables[2] && ( isset( $bp->is_item_admin ) || isset( $bp->is_item_mod ) ) ) {
    333                 /* Check the nonce */
     342                // Check the nonce
    334343                check_admin_referer( 'bp_forums_stick_topic' );
    335344
     
    343352            }
    344353
    345             /* Un-Sticky a topic */
     354            // Un-Sticky a topic
    346355            else if ( isset( $bp->action_variables[2] ) && 'unstick' == $bp->action_variables[2] && ( isset( $bp->is_item_admin ) || isset( $bp->is_item_mod ) ) ) {
    347                 /* Check the nonce */
     356                // Check the nonce
    348357                check_admin_referer( 'bp_forums_unstick_topic' );
    349358
     
    357366            }
    358367
    359             /* Close a topic */
     368            // Close a topic
    360369            else if ( isset( $bp->action_variables[2] ) && 'close' == $bp->action_variables[2] && ( isset( $bp->is_item_admin ) || isset( $bp->is_item_mod ) ) ) {
    361                 /* Check the nonce */
     370                // Check the nonce
    362371                check_admin_referer( 'bp_forums_close_topic' );
    363372
     
    371380            }
    372381
    373             /* Open a topic */
     382            // Open a topic
    374383            else if ( isset( $bp->action_variables[2] ) && 'open' == $bp->action_variables[2] && ( isset( $bp->is_item_admin ) || isset( $bp->is_item_mod ) ) ) {
    375                 /* Check the nonce */
     384                // Check the nonce
    376385                check_admin_referer( 'bp_forums_open_topic' );
    377386
     
    385394            }
    386395
    387             /* Delete a topic */
     396            // Delete a topic
    388397            else if ( !$user_is_banned && isset( $bp->action_variables[2] ) && 'delete' == $bp->action_variables[2] && empty( $bp->action_variables[3] ) ) {
    389                 /* Fetch the topic */
     398                // Fetch the topic
    390399                $topic = bp_forums_get_topic_details( $topic_id );
    391400
     
    394403                    bp_core_redirect( wp_get_referer() );
    395404
    396                 /* Check the nonce */
     405                // Check the nonce
    397406                check_admin_referer( 'bp_forums_delete_topic' );
    398407
     
    407416            }
    408417
    409             /* Editing a topic */
     418            // Editing a topic
    410419            else if ( !$user_is_banned && isset( $bp->action_variables[2] ) && 'edit' == $bp->action_variables[2] && empty( $bp->action_variables[3] ) ) {
    411                 /* Fetch the topic */
     420                // Fetch the topic
    412421                $topic = bp_forums_get_topic_details( $topic_id );
    413422
    414                 /* Check the logged in user can edit this topic */
     423                // Check the logged in user can edit this topic
    415424                if ( !$bp->is_item_admin && !$bp->is_item_mod && (int)$bp->loggedin_user->id != (int)$topic->topic_poster )
    416425                    bp_core_redirect( wp_get_referer() );
    417426
    418427                if ( isset( $_POST['save_changes'] ) ) {
    419                     /* Check the nonce */
     428                    // Check the nonce
    420429                    check_admin_referer( 'bp_forums_edit_topic' );
    421430
     
    432441            }
    433442
    434             /* Delete a post */
     443            // Delete a post
    435444            else if ( !$user_is_banned && isset( $bp->action_variables[2] ) && 'delete' == $bp->action_variables[2] && isset( $bp->action_variables[4] ) && $post_id = $bp->action_variables[4] ) {
    436                 /* Fetch the post */
     445                // Fetch the post
    437446                $post = bp_forums_get_post( $post_id );
    438447
    439                 /* Check the logged in user can edit this topic */
     448                // Check the logged in user can edit this topic
    440449                if ( !$bp->is_item_admin && !$bp->is_item_mod && (int)$bp->loggedin_user->id != (int)$post->poster_id )
    441450                    bp_core_redirect( wp_get_referer() );
    442451
    443                 /* Check the nonce */
     452                // Check the nonce
    444453                check_admin_referer( 'bp_forums_delete_post' );
    445454
     
    455464            }
    456465
    457             /* Editing a post */
     466            // Editing a post
    458467            else if ( !$user_is_banned && isset( $bp->action_variables[2] ) && 'edit' == $bp->action_variables[2] && isset( $bp->action_variables[4] ) && $post_id = $bp->action_variables[4] ) {
    459                 /* Fetch the post */
     468                // Fetch the post
    460469                $post = bp_forums_get_post( $bp->action_variables[4] );
    461470
    462                 /* Check the logged in user can edit this topic */
     471                // Check the logged in user can edit this topic
    463472                if ( !$bp->is_item_admin && !$bp->is_item_mod && (int)$bp->loggedin_user->id != (int)$post->poster_id )
    464473                    bp_core_redirect( wp_get_referer() );
    465474
    466475                if ( isset( $_POST['save_changes'] ) ) {
    467                     /* Check the nonce */
     476                    // Check the nonce
    468477                    check_admin_referer( 'bp_forums_edit_post' );
    469478
     
    483492            }
    484493
    485             /* Standard topic display */
     494            // Standard topic display
    486495            else {
    487496                if ( $user_is_banned )
     
    492501
    493502        } else {
    494             /* Posting a topic */
     503            // Posting a topic
    495504            if ( isset( $_POST['submit_topic'] ) && function_exists( 'bp_forums_new_topic') ) {
    496                 /* Check the nonce */
     505                // Check the nonce
    497506                check_admin_referer( 'bp_forums_new_topic' );
    498507
     
    578587        // If the user has submitted a request, send it.
    579588        if ( isset( $_POST['group-request-send']) ) {
    580             /* Check the nonce first. */
     589            // Check the nonce
    581590            if ( !check_admin_referer( 'groups_request_membership' ) )
    582591                return false;
     
    599608    global $bp;
    600609
    601     if ( $bp->current_component != $bp->groups->slug || $bp->current_action != $bp->activity->slug || empty( $bp->action_variables[0] ) )
     610    if ( !bp_is_current_component( $bp->groups->slug ) || $bp->current_action != $bp->activity->slug || empty( $bp->action_variables[0] ) )
    602611        return false;
    603612
     
    611620    global $bp;
    612621
    613     if ( $bp->current_component != BP_GROUPS_SLUG || 'admin' != $bp->current_action )
     622    if ( !bp_is_current_component( BP_GROUPS_SLUG ) || 'admin' != $bp->current_action )
    614623        return false;
    615624
     
    623632    global $bp;
    624633
    625     if ( $bp->current_component == $bp->groups->slug && 'edit-details' == $bp->action_variables[0] ) {
     634    if ( bp_is_current_component( $bp->groups->slug ) && 'edit-details' == $bp->action_variables[0] ) {
    626635
    627636        if ( $bp->is_item_admin || $bp->is_item_mod  ) {
     
    629638            // If the edit form has been submitted, save the edited details
    630639            if ( isset( $_POST['save'] ) ) {
    631                 /* Check the nonce first. */
     640                // Check the nonce
    632641                if ( !check_admin_referer( 'groups_edit_group_details' ) )
    633642                    return false;
     
    655664    global $bp;
    656665
    657     if ( $bp->current_component == $bp->groups->slug && 'group-settings' == $bp->action_variables[0] ) {
     666    if ( bp_is_current_component( $bp->groups->slug ) && 'group-settings' == $bp->action_variables[0] ) {
    658667
    659668        if ( !$bp->is_item_admin )
     
    667676            $status = ( in_array( $_POST['group-status'], (array)$allowed_status ) ) ? $_POST['group-status'] : 'public';
    668677
    669             /* Check the nonce first. */
     678            // Check the nonce
    670679            if ( !check_admin_referer( 'groups_edit_group_settings' ) )
    671680                return false;
     
    692701    global $bp;
    693702
    694     if ( $bp->current_component == $bp->groups->slug && 'group-avatar' == $bp->action_variables[0] ) {
     703    if ( bp_is_current_component( $bp->groups->slug ) && 'group-avatar' == $bp->action_variables[0] ) {
    695704
    696705        if ( !$bp->is_item_admin )
    697706            return false;
    698707
    699         /* If the group admin has deleted the admin avatar */
     708        // If the group admin has deleted the admin avatar
    700709        if ( 'delete' == $bp->action_variables[1] ) {
    701710
    702             /* Check the nonce */
     711            // Check the nonce
    703712            check_admin_referer( 'bp_group_avatar_delete' );
    704713
     
    714723        if ( !empty( $_FILES ) ) {
    715724
    716             /* Check the nonce */
     725            // Check the nonce
    717726            check_admin_referer( 'bp_avatar_upload' );
    718727
    719             /* Pass the file to the avatar upload handler */
     728            // Pass the file to the avatar upload handler
    720729            if ( bp_core_avatar_handle_upload( $_FILES, 'groups_avatar_upload_dir' ) ) {
    721730                $bp->avatar_admin->step = 'crop-image';
    722731
    723                 /* Make sure we include the jQuery jCrop file for image cropping */
     732                // Make sure we include the jQuery jCrop file for image cropping
    724733                add_action( 'wp_print_scripts', 'bp_core_add_jquery_cropper' );
    725734            }
     
    727736        }
    728737
    729         /* If the image cropping is done, crop the image and save a full/thumb version */
     738        // If the image cropping is done, crop the image and save a full/thumb version
    730739        if ( isset( $_POST['avatar-crop-submit'] ) ) {
    731740
    732             /* Check the nonce */
     741            // Check the nonce
    733742            check_admin_referer( 'bp_avatar_cropstore' );
    734743
     
    750759    global $bp;
    751760
    752     if ( $bp->current_component == $bp->groups->slug && 'manage-members' == $bp->action_variables[0] ) {
     761    if ( bp_is_current_component( $bp->groups->slug ) && 'manage-members' == $bp->action_variables[0] ) {
    753762
    754763        if ( !$bp->is_item_admin )
     
    856865    global $bp;
    857866
    858     if ( $bp->current_component == $bp->groups->slug && 'membership-requests' == $bp->action_variables[0] ) {
    859 
    860         /* Ask for a login if the user is coming here via an email notification */
     867    if ( bp_is_current_component( $bp->groups->slug ) && 'membership-requests' == $bp->action_variables[0] ) {
     868
     869        // Ask for a login if the user is coming here via an email notification
    861870        if ( !is_user_logged_in() )
    862871            bp_core_redirect( site_url( 'wp-login.php?redirect_to=' . $bp->root_domain . '/' . $bp->current_component . '/' . $bp->current_item . '/admin/membership-requests/' ) );
     
    874883            if ( 'accept' == $request_action && is_numeric($membership_id) ) {
    875884
    876                 /* Check the nonce first. */
     885                // Check the nonce first.
    877886                if ( !check_admin_referer( 'groups_accept_membership_request' ) )
    878887                    return false;
     
    914923    global $bp;
    915924
    916     if ( $bp->current_component == $bp->groups->slug && 'delete-group' == $bp->action_variables[0] ) {
     925    if ( bp_is_current_component( $bp->groups->slug ) && 'delete-group' == $bp->action_variables[0] ) {
    917926
    918927        if ( !$bp->is_item_admin && !is_super_admin() )
     
    920929
    921930        if ( isset( $_REQUEST['delete-group-button'] ) && isset( $_REQUEST['delete-group-understand'] ) ) {
    922             /* Check the nonce first. */
     931            // Check the nonce first.
    923932            if ( !check_admin_referer( 'groups_delete_group' ) )
    924933                return false;
     
    950959    global $bp;
    951960
    952     $group_invite = get_user_meta( $bp->displayed_user->id, 'notification_groups_invite', true );
    953     if ( !$group_invite )
    954         $group_invite = 'yes';
    955 
    956     $group_update = get_user_meta( $bp->displayed_user->id, 'notification_groups_group_updated', true );
    957     if ( !$group_update )
    958         $group_update = 'yes';
    959 
    960     $group_promo = get_user_meta( $bp->displayed_user->id, 'notification_groups_admin_promotion', true );
    961     if ( !$group_promo )
    962         $group_promo = 'yes';
    963 
    964     $group_request = get_user_meta( $bp->displayed_user->id, 'notification_groups_membership_request', true );
    965     if ( !$group_request )
     961    if ( !$group_invite = get_user_meta( $bp->displayed_user->id, 'notification_groups_invite', true ) )
     962        $group_invite  = 'yes';
     963
     964    if ( !$group_update = get_user_meta( $bp->displayed_user->id, 'notification_groups_group_updated', true ) )
     965        $group_update  = 'yes';
     966
     967    if ( !$group_promo = get_user_meta( $bp->displayed_user->id, 'notification_groups_admin_promotion', true ) )
     968        $group_promo   = 'yes';
     969
     970    if ( !$group_request = get_user_meta( $bp->displayed_user->id, 'notification_groups_membership_request', true ) )
    966971        $group_request = 'yes';
    967972?>
     973
    968974    <table class="notification-settings zebra" id="groups-notification-settings">
    969975        <thead>
     
    10031009
    10041010            <?php do_action( 'groups_screen_notification_settings' ); ?>
     1011
    10051012        </tbody>
    10061013    </table>
     1014
    10071015<?php
    10081016}
     
    10211029    global $bp;
    10221030
    1023     /* If we're not at domain.org/groups/create/ then return false */
    1024     if ( $bp->current_component != $bp->groups->slug || 'create' != $bp->current_action )
     1031    // If we're not at domain.org/groups/create/ then return false
     1032    if ( !bp_is_current_component( $bp->groups->slug ) || 'create' != $bp->current_action )
    10251033        return false;
    10261034
     
    10281036        return false;
    10291037
    1030     /* Make sure creation steps are in the right order */
     1038    // Make sure creation steps are in the right order
    10311039    groups_action_sort_creation_steps();
    10321040
    1033     /* If no current step is set, reset everything so we can start a fresh group creation */
     1041    // If no current step is set, reset everything so we can start a fresh group creation
    10341042    if ( !isset( $bp->action_variables[1] ) || !$bp->groups->current_create_step = $bp->action_variables[1] ) {
    10351043
     
    10411049
    10421050        $reset_steps = true;
    1043         bp_core_redirect( $bp->root_domain . '/' . $bp->groups->slug . '/create/step/' . array_shift( array_keys( $bp->groups->group_creation_steps ) ) . '/' );
    1044     }
    1045 
    1046     /* If this is a creation step that is not recognized, just redirect them back to the first screen */
     1051        bp_core_redirect( $bp->root_domain . '/' . $bp->groups->root_slug . '/create/step/' . array_shift( array_keys( $bp->groups->group_creation_steps ) ) . '/' );
     1052    }
     1053
     1054    // If this is a creation step that is not recognized, just redirect them back to the first screen
    10471055    if ( $bp->action_variables[1] && !$bp->groups->group_creation_steps[$bp->action_variables[1]] ) {
    10481056        bp_core_add_message( __('There was an error saving group details. Please try again.', 'buddypress'), 'error' );
    1049         bp_core_redirect( $bp->root_domain . '/' . $bp->groups->slug . '/create/' );
    1050     }
    1051 
    1052     /* Fetch the currently completed steps variable */
     1057        bp_core_redirect( $bp->root_domain . '/' . $bp->groups->root_slug . '/create/' );
     1058    }
     1059
     1060    // Fetch the currently completed steps variable
    10531061    if ( isset( $_COOKIE['bp_completed_create_steps'] ) && !isset( $reset_steps ) )
    10541062        $bp->groups->completed_create_steps = unserialize( stripslashes( $_COOKIE['bp_completed_create_steps'] ) );
    10551063
    1056     /* Set the ID of the new group, if it has already been created in a previous step */
     1064    // Set the ID of the new group, if it has already been created in a previous step
    10571065    if ( isset( $_COOKIE['bp_new_group_id'] ) ) {
    10581066        $bp->groups->new_group_id = $_COOKIE['bp_new_group_id'];
     
    10601068    }
    10611069
    1062     /* If the save, upload or skip button is hit, lets calculate what we need to save */
     1070    // If the save, upload or skip button is hit, lets calculate what we need to save
    10631071    if ( isset( $_POST['save'] ) ) {
    10641072
    1065         /* Check the nonce */
     1073        // Check the nonce
    10661074        check_admin_referer( 'groups_create_save_' . $bp->groups->current_create_step );
    10671075
     
    10691077            if ( empty( $_POST['group-name'] ) || empty( $_POST['group-desc'] ) || !strlen( trim( $_POST['group-name'] ) ) || !strlen( trim( $_POST['group-desc'] ) ) ) {
    10701078                bp_core_add_message( __( 'Please fill in all of the required fields', 'buddypress' ), 'error' );
    1071                 bp_core_redirect( $bp->root_domain . '/' . $bp->groups->slug . '/create/step/' . $bp->groups->current_create_step . '/' );
     1079                bp_core_redirect( $bp->root_domain . '/' . $bp->groups->root_slug . '/create/step/' . $bp->groups->current_create_step . '/' );
    10721080            }
    10731081
     
    10761084            if ( !$bp->groups->new_group_id = groups_create_group( array( 'group_id' => $new_group_id, 'name' => $_POST['group-name'], 'description' => $_POST['group-desc'], 'slug' => groups_check_slug( sanitize_title( esc_attr( $_POST['group-name'] ) ) ), 'date_created' => bp_core_current_time(), 'status' => 'public' ) ) ) {
    10771085                bp_core_add_message( __( 'There was an error saving group details, please try again.', 'buddypress' ), 'error' );
    1078                 bp_core_redirect( $bp->root_domain . '/' . $bp->groups->slug . '/create/step/' . $bp->groups->current_create_step . '/' );
     1086                bp_core_redirect( $bp->root_domain . '/' . $bp->groups->root_slug . '/create/step/' . $bp->groups->current_create_step . '/' );
    10791087            }
    10801088
     
    10901098                $group_enable_forum = 0;
    10911099            } else {
    1092                 /* Create the forum if enable_forum = 1 */
     1100                // Create the forum if enable_forum = 1
    10931101                if ( function_exists( 'bp_forums_setup' ) && '' == groups_get_groupmeta( $bp->groups->new_group_id, 'forum_id' ) ) {
    10941102                    groups_new_group_forum();
     
    11031111            if ( !$bp->groups->new_group_id = groups_create_group( array( 'group_id' => $bp->groups->new_group_id, 'status' => $group_status, 'enable_forum' => $group_enable_forum ) ) ) {
    11041112                bp_core_add_message( __( 'There was an error saving group details, please try again.', 'buddypress' ), 'error' );
    1105                 bp_core_redirect( $bp->root_domain . '/' . $bp->groups->slug . '/create/step/' . $bp->groups->current_create_step . '/' );
     1113                bp_core_redirect( $bp->root_domain . '/' . $bp->groups->root_slug . '/create/step/' . $bp->groups->current_create_step . '/' );
    11061114            }
    11071115        }
    11081116
    1109         if ( 'group-invites' == $bp->groups->current_create_step ) {
     1117        if ( 'group-invites' == $bp->groups->current_create_step )
    11101118            groups_send_invites( $bp->loggedin_user->id, $bp->groups->new_group_id );
    1111         }
    11121119
    11131120        do_action( 'groups_create_group_step_save_' . $bp->groups->current_create_step );
     
    11231130            $bp->groups->completed_create_steps[] = $bp->groups->current_create_step;
    11241131
    1125         /* Reset cookie info */
     1132        // Reset cookie info
    11261133        setcookie( 'bp_new_group_id', $bp->groups->new_group_id, time()+60*60*24, COOKIEPATH );
    11271134        setcookie( 'bp_completed_create_steps', serialize( $bp->groups->completed_create_steps ), time()+60*60*24, COOKIEPATH );
    11281135
    1129         /* If we have completed all steps and hit done on the final step we can redirect to the completed group */
     1136        // If we have completed all steps and hit done on the final step we
     1137        // can redirect to the completed group
    11301138        if ( count( $bp->groups->completed_create_steps ) == count( $bp->groups->group_creation_steps ) && $bp->groups->current_create_step == array_pop( array_keys( $bp->groups->group_creation_steps ) ) ) {
    11311139            unset( $bp->groups->current_create_step );
    11321140            unset( $bp->groups->completed_create_steps );
    11331141
    1134             /* Once we compelete all steps, record the group creation in the activity stream. */
     1142            // Once we compelete all steps, record the group creation in the activity stream.
    11351143            groups_record_activity( array(
    11361144                'action' => apply_filters( 'groups_activity_created_group_action', sprintf( __( '%1$s created the group %2$s', 'buddypress'), bp_core_get_userlink( $bp->loggedin_user->id ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . esc_attr( $bp->groups->current_group->name ) . '</a>' ) ),
     
    11591167            }
    11601168
    1161             bp_core_redirect( $bp->root_domain . '/' . $bp->groups->slug . '/create/step/' . $next_step . '/' );
    1162         }
    1163     }
    1164 
    1165     /* Group avatar is handled separately */
     1169            bp_core_redirect( $bp->root_domain . '/' . $bp->groups->root_slug . '/create/step/' . $next_step . '/' );
     1170        }
     1171    }
     1172
     1173    // Group avatar is handled separately
    11661174    if ( 'group-avatar' == $bp->groups->current_create_step && isset( $_POST['upload'] ) ) {
    11671175        if ( !empty( $_FILES ) && isset( $_POST['upload'] ) ) {
    1168             /* Normally we would check a nonce here, but the group save nonce is used instead */
    1169 
    1170             /* Pass the file to the avatar upload handler */
     1176            // Normally we would check a nonce here, but the group save nonce is used instead
     1177
     1178            // Pass the file to the avatar upload handler
    11711179            if ( bp_core_avatar_handle_upload( $_FILES, 'groups_avatar_upload_dir' ) ) {
    11721180                $bp->avatar_admin->step = 'crop-image';
    11731181
    1174                 /* Make sure we include the jQuery jCrop file for image cropping */
     1182                // Make sure we include the jQuery jCrop file for image cropping
    11751183                add_action( 'wp_print_scripts', 'bp_core_add_jquery_cropper' );
    11761184            }
    11771185        }
    11781186
    1179         /* If the image cropping is done, crop the image and save a full/thumb version */
     1187        // If the image cropping is done, crop the image and save a full/thumb version
    11801188        if ( isset( $_POST['avatar-crop-submit'] ) && isset( $_POST['upload'] ) ) {
    1181             /* Normally we would check a nonce here, but the group save nonce is used instead */
     1189            // Normally we would check a nonce here, but the group save nonce is used instead
    11821190
    11831191            if ( !bp_core_avatar_handle_crop( array( 'object' => 'group', 'avatar_dir' => 'group-avatars', 'item_id' => $bp->groups->current_group->id, 'original_file' => $_POST['image_src'], 'crop_x' => $_POST['x'], 'crop_y' => $_POST['y'], 'crop_w' => $_POST['w'], 'crop_h' => $_POST['h'] ) ) )
     
    11951203    global $bp;
    11961204
    1197     if ( !$bp->is_single_item || $bp->current_component != $bp->groups->slug || $bp->current_action != 'join' )
     1205    if ( !$bp->is_single_item || !bp_is_current_component( $bp->groups->slug ) || $bp->current_action != 'join' )
    11981206        return false;
    11991207
     
    12301238    global $bp;
    12311239
    1232     if ( !$bp->is_single_item || $bp->current_component != $bp->groups->slug || $bp->current_action != 'leave-group' )
     1240    if ( !$bp->is_single_item || !bp_is_current_component( $bp->groups->slug ) || $bp->current_action != 'leave-group' )
    12331241        return false;
    12341242
     
    12551263    global $bp;
    12561264
    1257     if ( $bp->current_component != BP_GROUPS_SLUG && $bp->current_action != 'create' )
     1265    if ( !bp_is_current_component( BP_GROUPS_SLUG ) && $bp->current_action != 'create' )
    12581266        return false;
    12591267
     
    12681276    }
    12691277
    1270     /* Sort the steps by their position key */
     1278    // Sort the steps by their position key
    12711279    ksort($temp);
    12721280    unset($bp->groups->group_creation_steps);
     
    12791287    global $bp, $wpdb;
    12801288
    1281     if ( $bp->current_component == $bp->groups->slug && isset( $_GET['random-group'] ) ) {
     1289    if ( bp_is_current_component( $bp->groups->slug ) && isset( $_GET['random-group'] ) ) {
    12821290        $group = groups_get_groups( array( 'type' => 'random', 'per_page' => 1 ) );
    12831291
     
    12901298    global $bp, $wp_query;
    12911299
    1292     if ( !bp_is_active( 'activity' ) || $bp->current_component != $bp->groups->slug || !isset( $bp->groups->current_group ) || $bp->current_action != 'feed' )
     1300    if ( !bp_is_active( 'activity' ) || !bp_is_current_component( $bp->groups->slug ) || !isset( $bp->groups->current_group ) || $bp->current_action != 'feed' )
    12931301        return false;
    12941302
     
    13201328        return false;
    13211329
    1322     bp_activity_set_action( $bp->groups->id, 'created_group', __( 'Created a group', 'buddypress' ) );
    1323     bp_activity_set_action( $bp->groups->id, 'joined_group', __( 'Joined a group', 'buddypress' ) );
     1330    bp_activity_set_action( $bp->groups->id, 'created_group',   __( 'Created a group',      'buddypress' ) );
     1331    bp_activity_set_action( $bp->groups->id, 'joined_group',    __( 'Joined a group',        'buddypress' ) );
    13241332    bp_activity_set_action( $bp->groups->id, 'new_forum_topic', __( 'New group forum topic', 'buddypress' ) );
    1325     bp_activity_set_action( $bp->groups->id, 'new_forum_post', __( 'New group forum post', 'buddypress' ) );
     1333    bp_activity_set_action( $bp->groups->id, 'new_forum_post',  __( 'New group forum post', 'buddypress' ) );
    13261334
    13271335    do_action( 'groups_register_activity_actions' );
     
    13351343        return false;
    13361344
    1337     /* If the group is not public, hide the activity sitewide. */
     1345    // If the group is not public, hide the activity sitewide.
    13381346    if ( 'public' == $bp->groups->current_group->status )
    13391347        $hide_sitewide = false;
     
    13411349        $hide_sitewide = true;
    13421350
    1343     $defaults = array(
    1344         'id' => false,
    1345         'user_id' => $bp->loggedin_user->id,
    1346         'action' => '',
    1347         'content' => '',
    1348         'primary_link' => '',
    1349         'component' => $bp->groups->id,
    1350         'type' => false,
    1351         'item_id' => false,
     1351    $defaults = array (
     1352        'id'                => false,
     1353        'user_id'           => $bp->loggedin_user->id,
     1354        'action'            => '',
     1355        'content'           => '',
     1356        'primary_link'      => '',
     1357        'component'         => $bp->groups->id,
     1358        'type'              => false,
     1359        'item_id'           => false,
    13521360        'secondary_item_id' => false,
    1353         'recorded_time' => bp_core_current_time(),
    1354         'hide_sitewide' => $hide_sitewide
     1361        'recorded_time'     => bp_core_current_time(),
     1362        'hide_sitewide'     => $hide_sitewide
    13551363    );
    13561364
     
    13611369}
    13621370
    1363 function groups_update_last_activity( $group_id = false ) {
     1371function groups_update_last_activity( $group_id = 0 ) {
    13641372    global $bp;
    13651373
     
    13951403                return apply_filters( 'bp_groups_single_new_membership_request_notification', '<a href="' . $group_link . 'admin/membership-requests/?n=1" title="' . sprintf( __( '%s requests group membership', 'buddypress' ), $user_fullname ) . '">' . sprintf( __( '%1$s requests membership for the group "%2$s"', 'buddypress' ), $user_fullname, $group->name ) . '</a>', $group_link, $user_fullname, $group->name );
    13961404            }
    1397         break;
     1405            break;
    13981406
    13991407        case 'membership_request_accepted':
     
    14081416                return apply_filters( 'bp_groups_single_membership_request_accepted_notification', '<a href="' . $group_link . '?n=1">' . sprintf( __( 'Membership for group "%s" accepted', 'buddypress' ), $group->name ) . '</a>', $group_link, $group->name );
    14091417
    1410         break;
     1418            break;
    14111419
    14121420        case 'membership_request_rejected':
     
    14211429                return apply_filters( 'bp_groups_single_membership_request_rejected_notification', '<a href="' . $group_link . '?n=1">' . sprintf( __( 'Membership for group "%s" rejected', 'buddypress' ), $group->name ) . '</a>', $group_link, $group->name );
    14221430
    1423         break;
     1431            break;
    14241432
    14251433        case 'member_promoted_to_admin':
     
    14341442                return apply_filters( 'bp_groups_single_member_promoted_to_admin_notification', '<a href="' . $group_link . '?n=1">' . sprintf( __( 'You were promoted to an admin in the group %s', 'buddypress' ), $group->name ) . '</a>', $group_link, $group->name );
    14351443
    1436         break;
     1444            break;
    14371445
    14381446        case 'member_promoted_to_mod':
     
    14471455                return apply_filters( 'bp_groups_single_member_promoted_to_mod_notification', '<a href="' . $group_link . '?n=1">' . sprintf( __( 'You were promoted to a mod in the group %s', 'buddypress' ), $group->name ) . '</a>', $group_link, $group->name );
    14481456
    1449         break;
     1457            break;
    14501458
    14511459        case 'group_invite':
     
    14601468                return apply_filters( 'bp_groups_single_group_invite_notification', '<a href="' . $bp->loggedin_user->domain . $bp->groups->slug . '/invites/?n=1" title="' . __( 'Group Invites', 'buddypress' ) . '">' . sprintf( __( 'You have an invitation to the group: %s', 'buddypress' ), $group->name ) . '</a>', $group->name );
    14611469
    1462         break;
     1470            break;
    14631471    }
    14641472
     
    14801488function groups_get_group( $args = '' ) {
    14811489    $defaults = array(
    1482         'group_id' => false,
     1490        'group_id'   => false,
    14831491        'load_users' => false
    14841492    );
     
    15441552        return false;
    15451553
     1554    // If this is a new group, set up the creator as the first member and admin
    15461555    if ( !$group_id ) {
    1547         // If this is a new group, set up the creator as the first member and admin
    1548         $member = new BP_Groups_Member;
    1549         $member->group_id = $group->id;
    1550         $member->user_id = $group->creator_id;
    1551         $member->is_admin = 1;
    1552         $member->user_title = __( 'Group Admin', 'buddypress' );
    1553         $member->is_confirmed = 1;
     1556        $member                = new BP_Groups_Member;
     1557        $member->group_id      = $group->id;
     1558        $member->user_id       = $group->creator_id;
     1559        $member->is_admin      = 1;
     1560        $member->user_title    = __( 'Group Admin', 'buddypress' );
     1561        $member->is_confirmed  = 1;
    15541562        $member->date_modified = bp_core_current_time();
    15551563
     
    15721580        return false;
    15731581
    1574     $group = new BP_Groups_Group( $group_id );
    1575     $group->name = $group_name;
     1582    $group              = new BP_Groups_Group( $group_id );
     1583    $group->name        = $group_name;
    15761584    $group->description = $group_desc;
    15771585
     
    16021610        groups_accept_all_pending_membership_requests( $group->id );
    16031611
    1604     /* Now update the status */
     1612    // Now update the status
    16051613    $group->status = $status;
    16061614
     
    16081616        return false;
    16091617
    1610     /* If forums have been enabled, and a forum does not yet exist, we need to create one. */
     1618    // If forums have been enabled, and a forum does not yet exist, we need to create one.
    16111619    if ( $group->enable_forum ) {
    16121620        if ( function_exists( 'bp_forums_setup' ) && '' == groups_get_groupmeta( $group->id, 'forum_id' ) ) {
     
    16751683        $slug = substr( $slug, 2, strlen( $slug ) - 2 );
    16761684
    1677     if ( in_array( $slug, (array)$bp->groups->forbidden_names ) ) {
     1685    if ( in_array( $slug, (array)$bp->groups->forbidden_names ) )
    16781686        $slug = $slug . '-' . rand();
    1679     }
    16801687
    16811688    if ( BP_Groups_Group::check_slug( $slug ) ) {
     
    16961703/*** User Actions ***************************************************************/
    16971704
    1698 function groups_leave_group( $group_id, $user_id = false ) {
     1705function groups_leave_group( $group_id, $user_id = 0 ) {
    16991706    global $bp;
    17001707
     
    17021709        $user_id = $bp->loggedin_user->id;
    17031710
    1704     /* Don't let single admins leave the group. */
     1711    // Don't let single admins leave the group.
    17051712    if ( count( groups_get_group_admins( $group_id ) ) < 2 ) {
    17061713        if ( groups_is_user_admin( $user_id, $group_id ) ) {
     
    17161723        return false;
    17171724
    1718     /* Modify group member count */
     1725    // Modify group member count
    17191726    groups_update_groupmeta( $group_id, 'total_member_count', (int) groups_get_groupmeta( $group_id, 'total_member_count') - 1 );
    17201727
    1721     /* Modify user's group memberhip count */
     1728    // Modify user's group memberhip count
    17221729    update_user_meta( $user_id, 'total_group_count', (int) get_user_meta( $user_id, 'total_group_count', true ) - 1 );
    17231730
    1724     /* If the user joined this group less than five minutes ago, remove the joined_group activity so
    1725      * users cannot flood the activity stream by joining/leaving the group in quick succession.
     1731    /**
     1732     * If the user joined this group less than five minutes ago, remove the
     1733     * joined_group activity so users cannot flood the activity stream by
     1734     * joining/leaving the group in quick succession.
    17261735     */
    17271736    if ( function_exists( 'bp_activity_delete' ) && gmmktime() <= strtotime( '+5 minutes', (int)strtotime( $membership->date_modified ) ) )
     
    17351744}
    17361745
    1737 function groups_join_group( $group_id, $user_id = false ) {
     1746function groups_join_group( $group_id, $user_id = 0 ) {
    17381747    global $bp;
    17391748
     
    17531762        return true;
    17541763
    1755     $new_member = new BP_Groups_Member;
    1756     $new_member->group_id = $group_id;
    1757     $new_member->user_id = $user_id;
    1758     $new_member->inviter_id = 0;
    1759     $new_member->is_admin = 0;
    1760     $new_member->user_title = '';
     1764    $new_member                = new BP_Groups_Member;
     1765    $new_member->group_id      = $group_id;
     1766    $new_member->user_id       = $user_id;
     1767    $new_member->inviter_id    = 0;
     1768    $new_member->is_admin      = 0;
     1769    $new_member->user_title    = '';
    17611770    $new_member->date_modified = bp_core_current_time();
    1762     $new_member->is_confirmed = 1;
     1771    $new_member->is_confirmed  = 1;
    17631772
    17641773    if ( !$new_member->save() )
     
    17721781    // Record this in activity streams
    17731782    groups_record_activity( array(
    1774         'action' => apply_filters( 'groups_activity_joined_group', sprintf( __( '%1$s joined the group %2$s', 'buddypress'), bp_core_get_userlink( $user_id ), '<a href="' . bp_get_group_permalink( $group ) . '">' . esc_attr( bp_get_group_name( $group ) ) . '</a>' ) ),
    1775         'type' => 'joined_group',
     1783        'action'  => apply_filters( 'groups_activity_joined_group', sprintf( __( '%1$s joined the group %2$s', 'buddypress'), bp_core_get_userlink( $user_id ), '<a href="' . bp_get_group_permalink( $group ) . '">' . esc_attr( bp_get_group_name( $group ) ) . '</a>' ) ),
     1784        'type'    => 'joined_group',
    17761785        'item_id' => $group_id,
    17771786        'user_id' => $user_id
     
    18151824
    18161825    $defaults = array(
    1817         'type' => 'active', // active, newest, alphabetical, random, popular, most-forum-topics or most-forum-posts
    1818         'user_id' => false, // Pass a user_id to limit to only groups that this user is a member of
    1819         'include' => false, // Only include these specific groups (group_ids)
    1820         'exclude' => false, // Do not include these specific groups (group_ids)
    1821         'search_terms' => false, // Limit to groups that match these search terms
    1822         'show_hidden' => false, // Show hidden groups to non-admins
    1823 
    1824         'per_page' => 20, // The number of results to return per page
    1825         'page' => 1, // The page to return if limiting per page
    1826         'populate_extras' => true, // Fetch meta such as is_banned and is_member
     1826        'type'            => 'active', // active, newest, alphabetical, random, popular, most-forum-topics or most-forum-posts
     1827        'user_id'         => false,    // Pass a user_id to limit to only groups that this user is a member of
     1828        'include'         => false,    // Only include these specific groups (group_ids)
     1829        'exclude'         => false,    // Do not include these specific groups (group_ids)
     1830        'search_terms'    => false,    // Limit to groups that match these search terms
     1831        'show_hidden'     => false,    // Show hidden groups to non-admins
     1832
     1833        'per_page'        => 20,      // The number of results to return per page
     1834        'page'            => 1,        // The page to return if limiting per page
     1835        'populate_extras' => true,     // Fetch meta such as is_banned and is_member
    18271836    );
    18281837
     
    18441853}
    18451854
    1846 function groups_get_user_groups( $user_id = false, $pag_num = false, $pag_page = false ) {
     1855function groups_get_user_groups( $user_id = 0, $pag_num = 0, $pag_page = 0 ) {
    18471856    global $bp;
    18481857
     
    18531862}
    18541863
    1855 function groups_total_groups_for_user( $user_id = false ) {
     1864function groups_total_groups_for_user( $user_id = 0 ) {
    18561865    global $bp;
    18571866
     
    18691878/*** Group Avatars *************************************************************/
    18701879
    1871 function groups_avatar_upload_dir( $group_id = false ) {
     1880function groups_avatar_upload_dir( $group_id = 0 ) {
    18721881    global $bp;
    18731882
     
    18751884        $group_id = $bp->groups->current_group->id;
    18761885
    1877     $path = BP_AVATAR_UPLOAD_PATH . '/group-avatars/' . $group_id;
     1886    $path    = BP_AVATAR_UPLOAD_PATH . '/group-avatars/' . $group_id;
    18781887    $newbdir = $path;
    18791888
     
    18811890        @wp_mkdir_p( $path );
    18821891
    1883     $newurl = BP_AVATAR_URL . '/group-avatars/' . $group_id;
    1884     $newburl = $newurl;
     1892    $newurl    = BP_AVATAR_URL . '/group-avatars/' . $group_id;
     1893    $newburl   = $newurl;
    18851894    $newsubdir = '/group-avatars/' . $group_id;
    18861895
     
    19241933
    19251934    $defaults = array(
    1926         'content' => false,
    1927         'user_id' => $bp->loggedin_user->id,
     1935        'content'  => false,
     1936        'user_id'  => $bp->loggedin_user->id,
    19281937        'group_id' => $bp->groups->current_group->id
    19291938    );
     
    19321941    extract( $r, EXTR_SKIP );
    19331942
    1934     if ( empty($content) || !strlen( trim( $content ) ) || empty($user_id) || empty($group_id) )
     1943    if ( empty( $content ) || !strlen( trim( $content ) ) || empty( $user_id ) || empty( $group_id ) )
    19351944        return false;
    19361945
    19371946    $bp->groups->current_group = new BP_Groups_Group( $group_id );
    19381947
    1939     /* Be sure the user is a member of the group before posting. */
     1948    // Be sure the user is a member of the group before posting.
    19401949    if ( !is_super_admin() && !groups_is_user_member( $user_id, $group_id ) )
    19411950        return false;
    19421951
    1943     /* Record this in activity streams */
    1944     $activity_action = sprintf( __( '%1$s posted an update in the group %2$s:', 'buddypress'), bp_core_get_userlink( $user_id ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . esc_attr( $bp->groups->current_group->name ) . '</a>' );
     1952    // Record this in activity streams
     1953    $activity_action  = sprintf( __( '%1$s posted an update in the group %2$s:', 'buddypress'), bp_core_get_userlink( $user_id ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . esc_attr( $bp->groups->current_group->name ) . '</a>' );
    19451954    $activity_content = $content;
    19461955
    19471956    $activity_id = groups_record_activity( array(
    19481957        'user_id' => $user_id,
    1949         'action' => apply_filters( 'groups_activity_new_update_action', $activity_action ),
     1958        'action'  => apply_filters( 'groups_activity_new_update_action',  $activity_action ),
    19501959        'content' => apply_filters( 'groups_activity_new_update_content', $activity_content ),
    1951         'type' => 'activity_update',
     1960        'type'    => 'activity_update',
    19521961        'item_id' => $group_id
    19531962    ) );
    19541963
    1955     /* Require the notifications code so email notifications can be set on the 'bp_activity_posted_update' action. */
     1964    // Require the notifications code so email notifications can be set on
     1965    // the 'bp_activity_posted_update' action.
    19561966    require_once( BP_PLUGIN_DIR . '/bp-groups/bp-groups-notifications.php' );
    19571967
     
    19641974/*** Group Forums **************************************************************/
    19651975
    1966 function groups_new_group_forum( $group_id = false, $group_name = false, $group_desc = false ) {
     1976function groups_new_group_forum( $group_id = 0, $group_name = '', $group_desc = '' ) {
    19671977    global $bp;
    19681978
     
    20082018
    20092019    $post_text = apply_filters( 'group_forum_post_text_before_save', $post_text );
    2010     $topic_id = apply_filters( 'group_forum_post_topic_id_before_save', $topic_id );
     2020    $topic_id  = apply_filters( 'group_forum_post_topic_id_before_save', $topic_id );
    20112021
    20122022    if ( $post_id = bp_forums_insert_post( array( 'post_text' => $post_text, 'topic_id' => $topic_id ) ) ) {
     
    20202030            $primary_link .= "?topic_page=" . $page;
    20212031
    2022         /* Record this in activity streams */
     2032        // Record this in activity streams
    20232033        groups_record_activity( array(
    2024             'action' => apply_filters( 'groups_activity_new_forum_post_action', $activity_action, $post_id, $post_text, &$topic ),
    2025             'content' => apply_filters( 'groups_activity_new_forum_post_content', $activity_content, $post_id, $post_text, &$topic ),
    2026             'primary_link' => apply_filters( 'groups_activity_new_forum_post_primary_link', "{$primary_link}#post-{$post_id}" ),
    2027             'type' => 'new_forum_post',
    2028             'item_id' => $bp->groups->current_group->id,
     2034            'action'            => apply_filters( 'groups_activity_new_forum_post_action', $activity_action, $post_id, $post_text, &$topic ),
     2035            'content'           => apply_filters( 'groups_activity_new_forum_post_content', $activity_content, $post_id, $post_text, &$topic ),
     2036            'primary_link'      => apply_filters( 'groups_activity_new_forum_post_primary_link', "{$primary_link}#post-{$post_id}" ),
     2037            'type'              => 'new_forum_post',
     2038            'item_id'           => $bp->groups->current_group->id,
    20292039            'secondary_item_id' => $post_id
    20302040        ) );
     
    20452055
    20462056    $topic_title = apply_filters( 'group_forum_topic_title_before_save', $topic_title );
    2047     $topic_text = apply_filters( 'group_forum_topic_text_before_save', $topic_text );
    2048     $topic_tags = apply_filters( 'group_forum_topic_tags_before_save', $topic_tags );
    2049     $forum_id = apply_filters( 'group_forum_topic_forum_id_before_save', $forum_id );
     2057    $topic_text  = apply_filters( 'group_forum_topic_text_before_save', $topic_text );
     2058    $topic_tags  = apply_filters( 'group_forum_topic_tags_before_save', $topic_tags );
     2059    $forum_id    = apply_filters( 'group_forum_topic_forum_id_before_save', $forum_id );
    20502060
    20512061    if ( $topic_id = bp_forums_new_topic( array( 'topic_title' => $topic_title, 'topic_text' => $topic_text, 'topic_tags' => $topic_tags, 'forum_id' => $forum_id ) ) ) {
     
    20552065        $activity_content = bp_create_excerpt( $topic_text );
    20562066
    2057         /* Record this in activity streams */
     2067        // Record this in activity streams
    20582068        groups_record_activity( array(
    2059             'action' => apply_filters( 'groups_activity_new_forum_topic_action', $activity_action, $topic_text, &$topic ),
    2060             'content' => apply_filters( 'groups_activity_new_forum_topic_content', $activity_content, $topic_text, &$topic ),
    2061             'primary_link' => apply_filters( 'groups_activity_new_forum_topic_primary_link', bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic->topic_slug . '/' ),
    2062             'type' => 'new_forum_topic',
    2063             'item_id' => $bp->groups->current_group->id,
     2069            'action'            => apply_filters( 'groups_activity_new_forum_topic_action', $activity_action, $topic_text, &$topic ),
     2070            'content'           => apply_filters( 'groups_activity_new_forum_topic_content', $activity_content, $topic_text, &$topic ),
     2071            'primary_link'      => apply_filters( 'groups_activity_new_forum_topic_primary_link', bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic->topic_slug . '/' ),
     2072            'type'              => 'new_forum_topic',
     2073            'item_id'           => $bp->groups->current_group->id,
    20642074            'secondary_item_id' => $topic->topic_id
    20652075        ) );
     
    20772087
    20782088    $topic_title = apply_filters( 'group_forum_topic_title_before_save', $topic_title );
    2079     $topic_text = apply_filters( 'group_forum_topic_text_before_save', $topic_text );
     2089    $topic_text  = apply_filters( 'group_forum_topic_text_before_save',  $topic_text );
    20802090
    20812091    if ( $topic = bp_forums_update_topic( array( 'topic_title' => $topic_title, 'topic_text' => $topic_text, 'topic_id' => $topic_id ) ) ) {
    2082         /* Update the activity stream item */
     2092        // Update the activity stream item
    20832093        if ( function_exists( 'bp_activity_delete_by_item_id' ) )
    20842094            bp_activity_delete_by_item_id( array( 'item_id' => $bp->groups->current_group->id, 'secondary_item_id' => $topic_id, 'component' => $bp->groups->id, 'type' => 'new_forum_topic' ) );
     
    20872097        $activity_content = bp_create_excerpt( $topic_text );
    20882098
    2089         /* Record this in activity streams */
     2099        // Record this in activity streams
    20902100        groups_record_activity( array(
    2091             'action' => apply_filters( 'groups_activity_new_forum_topic_action', $activity_action, $topic_text, &$topic ),
    2092             'content' => apply_filters( 'groups_activity_new_forum_topic_content', $activity_content, $topic_text, &$topic ),
    2093             'primary_link' => apply_filters( 'groups_activity_new_forum_topic_primary_link', bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic->topic_slug . '/' ),
    2094             'type' => 'new_forum_topic',
    2095             'item_id' => (int)$bp->groups->current_group->id,
    2096             'user_id' => (int)$topic->topic_poster,
     2101            'action'            => apply_filters( 'groups_activity_new_forum_topic_action', $activity_action, $topic_text, &$topic ),
     2102            'content'           => apply_filters( 'groups_activity_new_forum_topic_content', $activity_content, $topic_text, &$topic ),
     2103            'primary_link'      => apply_filters( 'groups_activity_new_forum_topic_primary_link', bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic->topic_slug . '/' ),
     2104            'type'              => 'new_forum_topic',
     2105            'item_id'           => (int)$bp->groups->current_group->id,
     2106            'user_id'           => (int)$topic->topic_poster,
    20972107            'secondary_item_id' => $topic->topic_id,
    2098             'recorded_time' => $topic->topic_time
     2108            'recorded_time '    => $topic->topic_time
    20992109        ) );
    21002110
     
    21112121
    21122122    $post_text = apply_filters( 'group_forum_post_text_before_save', $post_text );
    2113     $topic_id = apply_filters( 'group_forum_post_topic_id_before_save', $topic_id );
    2114 
    2115     $post = bp_forums_get_post( $post_id );
     2123    $topic_id  = apply_filters( 'group_forum_post_topic_id_before_save', $topic_id );
     2124    $post      = bp_forums_get_post( $post_id );
    21162125
    21172126    if ( $post_id = bp_forums_insert_post( array( 'post_id' => $post_id, 'post_text' => $post_text, 'post_time' => $post->post_time, 'topic_id' => $topic_id, 'poster_id' => $post->poster_id ) ) ) {
     
    21252134            $primary_link .= "?topic_page=" . $page;
    21262135
    2127         /* Fetch an existing entry and update if one exists. */
     2136        // Fetch an existing entry and update if one exists.
    21282137        if ( function_exists( 'bp_activity_get_activity_id' ) )
    21292138            $id = bp_activity_get_activity_id( array( 'user_id' => $post->poster_id, 'component' => $bp->groups->id, 'type' => 'new_forum_post', 'item_id' => $bp->groups->current_group->id, 'secondary_item_id' => $post_id ) );
    21302139
    2131         /* Update the entry in activity streams */
     2140        // Update the entry in activity streams
    21322141        groups_record_activity( array(
    2133             'id' => $id,
    2134             'action' => apply_filters( 'groups_activity_new_forum_post_action', $activity_action, $post_text, &$topic, &$forum_post ),
    2135             'content' => apply_filters( 'groups_activity_new_forum_post_content', $activity_content, $post_text, &$topic, &$forum_post ),
    2136             'primary_link' => apply_filters( 'groups_activity_new_forum_post_primary_link', $primary_link . "#post-" . $post_id ),
    2137             'type' => 'new_forum_post',
    2138             'item_id' => (int)$bp->groups->current_group->id,
    2139             'user_id' => (int)$post->poster_id,
     2142            'id'                => $id,
     2143            'action'            => apply_filters( 'groups_activity_new_forum_post_action', $activity_action, $post_text, &$topic, &$forum_post ),
     2144            'content'           => apply_filters( 'groups_activity_new_forum_post_content', $activity_content, $post_text, &$topic, &$forum_post ),
     2145            'primary_link'      => apply_filters( 'groups_activity_new_forum_post_primary_link', $primary_link . "#post-" . $post_id ),
     2146            'type'              => 'new_forum_post',
     2147            'item_id'           => (int)$bp->groups->current_group->id,
     2148            'user_id'           => (int)$post->poster_id,
    21402149            'secondary_item_id' => $post_id,
    2141             'recorded_time' => $post->post_time
     2150            'recorded_time'     => $post->post_time
    21422151        ) );
    21432152
     
    21562165        do_action( 'groups_before_delete_group_forum_topic', $topic_id );
    21572166
    2158         /* Delete the activity stream item */
    2159         if ( function_exists( 'bp_activity_delete' ) ) {
     2167        // Delete the activity stream item
     2168        if ( function_exists( 'bp_activity_delete' ) )
    21602169            bp_activity_delete( array( 'item_id' => $bp->groups->current_group->id, 'secondary_item_id' => $topic_id, 'component' => $bp->groups->id, 'type' => 'new_forum_topic' ) );
    2161         }
    21622170
    21632171        do_action( 'groups_delete_group_forum_topic', $topic_id );
     
    21752183        do_action( 'groups_before_delete_group_forum_post', $post_id, $topic_id );
    21762184
    2177         /* Delete the activity stream item */
    2178         if ( function_exists( 'bp_activity_delete' ) ) {
     2185        // Delete the activity stream item
     2186        if ( function_exists( 'bp_activity_delete' ) )
    21792187            bp_activity_delete( array( 'item_id' => $bp->groups->current_group->id, 'secondary_item_id' => $post_id, 'component' => $bp->groups->id, 'type' => 'new_forum_post' ) );
    2180         }
    21812188
    21822189        do_action( 'groups_delete_group_forum_post', $post_id, $topic_id );
     
    22082215
    22092216    $defaults = array(
    2210         'user_id' => false,
    2211         'group_id' => false,
    2212         'inviter_id' => $bp->loggedin_user->id,
     2217        'user_id'       => false,
     2218        'group_id'      => false,
     2219        'inviter_id'    => $bp->loggedin_user->id,
    22132220        'date_modified' => bp_core_current_time(),
    2214         'is_confirmed' => 0
     2221        'is_confirmed'  => 0
    22152222    );
    22162223
     
    22222229
    22232230    if ( !groups_is_user_member( $user_id, $group_id ) && !groups_check_user_has_invite( $user_id, $group_id ) ) {
    2224         $invite = new BP_Groups_Member;
    2225         $invite->group_id = $group_id;
    2226         $invite->user_id = $user_id;
     2231        $invite                = new BP_Groups_Member;
     2232        $invite->group_id      = $group_id;
     2233        $invite->user_id       = $user_id;
    22272234        $invite->date_modified = $date_modified;
    2228         $invite->inviter_id = $inviter_id;
    2229         $invite->is_confirmed = $is_confirmed;
     2235        $invite->inviter_id    = $inviter_id;
     2236        $invite->is_confirmed  = $is_confirmed;
    22302237
    22312238        if ( !$invite->save() )
     
    22612268        return false;
    22622269
    2263     /* Remove request to join */
     2270    // Remove request to join
    22642271    if ( $member->check_for_membership_request( $user_id, $group_id ) )
    22652272        $member->delete_request( $user_id, $group_id );
    22662273
    2267     /* Modify group meta */
     2274    // Modify group meta
    22682275    groups_update_groupmeta( $group_id, 'total_member_count', (int) groups_get_groupmeta( $group_id, 'total_member_count') + 1 );
    22692276    groups_update_groupmeta( $group_id, 'last_activity', bp_core_current_time() );
     
    24032410    global $bp;
    24042411
    2405     /* Prevent duplicate requests */
     2412    // Prevent duplicate requests
    24062413    if ( groups_check_for_membership_request( $requesting_user_id, $group_id ) )
    24072414        return false;
    24082415
    2409     /* Check if the user is already a member or is banned */
     2416    // Check if the user is already a member or is banned
    24102417    if ( groups_is_user_member( $requesting_user_id, $group_id ) || groups_is_user_banned( $requesting_user_id, $group_id ) )
    24112418        return false;
    24122419
    2413     $requesting_user = new BP_Groups_Member;
    2414     $requesting_user->group_id = $group_id;
    2415     $requesting_user->user_id = $requesting_user_id;
    2416     $requesting_user->inviter_id = 0;
    2417     $requesting_user->is_admin = 0;
    2418     $requesting_user->user_title = '';
     2420    $requesting_user                = new BP_Groups_Member;
     2421    $requesting_user->group_id      = $group_id;
     2422    $requesting_user->user_id       = $requesting_user_id;
     2423    $requesting_user->inviter_id    = 0;
     2424    $requesting_user->is_admin      = 0;
     2425    $requesting_user->user_title    = '';
    24192426    $requesting_user->date_modified = bp_core_current_time();
    2420     $requesting_user->is_confirmed = 0;
    2421     $requesting_user->comments = $_POST['group-request-membership-comments'];
     2427    $requesting_user->is_confirmed  = 0;
     2428    $requesting_user->comments      = $_POST['group-request-membership-comments'];
    24222429
    24232430    if ( $requesting_user->save() ) {
     
    24262433        require_once ( BP_PLUGIN_DIR . '/bp-groups/bp-groups-notifications.php' );
    24272434
    2428         for ( $i = 0; $i < count( $admins ); $i++ ) {
    2429             // Saved okay, now send the email notification
     2435        // Saved okay, now send the email notification
     2436        for ( $i = 0; $i < count( $admins ); $i++ )
    24302437            groups_notification_new_membership_request( $requesting_user_id, $admins[$i]->user_id, $group_id, $requesting_user->id );
    2431         }
    24322438
    24332439        do_action( 'groups_membership_requested', $requesting_user_id, $admins, $group_id, $requesting_user->id );
     
    24522458        return false;
    24532459
    2454     /* Check if the user has an outstanding invite, if so delete it. */
     2460    // Check if the user has an outstanding invite, if so delete it.
    24552461    if ( groups_check_user_has_invite( $membership->user_id, $membership->group_id ) )
    24562462        groups_delete_invite( $membership->user_id, $membership->group_id );
    24572463
    2458     /* Modify group member count */
     2464    // Modify group member count
    24592465    groups_update_groupmeta( $membership->group_id, 'total_member_count', (int) groups_get_groupmeta( $membership->group_id, 'total_member_count') + 1 );
    24602466
    2461     /* Record this in activity streams */
     2467    // Record this in activity streams
    24622468    $group = new BP_Groups_Group( $membership->group_id );
    24632469
    24642470    groups_record_activity( array(
    2465         'action'    => apply_filters( 'groups_activity_membership_accepted_action', sprintf( __( '%1$s joined the group %2$s', 'buddypress'), bp_core_get_userlink( $membership->user_id ), '<a href="' . bp_get_group_permalink( $group ) . '">' . esc_attr( $group->name ) . '</a>' ), $membership->user_id, &$group ),
    2466         'type'      => 'joined_group',
    2467         'item_id'   => $membership->group_id,
    2468         'user_id'   => $membership->user_id
     2471        'action'  => apply_filters( 'groups_activity_membership_accepted_action', sprintf( __( '%1$s joined the group %2$s', 'buddypress'), bp_core_get_userlink( $membership->user_id ), '<a href="' . bp_get_group_permalink( $group ) . '">' . esc_attr( $group->name ) . '</a>' ), $membership->user_id, &$group ),
     2472        'type'    => 'joined_group',
     2473        'item_id' => $membership->group_id,
     2474        'user_id' => $membership->user_id
    24692475    ) );
    24702476
    2471     /* Send a notification to the user. */
     2477    // Send a notification to the user.
    24722478    require_once ( BP_PLUGIN_DIR . '/bp-groups/bp-groups-notifications.php' );
    24732479    groups_notification_membership_request_completed( $membership->user_id, $membership->group_id, true );
     
    25132519        return false;
    25142520
    2515     foreach ( (array) $user_ids as $user_id ) {
     2521    foreach ( (array) $user_ids as $user_id )
    25162522        groups_accept_membership_request( false, $user_id, $group_id );
    2517     }
    25182523
    25192524    do_action( 'groups_accept_all_pending_membership_requests', $group_id );
     
    25302535        return false;
    25312536
    2532     $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key);
    2533 
    2534     if ( is_array($meta_value) || is_object($meta_value) )
     2537    $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
     2538
     2539    if ( is_array( $meta_value ) || is_object( $meta_value ) )
    25352540        $meta_value = serialize($meta_value);
    25362541
    25372542    $meta_value = trim( $meta_value );
    25382543
    2539     if ( !$meta_key ) {
     2544    if ( !$meta_key )
    25402545        $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp->groups->table_name_groupmeta . " WHERE group_id = %d", $group_id ) );
    2541     } else if ( $meta_value ) {
     2546    else if ( $meta_value )
    25422547        $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp->groups->table_name_groupmeta . " WHERE group_id = %d AND meta_key = %s AND meta_value = %s", $group_id, $meta_key, $meta_value ) );
    2543     } else {
     2548    else
    25442549        $wpdb->query( $wpdb->prepare( "DELETE FROM " . $bp->groups->table_name_groupmeta . " WHERE group_id = %d AND meta_key = %s", $group_id, $meta_key ) );
    2545     }
    2546 
    2547     /* Delete the cached object */
     2550
     2551    // Delete the cached object
    25482552    wp_cache_delete( 'bp_groups_groupmeta_' . $group_id . '_' . $meta_key, 'bp' );
    25492553
     
    25602564
    25612565    if ( !empty($meta_key) ) {
    2562         $meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key);
     2566        $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
    25632567
    25642568        if ( !$metas = wp_cache_get( 'bp_groups_groupmeta_' . $group_id . '_' . $meta_key, 'bp' ) ) {
     
    25702574    }
    25712575
    2572     if ( empty($metas) ) {
    2573         if ( empty($meta_key) )
     2576    if ( empty( $metas ) ) {
     2577        if ( empty( $meta_key ) )
    25742578            return array();
    25752579        else
     
    25772581    }
    25782582
    2579     $metas = array_map('maybe_unserialize', (array)$metas);
    2580 
    2581     if ( 1 == count($metas) )
     2583    $metas = array_map( 'maybe_unserialize', (array)$metas );
     2584
     2585    if ( 1 == count( $metas ) )
    25822586        return $metas[0];
    25832587    else
     
    25932597    $meta_key = preg_replace( '|[^a-z0-9_]|i', '', $meta_key );
    25942598
    2595     if ( is_string($meta_value) )
    2596         $meta_value = stripslashes($wpdb->escape($meta_value));
    2597 
    2598     $meta_value = maybe_serialize($meta_value);
    2599 
    2600     if (empty($meta_value)) {
     2599    if ( is_string( $meta_value ) )
     2600        $meta_value = stripslashes( $wpdb->escape( $meta_value ) );
     2601
     2602    $meta_value = maybe_serialize( $meta_value );
     2603
     2604    if ( empty( $meta_value ) )
    26012605        return groups_delete_groupmeta( $group_id, $meta_key );
    2602     }
    26032606
    26042607    $cur = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM " . $bp->groups->table_name_groupmeta . " WHERE group_id = %d AND meta_key = %s", $group_id, $meta_key ) );
    26052608
    2606     if ( !$cur ) {
     2609    if ( !$cur )
    26072610        $wpdb->query( $wpdb->prepare( "INSERT INTO " . $bp->groups->table_name_groupmeta . " ( group_id, meta_key, meta_value ) VALUES ( %d, %s, %s )", $group_id, $meta_key, $meta_value ) );
    2608     } else if ( $cur->meta_value != $meta_value ) {
     2611    else if ( $cur->meta_value != $meta_value )
    26092612        $wpdb->query( $wpdb->prepare( "UPDATE " . $bp->groups->table_name_groupmeta . " SET meta_value = %s WHERE group_id = %d AND meta_key = %s", $meta_value, $group_id, $meta_key ) );
    2610     } else {
    2611         return false;
    2612     }
    2613 
    2614     /* Update the cached object and recache */
     2613    else
     2614        return false;
     2615
     2616    // Update the cached object and recache
    26152617    wp_cache_set( 'bp_groups_groupmeta_' . $group_id . '_' . $meta_key, $meta_value, 'bp' );
    26162618
     
    26212623
    26222624function groups_remove_data_for_user( $user_id ) {
    2623     BP_Groups_Member::delete_all_for_user($user_id);
     2625    BP_Groups_Member::delete_all_for_user( $user_id );
    26242626
    26252627    do_action( 'groups_remove_data_for_user', $user_id );
    26262628}
    2627 add_action( 'wpmu_delete_user', 'groups_remove_data_for_user' );
    2628 add_action( 'delete_user', 'groups_remove_data_for_user' );
     2629add_action( 'wpmu_delete_user',  'groups_remove_data_for_user' );
     2630add_action( 'delete_user',       'groups_remove_data_for_user' );
    26292631add_action( 'bp_make_spam_user', 'groups_remove_data_for_user' );
    26302632
     
    26402642    wp_cache_delete( 'bp_total_group_count', 'bp' );
    26412643}
    2642 add_action( 'groups_group_deleted', 'groups_clear_group_object_cache' );
    2643 add_action( 'groups_settings_updated', 'groups_clear_group_object_cache' );
    2644 add_action( 'groups_details_updated', 'groups_clear_group_object_cache' );
    2645 add_action( 'groups_group_avatar_updated', 'groups_clear_group_object_cache' );
     2644add_action( 'groups_group_deleted',              'groups_clear_group_object_cache' );
     2645add_action( 'groups_settings_updated',           'groups_clear_group_object_cache' );
     2646add_action( 'groups_details_updated',            'groups_clear_group_object_cache' );
     2647add_action( 'groups_group_avatar_updated',       'groups_clear_group_object_cache' );
    26462648add_action( 'groups_create_group_step_complete', 'groups_clear_group_object_cache' );
    26472649
     
    26492651    wp_cache_delete( 'bp_total_groups_for_user_' . $user_id );
    26502652}
    2651 add_action( 'groups_join_group', 'groups_clear_group_user_object_cache', 10, 2 );
    2652 add_action( 'groups_leave_group', 'groups_clear_group_user_object_cache', 10, 2 );
    2653 add_action( 'groups_ban_member', 'groups_clear_group_user_object_cache', 10, 2 );
     2653add_action( 'groups_join_group',   'groups_clear_group_user_object_cache', 10, 2 );
     2654add_action( 'groups_leave_group',  'groups_clear_group_user_object_cache', 10, 2 );
     2655add_action( 'groups_ban_member',   'groups_clear_group_user_object_cache', 10, 2 );
    26542656add_action( 'groups_unban_member', 'groups_clear_group_user_object_cache', 10, 2 );
    26552657
    26562658/* List actions to clear super cached pages on, if super cache is installed */
    2657 add_action( 'groups_join_group', 'bp_core_clear_cache' );
    2658 add_action( 'groups_leave_group', 'bp_core_clear_cache' );
    2659 add_action( 'groups_accept_invite', 'bp_core_clear_cache' );
    2660 add_action( 'groups_reject_invite', 'bp_core_clear_cache' );
    2661 add_action( 'groups_invite_user', 'bp_core_clear_cache' );
    2662 add_action( 'groups_uninvite_user', 'bp_core_clear_cache' );
    2663 add_action( 'groups_details_updated', 'bp_core_clear_cache' );
    2664 add_action( 'groups_settings_updated', 'bp_core_clear_cache' );
    2665 add_action( 'groups_unban_member', 'bp_core_clear_cache' );
    2666 add_action( 'groups_ban_member', 'bp_core_clear_cache' );
    2667 add_action( 'groups_demote_member', 'bp_core_clear_cache' );
    2668 add_action( 'groups_premote_member', 'bp_core_clear_cache' );
    2669 add_action( 'groups_membership_rejected', 'bp_core_clear_cache' );
    2670 add_action( 'groups_membership_accepted', 'bp_core_clear_cache' );
    2671 add_action( 'groups_membership_requested', 'bp_core_clear_cache' );
     2659add_action( 'groups_join_group',                 'bp_core_clear_cache' );
     2660add_action( 'groups_leave_group',                'bp_core_clear_cache' );
     2661add_action( 'groups_accept_invite',              'bp_core_clear_cache' );
     2662add_action( 'groups_reject_invite',              'bp_core_clear_cache' );
     2663add_action( 'groups_invite_user',                'bp_core_clear_cache' );
     2664add_action( 'groups_uninvite_user',              'bp_core_clear_cache' );
     2665add_action( 'groups_details_updated',            'bp_core_clear_cache' );
     2666add_action( 'groups_settings_updated',           'bp_core_clear_cache' );
     2667add_action( 'groups_unban_member',               'bp_core_clear_cache' );
     2668add_action( 'groups_ban_member',                 'bp_core_clear_cache' );
     2669add_action( 'groups_demote_member',              'bp_core_clear_cache' );
     2670add_action( 'groups_premote_member',             'bp_core_clear_cache' );
     2671add_action( 'groups_membership_rejected',        'bp_core_clear_cache' );
     2672add_action( 'groups_membership_accepted',        'bp_core_clear_cache' );
     2673add_action( 'groups_membership_requested',       'bp_core_clear_cache' );
    26722674add_action( 'groups_create_group_step_complete', 'bp_core_clear_cache' );
    2673 add_action( 'groups_created_group', 'bp_core_clear_cache' );
    2674 add_action( 'groups_group_avatar_updated', 'bp_core_clear_cache' );
     2675add_action( 'groups_created_group',              'bp_core_clear_cache' );
     2676add_action( 'groups_group_avatar_updated',       'bp_core_clear_cache' );
    26752677
    26762678?>
Note: See TracChangeset for help on using the changeset viewer.