PageRenderTime 42ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/df_home/static/test/portalbkd/wp-admin/network/users.php

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