PageRenderTime 27ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/Thane2376/death-edge.ru
PHP | 303 lines | 206 code | 54 blank | 43 comment | 35 complexity | 1c24d7db33d815494bbb8598fd1451cc MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, LGPL-3.0, AGPL-1.0
  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. protected function pagination( $which ) {
  82. global $mode;
  83. parent::pagination ( $which );
  84. if ( 'top' == $which )
  85. $this->view_switcher( $mode );
  86. }
  87. public function get_columns() {
  88. $users_columns = array(
  89. 'cb' => '<input type="checkbox" />',
  90. 'username' => __( 'Username' ),
  91. 'name' => __( 'Name' ),
  92. 'email' => __( 'E-mail' ),
  93. 'registered' => _x( 'Registered', 'user' ),
  94. 'blogs' => __( 'Sites' )
  95. );
  96. /**
  97. * Filter the columns displayed in the Network Admin Users list table.
  98. *
  99. * @since MU
  100. *
  101. * @param array $users_columns An array of user columns. Default 'cb', 'username',
  102. * 'name', 'email', 'registered', 'blogs'.
  103. */
  104. $users_columns = apply_filters( 'wpmu_users_columns', $users_columns );
  105. return $users_columns;
  106. }
  107. protected function get_sortable_columns() {
  108. return array(
  109. 'username' => 'login',
  110. 'name' => 'name',
  111. 'email' => 'email',
  112. 'registered' => 'id',
  113. );
  114. }
  115. public function display_rows() {
  116. global $mode;
  117. $alt = '';
  118. $super_admins = get_super_admins();
  119. foreach ( $this->items as $user ) {
  120. $alt = ( 'alternate' == $alt ) ? '' : 'alternate';
  121. $status_list = array( 'spam' => 'site-spammed', 'deleted' => 'site-deleted' );
  122. foreach ( $status_list as $status => $col ) {
  123. if ( $user->$status )
  124. $alt .= " $col";
  125. }
  126. ?>
  127. <tr class="<?php echo $alt; ?>">
  128. <?php
  129. list( $columns, $hidden ) = $this->get_column_info();
  130. foreach ( $columns as $column_name => $column_display_name ) :
  131. $class = "class='$column_name column-$column_name'";
  132. $style = '';
  133. if ( in_array( $column_name, $hidden ) )
  134. $style = ' style="display:none;"';
  135. $attributes = "$class$style";
  136. switch ( $column_name ) {
  137. case 'cb': ?>
  138. <th scope="row" class="check-column">
  139. <label class="screen-reader-text" for="blog_<?php echo $user->ID; ?>"><?php echo sprintf( __( 'Select %s' ), $user->user_login ); ?></label>
  140. <input type="checkbox" id="blog_<?php echo $user->ID ?>" name="allusers[]" value="<?php echo esc_attr( $user->ID ) ?>" />
  141. </th>
  142. <?php
  143. break;
  144. case 'username':
  145. $avatar = get_avatar( $user->user_email, 32 );
  146. $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) );
  147. echo "<td $attributes>"; ?>
  148. <?php echo $avatar; ?><strong><a href="<?php echo $edit_link; ?>" class="edit"><?php echo $user->user_login; ?></a><?php
  149. if ( in_array( $user->user_login, $super_admins ) )
  150. echo ' - ' . __( 'Super Admin' );
  151. ?></strong>
  152. <br/>
  153. <?php
  154. $actions = array();
  155. $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
  156. if ( current_user_can( 'delete_user', $user->ID ) && ! in_array( $user->user_login, $super_admins ) ) {
  157. $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>';
  158. }
  159. /**
  160. * Filter the action links displayed under each user
  161. * in the Network Admin Users list table.
  162. *
  163. * @since 3.2.0
  164. *
  165. * @param array $actions An array of action links to be displayed.
  166. * Default 'Edit', 'Delete'.
  167. * @param WP_User $user WP_User object.
  168. */
  169. $actions = apply_filters( 'ms_user_row_actions', $actions, $user );
  170. echo $this->row_actions( $actions );
  171. ?>
  172. </td>
  173. <?php
  174. break;
  175. case 'name':
  176. echo "<td $attributes>$user->first_name $user->last_name</td>";
  177. break;
  178. case 'email':
  179. echo "<td $attributes><a href='mailto:$user->user_email'>$user->user_email</a></td>";
  180. break;
  181. case 'registered':
  182. if ( 'list' == $mode )
  183. $date = 'Y/m/d';
  184. else
  185. $date = 'Y/m/d \<\b\r \/\> g:i:s a';
  186. echo "<td $attributes>" . mysql2date( $date, $user->user_registered ) . "</td>";
  187. break;
  188. case 'blogs':
  189. $blogs = get_blogs_of_user( $user->ID, true );
  190. echo "<td $attributes>";
  191. if ( is_array( $blogs ) ) {
  192. foreach ( (array) $blogs as $key => $val ) {
  193. if ( !can_edit_network( $val->site_id ) )
  194. continue;
  195. $path = ( $val->path == '/' ) ? '' : $val->path;
  196. echo '<span class="site-' . $val->site_id . '" >';
  197. 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>';
  198. echo ' <small class="row-actions">';
  199. $actions = array();
  200. $actions['edit'] = '<a href="'. esc_url( network_admin_url( 'site-info.php?id=' . $val->userblog_id ) ) .'">' . __( 'Edit' ) . '</a>';
  201. $class = '';
  202. if ( get_blog_status( $val->userblog_id, 'spam' ) == 1 )
  203. $class .= 'site-spammed ';
  204. if ( get_blog_status( $val->userblog_id, 'mature' ) == 1 )
  205. $class .= 'site-mature ';
  206. if ( get_blog_status( $val->userblog_id, 'deleted' ) == 1 )
  207. $class .= 'site-deleted ';
  208. if ( get_blog_status( $val->userblog_id, 'archived' ) == 1 )
  209. $class .= 'site-archived ';
  210. $actions['view'] = '<a class="' . $class . '" href="' . esc_url( get_home_url( $val->userblog_id ) ) . '">' . __( 'View' ) . '</a>';
  211. /**
  212. * Filter the action links displayed next the sites a user belongs to
  213. * in the Network Admin Users list table.
  214. *
  215. * @since 3.1.0
  216. *
  217. * @param array $actions An array of action links to be displayed.
  218. * Default 'Edit', 'View'.
  219. * @param int $userblog_id The site ID.
  220. */
  221. $actions = apply_filters( 'ms_user_list_site_actions', $actions, $val->userblog_id );
  222. $i=0;
  223. $action_count = count( $actions );
  224. foreach ( $actions as $action => $link ) {
  225. ++$i;
  226. ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
  227. echo "<span class='$action'>$link$sep</span>";
  228. }
  229. echo '</small></span><br/>';
  230. }
  231. }
  232. ?>
  233. </td>
  234. <?php
  235. break;
  236. default:
  237. echo "<td $attributes>";
  238. /** This filter is documented in wp-admin/includes/class-wp-users-list-table.php */
  239. echo apply_filters( 'manage_users_custom_column', '', $column_name, $user->ID );
  240. echo "</td>";
  241. break;
  242. }
  243. endforeach
  244. ?>
  245. </tr>
  246. <?php
  247. }
  248. }
  249. }