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