users.php 9.2 KB

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