Changeset 5700 for trunk/bp-members/bp-members-screens.php
- Timestamp:
- 02/11/2012 02:29:55 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-members/bp-members-screens.php
r5072 r5700 1 1 <?php 2 2 3 /** 3 4 * BuddyPress Member Screens … … 6 7 * 7 8 * @package BuddyPress 8 * @subpackage Members 9 * @subpackage MembersScreens 9 10 */ 10 11 … … 46 47 47 48 49 function bp_core_screen_signup() { 50 global $bp; 51 52 if ( !bp_is_current_component( 'register' ) ) 53 return; 54 55 // Not a directory 56 bp_update_is_directory( false, 'register' ); 57 58 // If the user is logged in, redirect away from here 59 if ( is_user_logged_in() ) { 60 if ( bp_is_component_front_page( 'register' ) ) 61 $redirect_to = trailingslashit( bp_get_root_domain() . '/' . bp_get_members_root_slug() ); 62 else 63 $redirect_to = bp_get_root_domain(); 64 65 bp_core_redirect( apply_filters( 'bp_loggedin_register_page_redirect_to', $redirect_to ) ); 66 67 return; 68 } 69 70 $bp->signup->step = 'request-details'; 71 72 if ( !bp_get_signup_allowed() ) { 73 $bp->signup->step = 'registration-disabled'; 74 } 75 76 // If the signup page is submitted, validate and save 77 elseif ( isset( $_POST['signup_submit'] ) ) { 78 79 // Check the nonce 80 check_admin_referer( 'bp_new_signup' ); 81 82 // Check the base account details for problems 83 $account_details = bp_core_validate_user_signup( $_POST['signup_username'], $_POST['signup_email'] ); 84 85 // If there are errors with account details, set them for display 86 if ( !empty( $account_details['errors']->errors['user_name'] ) ) 87 $bp->signup->errors['signup_username'] = $account_details['errors']->errors['user_name'][0]; 88 89 if ( !empty( $account_details['errors']->errors['user_email'] ) ) 90 $bp->signup->errors['signup_email'] = $account_details['errors']->errors['user_email'][0]; 91 92 // Check that both password fields are filled in 93 if ( empty( $_POST['signup_password'] ) || empty( $_POST['signup_password_confirm'] ) ) 94 $bp->signup->errors['signup_password'] = __( 'Please make sure you enter your password twice', 'buddypress' ); 95 96 // Check that the passwords match 97 if ( ( !empty( $_POST['signup_password'] ) && !empty( $_POST['signup_password_confirm'] ) ) && $_POST['signup_password'] != $_POST['signup_password_confirm'] ) 98 $bp->signup->errors['signup_password'] = __( 'The passwords you entered do not match.', 'buddypress' ); 99 100 $bp->signup->username = $_POST['signup_username']; 101 $bp->signup->email = $_POST['signup_email']; 102 103 // Now we've checked account details, we can check profile information 104 if ( bp_is_active( 'xprofile' ) ) { 105 106 // Make sure hidden field is passed and populated 107 if ( isset( $_POST['signup_profile_field_ids'] ) && !empty( $_POST['signup_profile_field_ids'] ) ) { 108 109 // Let's compact any profile field info into an array 110 $profile_field_ids = explode( ',', $_POST['signup_profile_field_ids'] ); 111 112 // Loop through the posted fields formatting any datebox values then validate the field 113 foreach ( (array) $profile_field_ids as $field_id ) { 114 if ( !isset( $_POST['field_' . $field_id] ) ) { 115 if ( !empty( $_POST['field_' . $field_id . '_day'] ) && !empty( $_POST['field_' . $field_id . '_month'] ) && !empty( $_POST['field_' . $field_id . '_year'] ) ) 116 $_POST['field_' . $field_id] = date( 'Y-m-d H:i:s', strtotime( $_POST['field_' . $field_id . '_day'] . $_POST['field_' . $field_id . '_month'] . $_POST['field_' . $field_id . '_year'] ) ); 117 } 118 119 // Create errors for required fields without values 120 if ( xprofile_check_is_required_field( $field_id ) && empty( $_POST['field_' . $field_id] ) ) 121 $bp->signup->errors['field_' . $field_id] = __( 'This is a required field', 'buddypress' ); 122 } 123 124 // This situation doesn't naturally occur so bounce to website root 125 } else { 126 bp_core_redirect( bp_get_root_domain() ); 127 } 128 } 129 130 // Finally, let's check the blog details, if the user wants a blog and blog creation is enabled 131 if ( isset( $_POST['signup_with_blog'] ) ) { 132 $active_signup = $bp->site_options['registration']; 133 134 if ( 'blog' == $active_signup || 'all' == $active_signup ) { 135 $blog_details = bp_core_validate_blog_signup( $_POST['signup_blog_url'], $_POST['signup_blog_title'] ); 136 137 // If there are errors with blog details, set them for display 138 if ( !empty( $blog_details['errors']->errors['blogname'] ) ) 139 $bp->signup->errors['signup_blog_url'] = $blog_details['errors']->errors['blogname'][0]; 140 141 if ( !empty( $blog_details['errors']->errors['blog_title'] ) ) 142 $bp->signup->errors['signup_blog_title'] = $blog_details['errors']->errors['blog_title'][0]; 143 } 144 } 145 146 do_action( 'bp_signup_validate' ); 147 148 // Add any errors to the action for the field in the template for display. 149 if ( !empty( $bp->signup->errors ) ) { 150 foreach ( (array)$bp->signup->errors as $fieldname => $error_message ) 151 add_action( 'bp_' . $fieldname . '_errors', create_function( '', 'echo apply_filters(\'bp_members_signup_error_message\', "<div class=\"error\">' . $error_message . '</div>" );' ) ); 152 } else { 153 $bp->signup->step = 'save-details'; 154 155 // No errors! Let's register those deets. 156 $active_signup = !empty( $bp->site_options['registration'] ) ? $bp->site_options['registration'] : ''; 157 158 if ( 'none' != $active_signup ) { 159 160 // Let's compact any profile field info into usermeta 161 $profile_field_ids = explode( ',', $_POST['signup_profile_field_ids'] ); 162 163 // Loop through the posted fields formatting any datebox values then add to usermeta 164 foreach ( (array) $profile_field_ids as $field_id ) { 165 if ( !isset( $_POST['field_' . $field_id] ) ) { 166 if ( isset( $_POST['field_' . $field_id . '_day'] ) ) 167 $_POST['field_' . $field_id] = date( 'Y-m-d H:i:s', strtotime( $_POST['field_' . $field_id . '_day'] . $_POST['field_' . $field_id . '_month'] . $_POST['field_' . $field_id . '_year'] ) ); 168 } 169 170 if ( !empty( $_POST['field_' . $field_id] ) ) 171 $usermeta['field_' . $field_id] = $_POST['field_' . $field_id]; 172 } 173 174 // Store the profile field ID's in usermeta 175 $usermeta['profile_field_ids'] = $_POST['signup_profile_field_ids']; 176 177 // Hash and store the password 178 $usermeta['password'] = wp_hash_password( $_POST['signup_password'] ); 179 180 // If the user decided to create a blog, save those details to usermeta 181 if ( 'blog' == $active_signup || 'all' == $active_signup ) 182 $usermeta['public'] = ( isset( $_POST['signup_blog_privacy'] ) && 'public' == $_POST['signup_blog_privacy'] ) ? true : false; 183 184 $usermeta = apply_filters( 'bp_signup_usermeta', $usermeta ); 185 186 // Finally, sign up the user and/or blog 187 if ( isset( $_POST['signup_with_blog'] ) && is_multisite() ) 188 bp_core_signup_blog( $blog_details['domain'], $blog_details['path'], $blog_details['blog_title'], $_POST['signup_username'], $_POST['signup_email'], $usermeta ); 189 else 190 bp_core_signup_user( $_POST['signup_username'], $_POST['signup_password'], $_POST['signup_email'], $usermeta ); 191 192 $bp->signup->step = 'completed-confirmation'; 193 } 194 195 do_action( 'bp_complete_signup' ); 196 } 197 198 } 199 200 do_action( 'bp_core_screen_signup' ); 201 bp_core_load_template( apply_filters( 'bp_core_template_register', 'registration/register' ) ); 202 } 203 add_action( 'bp_screens', 'bp_core_screen_signup' ); 204 205 function bp_core_screen_activation() { 206 global $bp; 207 208 if ( !bp_is_current_component( 'activate' ) ) 209 return false; 210 211 // Check if an activation key has been passed 212 if ( isset( $_GET['key'] ) ) { 213 214 // Activate the signup 215 $user = apply_filters( 'bp_core_activate_account', bp_core_activate_signup( $_GET['key'] ) ); 216 217 // If there were errors, add a message and redirect 218 if ( !empty( $user->errors ) ) { 219 bp_core_add_message( $user->get_error_message(), 'error' ); 220 bp_core_redirect( trailingslashit( bp_get_root_domain() . '/' . $bp->pages->activate->slug ) ); 221 } 222 223 // Check for an uploaded avatar and move that to the correct user folder 224 if ( is_multisite() ) 225 $hashed_key = wp_hash( $_GET['key'] ); 226 else 227 $hashed_key = wp_hash( $user ); 228 229 // Check if the avatar folder exists. If it does, move rename it, move 230 // it and delete the signup avatar dir 231 if ( file_exists( bp_core_avatar_upload_path() . '/avatars/signups/' . $hashed_key ) ) 232 @rename( bp_core_avatar_upload_path() . '/avatars/signups/' . $hashed_key, bp_core_avatar_upload_path() . '/avatars/' . $user ); 233 234 bp_core_add_message( __( 'Your account is now active!', 'buddypress' ) ); 235 236 $bp->activation_complete = true; 237 } 238 239 if ( '' != locate_template( array( 'registration/activate' ), false ) ) 240 bp_core_load_template( apply_filters( 'bp_core_template_activate', 'activate' ) ); 241 else 242 bp_core_load_template( apply_filters( 'bp_core_template_activate', 'registration/activate' ) ); 243 } 244 add_action( 'bp_screens', 'bp_core_screen_activation' ); 245 48 246 ?>
Note: See TracChangeset
for help on using the changeset viewer.