users.php redesign. WIP
git-svn-id: http://svn.automattic.com/wordpress/trunk@6875 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
b6cc3da285
commit
22195eeaed
|
@ -511,6 +511,8 @@ function page_rows( $pages ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function user_row( $user_object, $style = '', $role = '' ) {
|
function user_row( $user_object, $style = '', $role = '' ) {
|
||||||
|
global $wp_roles;
|
||||||
|
|
||||||
if ( !( is_object( $user_object) && is_a( $user_object, 'WP_User' ) ) )
|
if ( !( is_object( $user_object) && is_a( $user_object, 'WP_User' ) ) )
|
||||||
$user_object = new WP_User( (int) $user_object );
|
$user_object = new WP_User( (int) $user_object );
|
||||||
$email = $user_object->user_email;
|
$email = $user_object->user_email;
|
||||||
|
@ -533,7 +535,7 @@ function user_row( $user_object, $style = '', $role = '' ) {
|
||||||
<td><strong>$edit</strong></td>
|
<td><strong>$edit</strong></td>
|
||||||
<td>$user_object->first_name $user_object->last_name</td>
|
<td>$user_object->first_name $user_object->last_name</td>
|
||||||
<td><a href='mailto:$email' title='" . sprintf( __('e-mail: %s' ), $email ) . "'>$email</a></td>
|
<td><a href='mailto:$email' title='" . sprintf( __('e-mail: %s' ), $email ) . "'>$email</a></td>
|
||||||
<td><a href='$url' title='website: $url'>$short_url</a></td>";
|
<td>{$wp_roles->role_names[$role]}</td>";
|
||||||
$r .= "\n\t\t<td>";
|
$r .= "\n\t\t<td>";
|
||||||
if ( $numposts > 0 ) {
|
if ( $numposts > 0 ) {
|
||||||
$r .= "<a href='edit.php?author=$user_object->ID' title='" . __( 'View posts by this author' ) . "' class='edit'>";
|
$r .= "<a href='edit.php?author=$user_object->ID' title='" . __( 'View posts by this author' ) . "' class='edit'>";
|
||||||
|
|
|
@ -289,6 +289,7 @@ class WP_User_Search {
|
||||||
var $results;
|
var $results;
|
||||||
var $search_term;
|
var $search_term;
|
||||||
var $page;
|
var $page;
|
||||||
|
var $role;
|
||||||
var $raw_page;
|
var $raw_page;
|
||||||
var $users_per_page = 50;
|
var $users_per_page = 50;
|
||||||
var $first_user;
|
var $first_user;
|
||||||
|
@ -299,10 +300,11 @@ class WP_User_Search {
|
||||||
var $too_many_total_users = false;
|
var $too_many_total_users = false;
|
||||||
var $search_errors;
|
var $search_errors;
|
||||||
|
|
||||||
function WP_User_Search ($search_term = '', $page = '') { // constructor
|
function WP_User_Search ($search_term = '', $page = '', $role = '') { // constructor
|
||||||
$this->search_term = $search_term;
|
$this->search_term = $search_term;
|
||||||
$this->raw_page = ( '' == $page ) ? false : (int) $page;
|
$this->raw_page = ( '' == $page ) ? false : (int) $page;
|
||||||
$this->page = (int) ( '' == $page ) ? 1 : $page;
|
$this->page = (int) ( '' == $page ) ? 1 : $page;
|
||||||
|
$this->role = $role;
|
||||||
|
|
||||||
$this->prepare_query();
|
$this->prepare_query();
|
||||||
$this->query();
|
$this->query();
|
||||||
|
@ -314,6 +316,7 @@ class WP_User_Search {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
$this->first_user = ($this->page - 1) * $this->users_per_page;
|
$this->first_user = ($this->page - 1) * $this->users_per_page;
|
||||||
$this->query_limit = 'LIMIT ' . $this->first_user . ',' . $this->users_per_page;
|
$this->query_limit = 'LIMIT ' . $this->first_user . ',' . $this->users_per_page;
|
||||||
|
$search_sql = '';
|
||||||
if ( $this->search_term ) {
|
if ( $this->search_term ) {
|
||||||
$searches = array();
|
$searches = array();
|
||||||
$search_sql = 'AND (';
|
$search_sql = 'AND (';
|
||||||
|
@ -322,7 +325,13 @@ class WP_User_Search {
|
||||||
$search_sql .= implode(' OR ', $searches);
|
$search_sql .= implode(' OR ', $searches);
|
||||||
$search_sql .= ')';
|
$search_sql .= ')';
|
||||||
}
|
}
|
||||||
$this->query_from_where = "FROM $wpdb->users WHERE 1=1 $search_sql";
|
|
||||||
|
$this->query_from_where = "FROM $wpdb->users";
|
||||||
|
if ( $this->role )
|
||||||
|
$this->query_from_where .= " INNER JOIN $wpdb->usermeta ON $wpdb->users.ID = $wpdb->usermeta.user_id WHERE $wpdb->usermeta.meta_key = '{$wpdb->prefix}capabilities' AND $wpdb->usermeta.meta_value LIKE '%$this->role%'";
|
||||||
|
else
|
||||||
|
$this->query_from_where .= " WHERE 1=1";
|
||||||
|
$this->query_from_where .= " $search_sql";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -345,8 +354,6 @@ class WP_User_Search {
|
||||||
$this->paging_text = paginate_links( array(
|
$this->paging_text = paginate_links( array(
|
||||||
'total' => ceil($this->total_users_for_query / $this->users_per_page),
|
'total' => ceil($this->total_users_for_query / $this->users_per_page),
|
||||||
'current' => $this->page,
|
'current' => $this->page,
|
||||||
'prev_text' => __('« Previous Page'),
|
|
||||||
'next_text' => __('Next Page »'),
|
|
||||||
'base' => 'users.php?%_%',
|
'base' => 'users.php?%_%',
|
||||||
'format' => 'userspage=%#%',
|
'format' => 'userspage=%#%',
|
||||||
'add_args' => array( 'usersearch' => urlencode($this->search_term) )
|
'add_args' => array( 'usersearch' => urlencode($this->search_term) )
|
||||||
|
|
|
@ -11,10 +11,13 @@ $parent_file = 'users.php';
|
||||||
$action = $_REQUEST['action'];
|
$action = $_REQUEST['action'];
|
||||||
$update = '';
|
$update = '';
|
||||||
|
|
||||||
if ( empty($_POST) ) {
|
if ( empty($action) && isset($_GET['deleteit']) )
|
||||||
|
$action = 'delete';
|
||||||
|
|
||||||
|
if ( empty($_REQUEST) ) {
|
||||||
$referer = '<input type="hidden" name="wp_http_referer" value="'. attribute_escape(stripslashes($_SERVER['REQUEST_URI'])) . '" />';
|
$referer = '<input type="hidden" name="wp_http_referer" value="'. attribute_escape(stripslashes($_SERVER['REQUEST_URI'])) . '" />';
|
||||||
} elseif ( isset($_POST['wp_http_referer']) ) {
|
} elseif ( isset($_REQUEST['wp_http_referer']) ) {
|
||||||
$redirect = remove_query_arg(array('wp_http_referer', 'updated', 'delete_count'), stripslashes($_POST['wp_http_referer']));
|
$redirect = remove_query_arg(array('wp_http_referer', 'updated', 'delete_count'), stripslashes($_REQUEST['wp_http_referer']));
|
||||||
$referer = '<input type="hidden" name="wp_http_referer" value="' . attribute_escape($redirect) . '" />';
|
$referer = '<input type="hidden" name="wp_http_referer" value="' . attribute_escape($redirect) . '" />';
|
||||||
} else {
|
} else {
|
||||||
$redirect = 'users.php';
|
$redirect = 'users.php';
|
||||||
|
@ -25,7 +28,7 @@ switch ($action) {
|
||||||
case 'promote':
|
case 'promote':
|
||||||
check_admin_referer('bulk-users');
|
check_admin_referer('bulk-users');
|
||||||
|
|
||||||
if (empty($_POST['users'])) {
|
if (empty($_REQUEST['users'])) {
|
||||||
wp_redirect($redirect);
|
wp_redirect($redirect);
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
@ -33,19 +36,19 @@ case 'promote':
|
||||||
if ( !current_user_can('edit_users') )
|
if ( !current_user_can('edit_users') )
|
||||||
wp_die(__('You can’t edit users.'));
|
wp_die(__('You can’t edit users.'));
|
||||||
|
|
||||||
$userids = $_POST['users'];
|
$userids = $_REQUEST['users'];
|
||||||
$update = 'promote';
|
$update = 'promote';
|
||||||
foreach($userids as $id) {
|
foreach($userids as $id) {
|
||||||
if ( ! current_user_can('edit_user', $id) )
|
if ( ! current_user_can('edit_user', $id) )
|
||||||
wp_die(__('You can’t edit that user.'));
|
wp_die(__('You can’t edit that user.'));
|
||||||
// The new role of the current user must also have edit_users caps
|
// 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')) {
|
if($id == $current_user->ID && !$wp_roles->role_objects[$_REQUEST['new_role']]->has_cap('edit_users')) {
|
||||||
$update = 'err_admin_role';
|
$update = 'err_admin_role';
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = new WP_User($id);
|
$user = new WP_User($id);
|
||||||
$user->set_role($_POST['new_role']);
|
$user->set_role($_REQUEST['new_role']);
|
||||||
}
|
}
|
||||||
|
|
||||||
wp_redirect(add_query_arg('update', $update, $redirect));
|
wp_redirect(add_query_arg('update', $update, $redirect));
|
||||||
|
@ -57,7 +60,7 @@ case 'dodelete':
|
||||||
|
|
||||||
check_admin_referer('delete-users');
|
check_admin_referer('delete-users');
|
||||||
|
|
||||||
if ( empty($_POST['users']) ) {
|
if ( empty($_REQUEST['users']) ) {
|
||||||
wp_redirect($redirect);
|
wp_redirect($redirect);
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
@ -65,7 +68,7 @@ case 'dodelete':
|
||||||
if ( !current_user_can('delete_users') )
|
if ( !current_user_can('delete_users') )
|
||||||
wp_die(__('You can’t delete users.'));
|
wp_die(__('You can’t delete users.'));
|
||||||
|
|
||||||
$userids = $_POST['users'];
|
$userids = $_REQUEST['users'];
|
||||||
$update = 'del';
|
$update = 'del';
|
||||||
$delete_count = 0;
|
$delete_count = 0;
|
||||||
|
|
||||||
|
@ -77,12 +80,12 @@ case 'dodelete':
|
||||||
$update = 'err_admin_del';
|
$update = 'err_admin_del';
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
switch($_POST['delete_option']) {
|
switch($_REQUEST['delete_option']) {
|
||||||
case 'delete':
|
case 'delete':
|
||||||
wp_delete_user($id);
|
wp_delete_user($id);
|
||||||
break;
|
break;
|
||||||
case 'reassign':
|
case 'reassign':
|
||||||
wp_delete_user($id, $_POST['reassign_user']);
|
wp_delete_user($id, $_REQUEST['reassign_user']);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
++$delete_count;
|
++$delete_count;
|
||||||
|
@ -98,7 +101,7 @@ case 'delete':
|
||||||
|
|
||||||
check_admin_referer('bulk-users');
|
check_admin_referer('bulk-users');
|
||||||
|
|
||||||
if ( empty($_POST['users']) ) {
|
if ( empty($_REQUEST['users']) ) {
|
||||||
wp_redirect($redirect);
|
wp_redirect($redirect);
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
@ -106,7 +109,7 @@ case 'delete':
|
||||||
if ( !current_user_can('delete_users') )
|
if ( !current_user_can('delete_users') )
|
||||||
$errors = new WP_Error('edit_users', __('You can’t delete users.'));
|
$errors = new WP_Error('edit_users', __('You can’t delete users.'));
|
||||||
|
|
||||||
$userids = $_POST['users'];
|
$userids = $_REQUEST['users'];
|
||||||
|
|
||||||
include ('admin-header.php');
|
include ('admin-header.php');
|
||||||
?>
|
?>
|
||||||
|
@ -167,7 +170,7 @@ case 'adduser':
|
||||||
if ( is_wp_error( $user_id ) )
|
if ( is_wp_error( $user_id ) )
|
||||||
$add_user_errors = $user_id;
|
$add_user_errors = $user_id;
|
||||||
else {
|
else {
|
||||||
$new_user_login = apply_filters('pre_user_login', sanitize_user(stripslashes($_POST['user_login']), true));
|
$new_user_login = apply_filters('pre_user_login', sanitize_user(stripslashes($_REQUEST['user_login']), true));
|
||||||
$redirect = add_query_arg( array('usersearch' => urlencode($new_user_login), 'update' => $update), $redirect );
|
$redirect = add_query_arg( array('usersearch' => urlencode($new_user_login), 'update' => $update), $redirect );
|
||||||
wp_redirect( $redirect . '#user-' . $user_id );
|
wp_redirect( $redirect . '#user-' . $user_id );
|
||||||
die();
|
die();
|
||||||
|
@ -180,7 +183,7 @@ default:
|
||||||
include('admin-header.php');
|
include('admin-header.php');
|
||||||
|
|
||||||
// Query the users
|
// Query the users
|
||||||
$wp_user_search = new WP_User_Search($_GET['usersearch'], $_GET['userspage']);
|
$wp_user_search = new WP_User_Search($_GET['usersearch'], $_GET['userspage'], $_GET['role']);
|
||||||
|
|
||||||
// Make the user objects
|
// Make the user objects
|
||||||
foreach ( $wp_user_search->get_results() as $userid ) {
|
foreach ( $wp_user_search->get_results() as $userid ) {
|
||||||
|
@ -236,16 +239,52 @@ default:
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<div class="wrap">
|
<div class="wrap">
|
||||||
|
<form id="posts-filter" action="" method="get">
|
||||||
<?php if ( $wp_user_search->is_search() ) : ?>
|
<?php if ( $wp_user_search->is_search() ) : ?>
|
||||||
<h2><?php printf(__('Users Matching "%s" by Role'), wp_specialchars($wp_user_search->search_term)); ?></h2>
|
<h2><?php printf(__('Users Matching "%s"'), wp_specialchars($wp_user_search->search_term)); ?></h2>
|
||||||
<?php else : ?>
|
<?php else : ?>
|
||||||
<h2><?php _e('User List by Role'); ?></h2>
|
<h2><?php _e('Manage Users'); ?></h2>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<form action="" method="get" name="search" id="search">
|
<ul class="subsubsub">
|
||||||
<p><input type="text" name="usersearch" id="usersearch" value="<?php echo attribute_escape($wp_user_search->search_term); ?>" /> <input type="submit" value="<?php _e('Search Users »'); ?>" class="button" /></p>
|
<?php
|
||||||
</form>
|
$role_links = array();
|
||||||
|
foreach ( $wp_roles->get_names() as $role => $name ) {
|
||||||
|
$class = '';
|
||||||
|
|
||||||
|
if ( $role == $_GET['role'] )
|
||||||
|
$class = ' class="current"';
|
||||||
|
|
||||||
|
$role_links[] = "<li><a href=\"users.php?role=$role\"$class>" . $name . '</a>';
|
||||||
|
}
|
||||||
|
$class = empty($_GET['role']) ? ' class="current"' : '';
|
||||||
|
$role_links[] = "<li><a href=\"users.php\"$class>" . __('All Users') . "</a>";
|
||||||
|
echo implode(' |</li>', $role_links) . '</li>';
|
||||||
|
unset($role_links);
|
||||||
|
?>
|
||||||
|
</ul>
|
||||||
|
<p id="post-search">
|
||||||
|
<input type="text" id="post-search-input" name="usersearch" value="<?php echo attribute_escape($wp_user_search->search_term); ?>" />
|
||||||
|
<input type="submit" value="<?php _e( 'Search Users' ); ?>" />
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<br style="clear:both;" />
|
||||||
|
|
||||||
|
<div class="tablenav">
|
||||||
|
|
||||||
|
<?php if ( $wp_user_search->results_are_paged() ) : ?>
|
||||||
|
<div class="tablenav-pages"><?php $wp_user_search->page_links(); ?></div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<div style="float: left">
|
||||||
|
<input type="submit" value="<?php _e('Delete'); ?>" name="deleteit" />
|
||||||
|
<?php wp_nonce_field('bulk-users'); ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<br style="clear:both;" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<br style="clear:both;" />
|
||||||
|
|
||||||
<?php if ( is_wp_error( $wp_user_search->search_errors ) ) : ?>
|
<?php if ( is_wp_error( $wp_user_search->search_errors ) ) : ?>
|
||||||
<div class="error">
|
<div class="error">
|
||||||
|
@ -271,34 +310,23 @@ default:
|
||||||
else
|
else
|
||||||
printf(__('%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>
|
printf(__('%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"><p><?php $wp_user_search->page_links(); ?></p></div>
|
|
||||||
<?php endif; ?>
|
|
||||||
|
|
||||||
<form action="" method="post" name="updateusers" id="updateusers">
|
<form action="" method="post" name="updateusers" id="updateusers">
|
||||||
<?php wp_nonce_field('bulk-users') ?>
|
<?php wp_nonce_field('bulk-users') ?>
|
||||||
<table class="widefat">
|
<table class="widefat">
|
||||||
<?php
|
|
||||||
foreach($roleclasses as $role => $roleclass) {
|
|
||||||
uksort($roleclass, "strnatcasecmp");
|
|
||||||
?>
|
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
|
||||||
<?php if ( !empty($role) ) : ?>
|
|
||||||
<th colspan="7"><h3><?php echo $wp_roles->role_names[$role]; ?></h3></th>
|
|
||||||
<?php else : ?>
|
|
||||||
<th colspan="7"><h3><em><?php _e('No role for this blog'); ?></em></h3></th>
|
|
||||||
<?php endif; ?>
|
|
||||||
</tr>
|
|
||||||
<tr class="thead">
|
<tr class="thead">
|
||||||
<th><input type="checkbox" onclick="checkAllUsers('<?php echo $role; ?>')"/> </th>
|
<th><input type="checkbox" onclick="checkAllUsers('<?php echo $role; ?>')"/> </th>
|
||||||
<th><?php _e('Username') ?></th>
|
<th><?php _e('Username') ?></th>
|
||||||
<th><?php _e('Name') ?></th>
|
<th><?php _e('Name') ?></th>
|
||||||
<th><?php _e('E-mail') ?></th>
|
<th><?php _e('E-mail') ?></th>
|
||||||
<th><?php _e('Website') ?></th>
|
<th><?php _e('Role') ?></th>
|
||||||
<th><?php _e('Posts') ?></th>
|
<th><?php _e('Posts') ?></th>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
<?php
|
||||||
|
foreach ($roleclasses as $role => $roleclass) {
|
||||||
|
uksort($roleclass, "strnatcasecmp");
|
||||||
|
?>
|
||||||
<tbody id="role-<?php echo $role; ?>" class="list:user user-list"><?php
|
<tbody id="role-<?php echo $role; ?>" class="list:user user-list"><?php
|
||||||
$style = '';
|
$style = '';
|
||||||
foreach ( (array) $roleclass as $user_object ) {
|
foreach ( (array) $roleclass as $user_object ) {
|
||||||
|
@ -311,36 +339,34 @@ foreach ( (array) $roleclass as $user_object ) {
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<br style="clear:both;" />
|
||||||
|
|
||||||
|
<div class="tablenav">
|
||||||
|
|
||||||
<?php if ( $wp_user_search->results_are_paged() ) : ?>
|
<?php if ( $wp_user_search->results_are_paged() ) : ?>
|
||||||
<div class="user-paging-text"><p><?php $wp_user_search->page_links(); ?></p></div>
|
<div class="tablenav-pages"><?php $wp_user_search->page_links(); ?></div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<h3><?php _e('Update Selected'); ?></h3>
|
<br style="clear:both;" />
|
||||||
<ul style="list-style:none;">
|
</div>
|
||||||
<li><input type="radio" name="action" id="action0" value="delete" /> <label for="action0"><?php _e('Delete 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" onchange="getElementById('action1').checked = 'true'"><?php wp_dropdown_roles(); ?></select>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
<p class="submit" style="width: 420px">
|
|
||||||
<?php echo $referer; ?>
|
|
||||||
<input type="submit" value="<?php _e('Bulk Update »'); ?>" />
|
|
||||||
</p>
|
|
||||||
</form>
|
</form>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
if ( is_wp_error($add_user_errors) ) {
|
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 ) {
|
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 = 'new_' . $var;
|
||||||
$$var = attribute_escape(stripslashes($_POST[$formpost]));
|
$$var = attribute_escape(stripslashes($_REQUEST[$formpost]));
|
||||||
}
|
}
|
||||||
unset($name);
|
unset($name);
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
<br style="clear:both;" />
|
||||||
|
|
||||||
<div class="wrap">
|
<div class="wrap">
|
||||||
<h2 id="add-new-user"><?php _e('Add New User') ?></h2>
|
<h2 id="add-new-user"><?php _e('Add New User') ?></h2>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue