X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/6c8f14c09105d0afa4c1574215c59b5021040e76..53f4633144ed68c8b8fb5861f992b5489894a940:/wp-admin/includes/class-wp-ms-users-list-table.php diff --git a/wp-admin/includes/class-wp-ms-users-list-table.php b/wp-admin/includes/class-wp-ms-users-list-table.php index 6a4268f6..39dadc78 100644 --- a/wp-admin/includes/class-wp-ms-users-list-table.php +++ b/wp-admin/includes/class-wp-ms-users-list-table.php @@ -8,15 +8,25 @@ * @access private */ class WP_MS_Users_List_Table extends WP_List_Table { - - function ajax_user_can() { + /** + * + * @return bool + */ + public function ajax_user_can() { return current_user_can( 'manage_network_users' ); } - function prepare_items() { + /** + * + * @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'] ) ? $_REQUEST['s'] : ''; + $usersearch = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : ''; $users_per_page = $this->get_items_per_page( 'users_network_per_page' ); @@ -40,8 +50,11 @@ class WP_MS_Users_List_Table extends WP_List_Table { $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 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'; @@ -69,7 +82,11 @@ class WP_MS_Users_List_Table extends WP_List_Table { ) ); } - function get_bulk_actions() { + /** + * + * @return array + */ + protected function get_bulk_actions() { $actions = array(); if ( current_user_can( 'delete_users' ) ) $actions['delete'] = __( 'Delete' ); @@ -79,18 +96,25 @@ class WP_MS_Users_List_Table extends WP_List_Table { return $actions; } - function no_items() { + /** + * @access public + */ + public function no_items() { _e( 'No users found.' ); } - function get_views() { - global $wp_roles, $role; + /** + * + * @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 ); - $current_role = false; $class = $role != 'super' ? ' class="current"' : ''; $role_links = array(); $role_links['all'] = "" . sprintf( _nx( 'All (%s)', 'All (%s)', $total_users, 'users' ), number_format_i18n( $total_users ) ) . ''; @@ -100,7 +124,11 @@ class WP_MS_Users_List_Table extends WP_List_Table { return $role_links; } - function pagination( $which ) { + /** + * @global string $mode + * @param string $which + */ + protected function pagination( $which ) { global $mode; parent::pagination ( $which ); @@ -109,7 +137,11 @@ class WP_MS_Users_List_Table extends WP_List_Table { $this->view_switcher( $mode ); } - function get_columns() { + /** + * + * @return array + */ + public function get_columns() { $users_columns = array( 'cb' => '', 'username' => __( 'Username' ), @@ -118,12 +150,22 @@ class WP_MS_Users_List_Table extends WP_List_Table { 'registered' => _x( 'Registered', 'user' ), 'blogs' => __( 'Sites' ) ); - $users_columns = apply_filters( 'wpmu_users_columns', $users_columns ); - - return $users_columns; + /** + * 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 ); } - function get_sortable_columns() { + /** + * + * @return array + */ + protected function get_sortable_columns() { return array( 'username' => 'login', 'name' => 'name', @@ -132,141 +174,251 @@ class WP_MS_Users_List_Table extends WP_List_Table { ); } - function display_rows() { - global $current_site, $mode; + /** + * 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 ) { + ?> + + + 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; + + ?>user_login; ?>user_login, $super_admins ) ) { + echo ' - ' . __( 'Super Admin' ); + } + ?> + first_name $user->last_name"; + } + + /** + * Handles the email column output. + * + * @since 4.3.0 + * @access public + * + * @param WP_User $user The current WP_User object. + */ + public function column_email( $user ) { + echo "$user->user_email"; + } + + /** + * Handles the registered date column output. + * + * @since 4.3.0 + * @access public + * + * @global string $mode + * + * @param WP_User $user The current WP_User object. + */ + public function column_registered( $user ) { + global $mode; + if ( 'list' == $mode ) { + $date = __( 'Y/m/d' ); + } else { + $date = __( 'Y/m/d g:i:s a' ); + } + echo mysql2date( $date, $user->user_registered ); + } + + /** + * @since 4.3.0 + * @access protected + * + * @param WP_User $user + * @param string $classes + * @param string $data + * @param string $primary + */ + protected function _column_blogs( $user, $classes, $data, $primary ) { + echo ''; + echo $this->column_blogs( $user ); + echo $this->handle_row_actions( $user, 'blogs', $primary ); + echo ''; + } + + /** + * Handles the blogs/sites column output. + * + * @since 4.3.0 + * @access public + * + * @param WP_User $user The current WP_User object. + */ + public function column_blogs( $user ) { + $blogs = get_blogs_of_user( $user->ID, true ); + if ( ! is_array( $blogs ) ) { + return; + } + + foreach ( $blogs as $val ) { + if ( ! can_edit_network( $val->site_id ) ) { + continue; + } + + $path = ( $val->path == '/' ) ? '' : $val->path; + echo ''; + echo '' . str_replace( '.' . get_current_site()->domain, '', $val->domain . $path ) . ''; + echo ' '; + $actions = array(); + $actions['edit'] = '' . __( 'Edit' ) . ''; + + $class = ''; + if ( $val->spam == 1 ) { + $class .= 'site-spammed '; + } + if ( $val->mature == 1 ) { + $class .= 'site-mature '; + } + if ( $val->deleted == 1 ) { + $class .= 'site-deleted '; + } + if ( $val->archived == 1 ) { + $class .= 'site-archived '; + } + + $actions['view'] = '' . __( 'View' ) . ''; + + /** + * Filter the action links displayed next the sites a user belongs to + * in the Network Admin Users list table. + * + * @since 3.1.0 + * + * @param array $actions An array of action links to be displayed. + * Default 'Edit', 'View'. + * @param int $userblog_id The site ID. + */ + $actions = apply_filters( 'ms_user_list_site_actions', $actions, $val->userblog_id ); + + $i=0; + $action_count = count( $actions ); + foreach ( $actions as $action => $link ) { + ++$i; + $sep = ( $i == $action_count ) ? '' : ' | '; + echo "$link$sep"; + } + echo '
'; + } + } + + /** + * Handles the default column output. + * + * @since 4.3.0 + * @access public + * + * @param WP_User $user The current WP_User object. + * @param string $column_name The current column name. + */ + public function column_default( $user, $column_name ) { + /** This filter is documented in wp-admin/includes/class-wp-users-list-table.php */ + echo apply_filters( 'manage_users_custom_column', '', $column_name, $user->ID ); + } + + public function display_rows() { foreach ( $this->items as $user ) { - $alt = ( 'alternate' == $alt ) ? '' : 'alternate'; + $class = ''; $status_list = array( 'spam' => 'site-spammed', 'deleted' => 'site-deleted' ); foreach ( $status_list as $status => $col ) { - if ( $user->$status ) - $alt .= " $col"; + if ( $user->$status ) { + $class .= " $col"; + } } ?> - - get_column_info(); - - foreach ( $columns as $column_name => $column_display_name ) : - $class = "class='$column_name column-$column_name'"; - - $style = ''; - if ( in_array( $column_name, $hidden ) ) - $style = ' style="display:none;"'; - - $attributes = "$class$style"; - - switch ( $column_name ) { - case 'cb': ?> - - - - - user_email, 32 ); - $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( stripslashes( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) ); - - echo ""; ?> - user_login ); ?>user_login, $super_admins ) ) - echo ' - ' . __( 'Super Admin' ); - ?> -
- ' . __( 'Edit' ) . ''; - - if ( current_user_can( 'delete_user', $user->ID ) && ! in_array( $user->user_login, $super_admins ) ) { - $actions['delete'] = '' . __( 'Delete' ) . ''; - } - - $actions = apply_filters( 'ms_user_row_actions', $actions, $user ); - echo $this->row_actions( $actions ); - ?> - - $user->first_name $user->last_name"; - break; - - case 'email': - echo "$user->user_email"; - break; - - case 'registered': - if ( 'list' == $mode ) - $date = 'Y/m/d'; - else - $date = 'Y/m/d \<\b\r \/\> g:i:s a'; - - echo "" . mysql2date( $date, $user->user_registered ) . ""; - break; - - case 'blogs': - $blogs = get_blogs_of_user( $user->ID, true ); - echo ""; - if ( is_array( $blogs ) ) { - foreach ( (array) $blogs as $key => $val ) { - if ( !can_edit_network( $val->site_id ) ) - continue; - - $path = ( $val->path == '/' ) ? '' : $val->path; - echo ''; - echo '' . str_replace( '.' . $current_site->domain, '', $val->domain . $path ) . ''; - echo ' '; - $actions = array(); - $actions['edit'] = '' . __( 'Edit' ) . ''; - - $class = ''; - if ( get_blog_status( $val->userblog_id, 'spam' ) == 1 ) - $class .= 'site-spammed '; - if ( get_blog_status( $val->userblog_id, 'mature' ) == 1 ) - $class .= 'site-mature '; - if ( get_blog_status( $val->userblog_id, 'deleted' ) == 1 ) - $class .= 'site-deleted '; - if ( get_blog_status( $val->userblog_id, 'archived' ) == 1 ) - $class .= 'site-archived '; - - $actions['view'] = '' . __( 'View' ) . ''; - - $actions = apply_filters('ms_user_list_site_actions', $actions, $val->userblog_id); - - $i=0; - $action_count = count( $actions ); - foreach ( $actions as $action => $link ) { - ++$i; - ( $i == $action_count ) ? $sep = '' : $sep = ' | '; - echo "$link$sep"; - } - echo '
'; - } - } - ?> - - "; - echo apply_filters( 'manage_users_custom_column', '', $column_name, $user->ID ); - echo ""; - break; - } - endforeach - ?> + + single_row_columns( $user ); ?> ID ) ) ); + + $actions = array(); + $actions['edit'] = '' . __( 'Edit' ) . ''; + + if ( current_user_can( 'delete_user', $user->ID ) && ! in_array( $user->user_login, $super_admins ) ) { + $actions['delete'] = '' . __( 'Delete' ) . ''; + } + + /** + * Filter the action links displayed under each user in the Network Admin Users list table. + * + * @since 3.2.0 + * + * @param array $actions An array of action links to be displayed. + * Default 'Edit', 'Delete'. + * @param WP_User $user WP_User object. + */ + $actions = apply_filters( 'ms_user_row_actions', $actions, $user ); + return $this->row_actions( $actions ); + } }