wp/wp-admin/includes/class-wp-users-list-table.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
--- a/wp/wp-admin/includes/class-wp-users-list-table.php	Wed Sep 21 18:19:35 2022 +0200
+++ b/wp/wp-admin/includes/class-wp-users-list-table.php	Tue Sep 27 16:37:53 2022 +0200
@@ -177,28 +177,33 @@
 
 		$wp_roles = wp_roles();
 
+		$count_users = ! wp_is_large_user_count();
+
 		if ( $this->is_site_users ) {
 			$url = 'site-users.php?id=' . $this->site_id;
-			switch_to_blog( $this->site_id );
-			$users_of_blog = count_users( 'time', $this->site_id );
-			restore_current_blog();
 		} else {
-			$url           = 'users.php';
-			$users_of_blog = count_users();
+			$url = 'users.php';
 		}
 
-		$total_users = $users_of_blog['total_users'];
-		$avail_roles =& $users_of_blog['avail_roles'];
-		unset( $users_of_blog );
-
+		$role_links              = array();
+		$avail_roles             = array();
+		$all_text                = __( 'All' );
 		$current_link_attributes = empty( $role ) ? ' class="current" aria-current="page"' : '';
 
-		$role_links        = array();
-		$role_links['all'] = sprintf(
-			'<a href="%s"%s>%s</a>',
-			$url,
-			$current_link_attributes,
-			sprintf(
+		if ( $count_users ) {
+			if ( $this->is_site_users ) {
+				switch_to_blog( $this->site_id );
+				$users_of_blog = count_users( 'time', $this->site_id );
+				restore_current_blog();
+			} else {
+				$users_of_blog = count_users();
+			}
+
+			$total_users = $users_of_blog['total_users'];
+			$avail_roles =& $users_of_blog['avail_roles'];
+			unset( $users_of_blog );
+
+			$all_text = sprintf(
 				/* translators: %s: Number of users. */
 				_nx(
 					'All <span class="count">(%s)</span>',
@@ -207,11 +212,13 @@
 					'users'
 				),
 				number_format_i18n( $total_users )
-			)
-		);
+			);
+		}
+
+		$role_links['all'] = sprintf( '<a href="%s"%s>%s</a>', $url, $current_link_attributes, $all_text );
 
 		foreach ( $wp_roles->get_names() as $this_role => $name ) {
-			if ( ! isset( $avail_roles[ $this_role ] ) ) {
+			if ( $count_users && ! isset( $avail_roles[ $this_role ] ) ) {
 				continue;
 			}
 
@@ -222,12 +229,14 @@
 			}
 
 			$name = translate_user_role( $name );
-			$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 ] )
-			);
+			if ( $count_users ) {
+				$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>";
 		}
@@ -362,7 +371,7 @@
 			'name'     => __( 'Name' ),
 			'email'    => __( 'Email' ),
 			'role'     => __( 'Role' ),
-			'posts'    => __( 'Posts' ),
+			'posts'    => _x( 'Posts', 'post type general name' ),
 		);
 
 		if ( $this->is_site_users ) {
@@ -447,7 +456,13 @@
 		// Check if the user for this row is editable.
 		if ( current_user_can( 'list_users' ) ) {
 			// 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 ) ) );
+			$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 ) ) {
 				$edit            = "<strong><a href=\"{$edit_link}\">{$user_object->user_login}</a>{$super_admin}</strong><br />";
@@ -456,10 +471,16 @@
 				$edit = "<strong>{$user_object->user_login}{$super_admin}</strong><br />";
 			}
 
-			if ( ! is_multisite() && get_current_user_id() != $user_object->ID && current_user_can( 'delete_user', $user_object->ID ) ) {
+			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() && 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>';
 			}
 
@@ -476,7 +497,9 @@
 			}
 
 			// Add a link to send the user a reset password link by email.
-			if ( get_current_user_id() !== $user_object->ID && current_user_can( 'edit_user', $user_object->ID ) ) {
+			if ( get_current_user_id() !== $user_object->ID
+				&& current_user_can( 'edit_user', $user_object->ID )
+			) {
 				$actions['resetpassword'] = "<a class='resetpassword' href='" . wp_nonce_url( "users.php?action=resetpassword&amp;users=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Send password reset' ) . '</a>';
 			}
 
@@ -615,12 +638,12 @@
 	}
 
 	/**
-	 * Returns an array of user roles for a given user object.
+	 * Returns an array of translated user role names for a given user object.
 	 *
 	 * @since 4.4.0
 	 *
 	 * @param WP_User $user_object The WP_User object.
-	 * @return string[] An array of user roles.
+	 * @return string[] An array of user role names keyed by role.
 	 */
 	protected function get_role_list( $user_object ) {
 		$wp_roles = wp_roles();
@@ -638,11 +661,11 @@
 		}
 
 		/**
-		 * Filters the returned array of roles for a user.
+		 * Filters the returned array of translated role names for a user.
 		 *
 		 * @since 4.4.0
 		 *
-		 * @param string[] $role_list   An array of user roles.
+		 * @param string[] $role_list   An array of translated user role names keyed by role.
 		 * @param WP_User  $user_object A WP_User object.
 		 */
 		return apply_filters( 'get_role_list', $role_list, $user_object );