| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
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 __DIR__ . '/admin.php'; 12 13 if ( ! current_user_can( 'manage_network_users' ) ) { 14 wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 ); 15 } 16 17 if ( isset( $_GET['action'] ) ) { 18 /** This action is documented in wp-admin/network/edit.php */ 19 do_action( 'wpmuadminedit' ); 20 21 switch ( $_GET['action'] ) { 22 case 'deleteuser': 23 if ( ! current_user_can( 'manage_network_users' ) ) { 24 wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 ); 25 } 26 27 check_admin_referer( 'deleteuser' ); 28 29 $id = (int) $_GET['id']; 30 if ( $id > 1 ) { 31 $_POST['allusers'] = array( $id ); // confirm_delete_users() can only handle arrays. 32 33 // Used in the HTML title tag. 34 $title = __( 'Users' ); 35 $parent_file = 'users.php'; 36 37 require_once ABSPATH . 'wp-admin/admin-header.php'; 38 39 echo '<div class="wrap">'; 40 confirm_delete_users( $_POST['allusers'] ); 41 echo '</div>'; 42 43 require_once ABSPATH . 'wp-admin/admin-footer.php'; 44 } else { 45 wp_redirect( network_admin_url( 'users.php' ) ); 46 } 47 exit; 48 49 case 'allusers': 50 if ( ! current_user_can( 'manage_network_users' ) ) { 51 wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 ); 52 } 53 54 if ( isset( $_POST['action'] ) && isset( $_POST['allusers'] ) ) { 55 check_admin_referer( 'bulk-users-network' ); 56 57 $doaction = $_POST['action']; 58 $userfunction = ''; 59 $allusers = (array) $_POST['allusers']; 60 61 foreach ( $allusers as $user_id ) { 62 if ( ! empty( $user_id ) ) { 63 switch ( $doaction ) { 64 case 'delete': 65 if ( ! current_user_can( 'delete_users' ) ) { 66 wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 ); 67 } 68 69 // Used in the HTML title tag. 70 $title = __( 'Users' ); 71 $parent_file = 'users.php'; 72 73 require_once ABSPATH . 'wp-admin/admin-header.php'; 74 75 echo '<div class="wrap">'; 76 confirm_delete_users( $allusers ); 77 echo '</div>'; 78 79 require_once ABSPATH . 'wp-admin/admin-footer.php'; 80 exit; 81 82 case 'spam': 83 $user = get_userdata( $user_id ); 84 if ( is_super_admin( $user->ID ) ) { 85 wp_die( 86 sprintf( 87 /* translators: %s: User login. */ 88 __( 'Warning! User cannot be modified. The user %s is a network administrator.' ), 89 esc_html( $user->user_login ) 90 ), 91 403 92 ); 93 } 94 95 $userfunction = 'all_spam'; 96 97 /** 98 * Filters whether to propagate the blog status when a user is marked as spam. 99 * 100 * @since 7.0.0 101 * 102 * @param bool $propagate Whether to propagate the blog status. Default false. 103 * @param int $user_id User ID. 104 */ 105 if ( apply_filters( 'propagate_network_user_spam_to_blogs', false, $user_id ) ) { 106 foreach ( get_blogs_of_user( $user_id, true ) as $details ) { 107 // Assuming the main site is not a spam. 108 if ( ! is_main_site( $details->userblog_id ) ) { 109 update_blog_status( $details->userblog_id, 'spam', '1' ); 110 } 111 } 112 } 113 114 $user_data = $user->to_array(); 115 $user_data['spam'] = '1'; 116 117 wp_update_user( $user_data ); 118 break; 119 120 case 'notspam': 121 $user = get_userdata( $user_id ); 122 123 if ( is_super_admin( $user->ID ) ) { 124 wp_die( 125 sprintf( 126 /* translators: %s: User login. */ 127 __( 'Warning! User cannot be modified. The user %s is a network administrator.' ), 128 esc_html( $user->user_login ) 129 ), 130 403 131 ); 132 } 133 134 $userfunction = 'all_notspam'; 135 $blogs = get_blogs_of_user( $user_id, true ); 136 137 /** This filter is documented in wp-admin/network/users.php */ 138 if ( apply_filters( 'propagate_network_user_spam_to_blogs', false, $user_id ) ) { 139 foreach ( get_blogs_of_user( $user_id, true ) as $details ) { 140 if ( ! is_main_site( $details->userblog_id ) && get_current_network_id() === $details->site_id ) { 141 // Assuming main site is never a spam and part of the current network. 142 update_blog_status( $details->userblog_id, 'spam', '0' ); 143 } 144 } 145 } 146 147 $user_data = $user->to_array(); 148 $user_data['spam'] = '0'; 149 150 wp_update_user( $user_data ); 151 break; 152 } 153 } 154 } 155 156 if ( ! in_array( $doaction, array( 'delete', 'spam', 'notspam' ), true ) ) { 157 $sendback = wp_get_referer(); 158 $user_ids = (array) $_POST['allusers']; 159 160 /** This action is documented in wp-admin/network/site-themes.php */ 161 $sendback = apply_filters( 'handle_network_bulk_actions-' . get_current_screen()->id, $sendback, $doaction, $user_ids ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores 162 163 wp_safe_redirect( $sendback ); 164 exit; 165 } 166 167 wp_safe_redirect( 168 add_query_arg( 169 array( 170 'updated' => 'true', 171 'action' => $userfunction, 172 ), 173 wp_get_referer() 174 ) 175 ); 176 } else { 177 $location = network_admin_url( 'users.php' ); 178 179 if ( ! empty( $_REQUEST['paged'] ) ) { 180 $location = add_query_arg( 'paged', (int) $_REQUEST['paged'], $location ); 181 } 182 wp_redirect( $location ); 183 } 184 exit; 185 186 case 'dodelete': 187 check_admin_referer( 'ms-users-delete' ); 188 if ( ! ( current_user_can( 'manage_network_users' ) && current_user_can( 'delete_users' ) ) ) { 189 wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 ); 190 } 191 192 /* 193 * Validate that every "reassign" choice has a real target before making 194 * any changes. The confirmation form blocks this client-side, so this is 195 * a defense-in-depth guard against an invalid reassignment (e.g. content 196 * reassigned to the non-existent user "-1") when JavaScript is bypassed. 197 * Bail out entirely so the deletion is all-or-nothing. 198 */ 199 if ( ! empty( $_POST['blog'] ) && is_array( $_POST['blog'] ) && ! empty( $_POST['delete'] ) ) { 200 foreach ( $_POST['blog'] as $id => $blogs ) { 201 foreach ( $blogs as $blogid => $reassign_user_id ) { 202 if ( isset( $_POST['delete'][ $blogid ][ $id ] ) 203 && 'reassign' === $_POST['delete'][ $blogid ][ $id ] 204 && (int) $reassign_user_id < 1 205 ) { 206 wp_redirect( 207 add_query_arg( 208 array( 'error' => 'missing_reassign' ), 209 network_admin_url( 'users.php' ) 210 ) 211 ); 212 exit; 213 } 214 } 215 } 216 } 217 218 if ( ! empty( $_POST['blog'] ) && is_array( $_POST['blog'] ) ) { 219 foreach ( $_POST['blog'] as $id => $users ) { 220 foreach ( $users as $blogid => $user_id ) { 221 if ( ! current_user_can( 'delete_user', $id ) ) { 222 continue; 223 } 224 225 if ( ! empty( $_POST['delete'] ) && 'reassign' === $_POST['delete'][ $blogid ][ $id ] ) { 226 remove_user_from_blog( $id, $blogid, (int) $user_id ); 227 } else { 228 remove_user_from_blog( $id, $blogid ); 229 } 230 } 231 } 232 } 233 234 $i = 0; 235 236 if ( is_array( $_POST['user'] ) && ! empty( $_POST['user'] ) ) { 237 foreach ( $_POST['user'] as $id ) { 238 if ( ! current_user_can( 'delete_user', $id ) ) { 239 continue; 240 } 241 wpmu_delete_user( $id ); 242 ++$i; 243 } 244 } 245 246 if ( 1 === $i ) { 247 $deletefunction = 'delete'; 248 } else { 249 $deletefunction = 'all_delete'; 250 } 251 252 wp_redirect( 253 add_query_arg( 254 array( 255 'updated' => 'true', 256 'action' => $deletefunction, 257 ), 258 network_admin_url( 'users.php' ) 259 ) 260 ); 261 exit; 262 } 263 } 264 265 $wp_list_table = _get_list_table( 'WP_MS_Users_List_Table' ); 266 $pagenum = $wp_list_table->get_pagenum(); 267 $wp_list_table->prepare_items(); 268 $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' ); 269 270 if ( $pagenum > $total_pages && $total_pages > 0 ) { 271 wp_redirect( add_query_arg( 'paged', $total_pages ) ); 272 exit; 273 } 274 275 // Used in the HTML title tag. 276 $title = __( 'Users' ); 277 $parent_file = 'users.php'; 278 279 add_screen_option( 'per_page' ); 280 281 get_current_screen()->add_help_tab( 282 array( 283 'id' => 'overview', 284 'title' => __( 'Overview' ), 285 'content' => 286 '<p>' . __( 'This table shows all users across the network and the sites to which they are assigned.' ) . '</p>' . 287 '<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>' . 288 '<p>' . __( 'You can also go to the user’s profile page by clicking on the individual username.' ) . '</p>' . 289 '<p>' . __( 'You can sort the table by clicking on any of the table headings and switch between list and excerpt views by using the icons above the users list.' ) . '</p>' . 290 '<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>' . 291 '<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>', 292 ) 293 ); 294 295 get_current_screen()->set_help_sidebar( 296 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . 297 '<p>' . __( '<a href="https://codex.wordpress.org/Network_Admin_Users_Screen">Documentation on Network Users</a>' ) . '</p>' . 298 '<p>' . __( '<a href="https://wordpress.org/support/forum/multisite/">Support forums</a>' ) . '</p>' 299 ); 300 301 get_current_screen()->set_screen_reader_content( 302 array( 303 'heading_views' => __( 'Filter users list' ), 304 'heading_pagination' => __( 'Users list navigation' ), 305 'heading_list' => __( 'Users list' ), 306 ) 307 ); 308 309 require_once ABSPATH . 'wp-admin/admin-header.php'; 310 311 if ( isset( $_REQUEST['updated'] ) && 'true' === $_REQUEST['updated'] && ! empty( $_REQUEST['action'] ) ) { 312 $message = ''; 313 switch ( $_REQUEST['action'] ) { 314 case 'delete': 315 $message = __( 'User deleted.' ); 316 break; 317 case 'all_spam': 318 $message = __( 'Users marked as spam.' ); 319 break; 320 case 'all_notspam': 321 $message = __( 'Users removed from spam.' ); 322 break; 323 case 'all_delete': 324 $message = __( 'Users deleted.' ); 325 break; 326 case 'add': 327 $message = __( 'User added.' ); 328 break; 329 } 330 331 wp_admin_notice( 332 $message, 333 array( 334 'type' => 'success', 335 'dismissible' => true, 336 'id' => 'message', 337 ) 338 ); 339 } 340 341 if ( isset( $_REQUEST['error'] ) && 'missing_reassign' === $_REQUEST['error'] ) { 342 wp_admin_notice( 343 __( 'No users were deleted because no user was selected for content reassignment.' ), 344 array( 345 'type' => 'error', 346 'dismissible' => true, 347 'id' => 'message', 348 ) 349 ); 350 } 351 ?> 352 <div class="wrap"> 353 <h1 class="wp-heading-inline"><?php esc_html_e( 'Users' ); ?></h1> 354 355 <?php 356 if ( current_user_can( 'create_users' ) ) : 357 ?> 358 <a href="<?php echo esc_url( network_admin_url( 'user-new.php' ) ); ?>" class="page-title-action"><?php echo esc_html__( 'Add User' ); ?></a> 359 <?php 360 endif; 361 362 if ( strlen( $usersearch ) ) { 363 echo '<span class="subtitle">'; 364 printf( 365 /* translators: %s: Search query. */ 366 __( 'Search results for: %s' ), 367 '<strong>' . esc_html( $usersearch ) . '</strong>' 368 ); 369 echo '</span>'; 370 } 371 ?> 372 373 <hr class="wp-header-end"> 374 375 <?php $wp_list_table->views(); ?> 376 377 <form method="get" class="search-form"> 378 <?php $wp_list_table->search_box( __( 'Search Users' ), 'all-user' ); ?> 379 </form> 380 381 <form id="form-user-list" action="users.php?action=allusers" method="post"> 382 <?php $wp_list_table->display(); ?> 383 </form> 384 </div> 385 386 <?php require_once ABSPATH . 'wp-admin/admin-footer.php'; ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Mon Jul 27 08:20:18 2026 | Cross-referenced by PHPXref |