diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php
index adf9bd8f6..a3bce779f 100644
--- a/wp-admin/admin-ajax.php
+++ b/wp-admin/admin-ajax.php
@@ -209,6 +209,25 @@ case 'update-meta' :
header('Content-type: text/xml');
die($r);
break;
+case 'add-user' :
+ if ( !current_user_can('edit_users') )
+ die('-1');
+ require_once( ABSPATH . WPINC . '/registration-functions.php');
+ $user_id = add_user();
+ if ( is_wp_error( $user_id ) ) {
+ foreach( $user_id->get_error_codes() as $code)
+ foreach( $user_id->get_error_messages($code) as $message )
+ echo "$message
";
+ exit;
+ } elseif ( !$user_id ) {
+ die('0');
+ }
+ $r = "$user_id";
+ $r .= user_row( $user_id );
+ $r .= "]]>";
+ header('Content-type: text/xml');
+ die($r);
+ break;
default :
die('0');
break;
diff --git a/wp-admin/admin-functions.php b/wp-admin/admin-functions.php
index 3b8e843ca..432c9d7d4 100644
--- a/wp-admin/admin-functions.php
+++ b/wp-admin/admin-functions.php
@@ -361,15 +361,38 @@ function get_category_to_edit($id) {
return $category;
}
+function wp_dropdown_roles( $default = false ) {
+ global $wp_roles;
+ $r = '';
+ foreach($wp_roles->role_names as $role => $name)
+ if ( $default == $role ) // Make default first in list
+ $p = "\n\t";
+ else
+ $r .= "\n\t";
+ echo $p . $r;
+}
+
+
// Creates a new user from the "Users" form using $_POST information.
function add_user() {
- return edit_user();
+ if ( func_num_args() ) { // The hackiest hack that ever did hack
+ global $current_user, $wp_roles;
+ $user_id = func_get_arg(0);
+ if (isset ($_POST['role'])) {
+ if($user_id != $current_user->id || $wp_roles->role_objects[$_POST['role']]->has_cap('edit_users')) {
+ $user = new WP_User($user_id);
+ $user->set_role($_POST['role']);
+ }
+ }
+ } else {
+ add_action('user_register', 'add_user'); // See above
+ return edit_user();
+ }
}
function edit_user($user_id = 0) {
global $current_user, $wp_roles, $wpdb;
-
if ($user_id != 0) {
$update = true;
$user->ID = $user_id;
@@ -417,49 +440,49 @@ function edit_user($user_id = 0) {
if (isset ($_POST['yim']))
$user->yim = wp_specialchars(trim($_POST['yim']));
- $errors = array ();
+ $errors = new WP_Error();
/* checking that username has been typed */
if ($user->user_login == '')
- $errors['user_login'] = __('ERROR: Please enter a username.');
+ $errors->add('user_login', __('ERROR: Please enter a username.'));
/* checking the password has been typed twice */
do_action('check_passwords', array ($user->user_login, & $pass1, & $pass2));
if (!$update) {
if ($pass1 == '' || $pass2 == '')
- $errors['pass'] = __('ERROR: Please enter your password twice.');
+ $errors->add('pass', __('ERROR: Please enter your password twice.'));
} else {
if ((empty ($pass1) && !empty ($pass2)) || (empty ($pass2) && !empty ($pass1)))
- $errors['pass'] = __("ERROR: you typed your new password only once.");
+ $errors->add('pass', __("ERROR: you typed your new password only once."));
}
/* Check for "\" in password */
if( strpos( " ".$pass1, "\\" ) )
- $errors['pass'] = __('ERROR: Passwords may not contain the character "\\".');
+ $errors->add('pass', __('ERROR: Passwords may not contain the character "\\".'));
/* checking the password has been typed twice the same */
if ($pass1 != $pass2)
- $errors['pass'] = __('ERROR: Please type the same password in the two password fields.');
+ $errors->add('pass', __('ERROR: Please type the same password in the two password fields.'));
if (!empty ($pass1))
$user->user_pass = $pass1;
if ( !validate_username($user->user_login) )
- $errors['user_login'] = __('ERROR: This username is invalid. Please enter a valid username.');
+ $errors->add('user_login', __('ERROR: This username is invalid. Please enter a valid username.'));
if (!$update && username_exists($user->user_login))
- $errors['user_login'] = __('ERROR: This username is already registered, please choose another one.');
+ $errors->add('user_login', __('ERROR: This username is already registered, please choose another one.'));
/* checking e-mail address */
if (empty ($user->user_email)) {
- $errors['user_email'] = __("ERROR: please type an e-mail address");
+ $errors->add('user_email', __("ERROR: please type an e-mail address"));
} else
if (!is_email($user->user_email)) {
- $errors['user_email'] = __("ERROR: the email address isn't correct");
+ $errors->add('user_email', __("ERROR: the email address isn't correct"));
}
- if (count($errors) != 0)
+ if ( $errors->get_error_codes() )
return $errors;
if ($update) {
@@ -468,8 +491,7 @@ function edit_user($user_id = 0) {
$user_id = wp_insert_user(get_object_vars($user));
wp_new_user_notification($user_id);
}
-
- return $errors;
+ return $user_id;
}
@@ -692,6 +714,33 @@ function page_rows($parent = 0, $level = 0, $pages = 0, $hierarchy = true) {
}
}
+function user_row( $user_object, $style = '' ) {
+ if ( !(is_object($user_object) && is_a($user_object, 'WP_User')) )
+ $user_object = new WP_User( (int) $user_object );
+ $email = $user_object->user_email;
+ $url = $user_object->user_url;
+ $short_url = str_replace('http://', '', $url);
+ $short_url = str_replace('www.', '', $short_url);
+ if ('/' == substr($short_url, -1))
+ $short_url = substr($short_url, 0, -1);
+ if (strlen($short_url) > 35)
+ $short_url = substr($short_url, 0, 32).'...';
+ $numposts = get_usernumposts($user_object->ID);
+ if (0 < $numposts) $numposts = "$numposts";
+ $r = "
+ |
+ |
+ |
+ $email |
+ $short_url | ";
+ $r .= "\n\t\t$numposts | ";
+ $r .= "\n\t\t";
+ if (current_user_can('edit_users'))
+ $r .= "".__('Edit')."";
+ $r .= " | \n\t
";
+ return $r;
+}
+
function wp_dropdown_cats($currentcat = 0, $currentparent = 0, $parent = 0, $level = 0, $categories = 0) {
global $wpdb, $bgcolor;
if (!$categories) {
diff --git a/wp-admin/admin-header.php b/wp-admin/admin-header.php
index 7721e3e0e..b05ac6cb0 100644
--- a/wp-admin/admin-header.php
+++ b/wp-admin/admin-header.php
@@ -40,6 +40,9 @@ function addLoadEvent(func) {if ( typeof wpOnload!='function'){wpOnload=func;}el
+
+
+