wp/wp-admin/includes/class-wp-ms-users-list-table.php
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
equal deleted inserted replaced
4:346c88efed21 5:5e2f62d02dcd
     7  * @since 3.1.0
     7  * @since 3.1.0
     8  * @access private
     8  * @access private
     9  */
     9  */
    10 class WP_MS_Users_List_Table extends WP_List_Table {
    10 class WP_MS_Users_List_Table extends WP_List_Table {
    11 
    11 
    12 	function ajax_user_can() {
    12 	public function ajax_user_can() {
    13 		return current_user_can( 'manage_network_users' );
    13 		return current_user_can( 'manage_network_users' );
    14 	}
    14 	}
    15 
    15 
    16 	function prepare_items() {
    16 	public function prepare_items() {
    17 		global $usersearch, $role, $wpdb, $mode;
    17 		global $usersearch, $role, $wpdb, $mode;
    18 
    18 
    19 		$usersearch = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '';
    19 		$usersearch = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : '';
    20 
    20 
    21 		$users_per_page = $this->get_items_per_page( 'users_network_per_page' );
    21 		$users_per_page = $this->get_items_per_page( 'users_network_per_page' );
    22 
    22 
    23 		$role = isset( $_REQUEST['role'] ) ? $_REQUEST['role'] : '';
    23 		$role = isset( $_REQUEST['role'] ) ? $_REQUEST['role'] : '';
    24 
    24 
    38 		if ( $role == 'super' ) {
    38 		if ( $role == 'super' ) {
    39 			$logins = implode( "', '", get_super_admins() );
    39 			$logins = implode( "', '", get_super_admins() );
    40 			$args['include'] = $wpdb->get_col( "SELECT ID FROM $wpdb->users WHERE user_login IN ('$logins')" );
    40 			$args['include'] = $wpdb->get_col( "SELECT ID FROM $wpdb->users WHERE user_login IN ('$logins')" );
    41 		}
    41 		}
    42 
    42 
    43 		// If the network is large and a search is not being performed, show only the latest users with no paging in order
    43 		/*
    44 		// to avoid expensive count queries.
    44 		 * If the network is large and a search is not being performed,
       
    45 		 * show only the latest users with no paging in order to avoid
       
    46 		 * expensive count queries.
       
    47 		 */
    45 		if ( !$usersearch && wp_is_large_network( 'users' ) ) {
    48 		if ( !$usersearch && wp_is_large_network( 'users' ) ) {
    46 			if ( !isset($_REQUEST['orderby']) )
    49 			if ( !isset($_REQUEST['orderby']) )
    47 				$_GET['orderby'] = $_REQUEST['orderby'] = 'id';
    50 				$_GET['orderby'] = $_REQUEST['orderby'] = 'id';
    48 			if ( !isset($_REQUEST['order']) )
    51 			if ( !isset($_REQUEST['order']) )
    49 				$_GET['order'] = $_REQUEST['order'] = 'DESC';
    52 				$_GET['order'] = $_REQUEST['order'] = 'DESC';
    67 			'total_items' => $wp_user_search->get_total(),
    70 			'total_items' => $wp_user_search->get_total(),
    68 			'per_page' => $users_per_page,
    71 			'per_page' => $users_per_page,
    69 		) );
    72 		) );
    70 	}
    73 	}
    71 
    74 
    72 	function get_bulk_actions() {
    75 	protected function get_bulk_actions() {
    73 		$actions = array();
    76 		$actions = array();
    74 		if ( current_user_can( 'delete_users' ) )
    77 		if ( current_user_can( 'delete_users' ) )
    75 			$actions['delete'] = __( 'Delete' );
    78 			$actions['delete'] = __( 'Delete' );
    76 		$actions['spam'] = _x( 'Mark as Spam', 'user' );
    79 		$actions['spam'] = _x( 'Mark as Spam', 'user' );
    77 		$actions['notspam'] = _x( 'Not Spam', 'user' );
    80 		$actions['notspam'] = _x( 'Not Spam', 'user' );
    78 
    81 
    79 		return $actions;
    82 		return $actions;
    80 	}
    83 	}
    81 
    84 
    82 	function no_items() {
    85 	public function no_items() {
    83 		_e( 'No users found.' );
    86 		_e( 'No users found.' );
    84 	}
    87 	}
    85 
    88 
    86 	function get_views() {
    89 	protected function get_views() {
    87 		global $wp_roles, $role;
    90 		global $role;
    88 
    91 
    89 		$total_users = get_user_count();
    92 		$total_users = get_user_count();
    90 		$super_admins = get_super_admins();
    93 		$super_admins = get_super_admins();
    91 		$total_admins = count( $super_admins );
    94 		$total_admins = count( $super_admins );
    92 
    95 
    93 		$current_role = false;
       
    94 		$class = $role != 'super' ? ' class="current"' : '';
    96 		$class = $role != 'super' ? ' class="current"' : '';
    95 		$role_links = array();
    97 		$role_links = array();
    96 		$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>';
    98 		$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>';
    97 		$class = $role == 'super' ? ' class="current"' : '';
    99 		$class = $role == 'super' ? ' class="current"' : '';
    98 		$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>';
   100 		$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>';
    99 
   101 
   100 		return $role_links;
   102 		return $role_links;
   101 	}
   103 	}
   102 
   104 
   103 	function pagination( $which ) {
   105 	/**
       
   106 	 * @global string $mode
       
   107 	 * @param string $which
       
   108 	 */
       
   109 	protected function pagination( $which ) {
   104 		global $mode;
   110 		global $mode;
   105 
   111 
   106 		parent::pagination ( $which );
   112 		parent::pagination ( $which );
   107 
   113 
   108 		if ( 'top' == $which )
   114 		if ( 'top' == $which )
   109 			$this->view_switcher( $mode );
   115 			$this->view_switcher( $mode );
   110 	}
   116 	}
   111 
   117 
   112 	function get_columns() {
   118 	public function get_columns() {
   113 		$users_columns = array(
   119 		$users_columns = array(
   114 			'cb'         => '<input type="checkbox" />',
   120 			'cb'         => '<input type="checkbox" />',
   115 			'username'   => __( 'Username' ),
   121 			'username'   => __( 'Username' ),
   116 			'name'       => __( 'Name' ),
   122 			'name'       => __( 'Name' ),
   117 			'email'      => __( 'E-mail' ),
   123 			'email'      => __( 'E-mail' ),
   118 			'registered' => _x( 'Registered', 'user' ),
   124 			'registered' => _x( 'Registered', 'user' ),
   119 			'blogs'      => __( 'Sites' )
   125 			'blogs'      => __( 'Sites' )
   120 		);
   126 		);
       
   127 		/**
       
   128 		 * Filter the columns displayed in the Network Admin Users list table.
       
   129 		 *
       
   130 		 * @since MU
       
   131 		 *
       
   132 		 * @param array $users_columns An array of user columns. Default 'cb', 'username',
       
   133 		 *                             'name', 'email', 'registered', 'blogs'.
       
   134 		 */
   121 		$users_columns = apply_filters( 'wpmu_users_columns', $users_columns );
   135 		$users_columns = apply_filters( 'wpmu_users_columns', $users_columns );
   122 
   136 
   123 		return $users_columns;
   137 		return $users_columns;
   124 	}
   138 	}
   125 
   139 
   126 	function get_sortable_columns() {
   140 	protected function get_sortable_columns() {
   127 		return array(
   141 		return array(
   128 			'username'   => 'login',
   142 			'username'   => 'login',
   129 			'name'       => 'name',
   143 			'name'       => 'name',
   130 			'email'      => 'email',
   144 			'email'      => 'email',
   131 			'registered' => 'id',
   145 			'registered' => 'id',
   132 		);
   146 		);
   133 	}
   147 	}
   134 
   148 
   135 	function display_rows() {
   149 	public function display_rows() {
   136 		global $current_site, $mode;
   150 		global $mode;
   137 
   151 
   138 		$alt = '';
       
   139 		$super_admins = get_super_admins();
   152 		$super_admins = get_super_admins();
   140 		foreach ( $this->items as $user ) {
   153 		foreach ( $this->items as $user ) {
   141 			$alt = ( 'alternate' == $alt ) ? '' : 'alternate';
   154 			$class = '';
   142 
   155 
   143 			$status_list = array( 'spam' => 'site-spammed', 'deleted' => 'site-deleted' );
   156 			$status_list = array( 'spam' => 'site-spammed', 'deleted' => 'site-deleted' );
   144 
   157 
   145 			foreach ( $status_list as $status => $col ) {
   158 			foreach ( $status_list as $status => $col ) {
   146 				if ( $user->$status )
   159 				if ( $user->$status )
   147 					$alt .= " $col";
   160 					$class .= " $col";
   148 			}
   161 			}
   149 
   162 
   150 			?>
   163 			?>
   151 			<tr class="<?php echo $alt; ?>">
   164 			<tr class="<?php echo trim( $class ); ?>">
   152 			<?php
   165 			<?php
   153 
   166 
   154 			list( $columns, $hidden ) = $this->get_column_info();
   167 			list( $columns, $hidden ) = $this->get_column_info();
   155 
   168 
   156 			foreach ( $columns as $column_name => $column_display_name ) :
   169 			foreach ( $columns as $column_name => $column_display_name ) :
   187 
   200 
   188 								if ( current_user_can( 'delete_user', $user->ID ) && ! in_array( $user->user_login, $super_admins ) ) {
   201 								if ( current_user_can( 'delete_user', $user->ID ) && ! in_array( $user->user_login, $super_admins ) ) {
   189 									$actions['delete'] = '<a href="' . $delete = esc_url( network_admin_url( add_query_arg( '_wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), wp_nonce_url( 'users.php', 'deleteuser' ) . '&amp;action=deleteuser&amp;id=' . $user->ID ) ) ) . '" class="delete">' . __( 'Delete' ) . '</a>';
   202 									$actions['delete'] = '<a href="' . $delete = esc_url( network_admin_url( add_query_arg( '_wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), wp_nonce_url( 'users.php', 'deleteuser' ) . '&amp;action=deleteuser&amp;id=' . $user->ID ) ) ) . '" class="delete">' . __( 'Delete' ) . '</a>';
   190 								}
   203 								}
   191 
   204 
       
   205 								/**
       
   206 								 * Filter the action links displayed under each user
       
   207 								 * in the Network Admin Users list table.
       
   208 								 *
       
   209 								 * @since 3.2.0
       
   210 								 *
       
   211 								 * @param array   $actions An array of action links to be displayed.
       
   212 								 *                         Default 'Edit', 'Delete'.
       
   213 								 * @param WP_User $user    WP_User object.
       
   214 								 */
   192 								$actions = apply_filters( 'ms_user_row_actions', $actions, $user );
   215 								$actions = apply_filters( 'ms_user_row_actions', $actions, $user );
   193 								echo $this->row_actions( $actions );
   216 								echo $this->row_actions( $actions );
   194 							?>
   217 							?>
   195 						</td>
   218 						</td>
   196 					<?php
   219 					<?php
   204 						echo "<td $attributes><a href='mailto:$user->user_email'>$user->user_email</a></td>";
   227 						echo "<td $attributes><a href='mailto:$user->user_email'>$user->user_email</a></td>";
   205 					break;
   228 					break;
   206 
   229 
   207 					case 'registered':
   230 					case 'registered':
   208 						if ( 'list' == $mode )
   231 						if ( 'list' == $mode )
   209 							$date = 'Y/m/d';
   232 							$date = __( 'Y/m/d' );
   210 						else
   233 						else
   211 							$date = 'Y/m/d \<\b\r \/\> g:i:s a';
   234 							$date = __( 'Y/m/d g:i:s a' );
   212 
   235 
   213 						echo "<td $attributes>" . mysql2date( $date, $user->user_registered ) . "</td>";
   236 						echo "<td $attributes>" . mysql2date( $date, $user->user_registered ) . "</td>";
   214 					break;
   237 					break;
   215 
   238 
   216 					case 'blogs':
   239 					case 'blogs':
   221 									if ( !can_edit_network( $val->site_id ) )
   244 									if ( !can_edit_network( $val->site_id ) )
   222 										continue;
   245 										continue;
   223 
   246 
   224 									$path	= ( $val->path == '/' ) ? '' : $val->path;
   247 									$path	= ( $val->path == '/' ) ? '' : $val->path;
   225 									echo '<span class="site-' . $val->site_id . '" >';
   248 									echo '<span class="site-' . $val->site_id . '" >';
   226 									echo '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . str_replace( '.' . $current_site->domain, '', $val->domain . $path ) . '</a>';
   249 									echo '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . str_replace( '.' . get_current_site()->domain, '', $val->domain . $path ) . '</a>';
   227 									echo ' <small class="row-actions">';
   250 									echo ' <small class="row-actions">';
   228 									$actions = array();
   251 									$actions = array();
   229 									$actions['edit'] = '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . __( 'Edit' ) . '</a>';
   252 									$actions['edit'] = '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . __( 'Edit' ) . '</a>';
   230 
   253 
   231 									$class = '';
   254 									$class = '';
   238 									if ( get_blog_status( $val->userblog_id, 'archived' ) == 1 )
   261 									if ( get_blog_status( $val->userblog_id, 'archived' ) == 1 )
   239 										$class .= 'site-archived ';
   262 										$class .= 'site-archived ';
   240 
   263 
   241 									$actions['view'] = '<a class="' . $class . '" href="' . esc_url( get_home_url( $val->userblog_id ) ) . '">' . __( 'View' ) . '</a>';
   264 									$actions['view'] = '<a class="' . $class . '" href="' . esc_url( get_home_url( $val->userblog_id ) ) . '">' . __( 'View' ) . '</a>';
   242 
   265 
   243 									$actions = apply_filters('ms_user_list_site_actions', $actions, $val->userblog_id);
   266 									/**
       
   267 									 * Filter the action links displayed next the sites a user belongs to
       
   268 									 * in the Network Admin Users list table.
       
   269 									 *
       
   270 									 * @since 3.1.0
       
   271 									 *
       
   272 									 * @param array $actions     An array of action links to be displayed.
       
   273 									 *                           Default 'Edit', 'View'.
       
   274 									 * @param int   $userblog_id The site ID.
       
   275 									 */
       
   276 									$actions = apply_filters( 'ms_user_list_site_actions', $actions, $val->userblog_id );
   244 
   277 
   245 									$i=0;
   278 									$i=0;
   246 									$action_count = count( $actions );
   279 									$action_count = count( $actions );
   247 									foreach ( $actions as $action => $link ) {
   280 									foreach ( $actions as $action => $link ) {
   248 										++$i;
   281 										++$i;
   257 					<?php
   290 					<?php
   258 					break;
   291 					break;
   259 
   292 
   260 					default:
   293 					default:
   261 						echo "<td $attributes>";
   294 						echo "<td $attributes>";
       
   295 						/** This filter is documented in wp-admin/includes/class-wp-users-list-table.php */
   262 						echo apply_filters( 'manage_users_custom_column', '', $column_name, $user->ID );
   296 						echo apply_filters( 'manage_users_custom_column', '', $column_name, $user->ID );
   263 						echo "</td>";
   297 						echo "</td>";
   264 					break;
   298 					break;
   265 				}
   299 				}
   266 			endforeach
   300 			endforeach