users.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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 __DIR__ . '/admin.php';
  11. if ( ! current_user_can( 'manage_network_users' ) ) {
  12. wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
  13. }
  14. if ( isset( $_GET['action'] ) ) {
  15. /** This action is documented in wp-admin/network/edit.php */
  16. do_action( 'wpmuadminedit' );
  17. switch ( $_GET['action'] ) {
  18. case 'deleteuser':
  19. if ( ! current_user_can( 'manage_network_users' ) ) {
  20. wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
  21. }
  22. check_admin_referer( 'deleteuser' );
  23. $id = (int) $_GET['id'];
  24. if ( $id > 1 ) {
  25. $_POST['allusers'] = array( $id ); // confirm_delete_users() can only handle arrays.
  26. // Used in the HTML title tag.
  27. $title = __( 'Users' );
  28. $parent_file = 'users.php';
  29. require_once ABSPATH . 'wp-admin/admin-header.php';
  30. echo '<div class="wrap">';
  31. confirm_delete_users( $_POST['allusers'] );
  32. echo '</div>';
  33. require_once ABSPATH . 'wp-admin/admin-footer.php';
  34. } else {
  35. wp_redirect( network_admin_url( 'users.php' ) );
  36. }
  37. exit;
  38. case 'allusers':
  39. if ( ! current_user_can( 'manage_network_users' ) ) {
  40. wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
  41. }
  42. if ( isset( $_POST['action'] ) && isset( $_POST['allusers'] ) ) {
  43. check_admin_referer( 'bulk-users-network' );
  44. $doaction = $_POST['action'];
  45. $userfunction = '';
  46. foreach ( (array) $_POST['allusers'] as $user_id ) {
  47. if ( ! empty( $user_id ) ) {
  48. switch ( $doaction ) {
  49. case 'delete':
  50. if ( ! current_user_can( 'delete_users' ) ) {
  51. wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
  52. }
  53. // Used in the HTML title tag.
  54. $title = __( 'Users' );
  55. $parent_file = 'users.php';
  56. require_once ABSPATH . 'wp-admin/admin-header.php';
  57. echo '<div class="wrap">';
  58. confirm_delete_users( $_POST['allusers'] );
  59. echo '</div>';
  60. require_once ABSPATH . 'wp-admin/admin-footer.php';
  61. exit;
  62. case 'spam':
  63. $user = get_userdata( $user_id );
  64. if ( is_super_admin( $user->ID ) ) {
  65. wp_die(
  66. sprintf(
  67. /* translators: %s: User login. */
  68. __( 'Warning! User cannot be modified. The user %s is a network administrator.' ),
  69. esc_html( $user->user_login )
  70. )
  71. );
  72. }
  73. $userfunction = 'all_spam';
  74. $blogs = get_blogs_of_user( $user_id, true );
  75. foreach ( (array) $blogs as $details ) {
  76. if ( get_network()->site_id != $details->userblog_id ) { // Main blog is not a spam!
  77. update_blog_status( $details->userblog_id, 'spam', '1' );
  78. }
  79. }
  80. $user_data = $user->to_array();
  81. $user_data['spam'] = '1';
  82. wp_update_user( $user_data );
  83. break;
  84. case 'notspam':
  85. $user = get_userdata( $user_id );
  86. $userfunction = 'all_notspam';
  87. $blogs = get_blogs_of_user( $user_id, true );
  88. foreach ( (array) $blogs as $details ) {
  89. update_blog_status( $details->userblog_id, 'spam', '0' );
  90. }
  91. $user_data = $user->to_array();
  92. $user_data['spam'] = '0';
  93. wp_update_user( $user_data );
  94. break;
  95. }
  96. }
  97. }
  98. if ( ! in_array( $doaction, array( 'delete', 'spam', 'notspam' ), true ) ) {
  99. $sendback = wp_get_referer();
  100. $user_ids = (array) $_POST['allusers'];
  101. /** This action is documented in wp-admin/network/site-themes.php */
  102. $sendback = apply_filters( 'handle_network_bulk_actions-' . get_current_screen()->id, $sendback, $doaction, $user_ids ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
  103. wp_safe_redirect( $sendback );
  104. exit;
  105. }
  106. wp_safe_redirect(
  107. add_query_arg(
  108. array(
  109. 'updated' => 'true',
  110. 'action' => $userfunction,
  111. ),
  112. wp_get_referer()
  113. )
  114. );
  115. } else {
  116. $location = network_admin_url( 'users.php' );
  117. if ( ! empty( $_REQUEST['paged'] ) ) {
  118. $location = add_query_arg( 'paged', (int) $_REQUEST['paged'], $location );
  119. }
  120. wp_redirect( $location );
  121. }
  122. exit;
  123. case 'dodelete':
  124. check_admin_referer( 'ms-users-delete' );
  125. if ( ! ( current_user_can( 'manage_network_users' ) && current_user_can( 'delete_users' ) ) ) {
  126. wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
  127. }
  128. if ( ! empty( $_POST['blog'] ) && is_array( $_POST['blog'] ) ) {
  129. foreach ( $_POST['blog'] as $id => $users ) {
  130. foreach ( $users as $blogid => $user_id ) {
  131. if ( ! current_user_can( 'delete_user', $id ) ) {
  132. continue;
  133. }
  134. if ( ! empty( $_POST['delete'] ) && 'reassign' === $_POST['delete'][ $blogid ][ $id ] ) {
  135. remove_user_from_blog( $id, $blogid, (int) $user_id );
  136. } else {
  137. remove_user_from_blog( $id, $blogid );
  138. }
  139. }
  140. }
  141. }
  142. $i = 0;
  143. if ( is_array( $_POST['user'] ) && ! empty( $_POST['user'] ) ) {
  144. foreach ( $_POST['user'] as $id ) {
  145. if ( ! current_user_can( 'delete_user', $id ) ) {
  146. continue;
  147. }
  148. wpmu_delete_user( $id );
  149. $i++;
  150. }
  151. }
  152. if ( 1 === $i ) {
  153. $deletefunction = 'delete';
  154. } else {
  155. $deletefunction = 'all_delete';
  156. }
  157. wp_redirect(
  158. add_query_arg(
  159. array(
  160. 'updated' => 'true',
  161. 'action' => $deletefunction,
  162. ),
  163. network_admin_url( 'users.php' )
  164. )
  165. );
  166. exit;
  167. }
  168. }
  169. $wp_list_table = _get_list_table( 'WP_MS_Users_List_Table' );
  170. $pagenum = $wp_list_table->get_pagenum();
  171. $wp_list_table->prepare_items();
  172. $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
  173. if ( $pagenum > $total_pages && $total_pages > 0 ) {
  174. wp_redirect( add_query_arg( 'paged', $total_pages ) );
  175. exit;
  176. }
  177. // Used in the HTML title tag.
  178. $title = __( 'Users' );
  179. $parent_file = 'users.php';
  180. add_screen_option( 'per_page' );
  181. get_current_screen()->add_help_tab(
  182. array(
  183. 'id' => 'overview',
  184. 'title' => __( 'Overview' ),
  185. 'content' =>
  186. '<p>' . __( 'This table shows all users across the network and the sites to which they are assigned.' ) . '</p>' .
  187. '<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>' .
  188. '<p>' . __( 'You can also go to the user&#8217;s profile page by clicking on the individual username.' ) . '</p>' .
  189. '<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>' .
  190. '<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>' .
  191. '<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>',
  192. )
  193. );
  194. get_current_screen()->set_help_sidebar(
  195. '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
  196. '<p>' . __( '<a href="https://codex.wordpress.org/Network_Admin_Users_Screen">Documentation on Network Users</a>' ) . '</p>' .
  197. '<p>' . __( '<a href="https://wordpress.org/support/forum/multisite/">Support Forums</a>' ) . '</p>'
  198. );
  199. get_current_screen()->set_screen_reader_content(
  200. array(
  201. 'heading_views' => __( 'Filter users list' ),
  202. 'heading_pagination' => __( 'Users list navigation' ),
  203. 'heading_list' => __( 'Users list' ),
  204. )
  205. );
  206. require_once ABSPATH . 'wp-admin/admin-header.php';
  207. if ( isset( $_REQUEST['updated'] ) && 'true' == $_REQUEST['updated'] && ! empty( $_REQUEST['action'] ) ) {
  208. ?>
  209. <div id="message" class="updated notice is-dismissible"><p>
  210. <?php
  211. switch ( $_REQUEST['action'] ) {
  212. case 'delete':
  213. _e( 'User deleted.' );
  214. break;
  215. case 'all_spam':
  216. _e( 'Users marked as spam.' );
  217. break;
  218. case 'all_notspam':
  219. _e( 'Users removed from spam.' );
  220. break;
  221. case 'all_delete':
  222. _e( 'Users deleted.' );
  223. break;
  224. case 'add':
  225. _e( 'User added.' );
  226. break;
  227. }
  228. ?>
  229. </p></div>
  230. <?php
  231. }
  232. ?>
  233. <div class="wrap">
  234. <h1 class="wp-heading-inline"><?php esc_html_e( 'Users' ); ?></h1>
  235. <?php
  236. if ( current_user_can( 'create_users' ) ) :
  237. ?>
  238. <a href="<?php echo esc_url( network_admin_url( 'user-new.php' ) ); ?>" class="page-title-action"><?php echo esc_html_x( 'Add New', 'user' ); ?></a>
  239. <?php
  240. endif;
  241. if ( strlen( $usersearch ) ) {
  242. echo '<span class="subtitle">';
  243. printf(
  244. /* translators: %s: Search query. */
  245. __( 'Search results for: %s' ),
  246. '<strong>' . esc_html( $usersearch ) . '</strong>'
  247. );
  248. echo '</span>';
  249. }
  250. ?>
  251. <hr class="wp-header-end">
  252. <?php $wp_list_table->views(); ?>
  253. <form method="get" class="search-form">
  254. <?php $wp_list_table->search_box( __( 'Search Users' ), 'all-user' ); ?>
  255. </form>
  256. <form id="form-user-list" action="users.php?action=allusers" method="post">
  257. <?php $wp_list_table->display(); ?>
  258. </form>
  259. </div>
  260. <?php require_once ABSPATH . 'wp-admin/admin-footer.php'; ?>