wp/wp-admin/includes/class-wp-users-list-table.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
--- a/wp/wp-admin/includes/class-wp-users-list-table.php	Tue Oct 22 16:11:46 2019 +0200
+++ b/wp/wp-admin/includes/class-wp-users-list-table.php	Tue Dec 15 13:49:49 2020 +0100
@@ -137,7 +137,7 @@
 		 */
 		$args = apply_filters( 'users_list_table_query_args', $args );
 
-		// Query the user IDs for this page
+		// Query the user IDs for this page.
 		$wp_user_search = new WP_User_Query( $args );
 
 		$this->items = $wp_user_search->get_results();
@@ -166,11 +166,11 @@
 	 * Provides a list of roles and user count for that role for easy
 	 * Filtersing of the user table.
 	 *
-	 * @since  3.1.0
+	 * @since 3.1.0
 	 *
 	 * @global string $role
 	 *
-	 * @return array An array of HTML links, one for each view.
+	 * @return string[] An array of HTML links keyed by their view.
 	 */
 	protected function get_views() {
 		global $role;
@@ -194,7 +194,22 @@
 		$current_link_attributes = empty( $role ) ? ' class="current" aria-current="page"' : '';
 
 		$role_links        = array();
-		$role_links['all'] = "<a href='$url'$current_link_attributes>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_users, 'users' ), number_format_i18n( $total_users ) ) . '</a>';
+		$role_links['all'] = sprintf(
+			'<a href="%s"%s>%s</a>',
+			$url,
+			$current_link_attributes,
+			sprintf(
+				/* translators: %s: Number of users. */
+				_nx(
+					'All <span class="count">(%s)</span>',
+					'All <span class="count">(%s)</span>',
+					$total_users,
+					'users'
+				),
+				number_format_i18n( $total_users )
+			)
+		);
+
 		foreach ( $wp_roles->get_names() as $this_role => $name ) {
 			if ( ! isset( $avail_roles[ $this_role ] ) ) {
 				continue;
@@ -207,8 +222,13 @@
 			}
 
 			$name = translate_user_role( $name );
-			/* translators: User role name with count */
-			$name                     = sprintf( __( '%1$s <span class="count">(%2$s)</span>' ), $name, number_format_i18n( $avail_roles[ $this_role ] ) );
+			$name = sprintf(
+				/* translators: 1: User role name, 2: Number of users. */
+				__( '%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 ) ) . "'$current_link_attributes>$name</a>";
 		}
 
@@ -221,10 +241,14 @@
 			}
 
 			$name = __( 'No role' );
-			/* translators: User role name with count */
-			$name               = sprintf( __( '%1$s <span class="count">(%2$s)</span>' ), $name, number_format_i18n( $avail_roles['none'] ) );
+			$name = sprintf(
+				/* translators: 1: User role name, 2: Number of users. */
+				__( '%1$s <span class="count">(%2$s)</span>' ),
+				$name,
+				number_format_i18n( $avail_roles['none'] )
+			);
+
 			$role_links['none'] = "<a href='" . esc_url( add_query_arg( 'role', 'none', $url ) ) . "'$current_link_attributes>$name</a>";
-
 		}
 
 		return $role_links;
@@ -233,9 +257,9 @@
 	/**
 	 * Retrieve an associative array of bulk actions available on this table.
 	 *
-	 * @since  3.1.0
+	 * @since 3.1.0
 	 *
-	 * @return array Array of bulk actions.
+	 * @return string[] Array of bulk action labels keyed by their action.
 	 */
 	protected function get_bulk_actions() {
 		$actions = array();
@@ -306,7 +330,7 @@
 	 * Overridden from the base class implementation to capture
 	 * the role change drop-down.
 	 *
-	 * @since  3.1.0
+	 * @since 3.1.0
 	 *
 	 * @return string The bulk action required.
 	 */
@@ -322,10 +346,9 @@
 	/**
 	 * Get a list of columns for the list table.
 	 *
-	 * @since  3.1.0
+	 * @since 3.1.0
 	 *
-	 * @return array Array in which the key is the ID of the column,
-	 *               and the value is the description.
+	 * @return string[] Array of column titles keyed by their column name.
 	 */
 	public function get_columns() {
 		$c = array(
@@ -366,7 +389,7 @@
 	 * @since 3.1.0
 	 */
 	public function display_rows() {
-		// Query the post counts for this page
+		// Query the post counts for this page.
 		if ( ! $this->is_site_users ) {
 			$post_counts = count_many_users_posts( array_keys( $this->items ) );
 		}
@@ -405,7 +428,7 @@
 
 		$user_roles = $this->get_role_list( $user_object );
 
-		// Set up the hover actions for this user
+		// Set up the hover actions for this user.
 		$actions     = array();
 		$checkbox    = '';
 		$super_admin = '';
@@ -416,9 +439,9 @@
 			}
 		}
 
-		// Check if the user for this row is editable
+		// Check if the user for this row is editable.
 		if ( current_user_can( 'list_users' ) ) {
-			// Set up the user editing link
+			// Set up the user editing link.
 			$edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user_object->ID ) ) );
 
 			if ( current_user_can( 'edit_user', $user_object->ID ) ) {
@@ -431,7 +454,7 @@
 			if ( ! is_multisite() && get_current_user_id() != $user_object->ID && current_user_can( 'delete_user', $user_object->ID ) ) {
 				$actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url( "users.php?action=delete&amp;user=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Delete' ) . '</a>';
 			}
-			if ( is_multisite() && get_current_user_id() != $user_object->ID && current_user_can( 'remove_user', $user_object->ID ) ) {
+			if ( is_multisite() && current_user_can( 'remove_user', $user_object->ID ) ) {
 				$actions['remove'] = "<a class='submitdelete' href='" . wp_nonce_url( $url . "action=remove&amp;user=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Remove' ) . '</a>';
 			}
 
@@ -441,7 +464,7 @@
 				$actions['view'] = sprintf(
 					'<a href="%s" aria-label="%s">%s</a>',
 					esc_url( $author_posts_url ),
-					/* translators: %s: author's display name */
+					/* translators: %s: Author's display name. */
 					esc_attr( sprintf( __( 'View posts by %s' ), $user_object->display_name ) ),
 					__( 'View' )
 				);
@@ -462,13 +485,20 @@
 			// Role classes.
 			$role_classes = esc_attr( implode( ' ', array_keys( $user_roles ) ) );
 
-			// Set up the checkbox ( because the user is editable, otherwise it's empty )
-			$checkbox = '<label class="screen-reader-text" for="user_' . $user_object->ID . '">' . sprintf( __( 'Select %s' ), $user_object->user_login ) . '</label>'
-						. "<input type='checkbox' name='users[]' id='user_{$user_object->ID}' class='{$role_classes}' value='{$user_object->ID}' />";
+			// Set up the checkbox (because the user is editable, otherwise it's empty).
+			$checkbox = sprintf(
+				'<label class="screen-reader-text" for="user_%1$s">%2$s</label>' .
+				'<input type="checkbox" name="users[]" id="user_%1$s" class="%3$s" value="%1$s" />',
+				$user_object->ID,
+				/* translators: %s: User login. */
+				sprintf( __( 'Select %s' ), $user_object->user_login ),
+				$role_classes
+			);
 
 		} else {
 			$edit = "<strong>{$user_object->user_login}{$super_admin}</strong>";
 		}
+
 		$avatar = get_avatar( $user_object->ID, 32 );
 
 		// Comma-separated list of user roles.
@@ -484,10 +514,10 @@
 				$classes .= ' has-row-actions column-primary';
 			}
 			if ( 'posts' === $column_name ) {
-				$classes .= ' num'; // Special case for that column
+				$classes .= ' num'; // Special case for that column.
 			}
 
-			if ( in_array( $column_name, $hidden ) ) {
+			if ( in_array( $column_name, $hidden, true ) ) {
 				$classes .= ' hidden';
 			}
 
@@ -511,7 +541,10 @@
 						} elseif ( $user_object->last_name ) {
 							$r .= $user_object->last_name;
 						} else {
-							$r .= '<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">' . _x( 'Unknown', 'name' ) . '</span>';
+							$r .= sprintf(
+								'<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">%s</span>',
+								_x( 'Unknown', 'name' )
+							);
 						}
 						break;
 					case 'email':
@@ -522,10 +555,16 @@
 						break;
 					case 'posts':
 						if ( $numposts > 0 ) {
-							$r .= "<a href='edit.php?author=$user_object->ID' class='edit'>";
-							$r .= '<span aria-hidden="true">' . $numposts . '</span>';
-							$r .= '<span class="screen-reader-text">' . sprintf( _n( '%s post by this author', '%s posts by this author', $numposts ), number_format_i18n( $numposts ) ) . '</span>';
-							$r .= '</a>';
+							$r .= sprintf(
+								'<a href="%s" class="edit"><span aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>',
+								"edit.php?author={$user_object->ID}",
+								$numposts,
+								sprintf(
+									/* translators: %s: Number of posts. */
+									_n( '%s post by this author', '%s posts by this author', $numposts ),
+									number_format_i18n( $numposts )
+								)
+							);
 						} else {
 							$r .= 0;
 						}