Changeset 2872 for trunk/wp-admin/admin-functions.php
- Timestamp:
- 09/14/2005 12:03:02 AM (21 years ago)
- File:
-
- 1 edited
-
trunk/wp-admin/admin-functions.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/admin-functions.php
r2866 r2872 343 343 344 344 return $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE category_nicename = '$category_nicename'"); 345 } 346 347 // Creates a new user from the "Users" form using $_POST information. 348 349 function add_user() { 350 return update_user(); 351 } 352 353 function update_user($user_id = 0) { 354 355 if ( $user_id != 0 ) { 356 $update = true; 357 $user->ID = $user_id; 358 $userdata = get_userdata($user_id); 359 $user->user_login = $userdata->user_login; 360 } else { 361 $update = false; 362 $user = ''; 363 } 364 365 if ( isset($_POST['user_login']) ) 366 $user->user_login = wp_specialchars(trim($_POST['user_login'])); 367 368 $pass1 = $pass2 = ''; 369 if ( isset($_POST['pass1']) ) 370 $pass1 = $_POST['pass1']; 371 if ( isset($_POST['pass2']) ) 372 $pass2 = $_POST['pass2']; 373 374 if ( isset($_POST['email']) ) 375 $user->user_email = wp_specialchars(trim($_POST['email'])); 376 if ( isset($_POST['url']) ) { 377 $user->user_url = wp_specialchars(trim($_POST['url'])); 378 $user->user_url = preg_match('/^(https?|ftps?|mailto|news|gopher):/is', $user->user_url) ? $user->user_url : 'http://' . $user->user_url; 379 } 380 if ( isset($_POST['first_name']) ) 381 $user->first_name = wp_specialchars(trim($_POST['first_name'])); 382 if ( isset($_POST['last_name']) ) 383 $user->last_name = wp_specialchars(trim($_POST['last_name'])); 384 if ( isset($_POST['nickname']) ) 385 $user->nickname = wp_specialchars(trim($_POST['nickname'])); 386 if ( isset($_POST['display_name']) ) 387 $user->display_name = wp_specialchars(trim($_POST['display_name'])); 388 if ( isset($_POST['description']) ) 389 $user->description = wp_specialchars(trim($_POST['description'])); 390 if ( isset($_POST['jabber']) ) 391 $user->jabber = wp_specialchars(trim($_POST['jabber'])); 392 if ( isset($_POST['aim']) ) 393 $user->aim = wp_specialchars(trim($_POST['aim'])); 394 if ( isset($_POST['yim']) ) 395 $user->yim = wp_specialchars(trim($_POST['yim'])); 396 397 $errors = array(); 398 399 /* checking that username has been typed */ 400 if ($user->user_login == '') 401 $errors['user_login'] = __('<strong>ERROR</strong>: Please enter a username.'); 402 403 /* checking the password has been typed twice */ 404 do_action('check_passwords', array($user->user_login, &$pass1, &$pass2)); 405 406 if ( !$update ) { 407 if ( $pass1 == '' || $pass2 == '' ) 408 $errors['pass'] = __('<strong>ERROR</strong>: Please enter your password twice.'); 409 } else { 410 if ( ( empty($pass1) && !empty($pass2) ) || ( empty($pass2) && !empty($pass1) ) ) 411 $errors['pass'] = __("<strong>ERROR</strong>: you typed your new password only once."); 412 } 413 414 /* checking the password has been typed twice the same */ 415 if ($pass1 != $pass2) 416 $errors['pass'] = __('<strong>ERROR</strong>: Please type the same password in the two password fields.'); 417 418 if ( !empty($pass1) ) 419 $user->user_pass = $pass1; 420 421 if ( !$update && username_exists( $user_login ) ) 422 $errors['user_login'] = __('<strong>ERROR</strong>: This username is already registered, please choose another one.'); 423 424 /* checking e-mail address */ 425 if (empty($user->user_email)) { 426 $errors['user_email'] = __("<strong>ERROR</strong>: please type an e-mail address"); 427 } else if (!is_email($user->user_email)) { 428 $errors['user_email'] = __("<strong>ERROR</strong>: the email address isn't correct"); 429 } 430 431 if ( count($errors) != 0 ) 432 return $errors; 433 434 if ( $update ) { 435 $user_id = wp_update_user(get_object_vars($user)); 436 } else { 437 $user_id = wp_insert_user(get_object_vars($user)); 438 wp_new_user_notification($user_id); 439 } 440 441 return $errors; 345 442 } 346 443
Note: See TracChangeset
for help on using the changeset viewer.