Changeset 3677 for trunk/wp-admin/admin-functions.php
- Timestamp:
- 04/02/2006 12:31:26 AM (20 years ago)
- File:
-
- 1 edited
-
trunk/wp-admin/admin-functions.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/admin-functions.php
r3676 r3677 362 362 } 363 363 364 function wp_dropdown_roles( $default = false ) { 365 global $wp_roles; 366 $r = ''; 367 foreach($wp_roles->role_names as $role => $name) 368 if ( $default == $role ) // Make default first in list 369 $p = "\n\t<option selected='selected' value='$role'>$name</option>"; 370 else 371 $r .= "\n\t<option value='$role'>$name</option>"; 372 echo $p . $r; 373 } 374 375 364 376 // Creates a new user from the "Users" form using $_POST information. 365 377 366 378 function add_user() { 367 return edit_user(); 379 if ( func_num_args() ) { // The hackiest hack that ever did hack 380 global $current_user, $wp_roles; 381 $user_id = func_get_arg(0); 382 if (isset ($_POST['role'])) { 383 if($user_id != $current_user->id || $wp_roles->role_objects[$_POST['role']]->has_cap('edit_users')) { 384 $user = new WP_User($user_id); 385 $user->set_role($_POST['role']); 386 } 387 } 388 } else { 389 add_action('user_register', 'add_user'); // See above 390 return edit_user(); 391 } 368 392 } 369 393 370 394 function edit_user($user_id = 0) { 371 395 global $current_user, $wp_roles, $wpdb; 372 373 396 if ($user_id != 0) { 374 397 $update = true; … … 418 441 $user->yim = wp_specialchars(trim($_POST['yim'])); 419 442 420 $errors = array();443 $errors = new WP_Error(); 421 444 422 445 /* checking that username has been typed */ 423 446 if ($user->user_login == '') 424 $errors ['user_login'] = __('<strong>ERROR</strong>: Please enter a username.');447 $errors->add('user_login', __('<strong>ERROR</strong>: Please enter a username.')); 425 448 426 449 /* checking the password has been typed twice */ … … 429 452 if (!$update) { 430 453 if ($pass1 == '' || $pass2 == '') 431 $errors ['pass'] = __('<strong>ERROR</strong>: Please enter your password twice.');454 $errors->add('pass', __('<strong>ERROR</strong>: Please enter your password twice.')); 432 455 } else { 433 456 if ((empty ($pass1) && !empty ($pass2)) || (empty ($pass2) && !empty ($pass1))) 434 $errors ['pass'] = __("<strong>ERROR</strong>: you typed your new password only once.");457 $errors->add('pass', __("<strong>ERROR</strong>: you typed your new password only once.")); 435 458 } 436 459 437 460 /* Check for "\" in password */ 438 461 if( strpos( " ".$pass1, "\\" ) ) 439 $errors ['pass'] = __('<strong>ERROR</strong>: Passwords may not contain the character "\\".');462 $errors->add('pass', __('<strong>ERROR</strong>: Passwords may not contain the character "\\".')); 440 463 441 464 /* checking the password has been typed twice the same */ 442 465 if ($pass1 != $pass2) 443 $errors ['pass'] = __('<strong>ERROR</strong>: Please type the same password in the two password fields.');466 $errors->add('pass', __('<strong>ERROR</strong>: Please type the same password in the two password fields.')); 444 467 445 468 if (!empty ($pass1)) … … 447 470 448 471 if ( !validate_username($user->user_login) ) 449 $errors ['user_login'] = __('<strong>ERROR</strong>: This username is invalid. Please enter a valid username.');472 $errors->add('user_login', __('<strong>ERROR</strong>: This username is invalid. Please enter a valid username.')); 450 473 451 474 if (!$update && username_exists($user->user_login)) 452 $errors ['user_login'] = __('<strong>ERROR</strong>: This username is already registered, please choose another one.');475 $errors->add('user_login', __('<strong>ERROR</strong>: This username is already registered, please choose another one.')); 453 476 454 477 /* checking e-mail address */ 455 478 if (empty ($user->user_email)) { 456 $errors ['user_email'] = __("<strong>ERROR</strong>: please type an e-mail address");479 $errors->add('user_email', __("<strong>ERROR</strong>: please type an e-mail address")); 457 480 } else 458 481 if (!is_email($user->user_email)) { 459 $errors ['user_email'] = __("<strong>ERROR</strong>: the email address isn't correct");460 } 461 462 if ( count($errors) != 0)482 $errors->add('user_email', __("<strong>ERROR</strong>: the email address isn't correct")); 483 } 484 485 if ( $errors->get_error_codes() ) 463 486 return $errors; 464 487 … … 469 492 wp_new_user_notification($user_id); 470 493 } 471 472 return $errors; 494 return $user_id; 473 495 } 474 496 … … 691 713 if ( $hierarchy) page_rows($id, $level + 1, $pages); 692 714 } 715 } 716 717 function user_row( $user_object, $style = '' ) { 718 if ( !(is_object($user_object) && is_a($user_object, 'WP_User')) ) 719 $user_object = new WP_User( (int) $user_object ); 720 $email = $user_object->user_email; 721 $url = $user_object->user_url; 722 $short_url = str_replace('http://', '', $url); 723 $short_url = str_replace('www.', '', $short_url); 724 if ('/' == substr($short_url, -1)) 725 $short_url = substr($short_url, 0, -1); 726 if (strlen($short_url) > 35) 727 $short_url = substr($short_url, 0, 32).'...'; 728 $numposts = get_usernumposts($user_object->ID); 729 if (0 < $numposts) $numposts = "<a href='edit.php?author=$user_object->ID' title='" . __('View posts') . "'>$numposts</a>"; 730 $r = "<tr id='user-$user_object->ID'$style> 731 <td><input type='checkbox' name='users[]' id='user_{$user_object->ID}' value='{$user_object->ID}' /> <label for='user_{$user_object->ID}'>{$user_object->ID}</label></td> 732 <td><label for='user_{$user_object->ID}'><strong>$user_object->user_login</strong></label></td> 733 <td><label for='user_{$user_object->ID}'>$user_object->first_name $user_object->last_name</label></td> 734 <td><a href='mailto:$email' title='" . sprintf(__('e-mail: %s'), $email) . "'>$email</a></td> 735 <td><a href='$url' title='website: $url'>$short_url</a></td>"; 736 $r .= "\n\t\t<td align='right'>$numposts</td>"; 737 $r .= "\n\t\t<td>"; 738 if (current_user_can('edit_users')) 739 $r .= "<a href='user-edit.php?user_id=$user_object->ID' class='edit'>".__('Edit')."</a>"; 740 $r .= "</td>\n\t</tr>"; 741 return $r; 693 742 } 694 743
Note: See TracChangeset
for help on using the changeset viewer.