Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/05/2016 04:55:58 AM (9 years ago)
Author:
boonebgorges
Message:

Move bp-groups classes to their own files.

See #6870.

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/classes/class-bp-groups-theme-compat.php

    r10515 r10520  
    11<?php
    22/**
    3  * BuddyPress Groups Screen Functions
    4  *
    5  * Screen functions are the controllers of BuddyPress. They will execute when
    6  * their specific URL is caught. They will first save or manipulate data using
    7  * business functions, then pass on the user to a template file.
     3 * BuddyPress Groups Theme Compat.
    84 *
    95 * @package BuddyPress
    10  * @subpackage GroupsScreens
    11  * @since 1.5.0
     6 * @since 1.7.0
    127 */
    138
    149// Exit if accessed directly.
    1510defined( 'ABSPATH' ) || exit;
    16 
    17 /**
    18  * Handle the display of the Groups directory index.
    19  *
    20  * @since 1.0.0
    21  */
    22 function groups_directory_groups_setup() {
    23     if ( bp_is_groups_directory() ) {
    24         bp_update_is_directory( true, 'groups' );
    25 
    26         /**
    27          * Fires before the loading of the Groups directory index.
    28          *
    29          * @since 1.1.0
    30          */
    31         do_action( 'groups_directory_groups_setup' );
    32 
    33         /**
    34          * Filters the template to load for the Groups directory index.
    35          *
    36          * @since 1.0.0
    37          *
    38          * @param string $value Path to the groups directory index template to load.
    39          */
    40         bp_core_load_template( apply_filters( 'groups_template_directory_groups', 'groups/index' ) );
    41     }
    42 }
    43 add_action( 'bp_screens', 'groups_directory_groups_setup', 2 );
    44 
    45 /**
    46  * Handle the loading of the My Groups page.
    47  *
    48  * @since 1.0.0
    49  */
    50 function groups_screen_my_groups() {
    51 
    52     /**
    53      * Fires before the loading of the My Groups page.
    54      *
    55      * @since 1.1.0
    56      */
    57     do_action( 'groups_screen_my_groups' );
    58 
    59     /**
    60      * Filters the template to load for the My Groups page.
    61      *
    62      * @since 1.0.0
    63      *
    64      * @param string $value Path to the My Groups page template to load.
    65      */
    66     bp_core_load_template( apply_filters( 'groups_template_my_groups', 'members/single/home' ) );
    67 }
    68 
    69 /**
    70  * Handle the loading of a user's Groups > Invites page.
    71  *
    72  * @since 1.0.0
    73  */
    74 function groups_screen_group_invites() {
    75     $group_id = (int)bp_action_variable( 1 );
    76 
    77     if ( bp_is_action_variable( 'accept' ) && is_numeric( $group_id ) ) {
    78         // Check the nonce.
    79         if ( !check_admin_referer( 'groups_accept_invite' ) )
    80             return false;
    81 
    82         if ( !groups_accept_invite( bp_loggedin_user_id(), $group_id ) ) {
    83             bp_core_add_message( __('Group invite could not be accepted', 'buddypress'), 'error' );
    84         } else {
    85             bp_core_add_message( __('Group invite accepted', 'buddypress') );
    86 
    87             // Record this in activity streams.
    88             $group = groups_get_group( array( 'group_id' => $group_id ) );
    89 
    90             groups_record_activity( array(
    91                 'type'    => 'joined_group',
    92                 'item_id' => $group->id
    93             ) );
    94         }
    95 
    96         if ( isset( $_GET['redirect_to'] ) ) {
    97             $redirect_to = urldecode( $_GET['redirect_to'] );
    98         } else {
    99             $redirect_to = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() . '/' . bp_current_action() );
    100         }
    101 
    102         bp_core_redirect( $redirect_to );
    103 
    104     } elseif ( bp_is_action_variable( 'reject' ) && is_numeric( $group_id ) ) {
    105         // Check the nonce.
    106         if ( !check_admin_referer( 'groups_reject_invite' ) )
    107             return false;
    108 
    109         if ( !groups_reject_invite( bp_loggedin_user_id(), $group_id ) ) {
    110             bp_core_add_message( __( 'Group invite could not be rejected', 'buddypress' ), 'error' );
    111         } else {
    112             bp_core_add_message( __( 'Group invite rejected', 'buddypress' ) );
    113         }
    114 
    115         if ( isset( $_GET['redirect_to'] ) ) {
    116             $redirect_to = urldecode( $_GET['redirect_to'] );
    117         } else {
    118             $redirect_to = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() . '/' . bp_current_action() );
    119         }
    120 
    121         bp_core_redirect( $redirect_to );
    122     }
    123 
    124     /**
    125      * Fires before the loading of a users Groups > Invites template.
    126      *
    127      * @since 1.0.0
    128      *
    129      * @param int $group_id ID of the group being displayed
    130      */
    131     do_action( 'groups_screen_group_invites', $group_id );
    132 
    133     /**
    134      * Filters the template to load for a users Groups > Invites page.
    135      *
    136      * @since 1.0.0
    137      *
    138      * @param string $value Path to a users Groups > Invites page template.
    139      */
    140     bp_core_load_template( apply_filters( 'groups_template_group_invites', 'members/single/home' ) );
    141 }
    142 
    143 /**
    144  * Handle the loading of a single group's page.
    145  *
    146  * @since 1.0.0
    147  */
    148 function groups_screen_group_home() {
    149 
    150     if ( ! bp_is_single_item() ) {
    151         return false;
    152     }
    153 
    154     /**
    155      * Fires before the loading of a single group's page.
    156      *
    157      * @since 1.0.0
    158      */
    159     do_action( 'groups_screen_group_home' );
    160 
    161     /**
    162      * Filters the template to load for a single group's page.
    163      *
    164      * @since 1.0.0
    165      *
    166      * @param string $value Path to a single group's template to load.
    167      */
    168     bp_core_load_template( apply_filters( 'groups_template_group_home', 'groups/single/home' ) );
    169 }
    170 
    171 /**
    172  * This screen function handles actions related to group forums.
    173  *
    174  * @since 1.0.0
    175  */
    176 function groups_screen_group_forum() {
    177 
    178     if ( !bp_is_active( 'forums' ) || !bp_forums_is_installed_correctly() )
    179         return false;
    180 
    181     if ( bp_action_variable( 0 ) && !bp_is_action_variable( 'topic', 0 ) ) {
    182         bp_do_404();
    183         return;
    184     }
    185 
    186     $bp = buddypress();
    187 
    188     if ( !$bp->groups->current_group->user_has_access ) {
    189         bp_core_no_access();
    190         return;
    191     }
    192 
    193     if ( ! bp_is_single_item() )
    194         return false;
    195 
    196     // Fetch the details we need.
    197     $topic_slug = (string)bp_action_variable( 1 );
    198     $topic_id       = bp_forums_get_topic_id_from_slug( $topic_slug );
    199     $forum_id       = groups_get_groupmeta( $bp->groups->current_group->id, 'forum_id' );
    200     $user_is_banned = false;
    201 
    202     if ( !bp_current_user_can( 'bp_moderate' ) && groups_is_user_banned( bp_loggedin_user_id(), $bp->groups->current_group->id ) )
    203         $user_is_banned = true;
    204 
    205     if ( !empty( $topic_slug ) && !empty( $topic_id ) ) {
    206 
    207         // Posting a reply.
    208         if ( !$user_is_banned && !bp_action_variable( 2 ) && isset( $_POST['submit_reply'] ) ) {
    209             // Check the nonce.
    210             check_admin_referer( 'bp_forums_new_reply' );
    211 
    212             // Auto join this user if they are not yet a member of this group.
    213             if ( bp_groups_auto_join() && !bp_current_user_can( 'bp_moderate' ) && 'public' == $bp->groups->current_group->status && !groups_is_user_member( bp_loggedin_user_id(), $bp->groups->current_group->id ) ) {
    214                 groups_join_group( $bp->groups->current_group->id, bp_loggedin_user_id() );
    215             }
    216 
    217             $topic_page = isset( $_GET['topic_page'] ) ? $_GET['topic_page'] : false;
    218 
    219             // Don't allow reply flooding.
    220             if ( bp_forums_reply_exists( $_POST['reply_text'], $topic_id, bp_loggedin_user_id() ) ) {
    221                 bp_core_add_message( __( 'It looks like you\'ve already said that!', 'buddypress' ), 'error' );
    222             } else {
    223                 if ( !$post_id = groups_new_group_forum_post( $_POST['reply_text'], $topic_id, $topic_page ) ) {
    224                     bp_core_add_message( __( 'There was an error when replying to that topic', 'buddypress'), 'error' );
    225                 } else {
    226                     bp_core_add_message( __( 'Your reply was posted successfully', 'buddypress') );
    227                 }
    228             }
    229 
    230             $query_vars = isset( $_SERVER['QUERY_STRING'] ) ? '?' . $_SERVER['QUERY_STRING'] : '';
    231 
    232             $redirect = bp_get_group_permalink( groups_get_current_group() ) . 'forum/topic/' . $topic_slug . '/' . $query_vars;
    233 
    234             if ( !empty( $post_id ) ) {
    235                 $redirect .= '#post-' . $post_id;
    236             }
    237 
    238             bp_core_redirect( $redirect );
    239         }
    240 
    241         // Sticky a topic.
    242         elseif ( bp_is_action_variable( 'stick', 2 ) && ( bp_is_item_admin() || bp_is_item_mod() ) ) {
    243             // Check the nonce.
    244             check_admin_referer( 'bp_forums_stick_topic' );
    245 
    246             if ( !bp_forums_sticky_topic( array( 'topic_id' => $topic_id ) ) ) {
    247                 bp_core_add_message( __( 'There was an error when making that topic a sticky', 'buddypress' ), 'error' );
    248             } else {
    249                 bp_core_add_message( __( 'The topic was made sticky successfully', 'buddypress' ) );
    250             }
    251 
    252             /**
    253              * Fires after a group forum topic has been stickied.
    254              *
    255              * @since 1.1.0
    256              *
    257              * @param int $topic_id ID of the topic being stickied.
    258              */
    259             do_action( 'groups_stick_forum_topic', $topic_id );
    260             bp_core_redirect( wp_get_referer() );
    261         }
    262 
    263         // Un-Sticky a topic.
    264         elseif ( bp_is_action_variable( 'unstick', 2 ) && ( bp_is_item_admin() || bp_is_item_mod() ) ) {
    265             // Check the nonce.
    266             check_admin_referer( 'bp_forums_unstick_topic' );
    267 
    268             if ( !bp_forums_sticky_topic( array( 'topic_id' => $topic_id, 'mode' => 'unstick' ) ) ) {
    269                 bp_core_add_message( __( 'There was an error when unsticking that topic', 'buddypress'), 'error' );
    270             } else {
    271                 bp_core_add_message( __( 'The topic was unstuck successfully', 'buddypress') );
    272             }
    273 
    274             /**
    275              * Fires after a group forum topic has been un-stickied.
    276              *
    277              * @since 1.1.0
    278              *
    279              * @param int $topic_id ID of the topic being un-stickied.
    280              */
    281             do_action( 'groups_unstick_forum_topic', $topic_id );
    282             bp_core_redirect( wp_get_referer() );
    283         }
    284 
    285         // Close a topic.
    286         elseif ( bp_is_action_variable( 'close', 2 ) && ( bp_is_item_admin() || bp_is_item_mod() ) ) {
    287             // Check the nonce.
    288             check_admin_referer( 'bp_forums_close_topic' );
    289 
    290             if ( !bp_forums_openclose_topic( array( 'topic_id' => $topic_id ) ) ) {
    291                 bp_core_add_message( __( 'There was an error when closing that topic', 'buddypress'), 'error' );
    292             } else {
    293                 bp_core_add_message( __( 'The topic was closed successfully', 'buddypress') );
    294             }
    295 
    296             /**
    297              * Fires after a group forum topic has been closed.
    298              *
    299              * @since 1.1.0
    300              *
    301              * @param int $topic_id ID of the topic being closed.
    302              */
    303             do_action( 'groups_close_forum_topic', $topic_id );
    304             bp_core_redirect( wp_get_referer() );
    305         }
    306 
    307         // Open a topic.
    308         elseif ( bp_is_action_variable( 'open', 2 ) && ( bp_is_item_admin() || bp_is_item_mod() ) ) {
    309             // Check the nonce.
    310             check_admin_referer( 'bp_forums_open_topic' );
    311 
    312             if ( !bp_forums_openclose_topic( array( 'topic_id' => $topic_id, 'mode' => 'open' ) ) ) {
    313                 bp_core_add_message( __( 'There was an error when opening that topic', 'buddypress'), 'error' );
    314             } else {
    315                 bp_core_add_message( __( 'The topic was opened successfully', 'buddypress') );
    316             }
    317 
    318             /**
    319              * Fires after a group forum topic has been opened.
    320              *
    321              * @since 1.1.0
    322              *
    323              * @param int $topic_id ID of the topic being opened.
    324              */
    325             do_action( 'groups_open_forum_topic', $topic_id );
    326             bp_core_redirect( wp_get_referer() );
    327         }
    328 
    329         // Delete a topic.
    330         elseif ( empty( $user_is_banned ) && bp_is_action_variable( 'delete', 2 ) && !bp_action_variable( 3 ) ) {
    331             // Fetch the topic.
    332             $topic = bp_forums_get_topic_details( $topic_id );
    333 
    334             /* Check the logged in user can delete this topic */
    335             if ( ! bp_is_item_admin() && ! bp_is_item_mod() && ( (int) bp_loggedin_user_id() != (int) $topic->topic_poster ) ) {
    336                 bp_core_redirect( wp_get_referer() );
    337             }
    338 
    339             // Check the nonce.
    340             check_admin_referer( 'bp_forums_delete_topic' );
    341 
    342             /**
    343              * Fires before a group forum topic is deleted.
    344              *
    345              * @since 1.5.0
    346              *
    347              * @param int $topic_id ID of the topic being deleted.
    348              */
    349             do_action( 'groups_before_delete_forum_topic', $topic_id );
    350 
    351             if ( !groups_delete_group_forum_topic( $topic_id ) ) {
    352                 bp_core_add_message( __( 'There was an error deleting the topic', 'buddypress' ), 'error' );
    353             } else {
    354                 bp_core_add_message( __( 'The topic was deleted successfully', 'buddypress' ) );
    355             }
    356 
    357             /**
    358              * Fires after a group forum topic has been deleted.
    359              *
    360              * @since 1.5.0
    361              *
    362              * @param int $topic_id ID of the topic being deleted.
    363              */
    364             do_action( 'groups_delete_forum_topic', $topic_id );
    365             bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'forum/' );
    366         }
    367 
    368         // Editing a topic.
    369         elseif ( empty( $user_is_banned ) && bp_is_action_variable( 'edit', 2 ) && !bp_action_variable( 3 ) ) {
    370             // Fetch the topic.
    371             $topic = bp_forums_get_topic_details( $topic_id );
    372 
    373             // Check the logged in user can edit this topic.
    374             if ( ! bp_is_item_admin() && ! bp_is_item_mod() && ( (int) bp_loggedin_user_id() != (int) $topic->topic_poster ) ) {
    375                 bp_core_redirect( wp_get_referer() );
    376             }
    377 
    378             if ( isset( $_POST['save_changes'] ) ) {
    379                 // Check the nonce.
    380                 check_admin_referer( 'bp_forums_edit_topic' );
    381 
    382                 $topic_tags = !empty( $_POST['topic_tags'] ) ? $_POST['topic_tags'] : false;
    383 
    384                 if ( !groups_update_group_forum_topic( $topic_id, $_POST['topic_title'], $_POST['topic_text'], $topic_tags ) ) {
    385                     bp_core_add_message( __( 'There was an error when editing that topic', 'buddypress'), 'error' );
    386                 } else {
    387                     bp_core_add_message( __( 'The topic was edited successfully', 'buddypress') );
    388                 }
    389 
    390                 /**
    391                  * Fires after a group forum topic has been edited.
    392                  *
    393                  * @since 1.1.0
    394                  *
    395                  * @param int $topic_id ID of the topic being edited.
    396                  */
    397                 do_action( 'groups_edit_forum_topic', $topic_id );
    398                 bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'forum/topic/' . $topic_slug . '/' );
    399             }
    400 
    401             /**
    402              * Filters the template to load for a topic edit page.
    403              *
    404              * @since 1.1.0
    405              *
    406              * @param string $value Path to a topic edit template.
    407              */
    408             bp_core_load_template( apply_filters( 'groups_template_group_forum_topic_edit', 'groups/single/home' ) );
    409 
    410         // Delete a post.
    411         } elseif ( empty( $user_is_banned ) && bp_is_action_variable( 'delete', 2 ) && $post_id = bp_action_variable( 4 ) ) {
    412             // Fetch the post.
    413             $post = bp_forums_get_post( $post_id );
    414 
    415             // Check the logged in user can edit this topic.
    416             if ( ! bp_is_item_admin() && ! bp_is_item_mod() && ( (int) bp_loggedin_user_id() != (int) $post->poster_id ) ) {
    417                 bp_core_redirect( wp_get_referer() );
    418             }
    419 
    420             // Check the nonce.
    421             check_admin_referer( 'bp_forums_delete_post' );
    422 
    423             /**
    424              * Fires before the deletion of a group forum post.
    425              *
    426              * @since 1.5.0
    427              *
    428              * @param int $post_id ID of the forum post being deleted.
    429              */
    430             do_action( 'groups_before_delete_forum_post', $post_id );
    431 
    432             if ( !groups_delete_group_forum_post( $post_id ) ) {
    433                 bp_core_add_message( __( 'There was an error deleting that post', 'buddypress'), 'error' );
    434             } else {
    435                 bp_core_add_message( __( 'The post was deleted successfully', 'buddypress') );
    436             }
    437 
    438             /**
    439              * Fires after the deletion of a group forum post.
    440              *
    441              * @since 1.1.0
    442              *
    443              * @param int $post_id ID of the forum post being deleted.
    444              */
    445             do_action( 'groups_delete_forum_post', $post_id );
    446             bp_core_redirect( wp_get_referer() );
    447 
    448         // Editing a post.
    449         } elseif ( empty( $user_is_banned ) && bp_is_action_variable( 'edit', 2 ) && $post_id = bp_action_variable( 4 ) ) {
    450 
    451             // Fetch the post.
    452             $post = bp_forums_get_post( $post_id );
    453 
    454             // Check the logged in user can edit this topic.
    455             if ( ! bp_is_item_admin() && ! bp_is_item_mod() && ( (int) bp_loggedin_user_id() != (int) $post->poster_id ) ) {
    456                 bp_core_redirect( wp_get_referer() );
    457             }
    458 
    459             if ( isset( $_POST['save_changes'] ) ) {
    460                 // Check the nonce.
    461                 check_admin_referer( 'bp_forums_edit_post' );
    462 
    463                 $topic_page = isset( $_GET['topic_page'] ) ? $_GET['topic_page'] : false;
    464 
    465                 if ( !$post_id = groups_update_group_forum_post( $post_id, $_POST['post_text'], $topic_id, $topic_page ) ) {
    466                     bp_core_add_message( __( 'There was an error when editing that post', 'buddypress'), 'error' );
    467                 } else {
    468                     bp_core_add_message( __( 'The post was edited successfully', 'buddypress') );
    469                 }
    470 
    471                 if ( $_SERVER['QUERY_STRING'] ) {
    472                     $query_vars = '?' . $_SERVER['QUERY_STRING'];
    473                 }
    474 
    475                 /**
    476                  * Fires after the editing of a group forum post.
    477                  *
    478                  * @since 1.1.0
    479                  *
    480                  * @param int $post_id ID of the forum post being edited.
    481                  */
    482                 do_action( 'groups_edit_forum_post', $post_id );
    483                 bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic_slug . '/' . $query_vars . '#post-' . $post_id );
    484             }
    485 
    486             /** This filter is documented in bp-groups/bp-groups-screens.php */
    487             bp_core_load_template( apply_filters( 'groups_template_group_forum_topic_edit', 'groups/single/home' ) );
    488 
    489         // Standard topic display.
    490         } else {
    491             if ( !empty( $user_is_banned ) ) {
    492                 bp_core_add_message( __( "You have been banned from this group.", 'buddypress' ) );
    493             }
    494 
    495             /**
    496              * Filters the template to load for a topic page.
    497              *
    498              * @since 1.1.0
    499              *
    500              * @param string $value Path to a topic template.
    501              */
    502             bp_core_load_template( apply_filters( 'groups_template_group_forum_topic', 'groups/single/home' ) );
    503         }
    504 
    505     // Forum topic does not exist.
    506     } elseif ( !empty( $topic_slug ) && empty( $topic_id ) ) {
    507         bp_do_404();
    508         return;
    509 
    510     } else {
    511         // Posting a topic.
    512         if ( isset( $_POST['submit_topic'] ) && bp_is_active( 'forums' ) ) {
    513 
    514             // Check the nonce.
    515             check_admin_referer( 'bp_forums_new_topic' );
    516 
    517             if ( $user_is_banned ) {
    518                 $error_message = __( "You have been banned from this group.", 'buddypress' );
    519 
    520             } elseif ( bp_groups_auto_join() && !bp_current_user_can( 'bp_moderate' ) && 'public' == $bp->groups->current_group->status && !groups_is_user_member( bp_loggedin_user_id(), $bp->groups->current_group->id ) ) {
    521                 // Auto join this user if they are not yet a member of this group.
    522                 groups_join_group( $bp->groups->current_group->id, bp_loggedin_user_id() );
    523             }
    524 
    525             if ( empty( $_POST['topic_title'] ) ) {
    526                 $error_message = __( 'Please provide a title for your forum topic.', 'buddypress' );
    527             } elseif ( empty( $_POST['topic_text'] ) ) {
    528                 $error_message = __( 'Forum posts cannot be empty. Please enter some text.', 'buddypress' );
    529             }
    530 
    531             if ( empty( $forum_id ) ) {
    532                 $error_message = __( 'This group does not have a forum setup yet.', 'buddypress' );
    533             }
    534 
    535             if ( isset( $error_message ) ) {
    536                 bp_core_add_message( $error_message, 'error' );
    537                 $redirect = bp_get_group_permalink( $bp->groups->current_group ) . 'forum';
    538             } else {
    539                 if ( !$topic = groups_new_group_forum_topic( $_POST['topic_title'], $_POST['topic_text'], $_POST['topic_tags'], $forum_id ) ) {
    540                     bp_core_add_message( __( 'There was an error when creating the topic', 'buddypress'), 'error' );
    541                     $redirect = bp_get_group_permalink( $bp->groups->current_group ) . 'forum';
    542                 } else {
    543                     bp_core_add_message( __( 'The topic was created successfully', 'buddypress') );
    544                     $redirect = bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic->topic_slug . '/';
    545                 }
    546             }
    547 
    548             bp_core_redirect( $redirect );
    549         }
    550 
    551         /**
    552          * Fires at the end of the group forum screen loading process.
    553          *
    554          * @since 1.0.0
    555          *
    556          * @param int $topic_id ID of the topic being displayed.
    557          * @param int $forum_id ID of the forum being displayed.
    558          */
    559         do_action( 'groups_screen_group_forum', $topic_id, $forum_id );
    560 
    561         /**
    562          * Filters the template to load for a group forum page.
    563          *
    564          * @since 1.0.0
    565          *
    566          * @param string $value Path to a group forum template.
    567          */
    568         bp_core_load_template( apply_filters( 'groups_template_group_forum', 'groups/single/home' ) );
    569     }
    570 }
    571 
    572 /**
    573  * Handle the display of a group's Members page.
    574  *
    575  * @since 1.0.0
    576  */
    577 function groups_screen_group_members() {
    578 
    579     if ( !bp_is_single_item() )
    580         return false;
    581 
    582     $bp = buddypress();
    583 
    584     // Refresh the group member count meta.
    585     groups_update_groupmeta( $bp->groups->current_group->id, 'total_member_count', groups_get_total_member_count( $bp->groups->current_group->id ) );
    586 
    587     /**
    588      * Fires before the loading of a group's Members page.
    589      *
    590      * @since 1.0.0
    591      *
    592      * @param int $id ID of the group whose members are being displayed.
    593      */
    594     do_action( 'groups_screen_group_members', $bp->groups->current_group->id );
    595 
    596     /**
    597      * Filters the template to load for a group's Members page.
    598      *
    599      * @since 1.0.0
    600      *
    601      * @param string $value Path to a group's Members template.
    602      */
    603     bp_core_load_template( apply_filters( 'groups_template_group_members', 'groups/single/home' ) );
    604 }
    605 
    606 /**
    607  * Handle the display of a group's Send Invites page.
    608  *
    609  * @since 1.0.0
    610  */
    611 function groups_screen_group_invite() {
    612 
    613     if ( !bp_is_single_item() )
    614         return false;
    615 
    616     $bp = buddypress();
    617 
    618     if ( bp_is_action_variable( 'send', 0 ) ) {
    619 
    620         if ( !check_admin_referer( 'groups_send_invites', '_wpnonce_send_invites' ) )
    621             return false;
    622 
    623         if ( !empty( $_POST['friends'] ) ) {
    624             foreach( (array) $_POST['friends'] as $friend ) {
    625                 groups_invite_user( array( 'user_id' => $friend, 'group_id' => $bp->groups->current_group->id ) );
    626             }
    627         }
    628 
    629         // Send the invites.
    630         groups_send_invites( bp_loggedin_user_id(), $bp->groups->current_group->id );
    631         bp_core_add_message( __('Group invites sent.', 'buddypress') );
    632 
    633         /**
    634          * Fires after the sending of a group invite inside the group's Send Invites page.
    635          *
    636          * @since 1.0.0
    637          *
    638          * @param int $id ID of the group whose members are being displayed.
    639          */
    640         do_action( 'groups_screen_group_invite', $bp->groups->current_group->id );
    641         bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) );
    642 
    643     } elseif ( !bp_action_variable( 0 ) ) {
    644 
    645         /**
    646          * Filters the template to load for a group's Send Invites page.
    647          *
    648          * @since 1.0.0
    649          *
    650          * @param string $value Path to a group's Send Invites template.
    651          */
    652         bp_core_load_template( apply_filters( 'groups_template_group_invite', 'groups/single/home' ) );
    653 
    654     } else {
    655         bp_do_404();
    656     }
    657 }
    658 
    659 /**
    660  * Process group invitation removal requests.
    661  *
    662  * Note that this function is only used when JS is disabled. Normally, clicking
    663  * Remove Invite removes the invitation via AJAX.
    664  *
    665  * @since 2.0.0
    666  */
    667 function groups_remove_group_invite() {
    668     if ( ! bp_is_group_invites() ) {
    669         return;
    670     }
    671 
    672     if ( ! bp_is_action_variable( 'remove', 0 ) || ! is_numeric( bp_action_variable( 1 ) ) ) {
    673         return;
    674     }
    675 
    676     if ( ! check_admin_referer( 'groups_invite_uninvite_user' ) ) {
    677         return false;
    678     }
    679 
    680     $friend_id = intval( bp_action_variable( 1 ) );
    681     $group_id  = bp_get_current_group_id();
    682     $message   = __( 'Invite successfully removed', 'buddypress' );
    683     $redirect  = wp_get_referer();
    684     $error     = false;
    685 
    686     if ( ! bp_groups_user_can_send_invites( $group_id ) ) {
    687         $message = __( 'You are not allowed to send or remove invites', 'buddypress' );
    688         $error = 'error';
    689     } elseif ( BP_Groups_Member::check_for_membership_request( $friend_id, $group_id ) ) {
    690         $message = __( 'The member requested to join the group', 'buddypress' );
    691         $error = 'error';
    692     } elseif ( ! groups_uninvite_user( $friend_id, $group_id ) ) {
    693         $message = __( 'There was an error removing the invite', 'buddypress' );
    694         $error = 'error';
    695     }
    696 
    697     bp_core_add_message( $message, $error );
    698     bp_core_redirect( $redirect );
    699 }
    700 add_action( 'bp_screens', 'groups_remove_group_invite' );
    701 
    702 /**
    703  * Handle the display of a group's Request Membership page.
    704  *
    705  * @since 1.0.0
    706  */
    707 function groups_screen_group_request_membership() {
    708 
    709     if ( !is_user_logged_in() )
    710         return false;
    711 
    712     $bp = buddypress();
    713 
    714     if ( 'private' != $bp->groups->current_group->status )
    715         return false;
    716 
    717     // If the user is already invited, accept invitation.
    718     if ( groups_check_user_has_invite( bp_loggedin_user_id(), $bp->groups->current_group->id ) ) {
    719         if ( groups_accept_invite( bp_loggedin_user_id(), $bp->groups->current_group->id ) )
    720             bp_core_add_message( __( 'Group invite accepted', 'buddypress' ) );
    721         else
    722             bp_core_add_message( __( 'There was an error accepting the group invitation. Please try again.', 'buddypress' ), 'error' );
    723         bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) );
    724     }
    725 
    726     // If the user has submitted a request, send it.
    727     if ( isset( $_POST['group-request-send']) ) {
    728 
    729         // Check the nonce.
    730         if ( !check_admin_referer( 'groups_request_membership' ) )
    731             return false;
    732 
    733         if ( !groups_send_membership_request( bp_loggedin_user_id(), $bp->groups->current_group->id ) ) {
    734             bp_core_add_message( __( 'There was an error sending your group membership request. Please try again.', 'buddypress' ), 'error' );
    735         } else {
    736             bp_core_add_message( __( 'Your membership request was sent to the group administrator successfully. You will be notified when the group administrator responds to your request.', 'buddypress' ) );
    737         }
    738         bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) );
    739     }
    740 
    741     /**
    742      * Fires before the loading of a group's Request Memebership page.
    743      *
    744      * @since 1.0.0
    745      *
    746      * @param int $id ID of the group currently being displayed.
    747      */
    748     do_action( 'groups_screen_group_request_membership', $bp->groups->current_group->id );
    749 
    750     /**
    751      * Filters the template to load for a group's Request Membership page.
    752      *
    753      * @since 1.0.0
    754      *
    755      * @param string $value Path to a group's Request Membership template.
    756      */
    757     bp_core_load_template( apply_filters( 'groups_template_group_request_membership', 'groups/single/home' ) );
    758 }
    759 
    760 /**
    761  * Handle the loading of a single group's activity.
    762  *
    763  * @since 2.4.0
    764  */
    765 function groups_screen_group_activity() {
    766 
    767     if ( ! bp_is_single_item() ) {
    768         return false;
    769     }
    770 
    771     /**
    772      * Fires before the loading of a single group's activity page.
    773      *
    774      * @since 2.4.0
    775      */
    776     do_action( 'groups_screen_group_activity' );
    777 
    778     /**
    779      * Filters the template to load for a single group's activity page.
    780      *
    781      * @since 2.4.0
    782      *
    783      * @param string $value Path to a single group's template to load.
    784      */
    785     bp_core_load_template( apply_filters( 'groups_screen_group_activity', 'groups/single/activity' ) );
    786 }
    787 
    788 /**
    789  * Handle the display of a single group activity item.
    790  *
    791  * @since 1.2.0
    792  */
    793 function groups_screen_group_activity_permalink() {
    794 
    795     if ( !bp_is_groups_component() || !bp_is_active( 'activity' ) || ( bp_is_active( 'activity' ) && !bp_is_current_action( bp_get_activity_slug() ) ) || !bp_action_variable( 0 ) )
    796         return false;
    797 
    798     buddypress()->is_single_item = true;
    799 
    800     /** This filter is documented in bp-groups/bp-groups-screens.php */
    801     bp_core_load_template( apply_filters( 'groups_template_group_home', 'groups/single/home' ) );
    802 }
    803 add_action( 'bp_screens', 'groups_screen_group_activity_permalink' );
    804 
    805 /**
    806  * Handle the display of a group's Admin pages.
    807  *
    808  * @since 1.0.0
    809  */
    810 function groups_screen_group_admin() {
    811     if ( !bp_is_groups_component() || !bp_is_current_action( 'admin' ) )
    812         return false;
    813 
    814     if ( bp_action_variables() )
    815         return false;
    816 
    817     bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/edit-details/' );
    818 }
    819 
    820 /**
    821  * Handle the display of a group's admin/edit-details page.
    822  *
    823  * @since 1.0.0
    824  */
    825 function groups_screen_group_admin_edit_details() {
    826 
    827     if ( 'edit-details' != bp_get_group_current_admin_tab() )
    828         return false;
    829 
    830     if ( bp_is_item_admin() ) {
    831 
    832         $bp = buddypress();
    833 
    834         // If the edit form has been submitted, save the edited details.
    835         if ( isset( $_POST['save'] ) ) {
    836             // Check the nonce.
    837             if ( !check_admin_referer( 'groups_edit_group_details' ) )
    838                 return false;
    839 
    840             $group_notify_members = isset( $_POST['group-notify-members'] ) ? (int) $_POST['group-notify-members'] : 0;
    841 
    842             if ( !groups_edit_base_group_details( $_POST['group-id'], $_POST['group-name'], $_POST['group-desc'], $group_notify_members ) ) {
    843                 bp_core_add_message( __( 'There was an error updating group details. Please try again.', 'buddypress' ), 'error' );
    844             } else {
    845                 bp_core_add_message( __( 'Group details were successfully updated.', 'buddypress' ) );
    846             }
    847 
    848             /**
    849              * Fires before the redirect if a group details has been edited and saved.
    850              *
    851              * @since 1.0.0
    852              *
    853              * @param int $id ID of the group that was edited.
    854              */
    855             do_action( 'groups_group_details_edited', $bp->groups->current_group->id );
    856 
    857             bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/edit-details/' );
    858         }
    859 
    860         /**
    861          * Fires before the loading of the group admin/edit-details page template.
    862          *
    863          * @since 1.0.0
    864          *
    865          * @param int $id ID of the group that is being displayed.
    866          */
    867         do_action( 'groups_screen_group_admin_edit_details', $bp->groups->current_group->id );
    868 
    869         /**
    870          * Filters the template to load for a group's admin/edit-details page.
    871          *
    872          * @since 1.0.0
    873          *
    874          * @param string $value Path to a group's admin/edit-details template.
    875          */
    876         bp_core_load_template( apply_filters( 'groups_template_group_admin', 'groups/single/home' ) );
    877     }
    878 }
    879 add_action( 'bp_screens', 'groups_screen_group_admin_edit_details' );
    880 
    881 /**
    882  * Handle the display of a group's admin/group-settings page.
    883  *
    884  * @since 1.0.0
    885  */
    886 function groups_screen_group_admin_settings() {
    887 
    888     if ( 'group-settings' != bp_get_group_current_admin_tab() )
    889         return false;
    890 
    891     if ( ! bp_is_item_admin() )
    892         return false;
    893 
    894     $bp = buddypress();
    895 
    896     // If the edit form has been submitted, save the edited details.
    897     if ( isset( $_POST['save'] ) ) {
    898         $enable_forum   = ( isset($_POST['group-show-forum'] ) ) ? 1 : 0;
    899 
    900         // Checked against a whitelist for security.
    901         /** This filter is documented in bp-groups/bp-groups-admin.php */
    902         $allowed_status = apply_filters( 'groups_allowed_status', array( 'public', 'private', 'hidden' ) );
    903         $status         = ( in_array( $_POST['group-status'], (array) $allowed_status ) ) ? $_POST['group-status'] : 'public';
    904 
    905         // Checked against a whitelist for security.
    906         /** This filter is documented in bp-groups/bp-groups-admin.php */
    907         $allowed_invite_status = apply_filters( 'groups_allowed_invite_status', array( 'members', 'mods', 'admins' ) );
    908         $invite_status         = isset( $_POST['group-invite-status'] ) && in_array( $_POST['group-invite-status'], (array) $allowed_invite_status ) ? $_POST['group-invite-status'] : 'members';
    909 
    910         // Check the nonce.
    911         if ( !check_admin_referer( 'groups_edit_group_settings' ) )
    912             return false;
    913 
    914         if ( !groups_edit_group_settings( $_POST['group-id'], $enable_forum, $status, $invite_status ) ) {
    915             bp_core_add_message( __( 'There was an error updating group settings. Please try again.', 'buddypress' ), 'error' );
    916         } else {
    917             bp_core_add_message( __( 'Group settings were successfully updated.', 'buddypress' ) );
    918         }
    919 
    920         /**
    921          * Fires before the redirect if a group settings has been edited and saved.
    922          *
    923          * @since 1.0.0
    924          *
    925          * @param int $id ID of the group that was edited.
    926          */
    927         do_action( 'groups_group_settings_edited', $bp->groups->current_group->id );
    928 
    929         bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/group-settings/' );
    930     }
    931 
    932     /**
    933      * Fires before the loading of the group admin/group-settings page template.
    934      *
    935      * @since 1.0.0
    936      *
    937      * @param int $id ID of the group that is being displayed.
    938      */
    939     do_action( 'groups_screen_group_admin_settings', $bp->groups->current_group->id );
    940 
    941     /**
    942      * Filters the template to load for a group's admin/group-settings page.
    943      *
    944      * @since 1.0.0
    945      *
    946      * @param string $value Path to a group's admin/group-settings template.
    947      */
    948     bp_core_load_template( apply_filters( 'groups_template_group_admin_settings', 'groups/single/home' ) );
    949 }
    950 add_action( 'bp_screens', 'groups_screen_group_admin_settings' );
    951 
    952 /**
    953  * Handle the display of a group's Change Avatar page.
    954  *
    955  * @since 1.0.0
    956  */
    957 function groups_screen_group_admin_avatar() {
    958 
    959     if ( 'group-avatar' != bp_get_group_current_admin_tab() )
    960         return false;
    961 
    962     // If the logged-in user doesn't have permission or if avatar uploads are disabled, then stop here.
    963     if ( ! bp_is_item_admin() || bp_disable_group_avatar_uploads() || ! buddypress()->avatar->show_avatars )
    964         return false;
    965 
    966     $bp = buddypress();
    967 
    968     // If the group admin has deleted the admin avatar.
    969     if ( bp_is_action_variable( 'delete', 1 ) ) {
    970 
    971         // Check the nonce.
    972         check_admin_referer( 'bp_group_avatar_delete' );
    973 
    974         if ( bp_core_delete_existing_avatar( array( 'item_id' => $bp->groups->current_group->id, 'object' => 'group' ) ) ) {
    975             bp_core_add_message( __( 'The group profile photo was deleted successfully!', 'buddypress' ) );
    976         } else {
    977             bp_core_add_message( __( 'There was a problem deleting the group profile photo. Please try again.', 'buddypress' ), 'error' );
    978         }
    979     }
    980 
    981     if ( ! isset( $bp->avatar_admin ) ) {
    982         $bp->avatar_admin = new stdClass();
    983     }
    984 
    985     $bp->avatar_admin->step = 'upload-image';
    986 
    987     if ( !empty( $_FILES ) ) {
    988 
    989         // Check the nonce.
    990         check_admin_referer( 'bp_avatar_upload' );
    991 
    992         // Pass the file to the avatar upload handler.
    993         if ( bp_core_avatar_handle_upload( $_FILES, 'groups_avatar_upload_dir' ) ) {
    994             $bp->avatar_admin->step = 'crop-image';
    995 
    996             // Make sure we include the jQuery jCrop file for image cropping.
    997             add_action( 'wp_print_scripts', 'bp_core_add_jquery_cropper' );
    998         }
    999 
    1000     }
    1001 
    1002     // If the image cropping is done, crop the image and save a full/thumb version.
    1003     if ( isset( $_POST['avatar-crop-submit'] ) ) {
    1004 
    1005         // Check the nonce.
    1006         check_admin_referer( 'bp_avatar_cropstore' );
    1007 
    1008         $args = array(
    1009             'object'        => 'group',
    1010             'avatar_dir'    => 'group-avatars',
    1011             'item_id'       => $bp->groups->current_group->id,
    1012             'original_file' => $_POST['image_src'],
    1013             'crop_x'        => $_POST['x'],
    1014             'crop_y'        => $_POST['y'],
    1015             'crop_w'        => $_POST['w'],
    1016             'crop_h'        => $_POST['h']
    1017         );
    1018 
    1019         if ( !bp_core_avatar_handle_crop( $args ) ) {
    1020             bp_core_add_message( __( 'There was a problem cropping the group profile photo.', 'buddypress' ), 'error' );
    1021         } else {
    1022             bp_core_add_message( __( 'The new group profile photo was uploaded successfully.', 'buddypress' ) );
    1023         }
    1024     }
    1025 
    1026     /**
    1027      * Fires before the loading of the group Change Avatar page template.
    1028      *
    1029      * @since 1.0.0
    1030      *
    1031      * @param int $id ID of the group that is being displayed.
    1032      */
    1033     do_action( 'groups_screen_group_admin_avatar', $bp->groups->current_group->id );
    1034 
    1035     /**
    1036      * Filters the template to load for a group's Change Avatar page.
    1037      *
    1038      * @since 1.0.0
    1039      *
    1040      * @param string $value Path to a group's Change Avatar template.
    1041      */
    1042     bp_core_load_template( apply_filters( 'groups_template_group_admin_avatar', 'groups/single/home' ) );
    1043 }
    1044 add_action( 'bp_screens', 'groups_screen_group_admin_avatar' );
    1045 
    1046 /**
    1047  * Handle the display of a group's Change cover image page.
    1048  *
    1049  * @since 2.4.0
    1050  */
    1051 function groups_screen_group_admin_cover_image() {
    1052     if ( 'group-cover-image' != bp_get_group_current_admin_tab() ) {
    1053         return false;
    1054     }
    1055 
    1056     // If the logged-in user doesn't have permission or if cover image uploads are disabled, then stop here.
    1057     if ( ! bp_is_item_admin() || ! bp_group_use_cover_image_header() ) {
    1058         return false;
    1059     }
    1060 
    1061     /**
    1062      * Fires before the loading of the group Change cover image page template.
    1063      *
    1064      * @since 2.4.0
    1065      *
    1066      * @param int $id ID of the group that is being displayed.
    1067      */
    1068     do_action( 'groups_screen_group_admin_cover_image', bp_get_current_group_id() );
    1069 
    1070     /**
    1071      * Filters the template to load for a group's Change cover image page.
    1072      *
    1073      * @since 2.4.0
    1074      *
    1075      * @param string $value Path to a group's Change cover image template.
    1076      */
    1077     bp_core_load_template( apply_filters( 'groups_template_group_admin_cover_image', 'groups/single/home' ) );
    1078 }
    1079 add_action( 'bp_screens', 'groups_screen_group_admin_cover_image' );
    1080 
    1081 /**
    1082  * This function handles actions related to member management on the group admin.
    1083  *
    1084  * @since 1.0.0
    1085  */
    1086 function groups_screen_group_admin_manage_members() {
    1087 
    1088     if ( 'manage-members' != bp_get_group_current_admin_tab() )
    1089         return false;
    1090 
    1091     if ( ! bp_is_item_admin() )
    1092         return false;
    1093 
    1094     $bp = buddypress();
    1095 
    1096     if ( bp_action_variable( 1 ) && bp_action_variable( 2 ) && bp_action_variable( 3 ) ) {
    1097         if ( bp_is_action_variable( 'promote', 1 ) && ( bp_is_action_variable( 'mod', 2 ) || bp_is_action_variable( 'admin', 2 ) ) && is_numeric( bp_action_variable( 3 ) ) ) {
    1098             $user_id = bp_action_variable( 3 );
    1099             $status  = bp_action_variable( 2 );
    1100 
    1101             // Check the nonce first.
    1102             if ( !check_admin_referer( 'groups_promote_member' ) )
    1103                 return false;
    1104 
    1105             // Promote a user.
    1106             if ( !groups_promote_member( $user_id, $bp->groups->current_group->id, $status ) )
    1107                 bp_core_add_message( __( 'There was an error when promoting that user. Please try again.', 'buddypress' ), 'error' );
    1108             else
    1109                 bp_core_add_message( __( 'User promoted successfully', 'buddypress' ) );
    1110 
    1111             /**
    1112              * Fires before the redirect after a group member has been promoted.
    1113              *
    1114              * @since 1.0.0
    1115              *
    1116              * @param int $user_id ID of the user being promoted.
    1117              * @param int $id      ID of the group user is promoted within.
    1118              */
    1119             do_action( 'groups_promoted_member', $user_id, $bp->groups->current_group->id );
    1120 
    1121             bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/manage-members/' );
    1122         }
    1123     }
    1124 
    1125     if ( bp_action_variable( 1 ) && bp_action_variable( 2 ) ) {
    1126         if ( bp_is_action_variable( 'demote', 1 ) && is_numeric( bp_action_variable( 2 ) ) ) {
    1127             $user_id = bp_action_variable( 2 );
    1128 
    1129             // Check the nonce first.
    1130             if ( !check_admin_referer( 'groups_demote_member' ) )
    1131                 return false;
    1132 
    1133             // Stop sole admins from abandoning their group.
    1134             $group_admins = groups_get_group_admins( $bp->groups->current_group->id );
    1135             if ( 1 == count( $group_admins ) && $group_admins[0]->user_id == $user_id )
    1136                 bp_core_add_message( __( 'This group must have at least one admin', 'buddypress' ), 'error' );
    1137 
    1138             // Demote a user.
    1139             elseif ( !groups_demote_member( $user_id, $bp->groups->current_group->id ) )
    1140                 bp_core_add_message( __( 'There was an error when demoting that user. Please try again.', 'buddypress' ), 'error' );
    1141             else
    1142                 bp_core_add_message( __( 'User demoted successfully', 'buddypress' ) );
    1143 
    1144             /**
    1145              * Fires before the redirect after a group member has been demoted.
    1146              *
    1147              * @since 1.0.0
    1148              *
    1149              * @param int $user_id ID of the user being demoted.
    1150              * @param int $id      ID of the group user is demoted within.
    1151              */
    1152             do_action( 'groups_demoted_member', $user_id, $bp->groups->current_group->id );
    1153 
    1154             bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/manage-members/' );
    1155         }
    1156 
    1157         if ( bp_is_action_variable( 'ban', 1 ) && is_numeric( bp_action_variable( 2 ) ) ) {
    1158             $user_id = bp_action_variable( 2 );
    1159 
    1160             // Check the nonce first.
    1161             if ( !check_admin_referer( 'groups_ban_member' ) )
    1162                 return false;
    1163 
    1164             // Ban a user.
    1165             if ( !groups_ban_member( $user_id, $bp->groups->current_group->id ) )
    1166                 bp_core_add_message( __( 'There was an error when banning that user. Please try again.', 'buddypress' ), 'error' );
    1167             else
    1168                 bp_core_add_message( __( 'User banned successfully', 'buddypress' ) );
    1169 
    1170             /**
    1171              * Fires before the redirect after a group member has been banned.
    1172              *
    1173              * @since 1.0.0
    1174              *
    1175              * @param int $user_id ID of the user being banned.
    1176              * @param int $id      ID of the group user is banned from.
    1177              */
    1178             do_action( 'groups_banned_member', $user_id, $bp->groups->current_group->id );
    1179 
    1180             bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/manage-members/' );
    1181         }
    1182 
    1183         if ( bp_is_action_variable( 'unban', 1 ) && is_numeric( bp_action_variable( 2 ) ) ) {
    1184             $user_id = bp_action_variable( 2 );
    1185 
    1186             // Check the nonce first.
    1187             if ( !check_admin_referer( 'groups_unban_member' ) )
    1188                 return false;
    1189 
    1190             // Remove a ban for user.
    1191             if ( !groups_unban_member( $user_id, $bp->groups->current_group->id ) )
    1192                 bp_core_add_message( __( 'There was an error when unbanning that user. Please try again.', 'buddypress' ), 'error' );
    1193             else
    1194                 bp_core_add_message( __( 'User ban removed successfully', 'buddypress' ) );
    1195 
    1196             /**
    1197              * Fires before the redirect after a group member has been unbanned.
    1198              *
    1199              * @since 1.0.0
    1200              *
    1201              * @param int $user_id ID of the user being unbanned.
    1202              * @param int $id      ID of the group user is unbanned from.
    1203              */
    1204             do_action( 'groups_unbanned_member', $user_id, $bp->groups->current_group->id );
    1205 
    1206             bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/manage-members/' );
    1207         }
    1208 
    1209         if ( bp_is_action_variable( 'remove', 1 ) && is_numeric( bp_action_variable( 2 ) ) ) {
    1210             $user_id = bp_action_variable( 2 );
    1211 
    1212             // Check the nonce first.
    1213             if ( !check_admin_referer( 'groups_remove_member' ) )
    1214                 return false;
    1215 
    1216             // Remove a user.
    1217             if ( !groups_remove_member( $user_id, $bp->groups->current_group->id ) )
    1218                 bp_core_add_message( __( 'There was an error removing that user from the group. Please try again.', 'buddypress' ), 'error' );
    1219             else
    1220                 bp_core_add_message( __( 'User removed successfully', 'buddypress' ) );
    1221 
    1222             /**
    1223              * Fires before the redirect after a group member has been removed.
    1224              *
    1225              * @since 1.2.6
    1226              *
    1227              * @param int $user_id ID of the user being removed.
    1228              * @param int $id      ID of the group the user is removed from.
    1229              */
    1230             do_action( 'groups_removed_member', $user_id, $bp->groups->current_group->id );
    1231 
    1232             bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/manage-members/' );
    1233         }
    1234     }
    1235 
    1236     /**
    1237      * Fires before the loading of a group's manage members template.
    1238      *
    1239      * @since 1.0.0
    1240      *
    1241      * @param int $id ID of the group whose manage members page is being displayed.
    1242      */
    1243     do_action( 'groups_screen_group_admin_manage_members', $bp->groups->current_group->id );
    1244 
    1245     /**
    1246      * Filters the template to load for a group's manage members page.
    1247      *
    1248      * @since 1.0.0
    1249      *
    1250      * @param string $value Path to a group's manage members template.
    1251      */
    1252     bp_core_load_template( apply_filters( 'groups_template_group_admin_manage_members', 'groups/single/home' ) );
    1253 }
    1254 add_action( 'bp_screens', 'groups_screen_group_admin_manage_members' );
    1255 
    1256 /**
    1257  * Handle the display of Admin > Membership Requests.
    1258  *
    1259  * @since 1.0.0
    1260  */
    1261 function groups_screen_group_admin_requests() {
    1262     $bp = buddypress();
    1263 
    1264     if ( 'membership-requests' != bp_get_group_current_admin_tab() ) {
    1265         return false;
    1266     }
    1267 
    1268     if ( ! bp_is_item_admin() || ( 'public' == $bp->groups->current_group->status ) ) {
    1269         return false;
    1270     }
    1271 
    1272     $request_action = (string) bp_action_variable( 1 );
    1273     $membership_id  = (int) bp_action_variable( 2 );
    1274 
    1275     if ( !empty( $request_action ) && !empty( $membership_id ) ) {
    1276         if ( 'accept' == $request_action && is_numeric( $membership_id ) ) {
    1277 
    1278             // Check the nonce first.
    1279             if ( !check_admin_referer( 'groups_accept_membership_request' ) )
    1280                 return false;
    1281 
    1282             // Accept the membership request.
    1283             if ( !groups_accept_membership_request( $membership_id ) )
    1284                 bp_core_add_message( __( 'There was an error accepting the membership request. Please try again.', 'buddypress' ), 'error' );
    1285             else
    1286                 bp_core_add_message( __( 'Group membership request accepted', 'buddypress' ) );
    1287 
    1288         } elseif ( 'reject' == $request_action && is_numeric( $membership_id ) ) {
    1289             /* Check the nonce first. */
    1290             if ( !check_admin_referer( 'groups_reject_membership_request' ) )
    1291                 return false;
    1292 
    1293             // Reject the membership request.
    1294             if ( !groups_reject_membership_request( $membership_id ) )
    1295                 bp_core_add_message( __( 'There was an error rejecting the membership request. Please try again.', 'buddypress' ), 'error' );
    1296             else
    1297                 bp_core_add_message( __( 'Group membership request rejected', 'buddypress' ) );
    1298         }
    1299 
    1300         /**
    1301          * Fires before the redirect if a group membership request has been handled.
    1302          *
    1303          * @since 1.0.0
    1304          *
    1305          * @param int    $id             ID of the group that was edited.
    1306          * @param string $request_action Membership request action being performed.
    1307          * @param int    $membership_id  The key of the action_variables array that you want.
    1308          */
    1309         do_action( 'groups_group_request_managed', $bp->groups->current_group->id, $request_action, $membership_id );
    1310         bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/membership-requests/' );
    1311     }
    1312 
    1313     /**
    1314      * Fires before the loading of the group membership request page template.
    1315      *
    1316      * @since 1.0.0
    1317      *
    1318      * @param int $id ID of the group that is being displayed.
    1319      */
    1320     do_action( 'groups_screen_group_admin_requests', $bp->groups->current_group->id );
    1321 
    1322     /**
    1323      * Filters the template to load for a group's membership request page.
    1324      *
    1325      * @since 1.0.0
    1326      *
    1327      * @param string $value Path to a group's membership request template.
    1328      */
    1329     bp_core_load_template( apply_filters( 'groups_template_group_admin_requests', 'groups/single/home' ) );
    1330 }
    1331 add_action( 'bp_screens', 'groups_screen_group_admin_requests' );
    1332 
    1333 /**
    1334  * Handle the display of the Delete Group page.
    1335  *
    1336  * @since 1.0.0
    1337  */
    1338 function groups_screen_group_admin_delete_group() {
    1339 
    1340     if ( 'delete-group' != bp_get_group_current_admin_tab() )
    1341         return false;
    1342 
    1343     if ( ! bp_is_item_admin() && !bp_current_user_can( 'bp_moderate' ) )
    1344         return false;
    1345 
    1346     $bp = buddypress();
    1347 
    1348     if ( isset( $_REQUEST['delete-group-button'] ) && isset( $_REQUEST['delete-group-understand'] ) ) {
    1349 
    1350         // Check the nonce first.
    1351         if ( !check_admin_referer( 'groups_delete_group' ) ) {
    1352             return false;
    1353         }
    1354 
    1355         /**
    1356          * Fires before the deletion of a group from the Delete Group page.
    1357          *
    1358          * @since 1.5.0
    1359          *
    1360          * @param int $id ID of the group being deleted.
    1361          */
    1362         do_action( 'groups_before_group_deleted', $bp->groups->current_group->id );
    1363 
    1364         // Group admin has deleted the group, now do it.
    1365         if ( !groups_delete_group( $bp->groups->current_group->id ) ) {
    1366             bp_core_add_message( __( 'There was an error deleting the group. Please try again.', 'buddypress' ), 'error' );
    1367         } else {
    1368             bp_core_add_message( __( 'The group was deleted successfully.', 'buddypress' ) );
    1369 
    1370             /**
    1371              * Fires after the deletion of a group from the Delete Group page.
    1372              *
    1373              * @since 1.0.0
    1374              *
    1375              * @param int $id ID of the group being deleted.
    1376              */
    1377             do_action( 'groups_group_deleted', $bp->groups->current_group->id );
    1378 
    1379             bp_core_redirect( trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() ) );
    1380         }
    1381 
    1382         bp_core_redirect( trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() ) );
    1383     }
    1384 
    1385     /**
    1386      * Fires before the loading of the Delete Group page template.
    1387      *
    1388      * @since 1.0.0
    1389      *
    1390      * @param int $id ID of the group that is being displayed.
    1391      */
    1392     do_action( 'groups_screen_group_admin_delete_group', $bp->groups->current_group->id );
    1393 
    1394     /**
    1395      * Filters the template to load for the Delete Group page.
    1396      *
    1397      * @since 1.0.0
    1398      *
    1399      * @param string $value Path to the Delete Group template.
    1400      */
    1401     bp_core_load_template( apply_filters( 'groups_template_group_admin_delete_group', 'groups/single/home' ) );
    1402 }
    1403 add_action( 'bp_screens', 'groups_screen_group_admin_delete_group' );
    1404 
    1405 /**
    1406  * Render the group settings fields on the Notification Settings page.
    1407  *
    1408  * @since 1.0.0
    1409  */
    1410 function groups_screen_notification_settings() {
    1411 
    1412     if ( !$group_invite = bp_get_user_meta( bp_displayed_user_id(), 'notification_groups_invite', true ) )
    1413         $group_invite  = 'yes';
    1414 
    1415     if ( !$group_update = bp_get_user_meta( bp_displayed_user_id(), 'notification_groups_group_updated', true ) )
    1416         $group_update  = 'yes';
    1417 
    1418     if ( !$group_promo = bp_get_user_meta( bp_displayed_user_id(), 'notification_groups_admin_promotion', true ) )
    1419         $group_promo   = 'yes';
    1420 
    1421     if ( !$group_request = bp_get_user_meta( bp_displayed_user_id(), 'notification_groups_membership_request', true ) )
    1422         $group_request = 'yes'; ?>
    1423 
    1424     <table class="notification-settings" id="groups-notification-settings">
    1425         <thead>
    1426             <tr>
    1427                 <th class="icon"></th>
    1428                 <th class="title"><?php _ex( 'Groups', 'Group settings on notification settings page', 'buddypress' ) ?></th>
    1429                 <th class="yes"><?php _e( 'Yes', 'buddypress' ) ?></th>
    1430                 <th class="no"><?php _e( 'No', 'buddypress' )?></th>
    1431             </tr>
    1432         </thead>
    1433 
    1434         <tbody>
    1435             <tr id="groups-notification-settings-invitation">
    1436                 <td></td>
    1437                 <td><?php _ex( 'A member invites you to join a group', 'group settings on notification settings page','buddypress' ) ?></td>
    1438                 <td class="yes"><input type="radio" name="notifications[notification_groups_invite]" id="notification-groups-invite-yes" value="yes" <?php checked( $group_invite, 'yes', true ) ?>/><label for="notification-groups-invite-yes" class="bp-screen-reader-text"><?php _e( 'Yes, send email', 'buddypress' ); ?></label></td>
    1439                 <td class="no"><input type="radio" name="notifications[notification_groups_invite]" id="notification-groups-invite-no" value="no" <?php checked( $group_invite, 'no', true ) ?>/><label for="notification-groups-invite-no" class="bp-screen-reader-text"><?php _e( 'No, do not send email', 'buddypress' ); ?></label></td>
    1440             </tr>
    1441             <tr id="groups-notification-settings-info-updated">
    1442                 <td></td>
    1443                 <td><?php _ex( 'Group information is updated', 'group settings on notification settings page', 'buddypress' ) ?></td>
    1444                 <td class="yes"><input type="radio" name="notifications[notification_groups_group_updated]" id="notification-groups-group-updated-yes" value="yes" <?php checked( $group_update, 'yes', true ) ?>/><label for="notification-groups-group-updated-yes" class="bp-screen-reader-text"><?php _e( 'Yes, send email', 'buddypress' ); ?></label></td>
    1445                 <td class="no"><input type="radio" name="notifications[notification_groups_group_updated]" id="notification-groups-group-updated-no" value="no" <?php checked( $group_update, 'no', true ) ?>/><label for="notification-groups-group-updated-no" class="bp-screen-reader-text"><?php _e( 'No, do not send email', 'buddypress' ); ?></label></td>
    1446             </tr>
    1447             <tr id="groups-notification-settings-promoted">
    1448                 <td></td>
    1449                 <td><?php _ex( 'You are promoted to a group administrator or moderator', 'group settings on notification settings page', 'buddypress' ) ?></td>
    1450                 <td class="yes"><input type="radio" name="notifications[notification_groups_admin_promotion]" id="notification-groups-admin-promotion-yes" value="yes" <?php checked( $group_promo, 'yes', true ) ?>/><label for="notification-groups-admin-promotion-yes" class="bp-screen-reader-text"><?php _e( 'Yes, send email', 'buddypress' ); ?></label></td>
    1451                 <td class="no"><input type="radio" name="notifications[notification_groups_admin_promotion]" id="notification-groups-admin-promotion-no" value="no" <?php checked( $group_promo, 'no', true ) ?>/><label for="notification-groups-admin-promotion-no" class="bp-screen-reader-text"><?php _e( 'No, do not send email', 'buddypress' ); ?></label></td>
    1452             </tr>
    1453             <tr id="groups-notification-settings-request">
    1454                 <td></td>
    1455                 <td><?php _ex( 'A member requests to join a private group for which you are an admin', 'group settings on notification settings page', 'buddypress' ) ?></td>
    1456                 <td class="yes"><input type="radio" name="notifications[notification_groups_membership_request]" id="notification-groups-membership-request-yes" value="yes" <?php checked( $group_request, 'yes', true ) ?>/><label for="notification-groups-membership-request-yes" class="bp-screen-reader-text"><?php _e( 'Yes, send email', 'buddypress' ); ?></label></td>
    1457                 <td class="no"><input type="radio" name="notifications[notification_groups_membership_request]" id="notification-groups-membership-request-no" value="no" <?php checked( $group_request, 'no', true ) ?>/><label for="notification-groups-membership-request-no" class="bp-screen-reader-text"><?php _e( 'No, do not send email', 'buddypress' ); ?></label></td>
    1458             </tr>
    1459 
    1460             <?php
    1461 
    1462             /**
    1463              * Fires at the end of the available group settings fields on Notification Settings page.
    1464              *
    1465              * @since 1.0.0
    1466              */
    1467             do_action( 'groups_screen_notification_settings' ); ?>
    1468 
    1469         </tbody>
    1470     </table>
    1471 
    1472 <?php
    1473 }
    1474 add_action( 'bp_notification_settings', 'groups_screen_notification_settings' );
    1475 
    1476 /** Theme Compatibility *******************************************************/
    147711
    147812/**
     
    1728262    }
    1729263}
    1730 new BP_Groups_Theme_Compat();
Note: See TracChangeset for help on using the changeset viewer.