[ 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      $redirect = bp_get_activation_page();
  90  
  91      /**
  92       * Filters the activation signup.
  93       *
  94       * @since 1.1.0
  95       *
  96       * @param bool|int $value Value returned by activation.
  97       *                        Integer on success, boolean on failure.
  98       */
  99      $user = apply_filters( 'bp_core_activate_account', bp_core_activate_signup( $key ) );
 100  
 101      // If there were errors, add a message and redirect.
 102      if ( ! empty( $user->errors ) ) {
 103          /**
 104           * Filter here to redirect the User to a different URL than the activation page.
 105           *
 106           * @since 10.0.0
 107           *
 108           * @param string   $redirect The URL to use to redirect the user.
 109           * @param WP_Error $user     The WP Error object.
 110           */
 111          $redirect = apply_filters( 'bp_members_action_activate_errored_redirect', $redirect, $user );
 112  
 113          bp_core_add_message( $user->get_error_message(), 'error' );
 114          bp_core_redirect( $redirect );
 115      }
 116  
 117      /**
 118       * Filter here to redirect the User to a different URL than the activation page.
 119       *
 120       * @since 10.0.0
 121       *
 122       * @param string $redirect The URL to use to redirect the user.
 123       */
 124      $redirect = apply_filters( 'bp_members_action_activate_successed_redirect', $redirect );
 125  
 126      bp_core_add_message( __( 'Your account is now active!', 'buddypress' ) );
 127      bp_core_redirect( add_query_arg( 'activated', '1', $redirect ) );
 128  
 129  }
 130  add_action( 'bp_actions', 'bp_members_action_activate_account' );


Generated: Sun Nov 24 01:00:53 2024 Cross-referenced by PHPXref 0.7.1