[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-groups/screens/single/ -> request-membership.php (source)

   1  <?php
   2  /**
   3   * Groups: Single group "Request Membership" screen handler
   4   *
   5   * @package BuddyPress
   6   * @subpackage GroupsScreens
   7   * @since 3.0.0
   8   */
   9  
  10  /**
  11   * Handle the display of a group's Request Membership page.
  12   *
  13   * @since 1.0.0
  14   */
  15  function groups_screen_group_request_membership() {
  16  
  17      if ( ! is_user_logged_in() ) {
  18          return false;
  19      }
  20  
  21      $bp = buddypress();
  22  
  23      if ( 'private' != $bp->groups->current_group->status ) {
  24          return false;
  25      }
  26  
  27      // If the user is already invited, accept invitation.
  28      if ( groups_check_user_has_invite( bp_loggedin_user_id(), $bp->groups->current_group->id ) ) {
  29          if ( groups_accept_invite( bp_loggedin_user_id(), $bp->groups->current_group->id ) ) {
  30              bp_core_add_message( __( 'Group invite accepted', 'buddypress' ) );
  31          } else {
  32              bp_core_add_message( __( 'There was an error accepting the group invitation. Please try again.', 'buddypress' ), 'error' );
  33          }
  34  
  35          bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) );
  36      }
  37  
  38      // If the user has submitted a request, send it.
  39      if ( isset( $_POST['group-request-send']) ) {
  40  
  41          // Check the nonce.
  42          if ( ! check_admin_referer( 'groups_request_membership' ) ) {
  43              return false;
  44          }
  45  
  46          // Default arguments for the membership request.
  47          $request_args = array(
  48              'user_id'  => bp_loggedin_user_id(),
  49              'group_id' => $bp->groups->current_group->id
  50          );
  51  
  52          // If the member added a message to their request include it into the request arguments.
  53          if ( isset( $_POST['group-request-membership-comments'] ) && $_POST['group-request-membership-comments'] ) {
  54              $request_args['content'] = strip_tags( wp_unslash( $_POST['group-request-membership-comments'] ) );
  55          }
  56  
  57          if ( ! groups_send_membership_request( $request_args ) ) {
  58              bp_core_add_message( __( 'There was an error sending your group membership request. Please try again.', 'buddypress' ), 'error' );
  59          } else {
  60              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' ) );
  61          }
  62          bp_core_redirect( bp_get_group_permalink( $bp->groups->current_group ) );
  63      }
  64  
  65      /**
  66       * Fires before the loading of a group's Request Memebership page.
  67       *
  68       * @since 1.0.0
  69       *
  70       * @param int $id ID of the group currently being displayed.
  71       */
  72      do_action( 'groups_screen_group_request_membership', $bp->groups->current_group->id );
  73  
  74      /**
  75       * Filters the template to load for a group's Request Membership page.
  76       *
  77       * @since 1.0.0
  78       *
  79       * @param string $value Path to a group's Request Membership template.
  80       */
  81      bp_core_load_template( apply_filters( 'groups_template_group_request_membership', 'groups/single/home' ) );
  82  }


Generated: Thu Nov 21 01:00:57 2024 Cross-referenced by PHPXref 0.7.1