[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
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 22 // Not a directory. 23 bp_update_is_directory( false, 'register' ); 24 25 // If the user is logged in, redirect away from here. 26 if ( is_user_logged_in() ) { 27 28 $redirect_to = bp_is_component_front_page( 'register' ) 29 ? bp_get_members_directory_permalink() 30 : bp_get_root_domain(); 31 32 /** 33 * Filters the URL to redirect logged in users to when visiting registration page. 34 * 35 * @since 1.5.1 36 * 37 * @param string $redirect_to URL to redirect user to. 38 */ 39 bp_core_redirect( apply_filters( 'bp_loggedin_register_page_redirect_to', $redirect_to ) ); 40 41 return; 42 } 43 44 $bp->signup->step = 'request-details'; 45 46 // Could the user be accepting an invitation? 47 $active_invite = false; 48 if ( bp_get_members_invitations_allowed() ) { 49 // Check to see if there's a valid invitation. 50 $maybe_invite = bp_get_members_invitation_from_request(); 51 if ( $maybe_invite->id && $maybe_invite->invitee_email ) { 52 // Check if this user is already a member. 53 $args = array( 54 'invitee_email' => $maybe_invite->invitee_email, 55 'accepted' => 'accepted', 56 'fields' => 'ids', 57 ); 58 $accepted_invites = bp_members_invitations_get_invites( $args ); 59 if ( ! $accepted_invites ) { 60 $active_invite = true; 61 } 62 } 63 } 64 65 $requests_enabled = bp_get_membership_requests_required(); 66 67 if ( ! bp_get_signup_allowed() && ! $active_invite && ! $requests_enabled ) { 68 $bp->signup->step = 'registration-disabled'; 69 // If the signup page is submitted, validate and save. 70 } elseif ( isset( $_POST['signup_submit'] ) && bp_verify_nonce_request( 'bp_new_signup' ) ) { 71 72 /** 73 * Fires before the validation of a new signup. 74 * 75 * @since 2.0.0 76 */ 77 do_action( 'bp_signup_pre_validate' ); 78 79 // Check the base account details for problems. 80 $account_details = bp_core_validate_user_signup( $_POST['signup_username'], $_POST['signup_email'] ); 81 82 // If there are errors with account details, set them for display. 83 if ( ! empty( $account_details['errors']->errors['user_name'] ) ) { 84 $bp->signup->errors['signup_username'] = $account_details['errors']->errors['user_name'][0]; 85 } 86 87 if ( ! empty( $account_details['errors']->errors['user_email'] ) ) { 88 $bp->signup->errors['signup_email'] = $account_details['errors']->errors['user_email'][0]; 89 } 90 91 // Password strength check. 92 $required_password_strength = bp_members_user_pass_required_strength(); 93 $current_password_strength = null; 94 if ( isset( $_POST['_password_strength_score'] ) ) { 95 $current_password_strength = (int) $_POST['_password_strength_score']; 96 } 97 98 if ( $required_password_strength && ! is_null( $current_password_strength ) && $required_password_strength > $current_password_strength ) { 99 $account_password = new WP_Error( 100 'not_strong_enough_password', 101 __( 'Your password is not strong enough to be allowed on this site. Please use a stronger password.', 'buddypress' ) 102 ); 103 } else { 104 $signup_pass = ''; 105 if ( isset( $_POST['signup_password'] ) ) { 106 $signup_pass = wp_unslash( $_POST['signup_password'] ); 107 } 108 109 $signup_pass_confirm = ''; 110 if ( isset( $_POST['signup_password_confirm'] ) ) { 111 $signup_pass_confirm = wp_unslash( $_POST['signup_password_confirm'] ); 112 } 113 114 // Check the account password for problems. 115 $account_password = bp_members_validate_user_password( $signup_pass, $signup_pass_confirm ); 116 } 117 118 $password_error = $account_password->get_error_message(); 119 120 if ( $password_error ) { 121 $bp->signup->errors['signup_password'] = $password_error; 122 } 123 124 if ( bp_signup_requires_privacy_policy_acceptance() && ! empty( $_POST['signup-privacy-policy-check'] ) && empty( $_POST['signup-privacy-policy-accept'] ) ) { 125 $bp->signup->errors['signup_privacy_policy'] = __( 'You must indicate that you have read and agreed to the Privacy Policy.', 'buddypress' ); 126 } 127 128 $bp->signup->username = $_POST['signup_username']; 129 $bp->signup->email = $_POST['signup_email']; 130 131 // Now we've checked account details, we can check profile information. 132 if ( bp_is_active( 'xprofile' ) ) { 133 134 // Make sure hidden field is passed and populated. 135 if ( isset( $_POST['signup_profile_field_ids'] ) && !empty( $_POST['signup_profile_field_ids'] ) ) { 136 137 // Let's compact any profile field info into an array. 138 $profile_field_ids = explode( ',', $_POST['signup_profile_field_ids'] ); 139 140 // Loop through the posted fields formatting any datebox values then validate the field. 141 foreach ( (array) $profile_field_ids as $field_id ) { 142 bp_xprofile_maybe_format_datebox_post_data( $field_id ); 143 144 // Trim post fields. 145 if ( isset( $_POST[ 'field_' . $field_id ] ) ) { 146 if ( is_array( $_POST[ 'field_' . $field_id ] ) ) { 147 $_POST[ 'field_' . $field_id ] = array_map( 'trim', $_POST[ 'field_' . $field_id ] ); 148 } else { 149 $_POST[ 'field_' . $field_id ] = trim( $_POST[ 'field_' . $field_id ] ); 150 } 151 } 152 153 // Create errors for required fields without values. 154 if ( xprofile_check_is_required_field( $field_id ) && empty( $_POST[ 'field_' . $field_id ] ) && ! bp_current_user_can( 'bp_moderate' ) ) 155 $bp->signup->errors['field_' . $field_id] = __( 'This is a required field', 'buddypress' ); 156 } 157 158 // This situation doesn't naturally occur so bounce to website root. 159 } else { 160 bp_core_redirect( bp_get_root_domain() ); 161 } 162 } 163 164 // Finally, let's check the blog details, if the user wants a blog and blog creation is enabled. 165 if ( isset( $_POST['signup_with_blog'] ) ) { 166 $active_signup = bp_core_get_root_option( 'registration' ); 167 168 if ( 'blog' == $active_signup || 'all' == $active_signup ) { 169 $blog_details = bp_core_validate_blog_signup( $_POST['signup_blog_url'], $_POST['signup_blog_title'] ); 170 171 // If there are errors with blog details, set them for display. 172 if ( !empty( $blog_details['errors']->errors['blogname'] ) ) 173 $bp->signup->errors['signup_blog_url'] = $blog_details['errors']->errors['blogname'][0]; 174 175 if ( !empty( $blog_details['errors']->errors['blog_title'] ) ) 176 $bp->signup->errors['signup_blog_title'] = $blog_details['errors']->errors['blog_title'][0]; 177 } 178 } 179 180 /** 181 * Fires after the validation of a new signup. 182 * 183 * @since 1.1.0 184 */ 185 do_action( 'bp_signup_validate' ); 186 187 // Add any errors to the action for the field in the template for display. 188 if ( !empty( $bp->signup->errors ) ) { 189 foreach ( (array) $bp->signup->errors as $fieldname => $error_message ) { 190 /** 191 * Filters the error message in the loop. 192 * 193 * @since 1.5.0 194 * @since 8.0.0 Adds the `$fieldname` parameter to the anonymous function. 195 * 196 * @param string $value Error message wrapped in html. 197 * @param string $fieldname The name of the signup field. 198 */ 199 add_action( 'bp_' . $fieldname . '_errors', function() use ( $error_message, $fieldname ) { 200 /** 201 * Filter here to edit the error message about the invalid field value. 202 * 203 * @since 1.5.0 204 * @since 8.0.0 Adds the `$fieldname` parameter. 205 * 206 * @param string $value Error message wrapped in html. 207 * @param string $fieldname The name of the signup field. 208 */ 209 echo apply_filters( 'bp_members_signup_error_message', "<div class=\"error\">" . $error_message . "</div>", $fieldname ); 210 } ); 211 } 212 } else { 213 $bp->signup->step = 'save-details'; 214 215 // No errors! Let's register those deets. 216 $active_signup = bp_core_get_root_option( 'registration' ); 217 218 if ( 'none' != $active_signup || $requests_enabled ) { 219 220 // Make sure the extended profiles module is enabled. 221 if ( bp_is_active( 'xprofile' ) ) { 222 // Let's compact any profile field info into usermeta. 223 $profile_field_ids = explode( ',', $_POST['signup_profile_field_ids'] ); 224 225 /* 226 * Loop through the posted fields, formatting any 227 * datebox values, then add to usermeta. 228 */ 229 foreach ( (array) $profile_field_ids as $field_id ) { 230 bp_xprofile_maybe_format_datebox_post_data( $field_id ); 231 232 if ( !empty( $_POST['field_' . $field_id] ) ) 233 $usermeta['field_' . $field_id] = $_POST['field_' . $field_id]; 234 235 if ( !empty( $_POST['field_' . $field_id . '_visibility'] ) ) 236 $usermeta['field_' . $field_id . '_visibility'] = $_POST['field_' . $field_id . '_visibility']; 237 } 238 239 // Store the profile field ID's in usermeta. 240 $usermeta['profile_field_ids'] = $_POST['signup_profile_field_ids']; 241 } 242 243 // Hash and store the password. 244 $usermeta['password'] = wp_hash_password( $_POST['signup_password'] ); 245 246 // If the user decided to create a blog, save those details to usermeta. 247 if ( 'blog' == $active_signup || 'all' == $active_signup ) 248 $usermeta['public'] = ( isset( $_POST['signup_blog_privacy'] ) && 'public' == $_POST['signup_blog_privacy'] ) ? true : false; 249 250 /** 251 * Filters the user meta used for signup. 252 * 253 * @since 1.1.0 254 * 255 * @param array $usermeta Array of user meta to add to signup. 256 */ 257 $usermeta = apply_filters( 'bp_signup_usermeta', $usermeta ); 258 259 // Finally, sign up the user and/or blog. 260 if ( isset( $_POST['signup_with_blog'] ) && is_multisite() ) 261 $wp_user_id = bp_core_signup_blog( $blog_details['domain'], $blog_details['path'], $blog_details['blog_title'], $_POST['signup_username'], $_POST['signup_email'], $usermeta ); 262 else 263 $wp_user_id = bp_core_signup_user( $_POST['signup_username'], $_POST['signup_password'], $_POST['signup_email'], $usermeta ); 264 265 if ( is_wp_error( $wp_user_id ) ) { 266 $bp->signup->step = 'request-details'; 267 bp_core_add_message( $wp_user_id->get_error_message(), 'error' ); 268 } else { 269 $bp->signup->step = 'completed-confirmation'; 270 } 271 } 272 273 /** 274 * Fires after the completion of a new signup. 275 * 276 * @since 1.1.0 277 */ 278 do_action( 'bp_complete_signup' ); 279 } 280 281 } 282 283 /** 284 * Fires right before the loading of the Member registration screen template file. 285 * 286 * @since 1.5.0 287 */ 288 do_action( 'bp_core_screen_signup' ); 289 290 /** 291 * Filters the template to load for the Member registration page screen. 292 * 293 * @since 1.5.0 294 * 295 * @param string $value Path to the Member registration template to load. 296 */ 297 bp_core_load_template( apply_filters( 'bp_core_template_register', array( 'register', 'registration/register' ) ) ); 298 } 299 add_action( 'bp_screens', 'bp_core_screen_signup' );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Nov 21 01:00:57 2024 | Cross-referenced by PHPXref 0.7.1 |