summaryrefslogtreecommitdiffstats
path: root/wp-inst/wp-admin/users.php
diff options
context:
space:
mode:
authordonncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2006-06-13 11:18:16 +0000
committerdonncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2006-06-13 11:18:16 +0000
commit19b51f30bd324ecb36f99d159947b75c22b6fecf (patch)
tree9423e53c5fddbfca6e4cd05f43c4e1e11bc508b4 /wp-inst/wp-admin/users.php
parent242d432d82cefdf3aab7135b5298c2db02c9114c (diff)
WP Merge
git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@559 7be80a69-a1ef-0310-a953-fb0f7c49ff36
Diffstat (limited to 'wp-inst/wp-admin/users.php')
-rw-r--r--wp-inst/wp-admin/users.php368
1 files changed, 272 insertions, 96 deletions
diff --git a/wp-inst/wp-admin/users.php b/wp-inst/wp-admin/users.php
index 6dfc57a..2ed85bf 100644
--- a/wp-inst/wp-admin/users.php
+++ b/wp-inst/wp-admin/users.php
@@ -1,41 +1,151 @@
<?php
require_once('admin.php');
-require_once( ABSPATH . WPINC . '/registration-functions.php');
+require_once( ABSPATH . WPINC . '/registration.php');
$title = __('Users');
-$parent_file = 'profile.php';
+if ( current_user_can('edit_users') )
+ $parent_file = 'users.php';
+else
+ $parent_file = 'profile.php';
$action = $_REQUEST['action'];
$update = '';
+if ( empty($_POST) ) {
+ $referer = '<input type="hidden" name="wp_http_referer" value="'. wp_specialchars(stripslashes($_SERVER['REQUEST_URI'])) . '" />';
+} elseif ( isset($_POST['wp_http_referer']) ) {
+ $redirect = remove_query_arg(array('wp_http_referer', 'updated', 'delete_count'), urlencode(stripslashes($_POST['wp_http_referer'])));
+ $referer = '<input type="hidden" name="wp_http_referer" value="' . wp_specialchars($redirect) . '" />';
+} else {
+ $redirect = 'users.php';
+}
+
+
+// WP_User_Search class
+// by Mark Jaquith
+
+
+class WP_User_Search {
+ var $results;
+ var $search_term;
+ var $page;
+ var $raw_page;
+ var $users_per_page = 50;
+ var $first_user;
+ var $last_user;
+ var $query_limit;
+ var $query_from_where;
+ var $total_users_for_query = 0;
+ var $too_many_total_users = false;
+ var $search_errors;
+
+ function WP_User_Search ($search_term = '', $page = '') { // constructor
+ $this->search_term = $search_term;
+ $this->raw_page = ( '' == $page ) ? false : (int) $page;
+ $this->page = (int) ( '' == $page ) ? 1 : $page;
+
+ $this->prepare_query();
+ $this->query();
+ $this->prepare_vars_for_template_usage();
+ $this->do_paging();
+ }
+
+ function prepare_query() {
+ global $wpdb;
+ $this->first_user = ($this->page - 1) * $this->users_per_page;
+ $this->query_limit = 'LIMIT ' . $this->first_user . ',' . $this->users_per_page;
+ if ( $this->search_term ) {
+ $searches = array();
+ $search_sql = 'AND (';
+ foreach ( array('user_login', 'user_nicename', 'user_email', 'user_url', 'display_name') as $col )
+ $searches[] = $col . " LIKE '%$this->search_term%'";
+ $search_sql .= implode(' OR ', $searches);
+ $search_sql .= ')';
+ }
+ $this->query_from_where = "FROM $wpdb->users, $wpdb->usermeta WHERE $wpdb->users.ID = $wpdb->usermeta.user_id AND meta_key = '".$wpdb->prefix."capabilities' $search_sql";
+
+ if ( !$_GET['update'] && !$this->search_term && !$this->raw_page && $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->users, $wpdb->usermeta WHERE $wpdb->users.ID = $wpdb->usermeta.user_id AND meta_key = '".$wpdb->prefix."capabilities'") > $this->users_per_page )
+ $this->too_many_total_users = sprintf(__('Because this blog has more than %s users, they cannot all be shown on one page. Use the paging or search functionality in order to find the user you want to edit.'), $this->users_per_page);
+ }
+
+ function query() {
+ global $wpdb;
+ $this->results = $wpdb->get_col('SELECT ID ' . $this->query_from_where . $this->query_limit);
+
+ if ( $this->results )
+ $this->total_users_for_query = $wpdb->get_var('SELECT COUNT(ID) ' . $this->query_from_where); // no limit
+ else
+ $this->search_errors = new WP_Error('no_matching_users_found', __('No matching users were found!'));
+ }
+
+ function prepare_vars_for_template_usage() {
+ $this->search_term = stripslashes($this->search_term); // done with DB, from now on we want slashes gone
+ }
+
+ function do_paging() {
+ if ( $this->total_users_for_query > $this->users_per_page ) { // have to page the results
+ $prev_page = ( $this->page > 1) ? true : false;
+ $next_page = ( ($this->page * $this->users_per_page) < $this->total_users_for_query ) ? true : false;
+ $this->paging_text = '';
+ if ( $prev_page )
+ $this->paging_text .= '<p class="alignleft"><a href="' . add_query_arg(array('usersearch' => $this->search_term, 'userspage' => $this->page - 1), 'users.php?') . '">&laquo; Previous Page</a></p>';
+ if ( $next_page )
+ $this->paging_text .= '<p class="alignright"><a href="' . add_query_arg(array('usersearch' => $this->search_term, 'userspage' => $this->page + 1), 'users.php?') . '">Next Page &raquo;</a></p>';
+ if ( $prev_page || $next_page )
+ $this->paging_text .= '<br style="clear:both" />';
+ }
+ }
+
+ function get_results() {
+ return $this->results;
+ }
+
+ function page_links() {
+ echo $this->paging_text;
+ }
+
+ function results_are_paged() {
+ if ( $this->paging_text )
+ return true;
+ return false;
+ }
+
+ function is_search() {
+ if ( $this->search_term )
+ return true;
+ return false;
+ }
+}
+
+
switch ($action) {
case 'promote':
check_admin_referer('bulk-users');
if (empty($_POST['users'])) {
- header('Location: users.php');
+ header('Location: ' . $redirect);
}
if ( !current_user_can('edit_users') )
die(__('You can&#8217;t edit users.'));
- $userids = $_POST['users'];
+ $userids = $_POST['users'];
$update = 'promote';
- foreach($userids as $id) {
- if ( ! current_user_can('edit_user', $id) )
- die(__('You can&#8217;t edit that user.'));
+ foreach($userids as $id) {
+ if ( ! current_user_can('edit_user', $id) )
+ die(__('You can&#8217;t edit that user.'));
// The new role of the current user must also have edit_users caps
if($id == $current_user->id && !$wp_roles->role_objects[$_POST['new_role']]->has_cap('edit_users')) {
$update = 'err_admin_role';
continue;
}
- $user = new WP_User($id);
- $user->set_role($_POST['new_role']);
- }
+ $user = new WP_User($id);
+ $user->set_role($_POST['new_role']);
+ }
- header('Location: users.php?update=' . $update);
+ header('Location: ' . add_query_arg('update', $update, $redirect));
break;
@@ -44,24 +154,25 @@ case 'dodelete':
check_admin_referer('delete-users');
if ( empty($_POST['users']) ) {
- header('Location: users.php');
+ header('Location: ' . $redirect);
}
if ( !current_user_can('delete_users') )
die(__('You can&#8217;t delete users.'));
$userids = $_POST['users'];
-
$update = 'del';
- foreach ($userids as $id) {
- if ( ! current_user_can('delete_user', $id) )
- die(__('You can&#8217;t delete that user.'));
-
+ $delete_count = 0;
+
+ foreach ( (array) $userids as $id) {
+ if ( ! current_user_can('delete_user', $id) )
+ die(__('You can&#8217;t delete that user.'));
+
if($id == $current_user->id) {
$update = 'err_admin_del';
continue;
}
- switch($_POST['delete_option']) {
+ switch($_POST['delete_option']) {
case 'delete':
wp_delete_user($id);
break;
@@ -69,9 +180,12 @@ case 'dodelete':
wp_delete_user($id, $_POST['reassign_user']);
break;
}
+ ++$delete_count;
}
- header('Location: users.php?update=' . $update);
+ $redirect = add_query_arg('delete_count', $delete_count, $redirect);
+
+ header('Location: ' . add_query_arg('update', $update, $redirect));
break;
@@ -79,12 +193,11 @@ case 'delete':
die( "This function is disabled." );
check_admin_referer('bulk-users');
- if (empty($_POST['users'])) {
- header('Location: users.php');
- }
+ if ( empty($_POST['users']) )
+ header('Location: ' . $redirect);
if ( !current_user_can('delete_users') )
- $error = new WP_Error('edit_users', __('You can&#8217;t delete users.'));
+ $errors = new WP_Error('edit_users', __('You can&#8217;t delete users.'));
$userids = $_POST['users'];
@@ -92,33 +205,32 @@ case 'delete':
?>
<form action="" method="post" name="updateusers" id="updateusers">
<?php wp_nonce_field('delete-users') ?>
+<?php echo $referer; ?>
<div class="wrap">
<h2><?php _e('Delete Users'); ?></h2>
<p><?php _e('You have specified these users for deletion:'); ?></p>
<ul>
<?php
$go_delete = false;
- foreach ($userids as $id) {
- $user = new WP_User($id);
- if ($id == $current_user->id) {
+ foreach ( (array) $userids as $id ) {
+ $user = new WP_User($id);
+ if ( $id == $current_user->id ) {
echo "<li>" . sprintf(__('ID #%1s: %2s <strong>The current user will not be deleted.</strong>'), $id, $user->user_login) . "</li>\n";
} else {
echo "<li><input type=\"hidden\" name=\"users[]\" value=\"{$id}\" />" . sprintf(__('ID #%1s: %2s'), $id, $user->user_login) . "</li>\n";
$go_delete = true;
}
- }
+ }
$all_logins = $wpdb->get_results("SELECT ID, user_login FROM $wpdb->users, $wpdb->usermeta WHERE $wpdb->users.ID = $wpdb->usermeta.user_id AND meta_key = '".$wpdb->prefix."capabilities'");
- $user_dropdown = '<select name="reassign_user">';
- foreach ($all_logins as $login) {
- if ( $login->ID == $current_user->id || !in_array($login->ID, $userids) ) {
- $user_dropdown .= "<option value=\"{$login->ID}\">{$login->user_login}</option>";
- }
- }
- $user_dropdown .= '</select>';
- ?>
- </ul>
-<?php if($go_delete) : ?>
- <p><?php _e('What should be done with posts and links owned by this user?'); ?></p>
+ $user_dropdown = '<select name="reassign_user">';
+ foreach ( (array) $all_logins as $login )
+ if ( $login->ID == $current_user->id || !in_array($login->ID, $userids) )
+ $user_dropdown .= "<option value=\"{$login->ID}\">{$login->user_login}</option>";
+ $user_dropdown .= '</select>';
+ ?>
+ </ul>
+<?php if ( $go_delete ) : ?>
+ <p><?php _e('What should be done with posts and links owned by this user?'); ?></p>
<ul style="list-style:none;">
<li><label><input type="radio" id="delete_option0" name="delete_option" value="delete" checked="checked" />
<?php _e('Delete all posts and links.'); ?></label></li>
@@ -137,7 +249,7 @@ case 'delete':
break;
case 'doremove':
- check_admin_referer();
+ check_admin_referer('remove-users');
if ( empty($_POST['users']) ) {
header('Location: users.php');
@@ -163,7 +275,7 @@ break;
case 'removeuser':
- check_admin_referer();
+ check_admin_referer('bulk-users');
if (empty($_POST['users'])) {
header('Location: users.php');
@@ -177,6 +289,7 @@ case 'removeuser':
include ('admin-header.php');
?>
<form action="" method="post" name="updateusers" id="updateusers">
+<?php wp_nonce_field('remove-users') ?>
<div class="wrap">
<h2><?php _e('Remove Users from Blog'); ?></h2>
<p><?php _e('You have specified these users for removal:'); ?></p>
@@ -213,15 +326,18 @@ case 'adduser':
die(__('You can&#8217;t create users.'));
$user_id = add_user();
+ $update = 'add';
if ( is_wp_error( $user_id ) )
- $errors = $user_id;
+ $add_user_errors = $user_id;
else {
- header('Location: users.php?update=add');
+ $new_user_login = apply_filters('pre_user_login', sanitize_user(stripslashes($_POST['user_login']), true));
+ $redirect = add_query_arg('usersearch', $new_user_login, $redirect);
+ header('Location: ' . add_query_arg('update', $update, $redirect) . '#user-' . $user_id);
die();
}
case 'addexistinguser':
- check_admin_referer();
+ check_admin_referer('add-user');
if ( !current_user_can('edit_users') )
die(__('You can&#8217;t edit users.'));
@@ -244,32 +360,28 @@ case 'addexistinguser':
die();
break;
default:
- wp_enqueue_script( 'admin-users' );
+ wp_enqueue_script('admin-users');
- include ('admin-header.php');
+ include('admin-header.php');
- if ( !current_user_can('edit_users') )
- die(__('You can&#8217;t edit users.'));
- $userids = array();
- $users = get_users_of_blog();
- foreach ( $users as $user )
- $userids[] = $user->user_id;
+ // Query the users
+ $wp_user_search = new WP_User_Search($_GET['usersearch'], $_GET['userspage']);
- foreach($userids as $userid) {
+ // Make the user objects
+ foreach ( $wp_user_search->get_results() as $userid ) {
$tmp_user = new WP_User($userid);
$roles = $tmp_user->roles;
$role = array_shift($roles);
$roleclasses[$role][$tmp_user->user_login] = $tmp_user;
}
- ?>
-
- <?php
- if (isset($_GET['update'])) :
+ if ( isset($_GET['update']) ) :
switch($_GET['update']) {
case 'del':
+ case 'del_many':
?>
- <div id="message" class="updated fade"><p><?php _e('User deleted.'); ?></p></div>
+ <?php $delete_count = (int) $_GET['delete_count']; ?>
+ <div id="message" class="updated fade"><p><?php printf(__('%1$s %2$s deleted.'), $delete_count, __ngettext('user', 'users', $delete_count) ); ?></p></div>
<?php
break;
case 'remove':
@@ -316,24 +428,63 @@ default:
<?php
break;
}
- endif;
- if ( is_wp_error( $errors ) ) : ?>
+ endif; ?>
+
+<?php if ( is_wp_error( $errors ) ) : ?>
<div class="error">
<ul>
<?php
foreach ( $errors->get_error_messages() as $message )
- echo "<li>$message</li>";
+ echo "<li>$message</li>";
?>
</ul>
</div>
- <?php
- endif;
- ?>
+<?php endif; ?>
+
+<?php if ( $wp_user_search->too_many_total_users ) : ?>
+ <div id="message" class="updated">
+ <p><?php echo $wp_user_search->too_many_total_users; ?></p>
+ </div>
+<?php endif; ?>
+
+<div class="wrap">
+
+ <?php if ( $wp_user_search->is_search() ) : ?>
+ <h2><?php printf(__('Users Matching "%s" by Role'), $wp_user_search->search_term); ?></h2>
+ <?php else : ?>
+ <h2><?php _e('User List by Role'); ?></h2>
+ <?php endif; ?>
+
+ <form action="" method="get" name="search" id="search">
+ <p><input type="text" name="usersearch" id="usersearch" value="<?php echo wp_specialchars($wp_user_search->search_term); ?>" /> <input type="submit" value="<?php _e('Search for users &raquo;'); ?>" /></p>
+ </form>
+
+ <?php if ( is_wp_error( $wp_user_search->search_errors ) ) : ?>
+ <div class="error">
+ <ul>
+ <?php
+ foreach ( $wp_user_search->search_errors->get_error_messages() as $message )
+ echo "<li>$message</li>";
+ ?>
+ </ul>
+ </div>
+ <?php endif; ?>
+
+
+<?php if ( $wp_user_search->get_results() ) : ?>
+
+ <?php if ( $wp_user_search->is_search() ) : ?>
+ <p><a href="users.php"><?php _e('&laquo; Back to All Users'); ?></a></p>
+ <?php endif; ?>
+
+ <h3><?php printf(__('Results %1$s - %2$s of %3$s shown below'), $wp_user_search->first_user + 1, min($wp_user_search->first_user + $wp_user_search->users_per_page, $wp_user_search->total_users_for_query), $wp_user_search->total_users_for_query); ?></h3>
+
+ <?php if ( $wp_user_search->results_are_paged() ) : ?>
+ <div class="user-paging-text"><?php $wp_user_search->page_links(); ?></p></div>
+ <?php endif; ?>
<form action="" method="post" name="updateusers" id="updateusers">
<?php wp_nonce_field('bulk-users') ?>
-<div class="wrap">
- <h2><?php _e('User List by Role'); ?></h2>
<table class="widefat">
<?php
foreach($roleclasses as $role => $roleclass) {
@@ -341,46 +492,62 @@ foreach($roleclasses as $role => $roleclass) {
?>
<tr>
- <th colspan="8" align="left"><h3><?php echo $wp_roles->role_names[$role]; ?></h3></th>
+<?php if ( !empty($role) ) : ?>
+ <th colspan="7" align="left"><h3><?php echo $wp_roles->role_names[$role]; ?></h3></th>
+<?php else : ?>
+ <th colspan="7" align="left"><h3><em><?php _e('No role for this blog'); ?></h3></th>
+<?php endif; ?>
</tr>
-<thead>
-<tr>
+<tr class="thead">
<th style="text-align: left"><?php _e('ID') ?></th>
<th style="text-align: left"><?php _e('Username') ?></th>
<th style="text-align: left"><?php _e('Name') ?></th>
<th style="text-align: left"><?php _e('E-mail') ?></th>
<th style="text-align: left"><?php _e('Website') ?></th>
- <th><?php _e('Posts') ?></th>
- <th>&nbsp;</th>
+ <th colspan="2"><?php _e('Actions') ?></th>
</tr>
</thead>
<tbody id="role-<?php echo $role; ?>"><?php
$style = '';
-foreach ($roleclass as $user_object) {
- $style = (' class="alternate"' == $style) ? '' : ' class="alternate"';
- echo "\n\t" . user_row( $user_object, $style );
+foreach ( (array) $roleclass as $user_object ) {
+ $style = ( ' class="alternate"' == $style ) ? '' : ' class="alternate"';
+ echo "\n\t" . user_row($user_object, $style);
}
-
?>
</tbody>
-<?php
-}
-?>
+<?php } ?>
</table>
+<?php if ( $wp_user_search->results_are_paged() ) : ?>
+ <div class="user-paging-text"><?php $wp_user_search->page_links(); ?></div>
+<?php endif; ?>
<h2><?php _e('Update Users'); ?></h2>
- <ul style="list-style:none;">
- <li><input type="radio" name="action" id="action0" value="removeuser" /> <label for="action0"><?php _e('Remove checked users from blog.'); ?></label></li>
- <li>
- <input type="radio" name="action" id="action1" value="promote" /> <label for="action1"><?php _e('Set the Role of checked users to:'); ?></label>
- <select name="new_role"><?php wp_dropdown_roles(); ?></select>
- </li>
- </ul>
- <p class="submit"><input type="submit" value="<?php _e('Update &raquo;'); ?>" /></p>
-</div>
+ <ul style="list-style:none;">
+ <li><input type="radio" name="action" id="action0" value="removeuser" /> <label for="action0"><?php _e('Remove checked users.'); ?></label></li>
+ <li>
+ <input type="radio" name="action" id="action1" value="promote" /> <label for="action1"><?php _e('Set the Role of checked users to:'); ?></label>
+ <select name="new_role"><?php wp_dropdown_roles(); ?></select>
+ </li>
+ </ul>
+ <p class="submit">
+ <?php echo $referer; ?>
+ <input type="submit" value="<?php _e('Update &raquo;'); ?>" />
+ </p>
</form>
+<?php endif; ?>
+</div>
+
+<?php
+ if ( is_wp_error($add_user_errors) ) {
+ foreach ( array('user_login' => 'user_login', 'first_name' => 'user_firstname', 'last_name' => 'user_lastname', 'email' => 'user_email', 'url' => 'user_uri', 'role' => 'user_role') as $formpost => $var ) {
+ $var = 'new_' . $var;
+ $$var = wp_specialchars(stripslashes($_POST[$formpost]));
+ }
+ unset($name);
+ }
+?>
<div class="wrap">
<h2><?php _e('Add User From Community') ?></h2>
@@ -402,20 +569,29 @@ foreach ($roleclass as $user_object) {
?></select></td>
</tr>
</table>
-<br />
-
- </td>
- </table>
- <p class="submit">
- <input name="adduser" type="submit" id="addusersub" value="<?php _e('Add User &raquo;') ?>" />
- </p>
- </form>
+<p class="submit">
+ <?php echo $referer; ?>
+ <input name="adduser" type="submit" id="addusersub" value="<?php _e('Add User &raquo;') ?>" />
+</p>
+</form>
+
+<?php if ( is_wp_error( $add_user_errors ) ) : ?>
+ <div class="error">
+ <ul>
+ <?php
+ foreach ( $add_user_errors->get_error_messages() as $message )
+ echo "$message<br />";
+ ?>
+ </ul>
+ </div>
+<?php endif; ?>
<div id="ajax-response"></div>
</div>
- <?php
+<?php
break;
-}
+
+} // end of the $action switch
include('admin-footer.php');
?>