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

/src/wp-admin/network/users.php

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