WP_MS_Users_List_Table

Core class used to implement displaying users in a list table for the network admin.

Defined (1)

The class is defined in the following location(s).

/wp-admin/includes/class-wp-ms-users-list-table.php  
  1. class WP_MS_Users_List_Table extends WP_List_Table { 
  2. /** 
  3. * @return bool 
  4. */ 
  5. public function ajax_user_can() { 
  6. return current_user_can( 'manage_network_users' ); 
  7.  
  8. /** 
  9. * @global string $usersearch 
  10. * @global string $role 
  11. * @global wpdb $wpdb 
  12. * @global string $mode 
  13. */ 
  14. public function prepare_items() { 
  15. global $usersearch, $role, $wpdb, $mode; 
  16.  
  17. $usersearch = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : ''; 
  18.  
  19. $users_per_page = $this->get_items_per_page( 'users_network_per_page' ); 
  20.  
  21. $role = isset( $_REQUEST['role'] ) ? $_REQUEST['role'] : ''; 
  22.  
  23. $paged = $this->get_pagenum(); 
  24.  
  25. $args = array( 
  26. 'number' => $users_per_page,  
  27. 'offset' => ( $paged-1 ) * $users_per_page,  
  28. 'search' => $usersearch,  
  29. 'blog_id' => 0,  
  30. 'fields' => 'all_with_meta' 
  31. ); 
  32.  
  33. if ( wp_is_large_network( 'users' ) ) { 
  34. $args['search'] = ltrim( $args['search'], '*' ); 
  35. } else if ( '' !== $args['search'] ) { 
  36. $args['search'] = trim( $args['search'], '*' ); 
  37. $args['search'] = '*' . $args['search'] . '*'; 
  38.  
  39. if ( $role === 'super' ) { 
  40. $logins = implode( "', '", get_super_admins() ); 
  41. $args['include'] = $wpdb->get_col( "SELECT ID FROM $wpdb->users WHERE user_login IN ('$logins')" ); 
  42.  
  43. /** 
  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. */ 
  48. if ( !$usersearch && wp_is_large_network( 'users' ) ) { 
  49. if ( !isset($_REQUEST['orderby']) ) 
  50. $_GET['orderby'] = $_REQUEST['orderby'] = 'id'; 
  51. if ( !isset($_REQUEST['order']) ) 
  52. $_GET['order'] = $_REQUEST['order'] = 'DESC'; 
  53. $args['count_total'] = false; 
  54.  
  55. if ( isset( $_REQUEST['orderby'] ) ) 
  56. $args['orderby'] = $_REQUEST['orderby']; 
  57.  
  58. if ( isset( $_REQUEST['order'] ) ) 
  59. $args['order'] = $_REQUEST['order']; 
  60.  
  61. if ( ! empty( $_REQUEST['mode'] ) ) { 
  62. $mode = $_REQUEST['mode'] === 'excerpt' ? 'excerpt' : 'list'; 
  63. set_user_setting( 'network_users_list_mode', $mode ); 
  64. } else { 
  65. $mode = get_user_setting( 'network_users_list_mode', 'list' ); 
  66.  
  67. /** This filter is documented in wp-admin/includes/class-wp-users-list-table.php */ 
  68. $args = apply_filters( 'users_list_table_query_args', $args ); 
  69.  
  70. // Query the user IDs for this page 
  71. $wp_user_search = new WP_User_Query( $args ); 
  72.  
  73. $this->items = $wp_user_search->get_results(); 
  74.  
  75. $this->set_pagination_args( array( 
  76. 'total_items' => $wp_user_search->get_total(),  
  77. 'per_page' => $users_per_page,  
  78. ) ); 
  79.  
  80. /** 
  81. * @return array 
  82. */ 
  83. protected function get_bulk_actions() { 
  84. $actions = array(); 
  85. if ( current_user_can( 'delete_users' ) ) 
  86. $actions['delete'] = __( 'Delete' ); 
  87. $actions['spam'] = _x( 'Mark as Spam', 'user' ); 
  88. $actions['notspam'] = _x( 'Not Spam', 'user' ); 
  89.  
  90. return $actions; 
  91.  
  92. /** 
  93. * @access public 
  94. */ 
  95. public function no_items() { 
  96. _e( 'No users found.' ); 
  97.  
  98. /** 
  99. * @global string $role 
  100. * @return array 
  101. */ 
  102. protected function get_views() { 
  103. global $role; 
  104.  
  105. $total_users = get_user_count(); 
  106. $super_admins = get_super_admins(); 
  107. $total_admins = count( $super_admins ); 
  108.  
  109. $class = $role != 'super' ? ' class="current"' : ''; 
  110. $role_links = array(); 
  111. $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>'; 
  112. $class = $role === 'super' ? ' class="current"' : ''; 
  113. $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>'; 
  114.  
  115. return $role_links; 
  116.  
  117. /** 
  118. * @global string $mode 
  119. * @param string $which 
  120. */ 
  121. protected function pagination( $which ) { 
  122. global $mode; 
  123.  
  124. parent::pagination ( $which ); 
  125.  
  126. if ( 'top' === $which ) { 
  127. $this->view_switcher( $mode ); 
  128.  
  129. /** 
  130. * @return array 
  131. */ 
  132. public function get_columns() { 
  133. $users_columns = array( 
  134. 'cb' => '<input type="checkbox" />',  
  135. 'username' => __( 'Username' ),  
  136. 'name' => __( 'Name' ),  
  137. 'email' => __( 'Email' ),  
  138. 'registered' => _x( 'Registered', 'user' ),  
  139. 'blogs' => __( 'Sites' ) 
  140. ); 
  141. /** 
  142. * Filters the columns displayed in the Network Admin Users list table. 
  143. * @since MU 
  144. * @param array $users_columns An array of user columns. Default 'cb', 'username',  
  145. * 'name', 'email', 'registered', 'blogs'. 
  146. */ 
  147. return apply_filters( 'wpmu_users_columns', $users_columns ); 
  148.  
  149. /** 
  150. * @return array 
  151. */ 
  152. protected function get_sortable_columns() { 
  153. return array( 
  154. 'username' => 'login',  
  155. 'name' => 'name',  
  156. 'email' => 'email',  
  157. 'registered' => 'id',  
  158. ); 
  159.  
  160. /** 
  161. * Handles the checkbox column output. 
  162. * @since 4.3.0 
  163. * @access public 
  164. * @param WP_User $user The current WP_User object. 
  165. */ 
  166. public function column_cb( $user ) { 
  167. if ( is_super_admin( $user->ID ) ) { 
  168. return; 
  169. ?> 
  170. <label class="screen-reader-text" for="blog_<?php echo $user->ID; ?>"><?php echo sprintf( __( 'Select %s' ), $user->user_login ); ?></label> 
  171. <input type="checkbox" id="blog_<?php echo $user->ID ?>" name="allusers[]" value="<?php echo esc_attr( $user->ID ) ?>" /> 
  172. <?php 
  173.  
  174. /** 
  175. * Handles the ID column output. 
  176. * @since 4.4.0 
  177. * @access public 
  178. * @param WP_User $user The current WP_User object. 
  179. */ 
  180. public function column_id( $user ) { 
  181. echo $user->ID; 
  182.  
  183. /** 
  184. * Handles the username column output. 
  185. * @since 4.3.0 
  186. * @access public 
  187. * @param WP_User $user The current WP_User object. 
  188. */ 
  189. public function column_username( $user ) { 
  190. $super_admins = get_super_admins(); 
  191. $avatar = get_avatar( $user->user_email, 32 ); 
  192. $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) ); 
  193.  
  194. echo $avatar; 
  195.  
  196. ?><strong><a href="<?php echo $edit_link; ?>" class="edit"><?php echo $user->user_login; ?></a><?php 
  197. if ( in_array( $user->user_login, $super_admins ) ) { 
  198. echo ' - ' . __( 'Super Admin' ); 
  199. ?></strong> 
  200. <?php 
  201.  
  202. /** 
  203. * Handles the name column output. 
  204. * @since 4.3.0 
  205. * @access public 
  206. * @param WP_User $user The current WP_User object. 
  207. */ 
  208. public function column_name( $user ) { 
  209. echo "$user->first_name $user->last_name"; 
  210.  
  211. /** 
  212. * Handles the email column output. 
  213. * @since 4.3.0 
  214. * @access public 
  215. * @param WP_User $user The current WP_User object. 
  216. */ 
  217. public function column_email( $user ) { 
  218. echo "<a href='" . esc_url( "mailto:$user->user_email" ) . "'>$user->user_email</a>"; 
  219.  
  220. /** 
  221. * Handles the registered date column output. 
  222. * @since 4.3.0 
  223. * @access public 
  224. * @global string $mode 
  225. * @param WP_User $user The current WP_User object. 
  226. */ 
  227. public function column_registered( $user ) { 
  228. global $mode; 
  229. if ( 'list' === $mode ) { 
  230. $date = __( 'Y/m/d' ); 
  231. } else { 
  232. $date = __( 'Y/m/d g:i:s a' ); 
  233. echo mysql2date( $date, $user->user_registered ); 
  234.  
  235. /** 
  236. * @since 4.3.0 
  237. * @access protected 
  238. * @param WP_User $user 
  239. * @param string $classes 
  240. * @param string $data 
  241. * @param string $primary 
  242. */ 
  243. protected function _column_blogs( $user, $classes, $data, $primary ) { 
  244. echo '<td class="', $classes, ' has-row-actions" ', $data, '>'; 
  245. echo $this->column_blogs( $user ); 
  246. echo $this->handle_row_actions( $user, 'blogs', $primary ); 
  247. echo '</td>'; 
  248.  
  249. /** 
  250. * Handles the sites column output. 
  251. * @since 4.3.0 
  252. * @access public 
  253. * @param WP_User $user The current WP_User object. 
  254. */ 
  255. public function column_blogs( $user ) { 
  256. $blogs = get_blogs_of_user( $user->ID, true ); 
  257. if ( ! is_array( $blogs ) ) { 
  258. return; 
  259.  
  260. foreach ( $blogs as $val ) { 
  261. if ( ! can_edit_network( $val->site_id ) ) { 
  262. continue; 
  263.  
  264. $path = ( $val->path === '/' ) ? '' : $val->path; 
  265. echo '<span class="site-' . $val->site_id . '" >'; 
  266. echo '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . str_replace( '.' . get_network()->domain, '', $val->domain . $path ) . '</a>'; 
  267. echo ' <small class="row-actions">'; 
  268. $actions = array(); 
  269. $actions['edit'] = '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . __( 'Edit' ) . '</a>'; 
  270.  
  271. $class = ''; 
  272. if ( $val->spam == 1 ) { 
  273. $class .= 'site-spammed '; 
  274. if ( $val->mature == 1 ) { 
  275. $class .= 'site-mature '; 
  276. if ( $val->deleted == 1 ) { 
  277. $class .= 'site-deleted '; 
  278. if ( $val->archived == 1 ) { 
  279. $class .= 'site-archived '; 
  280.  
  281. $actions['view'] = '<a class="' . $class . '" href="' . esc_url( get_home_url( $val->userblog_id ) ) . '">' . __( 'View' ) . '</a>'; 
  282.  
  283. /** 
  284. * Filters the action links displayed next the sites a user belongs to 
  285. * in the Network Admin Users list table. 
  286. * @since 3.1.0 
  287. * @param array $actions An array of action links to be displayed. 
  288. * Default 'Edit', 'View'. 
  289. * @param int $userblog_id The site ID. 
  290. */ 
  291. $actions = apply_filters( 'ms_user_list_site_actions', $actions, $val->userblog_id ); 
  292.  
  293. $i=0; 
  294. $action_count = count( $actions ); 
  295. foreach ( $actions as $action => $link ) { 
  296. ++$i; 
  297. $sep = ( $i == $action_count ) ? '' : ' | '; 
  298. echo "<span class='$action'>$link$sep</span>"; 
  299. echo '</small></span><br/>'; 
  300.  
  301. /** 
  302. * Handles the default column output. 
  303. * @since 4.3.0 
  304. * @access public 
  305. * @param WP_User $user The current WP_User object. 
  306. * @param string $column_name The current column name. 
  307. */ 
  308. public function column_default( $user, $column_name ) { 
  309. /** This filter is documented in wp-admin/includes/class-wp-users-list-table.php */ 
  310. echo apply_filters( 'manage_users_custom_column', '', $column_name, $user->ID ); 
  311.  
  312. public function display_rows() { 
  313. foreach ( $this->items as $user ) { 
  314. $class = ''; 
  315.  
  316. $status_list = array( 'spam' => 'site-spammed', 'deleted' => 'site-deleted' ); 
  317.  
  318. foreach ( $status_list as $status => $col ) { 
  319. if ( $user->$status ) { 
  320. $class .= " $col"; 
  321.  
  322. ?> 
  323. <tr class="<?php echo trim( $class ); ?>"> 
  324. <?php $this->single_row_columns( $user ); ?> 
  325. </tr> 
  326. <?php 
  327.  
  328. /** 
  329. * Gets the name of the default primary column. 
  330. * @since 4.3.0 
  331. * @access protected 
  332. * @return string Name of the default primary column, in this case, 'username'. 
  333. */ 
  334. protected function get_default_primary_column_name() { 
  335. return 'username'; 
  336.  
  337. /** 
  338. * Generates and displays row action links. 
  339. * @since 4.3.0 
  340. * @access protected 
  341. * @param object $user User being acted upon. 
  342. * @param string $column_name Current column name. 
  343. * @param string $primary Primary column name. 
  344. * @return string Row actions output for users in Multisite. 
  345. */ 
  346. protected function handle_row_actions( $user, $column_name, $primary ) { 
  347. if ( $primary !== $column_name ) { 
  348. return ''; 
  349.  
  350. $super_admins = get_super_admins(); 
  351. $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) ); 
  352.  
  353. $actions = array(); 
  354. $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>'; 
  355.  
  356. if ( current_user_can( 'delete_user', $user->ID ) && ! in_array( $user->user_login, $super_admins ) ) { 
  357. $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' ) . '&action=deleteuser&id=' . $user->ID ) ) ) . '" class="delete">' . __( 'Delete' ) . '</a>'; 
  358.  
  359. /** 
  360. * Filters the action links displayed under each user in the Network Admin Users list table. 
  361. * @since 3.2.0 
  362. * @param array $actions An array of action links to be displayed. 
  363. * Default 'Edit', 'Delete'. 
  364. * @param WP_User $user WP_User object. 
  365. */ 
  366. $actions = apply_filters( 'ms_user_row_actions', $actions, $user ); 
  367. return $this->row_actions( $actions );