wp/wp-admin/includes/class-wp-users-list-table.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
   175 	protected function get_views() {
   175 	protected function get_views() {
   176 		global $role;
   176 		global $role;
   177 
   177 
   178 		$wp_roles = wp_roles();
   178 		$wp_roles = wp_roles();
   179 
   179 
       
   180 		$count_users = ! wp_is_large_user_count();
       
   181 
   180 		if ( $this->is_site_users ) {
   182 		if ( $this->is_site_users ) {
   181 			$url = 'site-users.php?id=' . $this->site_id;
   183 			$url = 'site-users.php?id=' . $this->site_id;
   182 			switch_to_blog( $this->site_id );
       
   183 			$users_of_blog = count_users( 'time', $this->site_id );
       
   184 			restore_current_blog();
       
   185 		} else {
   184 		} else {
   186 			$url           = 'users.php';
   185 			$url = 'users.php';
   187 			$users_of_blog = count_users();
   186 		}
   188 		}
   187 
   189 
   188 		$role_links              = array();
   190 		$total_users = $users_of_blog['total_users'];
   189 		$avail_roles             = array();
   191 		$avail_roles =& $users_of_blog['avail_roles'];
   190 		$all_text                = __( 'All' );
   192 		unset( $users_of_blog );
       
   193 
       
   194 		$current_link_attributes = empty( $role ) ? ' class="current" aria-current="page"' : '';
   191 		$current_link_attributes = empty( $role ) ? ' class="current" aria-current="page"' : '';
   195 
   192 
   196 		$role_links        = array();
   193 		if ( $count_users ) {
   197 		$role_links['all'] = sprintf(
   194 			if ( $this->is_site_users ) {
   198 			'<a href="%s"%s>%s</a>',
   195 				switch_to_blog( $this->site_id );
   199 			$url,
   196 				$users_of_blog = count_users( 'time', $this->site_id );
   200 			$current_link_attributes,
   197 				restore_current_blog();
   201 			sprintf(
   198 			} else {
       
   199 				$users_of_blog = count_users();
       
   200 			}
       
   201 
       
   202 			$total_users = $users_of_blog['total_users'];
       
   203 			$avail_roles =& $users_of_blog['avail_roles'];
       
   204 			unset( $users_of_blog );
       
   205 
       
   206 			$all_text = sprintf(
   202 				/* translators: %s: Number of users. */
   207 				/* translators: %s: Number of users. */
   203 				_nx(
   208 				_nx(
   204 					'All <span class="count">(%s)</span>',
   209 					'All <span class="count">(%s)</span>',
   205 					'All <span class="count">(%s)</span>',
   210 					'All <span class="count">(%s)</span>',
   206 					$total_users,
   211 					$total_users,
   207 					'users'
   212 					'users'
   208 				),
   213 				),
   209 				number_format_i18n( $total_users )
   214 				number_format_i18n( $total_users )
   210 			)
   215 			);
   211 		);
   216 		}
       
   217 
       
   218 		$role_links['all'] = sprintf( '<a href="%s"%s>%s</a>', $url, $current_link_attributes, $all_text );
   212 
   219 
   213 		foreach ( $wp_roles->get_names() as $this_role => $name ) {
   220 		foreach ( $wp_roles->get_names() as $this_role => $name ) {
   214 			if ( ! isset( $avail_roles[ $this_role ] ) ) {
   221 			if ( $count_users && ! isset( $avail_roles[ $this_role ] ) ) {
   215 				continue;
   222 				continue;
   216 			}
   223 			}
   217 
   224 
   218 			$current_link_attributes = '';
   225 			$current_link_attributes = '';
   219 
   226 
   220 			if ( $this_role === $role ) {
   227 			if ( $this_role === $role ) {
   221 				$current_link_attributes = ' class="current" aria-current="page"';
   228 				$current_link_attributes = ' class="current" aria-current="page"';
   222 			}
   229 			}
   223 
   230 
   224 			$name = translate_user_role( $name );
   231 			$name = translate_user_role( $name );
   225 			$name = sprintf(
   232 			if ( $count_users ) {
   226 				/* translators: 1: User role name, 2: Number of users. */
   233 				$name = sprintf(
   227 				__( '%1$s <span class="count">(%2$s)</span>' ),
   234 					/* translators: 1: User role name, 2: Number of users. */
   228 				$name,
   235 					__( '%1$s <span class="count">(%2$s)</span>' ),
   229 				number_format_i18n( $avail_roles[ $this_role ] )
   236 					$name,
   230 			);
   237 					number_format_i18n( $avail_roles[ $this_role ] )
       
   238 				);
       
   239 			}
   231 
   240 
   232 			$role_links[ $this_role ] = "<a href='" . esc_url( add_query_arg( 'role', $this_role, $url ) ) . "'$current_link_attributes>$name</a>";
   241 			$role_links[ $this_role ] = "<a href='" . esc_url( add_query_arg( 'role', $this_role, $url ) ) . "'$current_link_attributes>$name</a>";
   233 		}
   242 		}
   234 
   243 
   235 		if ( ! empty( $avail_roles['none'] ) ) {
   244 		if ( ! empty( $avail_roles['none'] ) ) {
   360 			'cb'       => '<input type="checkbox" />',
   369 			'cb'       => '<input type="checkbox" />',
   361 			'username' => __( 'Username' ),
   370 			'username' => __( 'Username' ),
   362 			'name'     => __( 'Name' ),
   371 			'name'     => __( 'Name' ),
   363 			'email'    => __( 'Email' ),
   372 			'email'    => __( 'Email' ),
   364 			'role'     => __( 'Role' ),
   373 			'role'     => __( 'Role' ),
   365 			'posts'    => __( 'Posts' ),
   374 			'posts'    => _x( 'Posts', 'post type general name' ),
   366 		);
   375 		);
   367 
   376 
   368 		if ( $this->is_site_users ) {
   377 		if ( $this->is_site_users ) {
   369 			unset( $c['posts'] );
   378 			unset( $c['posts'] );
   370 		}
   379 		}
   445 		}
   454 		}
   446 
   455 
   447 		// Check if the user for this row is editable.
   456 		// Check if the user for this row is editable.
   448 		if ( current_user_can( 'list_users' ) ) {
   457 		if ( current_user_can( 'list_users' ) ) {
   449 			// Set up the user editing link.
   458 			// Set up the user editing link.
   450 			$edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user_object->ID ) ) );
   459 			$edit_link = esc_url(
       
   460 				add_query_arg(
       
   461 					'wp_http_referer',
       
   462 					urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ),
       
   463 					get_edit_user_link( $user_object->ID )
       
   464 				)
       
   465 			);
   451 
   466 
   452 			if ( current_user_can( 'edit_user', $user_object->ID ) ) {
   467 			if ( current_user_can( 'edit_user', $user_object->ID ) ) {
   453 				$edit            = "<strong><a href=\"{$edit_link}\">{$user_object->user_login}</a>{$super_admin}</strong><br />";
   468 				$edit            = "<strong><a href=\"{$edit_link}\">{$user_object->user_login}</a>{$super_admin}</strong><br />";
   454 				$actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
   469 				$actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
   455 			} else {
   470 			} else {
   456 				$edit = "<strong>{$user_object->user_login}{$super_admin}</strong><br />";
   471 				$edit = "<strong>{$user_object->user_login}{$super_admin}</strong><br />";
   457 			}
   472 			}
   458 
   473 
   459 			if ( ! is_multisite() && get_current_user_id() != $user_object->ID && current_user_can( 'delete_user', $user_object->ID ) ) {
   474 			if ( ! is_multisite()
       
   475 				&& get_current_user_id() !== $user_object->ID
       
   476 				&& current_user_can( 'delete_user', $user_object->ID )
       
   477 			) {
   460 				$actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url( "users.php?action=delete&amp;user=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Delete' ) . '</a>';
   478 				$actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url( "users.php?action=delete&amp;user=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Delete' ) . '</a>';
   461 			}
   479 			}
   462 			if ( is_multisite() && current_user_can( 'remove_user', $user_object->ID ) ) {
   480 
       
   481 			if ( is_multisite()
       
   482 				&& current_user_can( 'remove_user', $user_object->ID )
       
   483 			) {
   463 				$actions['remove'] = "<a class='submitdelete' href='" . wp_nonce_url( $url . "action=remove&amp;user=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Remove' ) . '</a>';
   484 				$actions['remove'] = "<a class='submitdelete' href='" . wp_nonce_url( $url . "action=remove&amp;user=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Remove' ) . '</a>';
   464 			}
   485 			}
   465 
   486 
   466 			// Add a link to the user's author archive, if not empty.
   487 			// Add a link to the user's author archive, if not empty.
   467 			$author_posts_url = get_author_posts_url( $user_object->ID );
   488 			$author_posts_url = get_author_posts_url( $user_object->ID );
   474 					__( 'View' )
   495 					__( 'View' )
   475 				);
   496 				);
   476 			}
   497 			}
   477 
   498 
   478 			// Add a link to send the user a reset password link by email.
   499 			// Add a link to send the user a reset password link by email.
   479 			if ( get_current_user_id() !== $user_object->ID && current_user_can( 'edit_user', $user_object->ID ) ) {
   500 			if ( get_current_user_id() !== $user_object->ID
       
   501 				&& current_user_can( 'edit_user', $user_object->ID )
       
   502 			) {
   480 				$actions['resetpassword'] = "<a class='resetpassword' href='" . wp_nonce_url( "users.php?action=resetpassword&amp;users=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Send password reset' ) . '</a>';
   503 				$actions['resetpassword'] = "<a class='resetpassword' href='" . wp_nonce_url( "users.php?action=resetpassword&amp;users=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Send password reset' ) . '</a>';
   481 			}
   504 			}
   482 
   505 
   483 			/**
   506 			/**
   484 			 * Filters the action links displayed under each user in the Users list table.
   507 			 * Filters the action links displayed under each user in the Users list table.
   613 	protected function get_default_primary_column_name() {
   636 	protected function get_default_primary_column_name() {
   614 		return 'username';
   637 		return 'username';
   615 	}
   638 	}
   616 
   639 
   617 	/**
   640 	/**
   618 	 * Returns an array of user roles for a given user object.
   641 	 * Returns an array of translated user role names for a given user object.
   619 	 *
   642 	 *
   620 	 * @since 4.4.0
   643 	 * @since 4.4.0
   621 	 *
   644 	 *
   622 	 * @param WP_User $user_object The WP_User object.
   645 	 * @param WP_User $user_object The WP_User object.
   623 	 * @return string[] An array of user roles.
   646 	 * @return string[] An array of user role names keyed by role.
   624 	 */
   647 	 */
   625 	protected function get_role_list( $user_object ) {
   648 	protected function get_role_list( $user_object ) {
   626 		$wp_roles = wp_roles();
   649 		$wp_roles = wp_roles();
   627 
   650 
   628 		$role_list = array();
   651 		$role_list = array();
   636 		if ( empty( $role_list ) ) {
   659 		if ( empty( $role_list ) ) {
   637 			$role_list['none'] = _x( 'None', 'no user roles' );
   660 			$role_list['none'] = _x( 'None', 'no user roles' );
   638 		}
   661 		}
   639 
   662 
   640 		/**
   663 		/**
   641 		 * Filters the returned array of roles for a user.
   664 		 * Filters the returned array of translated role names for a user.
   642 		 *
   665 		 *
   643 		 * @since 4.4.0
   666 		 * @since 4.4.0
   644 		 *
   667 		 *
   645 		 * @param string[] $role_list   An array of user roles.
   668 		 * @param string[] $role_list   An array of translated user role names keyed by role.
   646 		 * @param WP_User  $user_object A WP_User object.
   669 		 * @param WP_User  $user_object A WP_User object.
   647 		 */
   670 		 */
   648 		return apply_filters( 'get_role_list', $role_list, $user_object );
   671 		return apply_filters( 'get_role_list', $role_list, $user_object );
   649 	}
   672 	}
   650 
   673