bp_core_screen_signup

Handle the loading of the signup screen.

Description

bp_core_screen_signup(); 

Usage

  1. if ( !function_exists( 'bp_core_screen_signup' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-members/bp-members-screens.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bp_core_screen_signup(); 
  7.  

Defined (1)

The function is defined in the following location(s).

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