[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-groups/screens/single/admin/ -> manage-members.php (source)

   1  <?php
   2  /**
   3   * Groups: Single group "Manage > Members" screen handler
   4   *
   5   * @package BuddyPress
   6   * @subpackage GroupsScreens
   7   * @since 3.0.0
   8   */
   9  
  10  /**
  11   * This function handles actions related to member management on the group admin.
  12   *
  13   * @since 1.0.0
  14   */
  15  function groups_screen_group_admin_manage_members() {
  16  
  17      if ( 'manage-members' != bp_get_group_current_admin_tab() )
  18          return false;
  19  
  20      if ( ! bp_is_item_admin() )
  21          return false;
  22  
  23      $bp = buddypress();
  24  
  25      if ( bp_action_variable( 1 ) && bp_action_variable( 2 ) && bp_action_variable( 3 ) ) {
  26          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 ) ) ) {
  27              $user_id = bp_action_variable( 3 );
  28              $status  = bp_action_variable( 2 );
  29  
  30              // Check the nonce first.
  31              if ( !check_admin_referer( 'groups_promote_member' ) )
  32                  return false;
  33  
  34              // Promote a user.
  35              if ( !groups_promote_member( $user_id, $bp->groups->current_group->id, $status ) )
  36                  bp_core_add_message( __( 'There was an error when promoting that user. Please try again.', 'buddypress' ), 'error' );
  37              else
  38                  bp_core_add_message( __( 'User promoted successfully', 'buddypress' ) );
  39  
  40              /**
  41               * Fires before the redirect after a group member has been promoted.
  42               *
  43               * @since 1.0.0
  44               *
  45               * @param int $user_id ID of the user being promoted.
  46               * @param int $id      ID of the group user is promoted within.
  47               */
  48              do_action( 'groups_promoted_member', $user_id, $bp->groups->current_group->id );
  49  
  50              bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/manage-members/' );
  51          }
  52      }
  53  
  54      if ( bp_action_variable( 1 ) && bp_action_variable( 2 ) ) {
  55          if ( bp_is_action_variable( 'demote', 1 ) && is_numeric( bp_action_variable( 2 ) ) ) {
  56              $user_id = bp_action_variable( 2 );
  57  
  58              // Check the nonce first.
  59              if ( !check_admin_referer( 'groups_demote_member' ) )
  60                  return false;
  61  
  62              // Stop sole admins from abandoning their group.
  63              $group_admins = groups_get_group_admins( $bp->groups->current_group->id );
  64              if ( 1 == count( $group_admins ) && $group_admins[0]->user_id == $user_id )
  65                  bp_core_add_message( __( 'This group must have at least one admin', 'buddypress' ), 'error' );
  66  
  67              // Demote a user.
  68              elseif ( !groups_demote_member( $user_id, $bp->groups->current_group->id ) )
  69                  bp_core_add_message( __( 'There was an error when demoting that user. Please try again.', 'buddypress' ), 'error' );
  70              else
  71                  bp_core_add_message( __( 'User demoted successfully', 'buddypress' ) );
  72  
  73              /**
  74               * Fires before the redirect after a group member has been demoted.
  75               *
  76               * @since 1.0.0
  77               *
  78               * @param int $user_id ID of the user being demoted.
  79               * @param int $id      ID of the group user is demoted within.
  80               */
  81              do_action( 'groups_demoted_member', $user_id, $bp->groups->current_group->id );
  82  
  83              bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/manage-members/' );
  84          }
  85  
  86          if ( bp_is_action_variable( 'ban', 1 ) && is_numeric( bp_action_variable( 2 ) ) ) {
  87              $user_id = bp_action_variable( 2 );
  88  
  89              // Check the nonce first.
  90              if ( !check_admin_referer( 'groups_ban_member' ) )
  91                  return false;
  92  
  93              // Ban a user.
  94              if ( !groups_ban_member( $user_id, $bp->groups->current_group->id ) )
  95                  bp_core_add_message( __( 'There was an error when banning that user. Please try again.', 'buddypress' ), 'error' );
  96              else
  97                  bp_core_add_message( __( 'User banned successfully', 'buddypress' ) );
  98  
  99              /**
 100               * Fires before the redirect after a group member has been banned.
 101               *
 102               * @since 1.0.0
 103               *
 104               * @param int $user_id ID of the user being banned.
 105               * @param int $id      ID of the group user is banned from.
 106               */
 107              do_action( 'groups_banned_member', $user_id, $bp->groups->current_group->id );
 108  
 109              bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/manage-members/' );
 110          }
 111  
 112          if ( bp_is_action_variable( 'unban', 1 ) && is_numeric( bp_action_variable( 2 ) ) ) {
 113              $user_id = bp_action_variable( 2 );
 114  
 115              // Check the nonce first.
 116              if ( !check_admin_referer( 'groups_unban_member' ) )
 117                  return false;
 118  
 119              // Remove a ban for user.
 120              if ( !groups_unban_member( $user_id, $bp->groups->current_group->id ) )
 121                  bp_core_add_message( __( 'There was an error when unbanning that user. Please try again.', 'buddypress' ), 'error' );
 122              else
 123                  bp_core_add_message( __( 'User ban removed successfully', 'buddypress' ) );
 124  
 125              /**
 126               * Fires before the redirect after a group member has been unbanned.
 127               *
 128               * @since 1.0.0
 129               *
 130               * @param int $user_id ID of the user being unbanned.
 131               * @param int $id      ID of the group user is unbanned from.
 132               */
 133              do_action( 'groups_unbanned_member', $user_id, $bp->groups->current_group->id );
 134  
 135              bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/manage-members/' );
 136          }
 137  
 138          if ( bp_is_action_variable( 'remove', 1 ) && is_numeric( bp_action_variable( 2 ) ) ) {
 139              $user_id = bp_action_variable( 2 );
 140  
 141              // Check the nonce first.
 142              if ( !check_admin_referer( 'groups_remove_member' ) )
 143                  return false;
 144  
 145              // Remove a user.
 146              if ( !groups_remove_member( $user_id, $bp->groups->current_group->id ) )
 147                  bp_core_add_message( __( 'There was an error removing that user from the group. Please try again.', 'buddypress' ), 'error' );
 148              else
 149                  bp_core_add_message( __( 'User removed successfully', 'buddypress' ) );
 150  
 151              /**
 152               * Fires before the redirect after a group member has been removed.
 153               *
 154               * @since 1.2.6
 155               *
 156               * @param int $user_id ID of the user being removed.
 157               * @param int $id      ID of the group the user is removed from.
 158               */
 159              do_action( 'groups_removed_member', $user_id, $bp->groups->current_group->id );
 160  
 161              bp_core_redirect( bp_get_group_permalink( groups_get_current_group() ) . 'admin/manage-members/' );
 162          }
 163      }
 164  
 165      /**
 166       * Fires before the loading of a group's manage members template.
 167       *
 168       * @since 1.0.0
 169       *
 170       * @param int $id ID of the group whose manage members page is being displayed.
 171       */
 172      do_action( 'groups_screen_group_admin_manage_members', $bp->groups->current_group->id );
 173  
 174      /**
 175       * Filters the template to load for a group's manage members page.
 176       *
 177       * @since 1.0.0
 178       *
 179       * @param string $value Path to a group's manage members template.
 180       */
 181      bp_core_load_template( apply_filters( 'groups_template_group_admin_manage_members', 'groups/single/home' ) );
 182  }
 183  add_action( 'bp_screens', 'groups_screen_group_admin_manage_members' );


Generated: Sun Dec 22 01:00:54 2024 Cross-referenced by PHPXref 0.7.1