[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-groups/actions/ -> leave-group.php (source)

   1  <?php
   2  /**
   3   * Groups: Leave action
   4   *
   5   * @package BuddyPress
   6   * @subpackage GroupActions
   7   * @since 3.0.0
   8   */
   9  
  10  /**
  11   * Catch and process "Leave Group" button clicks.
  12   *
  13   * When a group member clicks on the "Leave Group" button from a group's page,
  14   * this function is run.
  15   *
  16   * Note: When leaving a group from the group directory, AJAX is used and
  17   * another function handles this. See {@link bp_legacy_theme_ajax_joinleave_group()}.
  18   *
  19   * @since 1.2.4
  20   *
  21   * @return bool
  22   */
  23  function groups_action_leave_group() {
  24      if ( ! bp_is_single_item() || ! bp_is_groups_component() || ! bp_is_current_action( 'leave-group' ) ) {
  25          return false;
  26      }
  27  
  28      // Nonce check.
  29      if ( ! check_admin_referer( 'groups_leave_group' ) ) {
  30          return false;
  31      }
  32  
  33      // User wants to leave any group.
  34      if ( groups_is_user_member( bp_loggedin_user_id(), bp_get_current_group_id() ) ) {
  35          $bp = buddypress();
  36  
  37          // Stop sole admins from abandoning their group.
  38          $group_admins = groups_get_group_admins( bp_get_current_group_id() );
  39  
  40          if ( 1 == count( $group_admins ) && $group_admins[0]->user_id == bp_loggedin_user_id() ) {
  41              bp_core_add_message( __( 'This group must have at least one admin', 'buddypress' ), 'error' );
  42          } elseif ( ! groups_leave_group( $bp->groups->current_group->id ) ) {
  43              bp_core_add_message( __( 'There was an error leaving the group.', 'buddypress' ), 'error' );
  44          } else {
  45              bp_core_add_message( __( 'You successfully left the group.', 'buddypress' ) );
  46          }
  47  
  48          $group = groups_get_current_group();
  49          $redirect = bp_get_group_permalink( $group );
  50  
  51          if ( ! $group->is_visible ) {
  52              $redirect = trailingslashit( bp_loggedin_user_domain() . bp_get_groups_slug() );
  53          }
  54  
  55          bp_core_redirect( $redirect );
  56      }
  57  
  58      /** This filter is documented in bp-groups/bp-groups-actions.php */
  59      bp_core_load_template( apply_filters( 'groups_template_group_home', 'groups/single/home' ) );
  60  }
  61  add_action( 'bp_actions', 'groups_action_leave_group' );


Generated: Fri Jul 19 01:01:43 2019 Cross-referenced by PHPXref 0.7.1