PageRenderTime 29ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/network/users.php

https://gitlab.com/thisishayat/itv-2016
PHP | 231 lines | 187 code | 35 blank | 9 comment | 45 complexity | 4806f9e366a38b3f2ac12917b976e598 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. if ( isset( $_GET['action'] ) ) {
  16. /** This action is documented in wp-admin/network/edit.php */
  17. do_action( 'wpmuadminedit' );
  18. switch ( $_GET['action'] ) {
  19. case 'deleteuser':
  20. if ( ! current_user_can( 'manage_network_users' ) )
  21. wp_die( __( 'You do not have permission to access this page.' ), 403 );
  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( __( 'You do not have permission to access this page.' ), 403 );
  40. if ( ( isset( $_POST['action']) || isset($_POST['action2'] ) ) && isset( $_POST['allusers'] ) ) {
  41. check_admin_referer( 'bulk-users-network' );
  42. $doaction = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2'];
  43. $userfunction = '';
  44. foreach ( (array) $_POST['allusers'] as $user_id ) {
  45. if ( !empty( $user_id ) ) {
  46. switch ( $doaction ) {
  47. case 'delete':
  48. if ( ! current_user_can( 'delete_users' ) )
  49. wp_die( __( 'You do not have permission to access this page.' ), 403 );
  50. $title = __( 'Users' );
  51. $parent_file = 'users.php';
  52. require_once( ABSPATH . 'wp-admin/admin-header.php' );
  53. echo '<div class="wrap">';
  54. confirm_delete_users( $_POST['allusers'] );
  55. echo '</div>';
  56. require_once( ABSPATH . 'wp-admin/admin-footer.php' );
  57. exit();
  58. case 'spam':
  59. $user = get_userdata( $user_id );
  60. if ( is_super_admin( $user->ID ) )
  61. wp_die( sprintf( __( 'Warning! User cannot be modified. The user %s is a network administrator.' ), esc_html( $user->user_login ) ) );
  62. $userfunction = 'all_spam';
  63. $blogs = get_blogs_of_user( $user_id, true );
  64. foreach ( (array) $blogs as $details ) {
  65. if ( $details->userblog_id != $current_site->blog_id ) // main blog not a spam !
  66. update_blog_status( $details->userblog_id, 'spam', '1' );
  67. }
  68. update_user_status( $user_id, 'spam', '1' );
  69. break;
  70. case 'notspam':
  71. $userfunction = 'all_notspam';
  72. $blogs = get_blogs_of_user( $user_id, true );
  73. foreach ( (array) $blogs as $details )
  74. update_blog_status( $details->userblog_id, 'spam', '0' );
  75. update_user_status( $user_id, 'spam', '0' );
  76. break;
  77. }
  78. }
  79. }
  80. wp_safe_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $userfunction ), wp_get_referer() ) );
  81. } else {
  82. $location = network_admin_url( 'users.php' );
  83. if ( ! empty( $_REQUEST['paged'] ) )
  84. $location = add_query_arg( 'paged', (int) $_REQUEST['paged'], $location );
  85. wp_redirect( $location );
  86. }
  87. exit();
  88. case 'dodelete':
  89. check_admin_referer( 'ms-users-delete' );
  90. if ( ! ( current_user_can( 'manage_network_users' ) && current_user_can( 'delete_users' ) ) )
  91. wp_die( __( 'You do not have permission to access this page.' ), 403 );
  92. if ( ! empty( $_POST['blog'] ) && is_array( $_POST['blog'] ) ) {
  93. foreach ( $_POST['blog'] as $id => $users ) {
  94. foreach ( $users as $blogid => $user_id ) {
  95. if ( ! current_user_can( 'delete_user', $id ) )
  96. continue;
  97. if ( ! empty( $_POST['delete'] ) && 'reassign' == $_POST['delete'][$blogid][$id] )
  98. remove_user_from_blog( $id, $blogid, $user_id );
  99. else
  100. remove_user_from_blog( $id, $blogid );
  101. }
  102. }
  103. }
  104. $i = 0;
  105. if ( is_array( $_POST['user'] ) && ! empty( $_POST['user'] ) )
  106. foreach ( $_POST['user'] as $id ) {
  107. if ( ! current_user_can( 'delete_user', $id ) )
  108. continue;
  109. wpmu_delete_user( $id );
  110. $i++;
  111. }
  112. if ( $i == 1 )
  113. $deletefunction = 'delete';
  114. else
  115. $deletefunction = 'all_delete';
  116. wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $deletefunction ), network_admin_url( 'users.php' ) ) );
  117. exit();
  118. }
  119. }
  120. $wp_list_table = _get_list_table('WP_MS_Users_List_Table');
  121. $pagenum = $wp_list_table->get_pagenum();
  122. $wp_list_table->prepare_items();
  123. $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
  124. if ( $pagenum > $total_pages && $total_pages > 0 ) {
  125. wp_redirect( add_query_arg( 'paged', $total_pages ) );
  126. exit;
  127. }
  128. $title = __( 'Users' );
  129. $parent_file = 'users.php';
  130. add_screen_option( 'per_page' );
  131. get_current_screen()->add_help_tab( array(
  132. 'id' => 'overview',
  133. 'title' => __('Overview'),
  134. 'content' =>
  135. '<p>' . __('This table shows all users across the network and the sites to which they are assigned.') . '</p>' .
  136. '<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>' .
  137. '<p>' . __('You can also go to the user&#8217;s profile page by clicking on the individual username.') . '</p>' .
  138. '<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>' .
  139. '<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>' .
  140. '<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>'
  141. ) );
  142. get_current_screen()->set_help_sidebar(
  143. '<p><strong>' . __('For more information:') . '</strong></p>' .
  144. '<p>' . __('<a href="https://codex.wordpress.org/Network_Admin_Users_Screen" target="_blank">Documentation on Network Users</a>') . '</p>' .
  145. '<p>' . __('<a href="https://wordpress.org/support/forum/multisite/" target="_blank">Support Forums</a>') . '</p>'
  146. );
  147. get_current_screen()->set_screen_reader_content( array(
  148. 'heading_views' => __( 'Filter users list' ),
  149. 'heading_pagination' => __( 'Users list navigation' ),
  150. 'heading_list' => __( 'Users list' ),
  151. ) );
  152. require_once( ABSPATH . 'wp-admin/admin-header.php' );
  153. if ( isset( $_REQUEST['updated'] ) && $_REQUEST['updated'] == 'true' && ! empty( $_REQUEST['action'] ) ) {
  154. ?>
  155. <div id="message" class="updated notice is-dismissible"><p>
  156. <?php
  157. switch ( $_REQUEST['action'] ) {
  158. case 'delete':
  159. _e( 'User deleted.' );
  160. break;
  161. case 'all_spam':
  162. _e( 'Users marked as spam.' );
  163. break;
  164. case 'all_notspam':
  165. _e( 'Users removed from spam.' );
  166. break;
  167. case 'all_delete':
  168. _e( 'Users deleted.' );
  169. break;
  170. case 'add':
  171. _e( 'User added.' );
  172. break;
  173. }
  174. ?>
  175. </p></div>
  176. <?php
  177. }
  178. ?>
  179. <div class="wrap">
  180. <h1><?php esc_html_e( 'Users' );
  181. if ( current_user_can( 'create_users') ) : ?>
  182. <a href="<?php echo network_admin_url('user-new.php'); ?>" class="page-title-action"><?php echo esc_html_x( 'Add New', 'user' ); ?></a><?php
  183. endif;
  184. if ( !empty( $usersearch ) )
  185. printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;' ) . '</span>', esc_html( $usersearch ) );
  186. ?>
  187. </h1>
  188. <?php $wp_list_table->views(); ?>
  189. <form method="get" class="search-form">
  190. <?php $wp_list_table->search_box( __( 'Search Users' ), 'all-user' ); ?>
  191. </form>
  192. <form id="form-user-list" action="users.php?action=allusers" method="post">
  193. <?php $wp_list_table->display(); ?>
  194. </form>
  195. </div>
  196. <?php require_once( ABSPATH . 'wp-admin/admin-footer.php' ); ?>