PageRenderTime 26ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/includes/class-wp-ms-users-list-table.php

https://github.com/mhoofman/wordpress-heroku
PHP | 307 lines | 206 code | 54 blank | 47 comment | 35 complexity | cddd08b3b3ed1ab3b09c1670d22347f4 MD5 | raw file
  1. <?php
  2. /**
  3. * Multisite Users List Table class.
  4. *
  5. * @package WordPress
  6. * @subpackage List_Table
  7. * @since 3.1.0
  8. * @access private
  9. */
  10. class WP_MS_Users_List_Table extends WP_List_Table {
  11. public function ajax_user_can() {
  12. return current_user_can( 'manage_network_users' );
  13. }
  14. public function prepare_items() {
  15. global $usersearch, $role, $wpdb, $mode;
  16. $usersearch = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : '';
  17. $users_per_page = $this->get_items_per_page( 'users_network_per_page' );
  18. $role = isset( $_REQUEST['role'] ) ? $_REQUEST['role'] : '';
  19. $paged = $this->get_pagenum();
  20. $args = array(
  21. 'number' => $users_per_page,
  22. 'offset' => ( $paged-1 ) * $users_per_page,
  23. 'search' => $usersearch,
  24. 'blog_id' => 0,
  25. 'fields' => 'all_with_meta'
  26. );
  27. if ( wp_is_large_network( 'users' ) )
  28. $args['search'] = ltrim( $args['search'], '*' );
  29. if ( $role == 'super' ) {
  30. $logins = implode( "', '", get_super_admins() );
  31. $args['include'] = $wpdb->get_col( "SELECT ID FROM $wpdb->users WHERE user_login IN ('$logins')" );
  32. }
  33. /*
  34. * If the network is large and a search is not being performed,
  35. * show only the latest users with no paging in order to avoid
  36. * expensive count queries.
  37. */
  38. if ( !$usersearch && wp_is_large_network( 'users' ) ) {
  39. if ( !isset($_REQUEST['orderby']) )
  40. $_GET['orderby'] = $_REQUEST['orderby'] = 'id';
  41. if ( !isset($_REQUEST['order']) )
  42. $_GET['order'] = $_REQUEST['order'] = 'DESC';
  43. $args['count_total'] = false;
  44. }
  45. if ( isset( $_REQUEST['orderby'] ) )
  46. $args['orderby'] = $_REQUEST['orderby'];
  47. if ( isset( $_REQUEST['order'] ) )
  48. $args['order'] = $_REQUEST['order'];
  49. $mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode'];
  50. // Query the user IDs for this page
  51. $wp_user_search = new WP_User_Query( $args );
  52. $this->items = $wp_user_search->get_results();
  53. $this->set_pagination_args( array(
  54. 'total_items' => $wp_user_search->get_total(),
  55. 'per_page' => $users_per_page,
  56. ) );
  57. }
  58. protected function get_bulk_actions() {
  59. $actions = array();
  60. if ( current_user_can( 'delete_users' ) )
  61. $actions['delete'] = __( 'Delete' );
  62. $actions['spam'] = _x( 'Mark as Spam', 'user' );
  63. $actions['notspam'] = _x( 'Not Spam', 'user' );
  64. return $actions;
  65. }
  66. public function no_items() {
  67. _e( 'No users found.' );
  68. }
  69. protected function get_views() {
  70. global $role;
  71. $total_users = get_user_count();
  72. $super_admins = get_super_admins();
  73. $total_admins = count( $super_admins );
  74. $class = $role != 'super' ? ' class="current"' : '';
  75. $role_links = array();
  76. $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>';
  77. $class = $role == 'super' ? ' class="current"' : '';
  78. $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>';
  79. return $role_links;
  80. }
  81. /**
  82. * @global string $mode
  83. * @param string $which
  84. */
  85. protected function pagination( $which ) {
  86. global $mode;
  87. parent::pagination ( $which );
  88. if ( 'top' == $which )
  89. $this->view_switcher( $mode );
  90. }
  91. public function get_columns() {
  92. $users_columns = array(
  93. 'cb' => '<input type="checkbox" />',
  94. 'username' => __( 'Username' ),
  95. 'name' => __( 'Name' ),
  96. 'email' => __( 'E-mail' ),
  97. 'registered' => _x( 'Registered', 'user' ),
  98. 'blogs' => __( 'Sites' )
  99. );
  100. /**
  101. * Filter the columns displayed in the Network Admin Users list table.
  102. *
  103. * @since MU
  104. *
  105. * @param array $users_columns An array of user columns. Default 'cb', 'username',
  106. * 'name', 'email', 'registered', 'blogs'.
  107. */
  108. $users_columns = apply_filters( 'wpmu_users_columns', $users_columns );
  109. return $users_columns;
  110. }
  111. protected function get_sortable_columns() {
  112. return array(
  113. 'username' => 'login',
  114. 'name' => 'name',
  115. 'email' => 'email',
  116. 'registered' => 'id',
  117. );
  118. }
  119. public function display_rows() {
  120. global $mode;
  121. $alt = '';
  122. $super_admins = get_super_admins();
  123. foreach ( $this->items as $user ) {
  124. $alt = ( 'alternate' == $alt ) ? '' : 'alternate';
  125. $status_list = array( 'spam' => 'site-spammed', 'deleted' => 'site-deleted' );
  126. foreach ( $status_list as $status => $col ) {
  127. if ( $user->$status )
  128. $alt .= " $col";
  129. }
  130. ?>
  131. <tr class="<?php echo $alt; ?>">
  132. <?php
  133. list( $columns, $hidden ) = $this->get_column_info();
  134. foreach ( $columns as $column_name => $column_display_name ) :
  135. $class = "class='$column_name column-$column_name'";
  136. $style = '';
  137. if ( in_array( $column_name, $hidden ) )
  138. $style = ' style="display:none;"';
  139. $attributes = "$class$style";
  140. switch ( $column_name ) {
  141. case 'cb': ?>
  142. <th scope="row" class="check-column">
  143. <label class="screen-reader-text" for="blog_<?php echo $user->ID; ?>"><?php echo sprintf( __( 'Select %s' ), $user->user_login ); ?></label>
  144. <input type="checkbox" id="blog_<?php echo $user->ID ?>" name="allusers[]" value="<?php echo esc_attr( $user->ID ) ?>" />
  145. </th>
  146. <?php
  147. break;
  148. case 'username':
  149. $avatar = get_avatar( $user->user_email, 32 );
  150. $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) );
  151. echo "<td $attributes>"; ?>
  152. <?php echo $avatar; ?><strong><a href="<?php echo $edit_link; ?>" class="edit"><?php echo $user->user_login; ?></a><?php
  153. if ( in_array( $user->user_login, $super_admins ) )
  154. echo ' - ' . __( 'Super Admin' );
  155. ?></strong>
  156. <br/>
  157. <?php
  158. $actions = array();
  159. $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
  160. if ( current_user_can( 'delete_user', $user->ID ) && ! in_array( $user->user_login, $super_admins ) ) {
  161. $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>';
  162. }
  163. /**
  164. * Filter the action links displayed under each user
  165. * in the Network Admin Users list table.
  166. *
  167. * @since 3.2.0
  168. *
  169. * @param array $actions An array of action links to be displayed.
  170. * Default 'Edit', 'Delete'.
  171. * @param WP_User $user WP_User object.
  172. */
  173. $actions = apply_filters( 'ms_user_row_actions', $actions, $user );
  174. echo $this->row_actions( $actions );
  175. ?>
  176. </td>
  177. <?php
  178. break;
  179. case 'name':
  180. echo "<td $attributes>$user->first_name $user->last_name</td>";
  181. break;
  182. case 'email':
  183. echo "<td $attributes><a href='mailto:$user->user_email'>$user->user_email</a></td>";
  184. break;
  185. case 'registered':
  186. if ( 'list' == $mode )
  187. $date = 'Y/m/d';
  188. else
  189. $date = 'Y/m/d \<\b\r \/\> g:i:s a';
  190. echo "<td $attributes>" . mysql2date( $date, $user->user_registered ) . "</td>";
  191. break;
  192. case 'blogs':
  193. $blogs = get_blogs_of_user( $user->ID, true );
  194. echo "<td $attributes>";
  195. if ( is_array( $blogs ) ) {
  196. foreach ( (array) $blogs as $key => $val ) {
  197. if ( !can_edit_network( $val->site_id ) )
  198. continue;
  199. $path = ( $val->path == '/' ) ? '' : $val->path;
  200. echo '<span class="site-' . $val->site_id . '" >';
  201. 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>';
  202. echo ' <small class="row-actions">';
  203. $actions = array();
  204. $actions['edit'] = '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . __( 'Edit' ) . '</a>';
  205. $class = '';
  206. if ( get_blog_status( $val->userblog_id, 'spam' ) == 1 )
  207. $class .= 'site-spammed ';
  208. if ( get_blog_status( $val->userblog_id, 'mature' ) == 1 )
  209. $class .= 'site-mature ';
  210. if ( get_blog_status( $val->userblog_id, 'deleted' ) == 1 )
  211. $class .= 'site-deleted ';
  212. if ( get_blog_status( $val->userblog_id, 'archived' ) == 1 )
  213. $class .= 'site-archived ';
  214. $actions['view'] = '<a class="' . $class . '" href="' . esc_url( get_home_url( $val->userblog_id ) ) . '">' . __( 'View' ) . '</a>';
  215. /**
  216. * Filter the action links displayed next the sites a user belongs to
  217. * in the Network Admin Users list table.
  218. *
  219. * @since 3.1.0
  220. *
  221. * @param array $actions An array of action links to be displayed.
  222. * Default 'Edit', 'View'.
  223. * @param int $userblog_id The site ID.
  224. */
  225. $actions = apply_filters( 'ms_user_list_site_actions', $actions, $val->userblog_id );
  226. $i=0;
  227. $action_count = count( $actions );
  228. foreach ( $actions as $action => $link ) {
  229. ++$i;
  230. ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
  231. echo "<span class='$action'>$link$sep</span>";
  232. }
  233. echo '</small></span><br/>';
  234. }
  235. }
  236. ?>
  237. </td>
  238. <?php
  239. break;
  240. default:
  241. echo "<td $attributes>";
  242. /** This filter is documented in wp-admin/includes/class-wp-users-list-table.php */
  243. echo apply_filters( 'manage_users_custom_column', '', $column_name, $user->ID );
  244. echo "</td>";
  245. break;
  246. }
  247. endforeach
  248. ?>
  249. </tr>
  250. <?php
  251. }
  252. }
  253. }