var $site_id;
var $is_site_users;
- function WP_Users_List_Table() {
- $screen = get_current_screen();
- $this->is_site_users = 'site-users-network' == $screen->id;
+ function __construct( $args = array() ) {
+ parent::__construct( array(
+ 'singular' => 'user',
+ 'plural' => 'users',
+ 'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
+ ) );
+
+ $this->is_site_users = 'site-users-network' == $this->screen->id;
if ( $this->is_site_users )
$this->site_id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
-
- parent::WP_List_Table( array(
- 'singular' => 'user',
- 'plural' => 'users'
- ) );
}
function ajax_user_can() {
function prepare_items() {
global $role, $usersearch;
- $usersearch = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '';
+ $usersearch = isset( $_REQUEST['s'] ) ? trim( $_REQUEST['s'] ) : '';
$role = isset( $_REQUEST['role'] ) ? $_REQUEST['role'] : '';
'fields' => 'all_with_meta'
);
- $args['search'] = '*' . $args['search'] . '*';
+ if ( '' !== $args['search'] )
+ $args['search'] = '*' . $args['search'] . '*';
if ( $this->is_site_users )
$args['blog_id'] = $this->site_id;
$name = translate_user_role( $name );
/* translators: User role name with count */
- $name = sprintf( __('%1$s <span class="count">(%2$s)</span>'), $name, $avail_roles[$this_role] );
- $role_links[$this_role] = "<a href='" . add_query_arg( 'role', $this_role, $url ) . "'$class>$name</a>";
+ $name = sprintf( __('%1$s <span class="count">(%2$s)</span>'), $name, number_format_i18n( $avail_roles[$this_role] ) );
+ $role_links[$this_role] = "<a href='" . esc_url( add_query_arg( 'role', $this_role, $url ) ) . "'$class>$name</a>";
}
return $role_links;
function extra_tablenav( $which ) {
if ( 'top' != $which )
return;
- if ( ! current_user_can( 'promote_users' ) )
- return;
-?>
+ ?>
<div class="alignleft actions">
+ <?php if ( current_user_can( 'promote_users' ) ) : ?>
<label class="screen-reader-text" for="new_role"><?php _e( 'Change role to…' ) ?></label>
<select name="new_role" id="new_role">
<option value=''><?php _e( 'Change role to…' ) ?></option>
<?php wp_dropdown_roles(); ?>
</select>
- <?php submit_button( __( 'Change' ), 'secondary', 'changeit', false ); ?>
- </div>
-<?php
+ <?php
+ submit_button( __( 'Change' ), 'button', 'changeit', false );
+ endif;
+
+ do_action( 'restrict_manage_users' );
+ echo '</div>';
}
function current_action() {
if ( ! $this->is_site_users )
$post_counts = count_many_users_posts( array_keys( $this->items ) );
+ $editable_roles = array_keys( get_editable_roles() );
+
$style = '';
foreach ( $this->items as $userid => $user_object ) {
- $role = reset( $user_object->roles );
+ if ( count( $user_object->roles ) <= 1 ) {
+ $role = reset( $user_object->roles );
+ } elseif ( $roles = array_intersect( array_values( $user_object->roles ), $editable_roles ) ) {
+ $role = reset( $roles );
+ } else {
+ $role = reset( $user_object->roles );
+ }
- if ( is_multisite() && empty( $role ) )
+ if ( is_multisite() && empty( $user_object->allcaps ) )
continue;
$style = ( ' class="alternate"' == $style ) ? '' : ' class="alternate"';
* @since 2.1.0
*
* @param object $user_object
- * @param string $style Optional. Attributes added to the TR element. Must be sanitized.
+ * @param string $style Optional. Attributes added to the TR element. Must be sanitized.
* @param string $role Key for the $wp_roles array.
- * @param int $numposts Optional. Post count to display for this user. Defaults to zero, as in, a new user has made zero posts.
+ * @param int $numposts Optional. Post count to display for this user. Defaults to zero, as in, a new user has made zero posts.
* @return string
*/
function single_row( $user_object, $style = '', $role = '', $numposts = 0 ) {
global $wp_roles;
if ( !( is_object( $user_object ) && is_a( $user_object, 'WP_User' ) ) )
- $user_object = new WP_User( (int) $user_object );
- $user_object = sanitize_user_object( $user_object, 'display' );
+ $user_object = get_userdata( (int) $user_object );
+ $user_object->filter = 'display';
$email = $user_object->user_email;
if ( $this->is_site_users )
// Check if the user for this row is editable
if ( current_user_can( 'list_users' ) ) {
// Set up the user editing link
- // TODO: make profile/user-edit determination a separate function
- if ( get_current_user_id() == $user_object->ID ) {
- $edit_link = 'profile.php';
- } else {
- $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( stripslashes( $_SERVER['REQUEST_URI'] ) ), "user-edit.php?user_id=$user_object->ID" ) );
- }
+ $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( stripslashes( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user_object->ID ) ) );
// Set up the hover actions for this user
$actions = array();
$edit .= $this->row_actions( $actions );
// Set up the checkbox ( because the user is editable, otherwise its empty )
- $checkbox = "<input type='checkbox' name='users[]' id='user_{$user_object->ID}' class='$role' value='{$user_object->ID}' />";
+ $checkbox = '<label class="screen-reader-text" for="cb-select-' . $user_object->ID . '">' . sprintf( __( 'Select %s' ), $user_object->user_login ) . '</label>'
+ . "<input type='checkbox' name='users[]' id='user_{$user_object->ID}' class='$role' value='{$user_object->ID}' />";
} else {
$edit = '<strong>' . $user_object->user_login . '</strong>';
return $r;
}
}
-
-?>