/wp-admin/includes/class-wp-ms-users-list-table.php
PHP | 460 lines | 224 code | 56 blank | 180 comment | 34 complexity | 2d61f76f0b6d9582514a821aa3987662 MD5 | raw file
- <?php
- /**
- * List Table API: WP_MS_Users_List_Table class
- *
- * @package WordPress
- * @subpackage Administration
- * @since 3.1.0
- */
- /**
- * Core class used to implement displaying users in a list table for the network admin.
- *
- * @since 3.1.0
- * @access private
- *
- * @see WP_List_Table
- */
- class WP_MS_Users_List_Table extends WP_List_Table {
- /**
- *
- * @return bool
- */
- public function ajax_user_can() {
- return current_user_can( 'manage_network_users' );
- }
- /**
- *
- * @global string $usersearch
- * @global string $role
- * @global wpdb $wpdb
- * @global string $mode
- */
- public function prepare_items() {
- global $usersearch, $role, $wpdb, $mode;
- $usersearch = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : '';
- $users_per_page = $this->get_items_per_page( 'users_network_per_page' );
- $role = isset( $_REQUEST['role'] ) ? $_REQUEST['role'] : '';
- $paged = $this->get_pagenum();
- $args = array(
- 'number' => $users_per_page,
- 'offset' => ( $paged-1 ) * $users_per_page,
- 'search' => $usersearch,
- 'blog_id' => 0,
- 'fields' => 'all_with_meta'
- );
- if ( wp_is_large_network( 'users' ) ) {
- $args['search'] = ltrim( $args['search'], '*' );
- } else if ( '' !== $args['search'] ) {
- $args['search'] = trim( $args['search'], '*' );
- $args['search'] = '*' . $args['search'] . '*';
- }
- if ( $role === 'super' ) {
- $logins = implode( "', '", get_super_admins() );
- $args['include'] = $wpdb->get_col( "SELECT ID FROM $wpdb->users WHERE user_login IN ('$logins')" );
- }
- /*
- * If the network is large and a search is not being performed,
- * show only the latest users with no paging in order to avoid
- * expensive count queries.
- */
- if ( !$usersearch && wp_is_large_network( 'users' ) ) {
- if ( !isset($_REQUEST['orderby']) )
- $_GET['orderby'] = $_REQUEST['orderby'] = 'id';
- if ( !isset($_REQUEST['order']) )
- $_GET['order'] = $_REQUEST['order'] = 'DESC';
- $args['count_total'] = false;
- }
- if ( isset( $_REQUEST['orderby'] ) )
- $args['orderby'] = $_REQUEST['orderby'];
- if ( isset( $_REQUEST['order'] ) )
- $args['order'] = $_REQUEST['order'];
- if ( ! empty( $_REQUEST['mode'] ) ) {
- $mode = $_REQUEST['mode'] === 'excerpt' ? 'excerpt' : 'list';
- set_user_setting( 'network_users_list_mode', $mode );
- } else {
- $mode = get_user_setting( 'network_users_list_mode', 'list' );
- }
- /** This filter is documented in wp-admin/includes/class-wp-users-list-table.php */
- $args = apply_filters( 'users_list_table_query_args', $args );
- // Query the user IDs for this page
- $wp_user_search = new WP_User_Query( $args );
- $this->items = $wp_user_search->get_results();
- $this->set_pagination_args( array(
- 'total_items' => $wp_user_search->get_total(),
- 'per_page' => $users_per_page,
- ) );
- }
- /**
- *
- * @return array
- */
- protected function get_bulk_actions() {
- $actions = array();
- if ( current_user_can( 'delete_users' ) )
- $actions['delete'] = __( 'Delete' );
- $actions['spam'] = _x( 'Mark as Spam', 'user' );
- $actions['notspam'] = _x( 'Not Spam', 'user' );
- return $actions;
- }
- /**
- * @access public
- */
- public function no_items() {
- _e( 'No users found.' );
- }
- /**
- *
- * @global string $role
- * @return array
- */
- protected function get_views() {
- global $role;
- $total_users = get_user_count();
- $super_admins = get_super_admins();
- $total_admins = count( $super_admins );
- $class = $role != 'super' ? ' class="current"' : '';
- $role_links = array();
- $role_links['all'] = "<a href='" . network_admin_url('users.php') . "'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_users, 'users' ), number_format_i18n( $total_users ) ) . '</a>';
- $class = $role === 'super' ? ' class="current"' : '';
- $role_links['super'] = "<a href='" . network_admin_url('users.php?role=super') . "'$class>" . sprintf( _n( 'Super Admin <span class="count">(%s)</span>', 'Super Admins <span class="count">(%s)</span>', $total_admins ), number_format_i18n( $total_admins ) ) . '</a>';
- return $role_links;
- }
- /**
- * @global string $mode
- * @param string $which
- */
- protected function pagination( $which ) {
- global $mode;
- parent::pagination ( $which );
- if ( 'top' === $which ) {
- $this->view_switcher( $mode );
- }
- }
- /**
- *
- * @return array
- */
- public function get_columns() {
- $users_columns = array(
- 'cb' => '<input type="checkbox" />',
- 'username' => __( 'Username' ),
- 'name' => __( 'Name' ),
- 'email' => __( 'Email' ),
- 'registered' => _x( 'Registered', 'user' ),
- 'blogs' => __( 'Sites' )
- );
- /**
- * Filter the columns displayed in the Network Admin Users list table.
- *
- * @since MU
- *
- * @param array $users_columns An array of user columns. Default 'cb', 'username',
- * 'name', 'email', 'registered', 'blogs'.
- */
- return apply_filters( 'wpmu_users_columns', $users_columns );
- }
- /**
- *
- * @return array
- */
- protected function get_sortable_columns() {
- return array(
- 'username' => 'login',
- 'name' => 'name',
- 'email' => 'email',
- 'registered' => 'id',
- );
- }
- /**
- * Handles the checkbox column output.
- *
- * @since 4.3.0
- * @access public
- *
- * @param WP_User $user The current WP_User object.
- */
- public function column_cb( $user ) {
- if ( is_super_admin( $user->ID ) ) {
- return;
- }
- ?>
- <label class="screen-reader-text" for="blog_<?php echo $user->ID; ?>"><?php echo sprintf( __( 'Select %s' ), $user->user_login ); ?></label>
- <input type="checkbox" id="blog_<?php echo $user->ID ?>" name="allusers[]" value="<?php echo esc_attr( $user->ID ) ?>" />
- <?php
- }
- /**
- * Handles the ID column output.
- *
- * @since 4.4.0
- * @access public
- *
- * @param WP_User $user The current WP_User object.
- */
- public function column_id( $user ) {
- echo $user->ID;
- }
- /**
- * Handles the username column output.
- *
- * @since 4.3.0
- * @access public
- *
- * @param WP_User $user The current WP_User object.
- */
- public function column_username( $user ) {
- $super_admins = get_super_admins();
- $avatar = get_avatar( $user->user_email, 32 );
- $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) );
- echo $avatar;
- ?><strong><a href="<?php echo $edit_link; ?>" class="edit"><?php echo $user->user_login; ?></a><?php
- if ( in_array( $user->user_login, $super_admins ) ) {
- echo ' - ' . __( 'Super Admin' );
- }
- ?></strong>
-