wp/wp-admin/includes/class-wp-ms-users-list-table.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
child 22 8c2e4d02f4ef
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
     9 
     9 
    10 /**
    10 /**
    11  * Core class used to implement displaying users in a list table for the network admin.
    11  * Core class used to implement displaying users in a list table for the network admin.
    12  *
    12  *
    13  * @since 3.1.0
    13  * @since 3.1.0
    14  * @access private
       
    15  *
    14  *
    16  * @see WP_List_Table
    15  * @see WP_List_Table
    17  */
    16  */
    18 class WP_MS_Users_List_Table extends WP_List_Table {
    17 class WP_MS_Users_List_Table extends WP_List_Table {
    19 	/**
    18 	/**
   135 
   134 
   136 		$total_users  = get_user_count();
   135 		$total_users  = get_user_count();
   137 		$super_admins = get_super_admins();
   136 		$super_admins = get_super_admins();
   138 		$total_admins = count( $super_admins );
   137 		$total_admins = count( $super_admins );
   139 
   138 
   140 		$current_link_attributes = 'super' !== $role ? ' class="current" aria-current="page"' : '';
   139 		$role_links        = array();
   141 		$role_links              = array();
   140 		$role_links['all'] = array(
   142 		$role_links['all']       = sprintf(
   141 			'url'     => network_admin_url( 'users.php' ),
   143 			'<a href="%s"%s>%s</a>',
   142 			'label'   => sprintf(
   144 			network_admin_url( 'users.php' ),
       
   145 			$current_link_attributes,
       
   146 			sprintf(
       
   147 				/* translators: Number of users. */
   143 				/* translators: Number of users. */
   148 				_nx(
   144 				_nx(
   149 					'All <span class="count">(%s)</span>',
   145 					'All <span class="count">(%s)</span>',
   150 					'All <span class="count">(%s)</span>',
   146 					'All <span class="count">(%s)</span>',
   151 					$total_users,
   147 					$total_users,
   152 					'users'
   148 					'users'
   153 				),
   149 				),
   154 				number_format_i18n( $total_users )
   150 				number_format_i18n( $total_users )
   155 			)
   151 			),
       
   152 			'current' => 'super' !== $role,
   156 		);
   153 		);
   157 		$current_link_attributes = 'super' === $role ? ' class="current" aria-current="page"' : '';
   154 
   158 		$role_links['super']     = sprintf(
   155 		$role_links['super'] = array(
   159 			'<a href="%s"%s>%s</a>',
   156 			'url'     => network_admin_url( 'users.php?role=super' ),
   160 			network_admin_url( 'users.php?role=super' ),
   157 			'label'   => sprintf(
   161 			$current_link_attributes,
       
   162 			sprintf(
       
   163 				/* translators: Number of users. */
   158 				/* translators: Number of users. */
   164 				_n(
   159 				_n(
   165 					'Super Admin <span class="count">(%s)</span>',
   160 					'Super Admin <span class="count">(%s)</span>',
   166 					'Super Admins <span class="count">(%s)</span>',
   161 					'Super Admins <span class="count">(%s)</span>',
   167 					$total_admins
   162 					$total_admins
   168 				),
   163 				),
   169 				number_format_i18n( $total_admins )
   164 				number_format_i18n( $total_admins )
   170 			)
   165 			),
       
   166 			'current' => 'super' === $role,
   171 		);
   167 		);
   172 
   168 
   173 		return $role_links;
   169 		return $this->get_views_links( $role_links );
   174 	}
   170 	}
   175 
   171 
   176 	/**
   172 	/**
   177 	 * @global string $mode List table view mode.
   173 	 * @global string $mode List table view mode.
   178 	 *
   174 	 *
   187 			$this->view_switcher( $mode );
   183 			$this->view_switcher( $mode );
   188 		}
   184 		}
   189 	}
   185 	}
   190 
   186 
   191 	/**
   187 	/**
   192 	 * @return array
   188 	 * @return string[] Array of column titles keyed by their column name.
   193 	 */
   189 	 */
   194 	public function get_columns() {
   190 	public function get_columns() {
   195 		$users_columns = array(
   191 		$users_columns = array(
   196 			'cb'         => '<input type="checkbox" />',
   192 			'cb'         => '<input type="checkbox" />',
   197 			'username'   => __( 'Username' ),
   193 			'username'   => __( 'Username' ),
   214 	/**
   210 	/**
   215 	 * @return array
   211 	 * @return array
   216 	 */
   212 	 */
   217 	protected function get_sortable_columns() {
   213 	protected function get_sortable_columns() {
   218 		return array(
   214 		return array(
   219 			'username'   => 'login',
   215 			'username'   => array( 'login', false, __( 'Username' ), __( 'Table ordered by Username.' ), 'asc' ),
   220 			'name'       => 'name',
   216 			'name'       => array( 'name', false, __( 'Name' ), __( 'Table ordered by Name.' ) ),
   221 			'email'      => 'email',
   217 			'email'      => array( 'email', false, __( 'E-mail' ), __( 'Table ordered by E-mail.' ) ),
   222 			'registered' => 'id',
   218 			'registered' => array( 'id', false, _x( 'Registered', 'user' ), __( 'Table ordered by User Registered Date.' ) ),
   223 		);
   219 		);
   224 	}
   220 	}
   225 
   221 
   226 	/**
   222 	/**
   227 	 * Handles the checkbox column output.
   223 	 * Handles the checkbox column output.
   237 
   233 
   238 		if ( is_super_admin( $user->ID ) ) {
   234 		if ( is_super_admin( $user->ID ) ) {
   239 			return;
   235 			return;
   240 		}
   236 		}
   241 		?>
   237 		?>
   242 		<label class="screen-reader-text" for="blog_<?php echo $user->ID; ?>">
   238 		<input type="checkbox" id="blog_<?php echo $user->ID; ?>" name="allusers[]" value="<?php echo esc_attr( $user->ID ); ?>" />
       
   239 		<label for="blog_<?php echo $user->ID; ?>">
       
   240 			<span class="screen-reader-text">
   243 			<?php
   241 			<?php
   244 			/* translators: %s: User login. */
   242 			/* translators: Hidden accessibility text. %s: User login. */
   245 			printf( __( 'Select %s' ), $user->user_login );
   243 			printf( __( 'Select %s' ), $user->user_login );
   246 			?>
   244 			?>
       
   245 			</span>
   247 		</label>
   246 		</label>
   248 		<input type="checkbox" id="blog_<?php echo $user->ID; ?>" name="allusers[]" value="<?php echo esc_attr( $user->ID ); ?>" />
       
   249 		<?php
   247 		<?php
   250 	}
   248 	}
   251 
   249 
   252 	/**
   250 	/**
   253 	 * Handles the ID column output.
   251 	 * Handles the ID column output.
   300 	 *
   298 	 *
   301 	 * @param WP_User $user The current WP_User object.
   299 	 * @param WP_User $user The current WP_User object.
   302 	 */
   300 	 */
   303 	public function column_name( $user ) {
   301 	public function column_name( $user ) {
   304 		if ( $user->first_name && $user->last_name ) {
   302 		if ( $user->first_name && $user->last_name ) {
   305 			echo "$user->first_name $user->last_name";
   303 			printf(
       
   304 				/* translators: 1: User's first name, 2: Last name. */
       
   305 				_x( '%1$s %2$s', 'Display name based on first name and last name' ),
       
   306 				$user->first_name,
       
   307 				$user->last_name
       
   308 			);
   306 		} elseif ( $user->first_name ) {
   309 		} elseif ( $user->first_name ) {
   307 			echo $user->first_name;
   310 			echo $user->first_name;
   308 		} elseif ( $user->last_name ) {
   311 		} elseif ( $user->last_name ) {
   309 			echo $user->last_name;
   312 			echo $user->last_name;
   310 		} else {
   313 		} else {
   311 			echo '<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">' . _x( 'Unknown', 'name' ) . '</span>';
   314 			echo '<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">' .
       
   315 				/* translators: Hidden accessibility text. */
       
   316 				_x( 'Unknown', 'name' ) .
       
   317 			'</span>';
   312 		}
   318 		}
   313 	}
   319 	}
   314 
   320 
   315 	/**
   321 	/**
   316 	 * Handles the email column output.
   322 	 * Handles the email column output.
   375 				continue;
   381 				continue;
   376 			}
   382 			}
   377 
   383 
   378 			$path         = ( '/' === $site->path ) ? '' : $site->path;
   384 			$path         = ( '/' === $site->path ) ? '' : $site->path;
   379 			$site_classes = array( 'site-' . $site->site_id );
   385 			$site_classes = array( 'site-' . $site->site_id );
       
   386 
   380 			/**
   387 			/**
   381 			 * Filters the span class for a site listing on the mulisite user list table.
   388 			 * Filters the span class for a site listing on the multisite user list table.
   382 			 *
   389 			 *
   383 			 * @since 5.2.0
   390 			 * @since 5.2.0
   384 			 *
   391 			 *
   385 			 * @param string[] $site_classes Array of class names used within the span tag. Default "site-#" with the site's network ID.
   392 			 * @param string[] $site_classes Array of class names used within the span tag.
       
   393 			 *                               Default "site-#" with the site's network ID.
   386 			 * @param int      $site_id      Site ID.
   394 			 * @param int      $site_id      Site ID.
   387 			 * @param int      $network_id   Network ID.
   395 			 * @param int      $network_id   Network ID.
   388 			 * @param WP_User  $user         WP_User object.
   396 			 * @param WP_User  $user         WP_User object.
   389 			 */
   397 			 */
   390 			$site_classes = apply_filters( 'ms_user_list_site_class', $site_classes, $site->userblog_id, $site->site_id, $user );
   398 			$site_classes = apply_filters( 'ms_user_list_site_class', $site_classes, $site->userblog_id, $site->site_id, $user );
       
   399 
   391 			if ( is_array( $site_classes ) && ! empty( $site_classes ) ) {
   400 			if ( is_array( $site_classes ) && ! empty( $site_classes ) ) {
   392 				$site_classes = array_map( 'sanitize_html_class', array_unique( $site_classes ) );
   401 				$site_classes = array_map( 'sanitize_html_class', array_unique( $site_classes ) );
   393 				echo '<span class="' . esc_attr( implode( ' ', $site_classes ) ) . '">';
   402 				echo '<span class="' . esc_attr( implode( ' ', $site_classes ) ) . '">';
   394 			} else {
   403 			} else {
   395 				echo '<span>';
   404 				echo '<span>';
   396 			}
   405 			}
       
   406 
   397 			echo '<a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $site->userblog_id ) ) . '">' . str_replace( '.' . get_network()->domain, '', $site->domain . $path ) . '</a>';
   407 			echo '<a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $site->userblog_id ) ) . '">' . str_replace( '.' . get_network()->domain, '', $site->domain . $path ) . '</a>';
   398 			echo ' <small class="row-actions">';
   408 			echo ' <small class="row-actions">';
       
   409 
   399 			$actions         = array();
   410 			$actions         = array();
   400 			$actions['edit'] = '<a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $site->userblog_id ) ) . '">' . __( 'Edit' ) . '</a>';
   411 			$actions['edit'] = '<a href="' . esc_url( network_admin_url( 'site-info.php?id=' . $site->userblog_id ) ) . '">' . __( 'Edit' ) . '</a>';
   401 
   412 
   402 			$class = '';
   413 			$class = '';
   403 			if ( 1 === (int) $site->spam ) {
   414 			if ( 1 === (int) $site->spam ) {
   431 			$i = 0;
   442 			$i = 0;
   432 
   443 
   433 			foreach ( $actions as $action => $link ) {
   444 			foreach ( $actions as $action => $link ) {
   434 				++$i;
   445 				++$i;
   435 
   446 
   436 				$sep = ( $i < $action_count ) ? ' | ' : '';
   447 				$separator = ( $i < $action_count ) ? ' | ' : '';
   437 
   448 
   438 				echo "<span class='$action'>$link$sep</span>";
   449 				echo "<span class='$action'>{$link}{$separator}</span>";
   439 			}
   450 			}
   440 
   451 
   441 			echo '</small></span><br/>';
   452 			echo '</small></span><br />';
   442 		}
   453 		}
   443 	}
   454 	}
   444 
   455 
   445 	/**
   456 	/**
   446 	 * Handles the default column output.
   457 	 * Handles the default column output.
   450 	 *
   461 	 *
   451 	 * @param WP_User $item        The current WP_User object.
   462 	 * @param WP_User $item        The current WP_User object.
   452 	 * @param string  $column_name The current column name.
   463 	 * @param string  $column_name The current column name.
   453 	 */
   464 	 */
   454 	public function column_default( $item, $column_name ) {
   465 	public function column_default( $item, $column_name ) {
       
   466 		// Restores the more descriptive, specific name for use within this method.
       
   467 		$user = $item;
       
   468 
   455 		/** This filter is documented in wp-admin/includes/class-wp-users-list-table.php */
   469 		/** This filter is documented in wp-admin/includes/class-wp-users-list-table.php */
   456 		echo apply_filters(
   470 		echo apply_filters( 'manage_users_custom_column', '', $column_name, $user->ID );
   457 			'manage_users_custom_column',
       
   458 			'', // Custom column output. Default empty.
       
   459 			$column_name,
       
   460 			$item->ID // User ID.
       
   461 		);
       
   462 	}
   471 	}
   463 
   472 
   464 	public function display_rows() {
   473 	public function display_rows() {
   465 		foreach ( $this->items as $user ) {
   474 		foreach ( $this->items as $user ) {
   466 			$class = '';
   475 			$class = '';
   511 		if ( $primary !== $column_name ) {
   520 		if ( $primary !== $column_name ) {
   512 			return '';
   521 			return '';
   513 		}
   522 		}
   514 
   523 
   515 		// Restores the more descriptive, specific name for use within this method.
   524 		// Restores the more descriptive, specific name for use within this method.
   516 		$user         = $item;
   525 		$user = $item;
       
   526 
   517 		$super_admins = get_super_admins();
   527 		$super_admins = get_super_admins();
   518 
   528 		$actions      = array();
   519 		$actions = array();
       
   520 
   529 
   521 		if ( current_user_can( 'edit_user', $user->ID ) ) {
   530 		if ( current_user_can( 'edit_user', $user->ID ) ) {
   522 			$edit_link       = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) );
   531 			$edit_link       = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) );
   523 			$actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
   532 			$actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
   524 		}
   533 		}