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

/wp-admin/network/users.php

https://bitbucket.org/julianelve/vendor-wordpress
PHP | 299 lines | 249 code | 42 blank | 8 comment | 58 complexity | 63260769abba905d1d245a528982f047 MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-2.1, GPL-2.0
  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( './admin.php' );
  11. if ( ! is_multisite() )
  12. wp_die( __( 'Multisite support is not enabled.' ) );
  13. if ( ! current_user_can( 'manage_network_users' ) )
  14. wp_die( __( 'You do not have permission to access this page.' ) );
  15. function confirm_delete_users( $users ) {
  16. $current_user = wp_get_current_user();
  17. if ( !is_array( $users ) )
  18. return false;
  19. screen_icon();
  20. ?>
  21. <h2><?php esc_html_e( 'Users' ); ?></h2>
  22. <p><?php _e( 'Transfer or delete posts before deleting users.' ); ?></p>
  23. <form action="users.php?action=dodelete" method="post">
  24. <input type="hidden" name="dodelete" />
  25. <?php
  26. wp_nonce_field( 'ms-users-delete' );
  27. $site_admins = get_super_admins();
  28. $admin_out = "<option value='$current_user->ID'>$current_user->user_login</option>";
  29. foreach ( ( $allusers = (array) $_POST['allusers'] ) as $key => $val ) {
  30. if ( $val != '' && $val != '0' ) {
  31. $delete_user = get_userdata( $val );
  32. if ( ! current_user_can( 'delete_user', $delete_user->ID ) )
  33. wp_die( sprintf( __( 'Warning! User %s cannot be deleted.' ), $delete_user->user_login ) );
  34. if ( in_array( $delete_user->user_login, $site_admins ) )
  35. wp_die( sprintf( __( 'Warning! User cannot be deleted. The user %s is a network administrator.' ), $delete_user->user_login ) );
  36. echo "<input type='hidden' name='user[]' value='{$val}'/>\n";
  37. $blogs = get_blogs_of_user( $val, true );
  38. if ( !empty( $blogs ) ) {
  39. ?>
  40. <br /><fieldset><p><legend><?php printf( __( "What should be done with posts owned by <em>%s</em>?" ), $delete_user->user_login ); ?></legend></p>
  41. <?php
  42. foreach ( (array) $blogs as $key => $details ) {
  43. $blog_users = get_users( array( 'blog_id' => $details->userblog_id ) );
  44. if ( is_array( $blog_users ) && !empty( $blog_users ) ) {
  45. $user_site = "<a href='" . esc_url( get_home_url( $details->userblog_id ) ) . "'>{$details->blogname}</a>";
  46. $user_dropdown = "<select name='blog[$val][{$key}]'>";
  47. $user_list = '';
  48. foreach ( $blog_users as $user ) {
  49. if ( ! in_array( $user->ID, $allusers ) )
  50. $user_list .= "<option value='{$user->ID}'>{$user->user_login}</option>";
  51. }
  52. if ( '' == $user_list )
  53. $user_list = $admin_out;
  54. $user_dropdown .= $user_list;
  55. $user_dropdown .= "</select>\n";
  56. ?>
  57. <ul style="list-style:none;">
  58. <li><?php printf( __( 'Site: %s' ), $user_site ); ?></li>
  59. <li><label><input type="radio" id="delete_option0" name="delete[<?php echo $details->userblog_id . '][' . $delete_user->ID ?>]" value="delete" checked="checked" />
  60. <?php _e( 'Delete all posts.' ); ?></label></li>
  61. <li><label><input type="radio" id="delete_option1" name="delete[<?php echo $details->userblog_id . '][' . $delete_user->ID ?>]" value="reassign" />
  62. <?php echo __( 'Attribute all posts to:' ) . '</label>' . $user_dropdown; ?></li>
  63. </ul>
  64. <?php
  65. }
  66. }
  67. echo "</fieldset>";
  68. }
  69. }
  70. }
  71. submit_button( __('Confirm Deletion'), 'delete' );
  72. ?>
  73. </form>
  74. <?php
  75. return true;
  76. }
  77. if ( isset( $_GET['action'] ) ) {
  78. do_action( 'wpmuadminedit' , '' );
  79. switch ( $_GET['action'] ) {
  80. case 'deleteuser':
  81. if ( ! current_user_can( 'manage_network_users' ) )
  82. wp_die( __( 'You do not have permission to access this page.' ) );
  83. check_admin_referer( 'deleteuser' );
  84. $id = intval( $_GET['id'] );
  85. if ( $id != '0' && $id != '1' ) {
  86. $_POST['allusers'] = array( $id ); // confirm_delete_users() can only handle with arrays
  87. $title = __( 'Users' );
  88. $parent_file = 'users.php';
  89. require_once( '../admin-header.php' );
  90. echo '<div class="wrap">';
  91. confirm_delete_users( $_POST['allusers'] );
  92. echo '</div>';
  93. require_once( '../admin-footer.php' );
  94. } else {
  95. wp_redirect( network_admin_url( 'users.php' ) );
  96. }
  97. exit();
  98. break;
  99. case 'allusers':
  100. if ( !current_user_can( 'manage_network_users' ) )
  101. wp_die( __( 'You do not have permission to access this page.' ) );
  102. if ( ( isset( $_POST['action']) || isset($_POST['action2'] ) ) && isset( $_POST['allusers'] ) ) {
  103. check_admin_referer( 'bulk-users-network' );
  104. $doaction = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2'];
  105. $userfunction = '';
  106. foreach ( (array) $_POST['allusers'] as $key => $val ) {
  107. if ( !empty( $val ) ) {
  108. switch ( $doaction ) {
  109. case 'delete':
  110. if ( ! current_user_can( 'delete_users' ) )
  111. wp_die( __( 'You do not have permission to access this page.' ) );
  112. $title = __( 'Users' );
  113. $parent_file = 'users.php';
  114. require_once( '../admin-header.php' );
  115. echo '<div class="wrap">';
  116. confirm_delete_users( $_POST['allusers'] );
  117. echo '</div>';
  118. require_once( '../admin-footer.php' );
  119. exit();
  120. break;
  121. case 'spam':
  122. $user = get_userdata( $val );
  123. if ( is_super_admin( $user->ID ) )
  124. wp_die( sprintf( __( 'Warning! User cannot be modified. The user %s is a network administrator.' ), esc_html( $user->user_login ) ) );
  125. $userfunction = 'all_spam';
  126. $blogs = get_blogs_of_user( $val, true );
  127. foreach ( (array) $blogs as $key => $details ) {
  128. if ( $details->userblog_id != $current_site->blog_id ) // main blog not a spam !
  129. update_blog_status( $details->userblog_id, 'spam', '1' );
  130. }
  131. update_user_status( $val, 'spam', '1' );
  132. break;
  133. case 'notspam':
  134. $userfunction = 'all_notspam';
  135. $blogs = get_blogs_of_user( $val, true );
  136. foreach ( (array) $blogs as $key => $details )
  137. update_blog_status( $details->userblog_id, 'spam', '0' );
  138. update_user_status( $val, 'spam', '0' );
  139. break;
  140. }
  141. }
  142. }
  143. wp_safe_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $userfunction ), wp_get_referer() ) );
  144. } else {
  145. $location = network_admin_url( 'users.php' );
  146. if ( ! empty( $_REQUEST['paged'] ) )
  147. $location = add_query_arg( 'paged', (int) $_REQUEST['paged'], $location );
  148. wp_redirect( $location );
  149. }
  150. exit();
  151. break;
  152. case 'dodelete':
  153. check_admin_referer( 'ms-users-delete' );
  154. if ( ! ( current_user_can( 'manage_network_users' ) && current_user_can( 'delete_users' ) ) )
  155. wp_die( __( 'You do not have permission to access this page.' ) );
  156. if ( ! empty( $_POST['blog'] ) && is_array( $_POST['blog'] ) ) {
  157. foreach ( $_POST['blog'] as $id => $users ) {
  158. foreach ( $users as $blogid => $user_id ) {
  159. if ( ! current_user_can( 'delete_user', $id ) )
  160. continue;
  161. if ( ! empty( $_POST['delete'] ) && 'reassign' == $_POST['delete'][$blogid][$id] )
  162. remove_user_from_blog( $id, $blogid, $user_id );
  163. else
  164. remove_user_from_blog( $id, $blogid );
  165. }
  166. }
  167. }
  168. $i = 0;
  169. if ( is_array( $_POST['user'] ) && ! empty( $_POST['user'] ) )
  170. foreach( $_POST['user'] as $id ) {
  171. if ( ! current_user_can( 'delete_user', $id ) )
  172. continue;
  173. wpmu_delete_user( $id );
  174. $i++;
  175. }
  176. if ( $i == 1 )
  177. $deletefunction = 'delete';
  178. else
  179. $deletefunction = 'all_delete';
  180. wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $deletefunction ), network_admin_url( 'users.php' ) ) );
  181. exit();
  182. break;
  183. }
  184. }
  185. $wp_list_table = _get_list_table('WP_MS_Users_List_Table');
  186. $pagenum = $wp_list_table->get_pagenum();
  187. $wp_list_table->prepare_items();
  188. $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
  189. if ( $pagenum > $total_pages && $total_pages > 0 ) {
  190. wp_redirect( add_query_arg( 'paged', $total_pages ) );
  191. exit;
  192. }
  193. $title = __( 'Users' );
  194. $parent_file = 'users.php';
  195. add_screen_option( 'per_page', array('label' => _x( 'Users', 'users per page (screen options)' )) );
  196. get_current_screen()->add_help_tab( array(
  197. 'id' => 'overview',
  198. 'title' => __('Overview'),
  199. 'content' =>
  200. '<p>' . __('This table shows all users across the network and the sites to which they are assigned.') . '</p>' .
  201. '<p>' . __('Hover over any user on the list to make the edit links appear. The Edit link on the left will take you to his or her Edit User profile page; the Edit link on the right by any site name goes to an Edit Site screen for that site.') . '</p>' .
  202. '<p>' . __('You can also go to the user&#8217;s profile page by clicking on the individual username.') . '</p>' .
  203. '<p>' . __('You can sort the table by clicking on any of the bold headings and switch between list and excerpt views by using the icons in the upper right.') . '</p>' .
  204. '<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>' .
  205. '<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>'
  206. ) );
  207. get_current_screen()->set_help_sidebar(
  208. '<p><strong>' . __('For more information:') . '</strong></p>' .
  209. '<p>' . __('<a href="http://codex.wordpress.org/Network_Admin_Users_Screen" target="_blank">Documentation on Network Users</a>') . '</p>' .
  210. '<p>' . __('<a href="http://wordpress.org/support/forum/multisite/" target="_blank">Support Forums</a>') . '</p>'
  211. );
  212. require_once( '../admin-header.php' );
  213. if ( isset( $_REQUEST['updated'] ) && $_REQUEST['updated'] == 'true' && ! empty( $_REQUEST['action'] ) ) {
  214. ?>
  215. <div id="message" class="updated"><p>
  216. <?php
  217. switch ( $_REQUEST['action'] ) {
  218. case 'delete':
  219. _e( 'User deleted.' );
  220. break;
  221. case 'all_spam':
  222. _e( 'Users marked as spam.' );
  223. break;
  224. case 'all_notspam':
  225. _e( 'Users removed from spam.' );
  226. break;
  227. case 'all_delete':
  228. _e( 'Users deleted.' );
  229. break;
  230. case 'add':
  231. _e( 'User added.' );
  232. break;
  233. }
  234. ?>
  235. </p></div>
  236. <?php
  237. }
  238. ?>
  239. <div class="wrap">
  240. <?php screen_icon(); ?>
  241. <h2><?php esc_html_e( 'Users' );
  242. if ( current_user_can( 'create_users') ) : ?>
  243. <a href="<?php echo network_admin_url('user-new.php'); ?>" class="add-new-h2"><?php echo esc_html_x( 'Add New', 'user' ); ?></a><?php
  244. endif;
  245. if ( !empty( $usersearch ) )
  246. printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;' ) . '</span>', esc_html( $usersearch ) );
  247. ?>
  248. </h2>
  249. <?php $wp_list_table->views(); ?>
  250. <form action="" method="get" class="search-form">
  251. <?php $wp_list_table->search_box( __( 'Search Users' ), 'all-user' ); ?>
  252. </form>
  253. <form id="form-user-list" action='users.php?action=allusers' method='post'>
  254. <?php $wp_list_table->display(); ?>
  255. </form>
  256. </div>
  257. <?php require_once( '../admin-footer.php' ); ?>