[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-members/screens/ -> activate.php (source)

   1  <?php
   2  /**
   3   * Members: Activate screen handler
   4   *
   5   * @package BuddyPress
   6   * @subpackage MembersScreens
   7   * @since 3.0.0
   8   */
   9  
  10  /**
  11   * Handle the loading of the Activate screen.
  12   *
  13   * @since 1.1.0
  14   */
  15  function bp_core_screen_activation() {
  16  
  17      // Bail if not viewing the activation page.
  18      if ( ! bp_is_current_component( 'activate' ) ) {
  19          return false;
  20      }
  21  
  22      // If the user is already logged in, redirect away from here.
  23      if ( is_user_logged_in() ) {
  24  
  25          // If activation page is also front page, set to members directory to
  26          // avoid an infinite loop. Otherwise, set to root domain.
  27          $redirect_to = bp_is_component_front_page( 'activate' )
  28              ? bp_get_members_directory_permalink()
  29              : bp_get_root_domain();
  30  
  31          // Trailing slash it, as we expect these URL's to be.
  32          $redirect_to = trailingslashit( $redirect_to );
  33  
  34          /**
  35           * Filters the URL to redirect logged in users to when visiting activation page.
  36           *
  37           * @since 1.9.0
  38           *
  39           * @param string $redirect_to URL to redirect user to.
  40           */
  41          $redirect_to = apply_filters( 'bp_loggedin_activate_page_redirect_to', $redirect_to );
  42  
  43          // Redirect away from the activation page.
  44          bp_core_redirect( $redirect_to );
  45      }
  46  
  47      // Get BuddyPress.
  48      $bp = buddypress();
  49  
  50      /**
  51       * Filters the template to load for the Member activation page screen.
  52       *
  53       * @since 1.1.1
  54       *
  55       * @param string $value Path to the Member activation template to load.
  56       */
  57      bp_core_load_template( apply_filters( 'bp_core_template_activate', array( 'activate', 'registration/activate' ) ) );
  58  }
  59  add_action( 'bp_screens', 'bp_core_screen_activation' );
  60  
  61  
  62  /**
  63   * Catches and processes account activation requests.
  64   *
  65   * @since 3.0.0
  66   */
  67  function bp_members_action_activate_account() {
  68      if ( ! bp_is_current_component( 'activate' ) ) {
  69          return;
  70      }
  71  
  72      if ( is_user_logged_in() ) {
  73          return;
  74      }
  75  
  76      if ( ! empty( $_POST['key'] ) ) {
  77          $key = wp_unslash( $_POST['key'] );
  78  
  79      // Backward compatibility with templates using `method="get"` in their activation forms.
  80      } elseif ( ! empty( $_GET['key'] ) ) {
  81          $key = wp_unslash( $_GET['key'] );
  82      }
  83  
  84      if ( empty( $key ) ) {
  85          return;
  86      }
  87  
  88      $bp = buddypress();
  89  
  90      /**
  91       * Filters the activation signup.
  92       *
  93       * @since 1.1.0
  94       *
  95       * @param bool|int $value Value returned by activation.
  96       *                        Integer on success, boolean on failure.
  97       */
  98      $user = apply_filters( 'bp_core_activate_account', bp_core_activate_signup( $key ) );
  99  
 100      // If there were errors, add a message and redirect.
 101      if ( ! empty( $user->errors ) ) {
 102          bp_core_add_message( $user->get_error_message(), 'error' );
 103          bp_core_redirect( trailingslashit( bp_get_root_domain() . '/' . $bp->pages->activate->slug ) );
 104      }
 105  
 106      bp_core_add_message( __( 'Your account is now active!', 'buddypress' ) );
 107      bp_core_redirect( add_query_arg( 'activated', '1', bp_get_activation_page() ) );
 108  
 109  }
 110  add_action( 'bp_actions', 'bp_members_action_activate_account' );


Generated: Wed Jul 17 01:01:40 2019 Cross-referenced by PHPXref 0.7.1