Changeset 1503 for trunk/bp-xprofile/bp-xprofile-signup.php
- Timestamp:
- 06/03/2009 10:49:34 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-xprofile/bp-xprofile-signup.php
r1473 r1503 86 86 87 87 function xprofile_validate_signup_fields( $result ) { 88 global $bp_xprofile_callback, $avatar_error , $avatar_error_msg, $has_errors;88 global $bp_xprofile_callback, $avatar_error_msg; 89 89 global $canvas, $original; 90 90 global $current_site, $active_signup; 91 91 global $wp_upload_error; 92 global $bp_signup_has_errors, $bp_signup_avatar_has_errors; 92 93 93 94 if ( $_POST['stage'] != 'validate-user-signup' ) return $result; 94 95 95 // form has been submitted, let's validate the form96 // using the built in Wordpress functions and our own.97 98 96 extract($result); 99 97 98 if ( $bp_signup_has_errors || $bp_signup_avatar_has_errors ) 99 $errors->add( 'bp_xprofile_errors', '' ); 100 101 return array('user_name' => $user_name, 'user_email' => $user_email, 'errors' => $errors); 102 } 103 add_filter( 'wpmu_validate_user_signup', 'xprofile_validate_signup_fields', 10, 1 ); 104 105 function xprofile_add_profile_meta( $meta ) { 106 global $bp, $bp_blog_signup_meta; 107 108 if ( $_POST['stage'] == 'validate-blog-signup' ) { 109 $bp_meta = $bp_blog_signup_meta; 110 } else if ( $_POST['stage'] == 'validate-user-signup' ) { 111 $bp_meta = unserialize( stripslashes( $_COOKIE['bp_xprofile_meta'] ) ); 112 } else { 113 $bp_meta = $meta; 114 } 115 116 return $bp_meta; 117 } 118 add_filter( 'add_signup_meta', 'xprofile_add_profile_meta' ); 119 120 function xprofile_load_signup_meta() { 121 global $bp_signup_has_errors, $bp_signup_avatar_has_errors; 122 global $bp_xprofile_callback, $avatar_error_msg; 123 global $canvas, $original; 124 global $current_site, $active_signup; 125 global $wp_upload_error; 126 127 if ( $_POST['stage'] != 'validate-user-signup' ) return; 128 100 129 $counter = 0; 101 $ has_errors = false;130 $bp_signup_has_errors = false; 102 131 $prev_field_id = -1; 103 132 104 133 // Validate all sign up fields 105 134 $fields = BP_XProfile_Field::get_signup_fields(); 106 135 107 136 if ( $fields ) { 108 137 foreach ( $fields as $field ) { 109 138 110 139 $value = $_POST['field_' . $field->id]; 111 140 112 141 // Need to check if the previous field had 113 142 // the same ID, as to not validate individual … … 133 162 "value" => $value 134 163 ); 135 164 136 165 if ( $field->is_required && empty( $value ) ) { 137 166 $bp_xprofile_callback[$counter]["error_msg"] = sprintf( __( '%s cannot be left blank', 'buddypress' ), $field->name ); 138 $ has_errors = true;167 $bp_signup_has_errors = true; 139 168 } 140 169 … … 167 196 if ( 4 !== $_FILES['file']['error'] ) { 168 197 if ( !$checked_upload = bp_core_check_avatar_upload($_FILES) ) { 169 $ avatar_error= true;198 $bp_signup_avatar_has_errors = true; 170 199 $avatar_error_msg = $uploadErrors[$_FILES['file']['error']]; 171 200 } 172 201 173 202 if ( $checked_upload && !$checked_size = bp_core_check_avatar_size($_FILES) ) { 174 $ avatar_error= true;203 $bp_signup_avatar_has_errors = true; 175 204 $avatar_size = size_format(CORE_MAX_FILE_SIZE); 176 205 $avatar_error_msg = sprintf( __('The file you uploaded is too big. Please upload a file under %s', 'buddypress'), $avatar_size); … … 178 207 179 208 if ( $checked_upload && $checked_size && !$checked_type = bp_core_check_avatar_type($_FILES) ) { 180 $ avatar_error= true;209 $bp_signup_avatar_has_errors = true; 181 210 $avatar_error_msg = __('Please upload only JPG, GIF or PNG photos.', 'buddypress'); 182 211 } … … 184 213 // "Handle" upload into temporary location 185 214 if ( $checked_upload && $checked_size && $checked_type && !$original = bp_core_handle_avatar_upload($_FILES) ) { 186 $ avatar_error= true;215 $bp_signup_avatar_has_errors = true; 187 216 $avatar_error_msg = sprintf( __('Upload Failed! Error was: %s', 'buddypress'), $wp_upload_error ); 188 217 } … … 192 221 } 193 222 } 194 195 if ( !$has_errors && !$avatar_error ) { 223 224 if ( !$bp_signup_has_errors && !$bp_signup_avatar_has_errors ) { 225 /* Destroy and existing cookies */ 226 setcookie( 'bp_xprofile_meta', false, time()-1000, COOKIEPATH ); 227 196 228 $public = (int) $_POST['blog_public']; 197 229 198 230 // put the user profile meta in a session ready to store. 199 231 for ( $i = 0; $i < count($bp_xprofile_callback); $i++ ) { 200 $meta['field_' . $bp_xprofile_callback[$i]['field_id']] .= $bp_xprofile_callback[$i]['value']; 201 } 202 203 $meta['xprofile_field_ids'] = $_POST['xprofile_ids']; 204 $meta['avatar_image_resized'] = $canvas; 205 $meta['avatar_image_original'] = $original; 206 207 $_SESSION['xprofile_meta'] = $meta; 208 } else { 209 $errors->add( 'bp_xprofile_errors', '' ); 210 } 211 212 return array('user_name' => $user_name, 'user_email' => $user_email, 'errors' => $errors); 213 } 214 add_filter( 'wpmu_validate_user_signup', 'xprofile_validate_signup_fields', 10, 1 ); 215 216 217 function xprofile_add_blog_signup_meta( $meta ) { 218 $_SESSION['xprofile_meta']['public'] = (int) $_POST['blog_public']; 219 $_SESSION['xprofile_meta']['lang_id'] = 1; // deprecated 220 $_SESSION['xprofile_meta']['blogname'] = $_POST['blogname']; 221 $_SESSION['xprofile_meta']['blog_title'] = $_POST['blog_title']; 222 223 return $meta; 224 } 225 226 add_filter( 'wpmu_validate_blog_signup', 'xprofile_add_blog_signup_meta' ); 227 228 229 function xprofile_add_profile_meta( $meta ) { 230 global $bp; 231 232 if ( $bp->current_component != $bp->blogs->slug ) 233 return $_SESSION['xprofile_meta']; 234 else 235 return $meta; 236 } 237 add_filter( 'add_signup_meta', 'xprofile_add_profile_meta' ); 232 $bp_meta['field_' . $bp_xprofile_callback[$i]['field_id']] .= $bp_xprofile_callback[$i]['value']; 233 } 234 235 $bp_meta['xprofile_field_ids'] = $_POST['xprofile_ids']; 236 $bp_meta['avatar_image_resized'] = $canvas; 237 $bp_meta['avatar_image_original'] = $original; 238 239 setcookie( 'bp_xprofile_meta', serialize($bp_meta), time()+60*60*24, COOKIEPATH ); 240 } 241 } 242 add_action( 'init', 'xprofile_load_signup_meta' ); 243 244 function xprofile_load_blog_signup_meta() { 245 global $bp_blog_signup_meta; 246 247 if ( $_POST['stage'] != 'validate-blog-signup' ) return; 248 249 $blog_meta = array( 250 'public' => $_POST['blog_public'], 251 'lang_id' => 1, // deprecated 252 'blogname' => $_POST['blogname'], 253 'blog_title' => $_POST['blog_title'] 254 ); 255 256 $bp_meta = unserialize( stripslashes( $_COOKIE['bp_xprofile_meta'] ) ); 257 $bp_blog_signup_meta = array_merge( $bp_meta, $blog_meta ); 258 } 259 add_action( 'init', 'xprofile_load_blog_signup_meta' ); 238 260 239 261 /************************************************************************** … … 265 287 add_action( 'wpmu_activate_user', 'xprofile_on_activate_user', 1, 3 ); 266 288 267 268 289 function xprofile_extract_signup_meta( $user_id, $meta ) { 269 290 // Extract signup meta fields to fill out profile
Note: See TracChangeset
for help on using the changeset viewer.