X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/f9001779751f83dc8a10e478bfecb4d8dd5f964c..61343b82c4f0da4c68e4c6373daafff4a81efdd1:/wp-admin/includes/class-wp-users-list-table.php diff --git a/wp-admin/includes/class-wp-users-list-table.php b/wp-admin/includes/class-wp-users-list-table.php index d52d75f0..48c9c0c2 100644 --- a/wp-admin/includes/class-wp-users-list-table.php +++ b/wp-admin/includes/class-wp-users-list-table.php @@ -12,17 +12,17 @@ class WP_Users_List_Table extends WP_List_Table { 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() { @@ -35,7 +35,7 @@ class WP_Users_List_Table extends WP_List_Table { 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'] : ''; @@ -52,7 +52,8 @@ class WP_Users_List_Table extends WP_List_Table { '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; @@ -111,8 +112,8 @@ class WP_Users_List_Table extends WP_List_Table { $name = translate_user_role( $name ); /* translators: User role name with count */ - $name = sprintf( __('%1$s (%2$s)'), $name, $avail_roles[$this_role] ); - $role_links[$this_role] = "$name"; + $name = sprintf( __('%1$s (%2$s)'), $name, number_format_i18n( $avail_roles[$this_role] ) ); + $role_links[$this_role] = "$name"; } return $role_links; @@ -135,18 +136,20 @@ class WP_Users_List_Table extends WP_List_Table { function extra_tablenav( $which ) { if ( 'top' != $which ) return; - if ( ! current_user_can( 'promote_users' ) ) - return; -?> + ?>
+ - -
-'; } function current_action() { @@ -190,15 +193,23 @@ class WP_Users_List_Table extends WP_List_Table { 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"'; - echo "\n\t", $this->single_row( $user_object, $style, $role, isset( $post_counts ) ? $post_counts[ $userid ] : 0 ); + echo "\n\t" . $this->single_row( $user_object, $style, $role, isset( $post_counts ) ? $post_counts[ $userid ] : 0 ); } } @@ -208,17 +219,17 @@ class WP_Users_List_Table extends WP_List_Table { * @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 ) @@ -230,12 +241,7 @@ class WP_Users_List_Table extends WP_List_Table { // 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( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user_object->ID ) ) ); // Set up the hover actions for this user $actions = array(); @@ -254,8 +260,9 @@ class WP_Users_List_Table extends WP_List_Table { $actions = apply_filters( 'user_row_actions', $actions, $user_object ); $edit .= $this->row_actions( $actions ); - // Set up the checkbox ( because the user is editable, otherwise its empty ) - $checkbox = ""; + // Set up the checkbox ( because the user is editable, otherwise it's empty ) + $checkbox = '' + . ""; } else { $edit = '' . $user_object->user_login . ''; @@ -315,5 +322,3 @@ class WP_Users_List_Table extends WP_List_Table { return $r; } } - -?>