users.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <?php
  2. /**
  3. * Multisite users administration panel.
  4. *
  5. * @package WordPress
  6. * @subpackage Multisite
  7. * @since 3.0.0
  8. */
  9. /** Load WordPress Administration Bootstrap */
  10. require_once( dirname( __FILE__ ) . '/admin.php' );
  11. if ( ! current_user_can( 'manage_network_users' ) )
  12. wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
  13. if ( isset( $_GET['action'] ) ) {
  14. /** This action is documented in wp-admin/network/edit.php */
  15. do_action( 'wpmuadminedit' );
  16. switch ( $_GET['action'] ) {
  17. case 'deleteuser':
  18. if ( ! current_user_can( 'manage_network_users' ) )
  19. wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
  20. check_admin_referer( 'deleteuser' );
  21. $id = intval( $_GET['id'] );
  22. if ( $id != '0' && $id != '1' ) {
  23. $_POST['allusers'] = array( $id ); // confirm_delete_users() can only handle with arrays
  24. $title = __( 'Users' );
  25. $parent_file = 'users.php';
  26. require_once( ABSPATH . 'wp-admin/admin-header.php' );
  27. echo '<div class="wrap">';
  28. confirm_delete_users( $_POST['allusers'] );
  29. echo '</div>';
  30. require_once( ABSPATH . 'wp-admin/admin-footer.php' );
  31. } else {
  32. wp_redirect( network_admin_url( 'users.php' ) );
  33. }
  34. exit();
  35. case 'allusers':
  36. if ( !current_user_can( 'manage_network_users' ) )
  37. wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
  38. if ( ( isset( $_POST['action']) || isset($_POST['action2'] ) ) && isset( $_POST['allusers'] ) ) {
  39. check_admin_referer( 'bulk-users-network' );
  40. $doaction = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2'];
  41. $userfunction = '';
  42. foreach ( (array) $_POST['allusers'] as $user_id ) {
  43. if ( !empty( $user_id ) ) {
  44. switch ( $doaction ) {
  45. case 'delete':
  46. if ( ! current_user_can( 'delete_users' ) )
  47. wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
  48. $title = __( 'Users' );
  49. $parent_file = 'users.php';
  50. require_once( ABSPATH . 'wp-admin/admin-header.php' );
  51. echo '<div class="wrap">';
  52. confirm_delete_users( $_POST['allusers'] );
  53. echo '</div>';
  54. require_once( ABSPATH . 'wp-admin/admin-footer.php' );
  55. exit();
  56. case 'spam':
  57. $user = get_userdata( $user_id );
  58. if ( is_super_admin( $user->ID ) )
  59. wp_die( sprintf( __( 'Warning! User cannot be modified. The user %s is a network administrator.' ), esc_html( $user->user_login ) ) );
  60. $userfunction = 'all_spam';
  61. $blogs = get_blogs_of_user( $user_id, true );
  62. foreach ( (array) $blogs as $details ) {
  63. if ( $details->userblog_id != get_network()->site_id ) // main blog not a spam !
  64. update_blog_status( $details->userblog_id, 'spam', '1' );
  65. }
  66. update_user_status( $user_id, 'spam', '1' );
  67. break;
  68. case 'notspam':
  69. $userfunction = 'all_notspam';
  70. $blogs = get_blogs_of_user( $user_id, true );
  71. foreach ( (array) $blogs as $details )
  72. update_blog_status( $details->userblog_id, 'spam', '0' );
  73. update_user_status( $user_id, 'spam', '0' );
  74. break;
  75. }
  76. }
  77. }
  78. if ( ! in_array( $doaction, array( 'delete', 'spam', 'notspam' ), true ) ) {
  79. $sendback = wp_get_referer();
  80. $user_ids = (array) $_POST['allusers'];
  81. /** This action is documented in wp-admin/network/site-themes.php */
  82. $sendback = apply_filters( 'handle_network_bulk_actions-' . get_current_screen()->id, $sendback, $doaction, $user_ids );
  83. wp_safe_redirect( $sendback );
  84. exit();
  85. }
  86. wp_safe_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $userfunction ), wp_get_referer() ) );
  87. } else {
  88. $location = network_admin_url( 'users.php' );
  89. if ( ! empty( $_REQUEST['paged'] ) )
  90. $location = add_query_arg( 'paged', (int) $_REQUEST['paged'], $location );
  91. wp_redirect( $location );
  92. }
  93. exit();
  94. case 'dodelete':
  95. check_admin_referer( 'ms-users-delete' );
  96. if ( ! ( current_user_can( 'manage_network_users' ) && current_user_can( 'delete_users' ) ) )
  97. wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
  98. if ( ! empty( $_POST['blog'] ) && is_array( $_POST['blog'] ) ) {
  99. foreach ( $_POST['blog'] as $id => $users ) {
  100. foreach ( $users as $blogid => $user_id ) {
  101. if ( ! current_user_can( 'delete_user', $id ) )
  102. continue;
  103. if ( ! empty( $_POST['delete'] ) && 'reassign' == $_POST['delete'][$blogid][$id] )
  104. remove_user_from_blog( $id, $blogid, $user_id );
  105. else
  106. remove_user_from_blog( $id, $blogid );
  107. }
  108. }
  109. }
  110. $i = 0;
  111. if ( is_array( $_POST['user'] ) && ! empty( $_POST['user'] ) )
  112. foreach ( $_POST['user'] as $id ) {
  113. if ( ! current_user_can( 'delete_user', $id ) )
  114. continue;
  115. wpmu_delete_user( $id );
  116. $i++;
  117. }
  118. if ( $i == 1 )
  119. $deletefunction = 'delete';
  120. else
  121. $deletefunction = 'all_delete';
  122. wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $deletefunction ), network_admin_url( 'users.php' ) ) );
  123. exit();
  124. }
  125. }
  126. $wp_list_table = _get_list_table('WP_MS_Users_List_Table');
  127. $pagenum = $wp_list_table->get_pagenum();
  128. $wp_list_table->prepare_items();
  129. $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
  130. if ( $pagenum > $total_pages && $total_pages > 0 ) {
  131. wp_redirect( add_query_arg( 'paged', $total_pages ) );
  132. exit;
  133. }
  134. $title = __( 'Users' );
  135. $parent_file = 'users.php';
  136. add_screen_option( 'per_page' );
  137. get_current_screen()->add_help_tab( array(
  138. 'id' => 'overview',
  139. 'title' => __('Overview'),
  140. 'content' =>
  141. '<p>' . __('This table shows all users across the network and the sites to which they are assigned.') . '</p>' .
  142. '<p>' . __('Hover over any user on the list to make the edit links appear. The Edit link on the left will take you to their Edit User profile page; the Edit link on the right by any site name goes to an Edit Site screen for that site.') . '</p>' .
  143. '<p>' . __('You can also go to the user&#8217;s profile page by clicking on the individual username.') . '</p>' .
  144. '<p>' . __( 'You can sort the table by clicking on any of the table headings and switch between list and excerpt views by using the icons above the users list.' ) . '</p>' .
  145. '<p>' . __('The bulk action will permanently delete selected users, or mark/unmark those selected as spam. Spam users will have posts removed and will be unable to sign up again with the same email addresses.') . '</p>' .
  146. '<p>' . __('You can make an existing user an additional super admin by going to the Edit User profile page and checking the box to grant that privilege.') . '</p>'
  147. ) );
  148. get_current_screen()->set_help_sidebar(
  149. '<p><strong>' . __('For more information:') . '</strong></p>' .
  150. '<p>' . __('<a href="https://codex.wordpress.org/Network_Admin_Users_Screen">Documentation on Network Users</a>') . '</p>' .
  151. '<p>' . __('<a href="https://wordpress.org/support/forum/multisite/">Support Forums</a>') . '</p>'
  152. );
  153. get_current_screen()->set_screen_reader_content( array(
  154. 'heading_views' => __( 'Filter users list' ),
  155. 'heading_pagination' => __( 'Users list navigation' ),
  156. 'heading_list' => __( 'Users list' ),
  157. ) );
  158. require_once( ABSPATH . 'wp-admin/admin-header.php' );
  159. if ( isset( $_REQUEST['updated'] ) && $_REQUEST['updated'] == 'true' && ! empty( $_REQUEST['action'] ) ) {
  160. ?>
  161. <div id="message" class="updated notice is-dismissible"><p>
  162. <?php
  163. switch ( $_REQUEST['action'] ) {
  164. case 'delete':
  165. _e( 'User deleted.' );
  166. break;
  167. case 'all_spam':
  168. _e( 'Users marked as spam.' );
  169. break;
  170. case 'all_notspam':
  171. _e( 'Users removed from spam.' );
  172. break;
  173. case 'all_delete':
  174. _e( 'Users deleted.' );
  175. break;
  176. case 'add':
  177. _e( 'User added.' );
  178. break;
  179. }
  180. ?>
  181. </p></div>
  182. <?php
  183. }
  184. ?>
  185. <div class="wrap">
  186. <h1><?php esc_html_e( 'Users' );
  187. if ( current_user_can( 'create_users') ) : ?>
  188. <a href="<?php echo network_admin_url('user-new.php'); ?>" class="page-title-action"><?php echo esc_html_x( 'Add New', 'user' ); ?></a><?php
  189. endif;
  190. if ( strlen( $usersearch ) ) {
  191. /* translators: %s: search keywords */
  192. printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;' ) . '</span>', esc_html( $usersearch ) );
  193. }
  194. ?>
  195. </h1>
  196. <?php $wp_list_table->views(); ?>
  197. <form method="get" class="search-form">
  198. <?php $wp_list_table->search_box( __( 'Search Users' ), 'all-user' ); ?>
  199. </form>
  200. <form id="form-user-list" action="users.php?action=allusers" method="post">
  201. <?php $wp_list_table->display(); ?>
  202. </form>
  203. </div>
  204. <?php require_once( ABSPATH . 'wp-admin/admin-footer.php' ); ?>