PageRenderTime 51ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-admin/network/users.php

https://bitbucket.org/aqge/deptandashboard
PHP | 301 lines | 250 code | 43 blank | 8 comment | 62 complexity | 924ff81fc34da7b99560e1bedd764a85 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1
  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 and links 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 = new WP_User( $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 admnistrator.' ), $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 and links 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 and links.' ); ?></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 and links 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. if ( $_GET['action'] != -1 || $_POST['action2'] != -1 )
  105. $doaction = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2'];
  106. $userfunction = '';
  107. foreach ( (array) $_POST['allusers'] as $key => $val ) {
  108. if ( !empty( $val ) ) {
  109. switch ( $doaction ) {
  110. case 'delete':
  111. if ( ! current_user_can( 'delete_users' ) )
  112. wp_die( __( 'You do not have permission to access this page.' ) );
  113. $title = __( 'Users' );
  114. $parent_file = 'users.php';
  115. require_once( '../admin-header.php' );
  116. echo '<div class="wrap">';
  117. confirm_delete_users( $_POST['allusers'] );
  118. echo '</div>';
  119. require_once( '../admin-footer.php' );
  120. exit();
  121. break;
  122. case 'spam':
  123. $user = new WP_User( $val );
  124. if ( in_array( $user->user_login, get_super_admins() ) )
  125. wp_die( sprintf( __( 'Warning! User cannot be modified. The user %s is a network administrator.' ), esc_html( $user->user_login ) ) );
  126. $userfunction = 'all_spam';
  127. $blogs = get_blogs_of_user( $val, true );
  128. foreach ( (array) $blogs as $key => $details ) {
  129. if ( $details->userblog_id != $current_site->blog_id ) // main blog not a spam !
  130. update_blog_status( $details->userblog_id, 'spam', '1' );
  131. }
  132. update_user_status( $val, 'spam', '1' );
  133. break;
  134. case 'notspam':
  135. $userfunction = 'all_notspam';
  136. $blogs = get_blogs_of_user( $val, true );
  137. foreach ( (array) $blogs as $key => $details )
  138. update_blog_status( $details->userblog_id, 'spam', '0' );
  139. update_user_status( $val, 'spam', '0' );
  140. break;
  141. }
  142. }
  143. }
  144. wp_safe_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $userfunction ), wp_get_referer() ) );
  145. } else {
  146. $location = network_admin_url( 'users.php' );
  147. if ( ! empty( $_REQUEST['paged'] ) )
  148. $location = add_query_arg( 'paged', (int) $_REQUEST['paged'], $location );
  149. wp_redirect( $location );
  150. }
  151. exit();
  152. break;
  153. case 'dodelete':
  154. check_admin_referer( 'ms-users-delete' );
  155. if ( ! ( current_user_can( 'manage_network_users' ) && current_user_can( 'delete_users' ) ) )
  156. wp_die( __( 'You do not have permission to access this page.' ) );
  157. if ( ! empty( $_POST['blog'] ) && is_array( $_POST['blog'] ) ) {
  158. foreach ( $_POST['blog'] as $id => $users ) {
  159. foreach ( $users as $blogid => $user_id ) {
  160. if ( ! current_user_can( 'delete_user', $id ) )
  161. continue;
  162. if ( ! empty( $_POST['delete'] ) && 'reassign' == $_POST['delete'][$blogid][$id] )
  163. remove_user_from_blog( $id, $blogid, $user_id );
  164. else
  165. remove_user_from_blog( $id, $blogid );
  166. }
  167. }
  168. }
  169. $i = 0;
  170. if ( is_array( $_POST['user'] ) && ! empty( $_POST['user'] ) )
  171. foreach( $_POST['user'] as $id ) {
  172. if ( ! current_user_can( 'delete_user', $id ) )
  173. continue;
  174. wpmu_delete_user( $id );
  175. $i++;
  176. }
  177. if ( $i == 1 )
  178. $deletefunction = 'delete';
  179. else
  180. $deletefunction = 'all_delete';
  181. wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $deletefunction ), network_admin_url( 'users.php' ) ) );
  182. exit();
  183. break;
  184. }
  185. }
  186. $wp_list_table = _get_list_table('WP_MS_Users_List_Table');
  187. $pagenum = $wp_list_table->get_pagenum();
  188. $wp_list_table->prepare_items();
  189. $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
  190. if ( $pagenum > $total_pages && $total_pages > 0 ) {
  191. wp_redirect( add_query_arg( 'paged', $total_pages ) );
  192. exit;
  193. }
  194. $title = __( 'Users' );
  195. $parent_file = 'users.php';
  196. add_screen_option( 'per_page', array('label' => _x( 'Users', 'users per page (screen options)' )) );
  197. get_current_screen()->add_help_tab( array(
  198. 'id' => 'overview',
  199. 'title' => __('Overview'),
  200. 'content' =>
  201. '<p>' . __('This table shows all users across the network and the sites to which they are assigned.') . '</p>' .
  202. '<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>' .
  203. '<p>' . __('You can also go to the user&#8217;s profile page by clicking on the individual username.') . '</p>' .
  204. '<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>' .
  205. '<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>' .
  206. '<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>'
  207. ) );
  208. get_current_screen()->set_help_sidebar(
  209. '<p><strong>' . __('For more information:') . '</strong></p>' .
  210. '<p>' . __('<a href="http://codex.wordpress.org/Network_Admin_Users_Screen" target="_blank">Documentation on Network Users</a>') . '</p>' .
  211. '<p>' . __('<a href="http://wordpress.org/support/forum/multisite/" target="_blank">Support Forums</a>') . '</p>'
  212. );
  213. require_once( '../admin-header.php' );
  214. if ( isset( $_REQUEST['updated'] ) && $_REQUEST['updated'] == 'true' && ! empty( $_REQUEST['action'] ) ) {
  215. ?>
  216. <div id="message" class="updated"><p>
  217. <?php
  218. switch ( $_REQUEST['action'] ) {
  219. case 'delete':
  220. _e( 'User deleted.' );
  221. break;
  222. case 'all_spam':
  223. _e( 'Users marked as spam.' );
  224. break;
  225. case 'all_notspam':
  226. _e( 'Users removed from spam.' );
  227. break;
  228. case 'all_delete':
  229. _e( 'Users deleted.' );
  230. break;
  231. case 'add':
  232. _e( 'User added.' );
  233. break;
  234. }
  235. ?>
  236. </p></div>
  237. <?php
  238. }
  239. ?>
  240. <div class="wrap">
  241. <?php screen_icon(); ?>
  242. <h2><?php esc_html_e( 'Users' );
  243. if ( current_user_can( 'create_users') ) : ?>
  244. <a href="<?php echo network_admin_url('user-new.php'); ?>" class="add-new-h2"><?php echo esc_html_x( 'Add New', 'user' ); ?></a><?php
  245. endif;
  246. if ( !empty( $usersearch ) )
  247. printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;' ) . '</span>', esc_html( $usersearch ) );
  248. ?>
  249. </h2>
  250. <?php $wp_list_table->views(); ?>
  251. <form action="" method="get" class="search-form">
  252. <?php $wp_list_table->search_box( __( 'Search Users' ), 'user' ); ?>
  253. </form>
  254. <form id="form-user-list" action='users.php?action=allusers' method='post'>
  255. <?php $wp_list_table->display(); ?>
  256. </form>
  257. </div>
  258. <?php require_once( '../admin-footer.php' ); ?>