PageRenderTime 49ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

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

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