@@ -112,14 +133,19 @@ if ($edituser->user_level >= $user_level) die( __('You do not have permission to
|
- |
- user_level; ?> |
+ |
+ |
|
ID); ?> |
-user_registered ) { ?>
+user_registered) && ('0000-00-00 00:00:00' != $edituser->user_registered) ) { ?>
|
user_registered, 0, 11); ?> |
@@ -135,7 +161,7 @@ if ($edituser->user_level >= $user_level) die( __('You do not have permission to
|
- |
+ |
|
@@ -189,6 +215,8 @@ if ($edituser->user_level >= $user_level) die( __('You do not have permission to
diff --git a/wp-admin/users.php b/wp-admin/users.php
index 296c6a82bb..7e91124dba 100644
--- a/wp-admin/users.php
+++ b/wp-admin/users.php
@@ -8,88 +8,52 @@ $parent_file = 'profile.php';
$action = $_REQUEST['action'];
switch ($action) {
-case 'adduser':
- check_admin_referer();
-
- $user_login = wp_specialchars(trim($_POST['user_login']));
- $pass1 = $_POST['pass1'];
- $pass2 = $_POST['pass2'];
- $user_email = wp_specialchars(trim($_POST['email']));
- $user_firstname = wp_specialchars(trim($_POST['firstname']));
- $user_lastname = wp_specialchars(trim($_POST['lastname']));
- $user_uri = wp_specialchars(trim($_POST['uri']));
-
- /* checking that username has been typed */
- if ($user_login == '')
- die (__('
ERROR: Please enter a username.'));
-
- /* checking the password has been typed twice */
- do_action('check_passwords', array($user_login, &$pass1, &$pass2));
- if ($pass1 == '' || $pass2 == '')
- die (__('
ERROR: Please enter your password twice.'));
-
- /* checking the password has been typed twice the same */
- if ($pass1 != $pass2)
- die (__('
ERROR: Please type the same password in the two password fields.'));
-
- $user_nickname = $user_login;
-
- if ( username_exists( $user_login ) )
- die (__('
ERROR: This username is already registered, please choose another one.'));
-
- /* checking e-mail address */
- if (empty($user_email)) {
- die (__("
ERROR: please type an e-mail address"));
- return false;
- } else if (!is_email($user_email)) {
- die (__("
ERROR: the email address isn't correct"));
- return false;
- }
-
- $user_ID = create_user( $user_login, $pass1, $user_email, 0 );
-
- update_usermeta( $user_ID, 'first_name', $user_firstname);
- update_usermeta( $user_ID, 'last_name', $user_lastname);
- update_usermeta( $user_ID, 'first_name', $user_firstname);
-
- $stars = '';
- for ($i = 0; $i < strlen($pass1); $i = $i + 1)
- $stars .= '*';
-
- $user_login = stripslashes($user_login);
- $message = sprintf(__('New user registration on your blog %s:'), get_settings('blogname')) . "\r\n\r\n";
- $message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
- $message .= sprintf(__('E-mail: %s'), $user_email) . "\r\n";
-
- @wp_mail(get_settings('admin_email'), sprintf(__('[%s] New User Registration'), get_settings('blogname')), $message);
- header('Location: users.php');
-break;
case 'promote':
check_admin_referer();
- if (empty($_GET['prom'])) {
+ if (empty($_POST['users'])) {
header('Location: users.php');
}
- $id = (int) $_GET['id'];
- $prom = $_GET['prom'];
+ if ( !current_user_can('edit_users') )
+ die(__('You can’t edit users.'));
- $user_data = get_userdata($id);
-
- $usertopromote_level = $user_data->user_level;
-
- if ( $user_level <= $usertopromote_level )
- die(__('Can’t change the level of a user whose level is higher than yours.'));
-
- if ('up' == $prom) {
- $new_level = $usertopromote_level + 1;
- } elseif ('down' == $prom) {
- $new_level = $usertopromote_level - 1;
+ $userids = $_POST['users'];
+ foreach($userids as $id) {
+ $user = new WP_User($id);
+ $user->set_role($_POST['new_role']);
}
- update_usermeta( $id, $wpdb->prefix . 'user_level', $new_level);
+
+ header('Location: users.php?update=promote');
- header('Location: users.php');
+break;
+
+case 'dodelete':
+
+ check_admin_referer();
+
+ if (empty($_POST['users'])) {
+ header('Location: users.php');
+ }
+
+ if ( !current_user_can('edit_users') )
+ die(__('You can’t delete users.'));
+
+ $userids = $_POST['users'];
+
+ foreach($userids as $id) {
+ switch($_POST['delete_option']) {
+ case 'delete':
+ wp_delete_user($id);
+ break;
+ case 'reassign':
+ wp_delete_user($id, $_POST['reassign_user']);
+ break;
+ }
+ }
+
+ header('Location: users.php?update=del');
break;
@@ -97,51 +61,189 @@ case 'delete':
check_admin_referer();
- $id = (int) $_GET['id'];
-
- if (!$id) {
+ if (empty($_POST['users'])) {
header('Location: users.php');
}
- $user_data = get_userdata($id);
- $usertodelete_level = $user_data->user_level;
+ if ( !current_user_can('edit_users') )
+ $error['edit_users'] = __('You can’t delete users.');
- if ($user_level <= $usertodelete_level)
- die(__('Can’t delete a user whose level is higher than yours.'));
+ $userids = $_POST['users'];
- wp_delete_user($id);
-
- header('Location: users.php?deleted=true');
+ include ('admin-header.php');
+?>
+
+ERROR: Please enter a username.');
+
+ /* checking the password has been typed twice */
+ do_action('check_passwords', array($new_user_login, &$new_pass1, &$new_pass2));
+ if ($new_pass1 == '' || $new_pass2 == '')
+ $errors['pass'] = __('
ERROR: Please enter your password twice.');
+
+ /* checking the password has been typed twice the same */
+ if ($new_pass1 != $new_pass2)
+ $errors['pass'] = __('
ERROR: Please type the same password in the two password fields.');
+
+ $new_user_nickname = $new_user_login;
+
+ if ( username_exists( $new_user_login ) )
+ $errors['pass'] = __('
ERROR: This username is already registered, please choose another one.');
+
+ /* checking e-mail address */
+ if (empty($new_user_email)) {
+ $errors['user_email'] = __("
ERROR: please type an e-mail address");
+ } else if (!is_email($new_user_email)) {
+ $errors['user_email'] = __("
ERROR: the email address isn't correct");
+ }
+
+ if(count($errors) == 0) {
+ $user_ID = create_user( $new_user_login, $new_pass1, $new_user_email, 0 );
+
+ update_usermeta( $user_ID, 'first_name', $new_user_firstname);
+ update_usermeta( $user_ID, 'last_name', $new_user_lastname);
+ update_usermeta( $user_ID, 'first_name', $new_user_firstname);
+
+ $user = new WP_User($user_ID);
+ $user->set_role(get_settings('default_role'));
+
+ $stars = '';
+ for ($i = 0; $i < strlen($pass1); $i = $i + 1)
+ $stars .= '*';
+
+ $user_login = stripslashes($new_user_login);
+ $message = sprintf(__('New user registration on your blog %s:'), get_settings('blogname')) . "\r\n\r\n";
+ $message .= sprintf(__('Username: %s'), $new_user_login) . "\r\n\r\n";
+ $message .= sprintf(__('E-mail: %s'), $new_user_email) . "\r\n";
+
+ @wp_mail(get_settings('admin_email'), sprintf(__('[%s] New User Registration'), get_settings('blogname')), $message);
+ header('Location: users.php?update=add');
+ die();
+ }
+
default:
include ('admin-header.php');
+
+ $userids = $wpdb->get_col("SELECT ID FROM $wpdb->users;");
+
+ foreach($userids as $userid) {
+ $tmp_user = new WP_User($userid);
+ $roles = array_keys($tmp_user->roles);
+ $role = $roles[0];
+ $roleclasses[$role][$tmp_user->data->user_login] = $tmp_user;
+ }
+
?>
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
Users can
register themselves or you can manually create users here.'), get_settings('siteurl')); ?>
@@ -246,23 +303,23 @@ echo "\n
|
- |
+ |
|
- |
+ |
|
- |
+ |
|
- |
+ |
|
- |
+ |
get_results("SELECT * FROM $wpdb->categories")):
- foreach ($dogs as $catt)
- $cache_categories[$catt->cat_ID] = $catt;
+ foreach ($dogs as $catt)
+ $cache_categories[$catt->cat_ID] = $catt;
return true;
- else:
+ else :
return false;
endif;
}
diff --git a/wp-includes/pluggable-functions.php b/wp-includes/pluggable-functions.php
index 4d25ffd781..5ca232800d 100644
--- a/wp-includes/pluggable-functions.php
+++ b/wp-includes/pluggable-functions.php
@@ -31,7 +31,7 @@ function get_userdata( $user_id ) {
$user_id = (int) $user_id;
if ( $user_id == 0 )
return false;
-
+
if ( isset( $cache_userdata[$user_id] ) )
return $cache_userdata[$user_id];
@@ -52,13 +52,42 @@ function get_userdata( $user_id ) {
}
$cache_userdata[$user_id] = $user;
-
$cache_userdata[$cache_userdata[$userid]->user_login] =& $cache_userdata[$user_id];
return $cache_userdata[$user_id];
}
endif;
+if ( !function_exists('update_user_cache') ) :
+function update_user_cache() {
+ global $cache_userdata, $wpdb;
+ $level_key = $wpdb->prefix . 'user_level';
+ $user_ids = $wpdb->get_col("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$level_key'");
+ $user_ids = join(',', $user_ids);
+ $query = apply_filters('user_cache_query', "SELECT * FROM $wpdb->users WHERE ID IN ($user_ids)");
+ if ( $users = $wpdb->get_results( $query ) ) :
+ foreach ($users as $user) :
+ $metavalues = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->usermeta WHERE user_id = '$user->ID'");
+ foreach ( $metavalues as $meta ) {
+ @ $value = unserialize($meta->meta_value);
+ if ($value === FALSE)
+ $value = $meta->meta_value;
+ $user->{$meta->meta_key} = $value;
+ // We need to set user_level from meta, not row
+ if ( $wpdb->prefix . 'user_level' == $meta->meta_key )
+ $user->user_level = $meta->meta_value;
+ }
+
+ $cache_userdata[$user->ID] = $user;
+ $cache_userdata[$user->user_login] =& $cache_userdata[$user->ID];
+ endforeach;
+ return true;
+ else :
+ return false;
+ endif;
+}
+endif;
+
if ( !function_exists('get_userdatabylogin') ) :
function get_userdatabylogin($user_login) {
global $cache_userdata, $wpdb;
@@ -279,4 +308,4 @@ function wp_notify_moderator($comment_id) {
}
endif;
-?>
\ No newline at end of file
+?>
diff --git a/wp-register.php b/wp-register.php
index 4a3e0d3ca1..327c7fc19c 100644
--- a/wp-register.php
+++ b/wp-register.php
@@ -14,47 +14,52 @@ case 'register':
$user_login = sanitize_user( $_POST['user_login'] );
$user_email = $_POST['user_email'];
+
+ $errors = array();
if ( $user_login == '' )
- die (__('
ERROR: Please enter a username.'));
+ $errors['user_login'] = __('
ERROR: Please enter a username.');
/* checking e-mail address */
if ($user_email == '') {
- die (__('
ERROR: Please type your e-mail address.'));
+ $errors['user_email'] = __('
ERROR: Please type your e-mail address.');
} else if (!is_email($user_email)) {
- die (__('
ERROR: The email address isn’t correct.'));
+ $errors['user_email'] = __('
ERROR: The email address isn’t correct.');
}
- if ( username_exists( $user_login ) )
- die (__('
ERROR: This username is already registered, please choose another one.'));
+ if ( username_exists( $user_login ) )
+ $errors['user_login'] = __('
ERROR: This username is already registered, please choose another one.');
- $user_level = get_settings('new_users_can_blog');
$password = substr( md5( uniqid( microtime() ) ), 0, 7);
- $user_id = create_user( $user_login, $password, $user_email, $user_level );
-
- do_action('user_register', $user_id);
-
+ $user_id = create_user( $user_login, $password, $user_email, 0 );
if ( !$user_id ) {
- die (sprintf(__('
ERROR: Couldn’t register you... please contact the
webmaster !'), get_settings('admin_email')));
+ $errors['user_id'] = sprintf(__('
ERROR: Couldn’t register you... please contact the
webmaster !'), get_settings('admin_email'));
}
- $stars = '';
- for ($i = 0; $i < strlen($pass1); $i = $i + 1) {
- $stars .= '*';
- }
+ if(count($errors) == 0) {
+ $user = new WP_User($user_id);
+ $user->set_role(get_settings('default_role'));
- $message = sprintf(__('Username: %s'), $user_login) . "\r\n";
- $message .= sprintf(__('Password: %s'), $password) . "\r\n";
- $message .= get_settings('siteurl') . "/wp-login.php\r\n";
+ do_action('user_register', $user_id);
- wp_mail($user_email, sprintf(__('[%s] Your username and password'), get_settings('blogname')), $message);
-
- $message = sprintf(__('New user registration on your blog %s:'), get_settings('blogname')) . "\r\n\r\n";
- $message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
- $message .= sprintf(__('E-mail: %s'), $user_email) . "\r\n";
-
- @wp_mail(get_settings('admin_email'), sprintf(__('[%s] New User Registration'), get_settings('blogname')), $message);
+
+ $stars = '';
+ for ($i = 0; $i < strlen($pass1); $i = $i + 1) {
+ $stars .= '*';
+ }
+
+ $message = sprintf(__('Username: %s'), $user_login) . "\r\n";
+ $message .= sprintf(__('Password: %s'), $password) . "\r\n";
+ $message .= get_settings('siteurl') . "/wp-login.php\r\n";
+
+ wp_mail($user_email, sprintf(__('[%s] Your username and password'), get_settings('blogname')), $message);
+
+ $message = sprintf(__('New user registration on your blog %s:'), get_settings('blogname')) . "\r\n\r\n";
+ $message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
+ $message .= sprintf(__('E-mail: %s'), $user_email) . "\r\n";
+
+ @wp_mail(get_settings('admin_email'), sprintf(__('[%s] New User Registration'), get_settings('blogname')), $message);
?>
@@ -81,7 +86,57 @@ case 'register':