[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * Members: Register screen handler
   4   *
   5   * @package BuddyPress
   6   * @subpackage MembersScreens
   7   * @since 3.0.0
   8   */
   9  
  10  /**
  11   * Handle the loading of the signup screen.
  12   *
  13   * @since 1.1.0
  14   */
  15  function bp_core_screen_signup() {
  16      $bp = buddypress();
  17  
  18      if ( ! bp_is_current_component( 'register' ) || bp_current_action() )
  19          return;
  20  
  21      // Not a directory.
  22      bp_update_is_directory( false, 'register' );
  23  
  24      // If the user is logged in, redirect away from here.
  25      if ( is_user_logged_in() ) {
  26  
  27          $redirect_to = bp_is_component_front_page( 'register' )
  28              ? bp_get_members_directory_permalink()
  29              : bp_get_root_domain();
  30  
  31          /**
  32           * Filters the URL to redirect logged in users to when visiting registration page.
  33           *
  34           * @since 1.5.1
  35           *
  36           * @param string $redirect_to URL to redirect user to.
  37           */
  38          bp_core_redirect( apply_filters( 'bp_loggedin_register_page_redirect_to', $redirect_to ) );
  39  
  40          return;
  41      }
  42  
  43      $bp->signup->step = 'request-details';
  44  
  45      if ( !bp_get_signup_allowed() ) {
  46          $bp->signup->step = 'registration-disabled';
  47  
  48          // If the signup page is submitted, validate and save.
  49      } elseif ( isset( $_POST['signup_submit'] ) && bp_verify_nonce_request( 'bp_new_signup' ) ) {
  50  
  51          /**
  52           * Fires before the validation of a new signup.
  53           *
  54           * @since 2.0.0
  55           */
  56          do_action( 'bp_signup_pre_validate' );
  57  
  58          // Check the base account details for problems.
  59          $account_details = bp_core_validate_user_signup( $_POST['signup_username'], $_POST['signup_email'] );
  60  
  61          // If there are errors with account details, set them for display.
  62          if ( !empty( $account_details['errors']->errors['user_name'] ) )
  63              $bp->signup->errors['signup_username'] = $account_details['errors']->errors['user_name'][0];
  64  
  65          if ( !empty( $account_details['errors']->errors['user_email'] ) )
  66              $bp->signup->errors['signup_email'] = $account_details['errors']->errors['user_email'][0];
  67  
  68          // Check that both password fields are filled in.
  69          if ( empty( $_POST['signup_password'] ) || empty( $_POST['signup_password_confirm'] ) )
  70              $bp->signup->errors['signup_password'] = __( 'Please make sure you enter your password twice', 'buddypress' );
  71  
  72          // Check that the passwords match.
  73          if ( ( !empty( $_POST['signup_password'] ) && !empty( $_POST['signup_password_confirm'] ) ) && $_POST['signup_password'] != $_POST['signup_password_confirm'] )
  74              $bp->signup->errors['signup_password'] = __( 'The passwords you entered do not match.', 'buddypress' );
  75  
  76          if ( bp_signup_requires_privacy_policy_acceptance() && ! empty( $_POST['signup-privacy-policy-check'] ) && empty( $_POST['signup-privacy-policy-accept'] ) ) {
  77              $bp->signup->errors['signup_privacy_policy'] = __( 'You must indicate that you have read and agreed to the Privacy Policy.', 'buddypress' );
  78          }
  79  
  80          $bp->signup->username = $_POST['signup_username'];
  81          $bp->signup->email = $_POST['signup_email'];
  82  
  83          // Now we've checked account details, we can check profile information.
  84          if ( bp_is_active( 'xprofile' ) ) {
  85  
  86              // Make sure hidden field is passed and populated.
  87              if ( isset( $_POST['signup_profile_field_ids'] ) && !empty( $_POST['signup_profile_field_ids'] ) ) {
  88  
  89                  // Let's compact any profile field info into an array.
  90                  $profile_field_ids = explode( ',', $_POST['signup_profile_field_ids'] );
  91  
  92                  // Loop through the posted fields formatting any datebox values then validate the field.
  93                  foreach ( (array) $profile_field_ids as $field_id ) {
  94                      bp_xprofile_maybe_format_datebox_post_data( $field_id );
  95  
  96                      // Trim post fields.
  97                      if ( isset( $_POST[ 'field_' . $field_id ] ) ) {
  98                          if ( is_array( $_POST[ 'field_' . $field_id ] ) ) {
  99                              $_POST[ 'field_' . $field_id ] = array_map( 'trim', $_POST[ 'field_' . $field_id ] );
 100                          } else {
 101                              $_POST[ 'field_' . $field_id ] = trim( $_POST[ 'field_' . $field_id ] );
 102                          }
 103                      }
 104  
 105                      // Create errors for required fields without values.
 106                      if ( xprofile_check_is_required_field( $field_id ) && empty( $_POST[ 'field_' . $field_id ] ) && ! bp_current_user_can( 'bp_moderate' ) )
 107                          $bp->signup->errors['field_' . $field_id] = __( 'This is a required field', 'buddypress' );
 108                  }
 109  
 110                  // This situation doesn't naturally occur so bounce to website root.
 111              } else {
 112                  bp_core_redirect( bp_get_root_domain() );
 113              }
 114          }
 115  
 116          // Finally, let's check the blog details, if the user wants a blog and blog creation is enabled.
 117          if ( isset( $_POST['signup_with_blog'] ) ) {
 118              $active_signup = bp_core_get_root_option( 'registration' );
 119  
 120              if ( 'blog' == $active_signup || 'all' == $active_signup ) {
 121                  $blog_details = bp_core_validate_blog_signup( $_POST['signup_blog_url'], $_POST['signup_blog_title'] );
 122  
 123                  // If there are errors with blog details, set them for display.
 124                  if ( !empty( $blog_details['errors']->errors['blogname'] ) )
 125                      $bp->signup->errors['signup_blog_url'] = $blog_details['errors']->errors['blogname'][0];
 126  
 127                  if ( !empty( $blog_details['errors']->errors['blog_title'] ) )
 128                      $bp->signup->errors['signup_blog_title'] = $blog_details['errors']->errors['blog_title'][0];
 129              }
 130          }
 131  
 132          /**
 133           * Fires after the validation of a new signup.
 134           *
 135           * @since 1.1.0
 136           */
 137          do_action( 'bp_signup_validate' );
 138  
 139          // Add any errors to the action for the field in the template for display.
 140          if ( !empty( $bp->signup->errors ) ) {
 141              foreach ( (array) $bp->signup->errors as $fieldname => $error_message ) {
 142                  /**
 143                   * Filters the error message in the loop.
 144                   *
 145                   * @since 1.5.0
 146                   *
 147                   * @param string $value Error message wrapped in html.
 148                   */
 149                  add_action( 'bp_' . $fieldname . '_errors', function() use ( $error_message ) {
 150                      echo apply_filters( 'bp_members_signup_error_message', "<div class=\"error\">" . $error_message . "</div>" );
 151                  } );
 152              }
 153          } else {
 154              $bp->signup->step = 'save-details';
 155  
 156              // No errors! Let's register those deets.
 157              $active_signup = bp_core_get_root_option( 'registration' );
 158  
 159              if ( 'none' != $active_signup ) {
 160  
 161                  // Make sure the extended profiles module is enabled.
 162                  if ( bp_is_active( 'xprofile' ) ) {
 163                      // Let's compact any profile field info into usermeta.
 164                      $profile_field_ids = explode( ',', $_POST['signup_profile_field_ids'] );
 165  
 166                      /*
 167                       * Loop through the posted fields, formatting any
 168                       * datebox values, then add to usermeta.
 169                       */
 170                      foreach ( (array) $profile_field_ids as $field_id ) {
 171                          bp_xprofile_maybe_format_datebox_post_data( $field_id );
 172  
 173                          if ( !empty( $_POST['field_' . $field_id] ) )
 174                              $usermeta['field_' . $field_id] = $_POST['field_' . $field_id];
 175  
 176                          if ( !empty( $_POST['field_' . $field_id . '_visibility'] ) )
 177                              $usermeta['field_' . $field_id . '_visibility'] = $_POST['field_' . $field_id . '_visibility'];
 178                      }
 179  
 180                      // Store the profile field ID's in usermeta.
 181                      $usermeta['profile_field_ids'] = $_POST['signup_profile_field_ids'];
 182                  }
 183  
 184                  // Hash and store the password.
 185                  $usermeta['password'] = wp_hash_password( $_POST['signup_password'] );
 186  
 187                  // If the user decided to create a blog, save those details to usermeta.
 188                  if ( 'blog' == $active_signup || 'all' == $active_signup )
 189                      $usermeta['public'] = ( isset( $_POST['signup_blog_privacy'] ) && 'public' == $_POST['signup_blog_privacy'] ) ? true : false;
 190  
 191                  /**
 192                   * Filters the user meta used for signup.
 193                   *
 194                   * @since 1.1.0
 195                   *
 196                   * @param array $usermeta Array of user meta to add to signup.
 197                   */
 198                  $usermeta = apply_filters( 'bp_signup_usermeta', $usermeta );
 199  
 200                  // Finally, sign up the user and/or blog.
 201                  if ( isset( $_POST['signup_with_blog'] ) && is_multisite() )
 202                      $wp_user_id = bp_core_signup_blog( $blog_details['domain'], $blog_details['path'], $blog_details['blog_title'], $_POST['signup_username'], $_POST['signup_email'], $usermeta );
 203                  else
 204                      $wp_user_id = bp_core_signup_user( $_POST['signup_username'], $_POST['signup_password'], $_POST['signup_email'], $usermeta );
 205  
 206                  if ( is_wp_error( $wp_user_id ) ) {
 207                      $bp->signup->step = 'request-details';
 208                      bp_core_add_message( $wp_user_id->get_error_message(), 'error' );
 209                  } else {
 210                      $bp->signup->step = 'completed-confirmation';
 211                  }
 212              }
 213  
 214              /**
 215               * Fires after the completion of a new signup.
 216               *
 217               * @since 1.1.0
 218               */
 219              do_action( 'bp_complete_signup' );
 220          }
 221  
 222      }
 223  
 224      /**
 225       * Fires right before the loading of the Member registration screen template file.
 226       *
 227       * @since 1.5.0
 228       */
 229      do_action( 'bp_core_screen_signup' );
 230  
 231      /**
 232       * Filters the template to load for the Member registration page screen.
 233       *
 234       * @since 1.5.0
 235       *
 236       * @param string $value Path to the Member registration template to load.
 237       */
 238      bp_core_load_template( apply_filters( 'bp_core_template_register', array( 'register', 'registration/register' ) ) );
 239  }
 240  add_action( 'bp_screens', 'bp_core_screen_signup' );


Generated: Fri Dec 13 01:01:36 2019 Cross-referenced by PHPXref 0.7.1