author | ymh <ymh.work@gmail.com> |
Mon, 08 Sep 2025 19:44:41 +0200 | |
changeset 23 | 417f20492bf7 |
parent 22 | 8c2e4d02f4ef |
permissions | -rw-r--r-- |
0 | 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 */ |
|
16 | 11 |
require_once __DIR__ . '/admin.php'; |
0 | 12 |
|
9 | 13 |
if ( ! current_user_can( 'manage_network_users' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
14 |
wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 ); |
9 | 15 |
} |
0 | 16 |
|
17 |
if ( isset( $_GET['action'] ) ) { |
|
5 | 18 |
/** This action is documented in wp-admin/network/edit.php */ |
19 |
do_action( 'wpmuadminedit' ); |
|
0 | 20 |
|
21 |
switch ( $_GET['action'] ) { |
|
22 |
case 'deleteuser': |
|
9 | 23 |
if ( ! current_user_can( 'manage_network_users' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
24 |
wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 ); |
9 | 25 |
} |
0 | 26 |
|
27 |
check_admin_referer( 'deleteuser' ); |
|
28 |
||
18 | 29 |
$id = (int) $_GET['id']; |
16 | 30 |
if ( $id > 1 ) { |
31 |
$_POST['allusers'] = array( $id ); // confirm_delete_users() can only handle arrays. |
|
19 | 32 |
|
33 |
// Used in the HTML title tag. |
|
34 |
$title = __( 'Users' ); |
|
35 |
$parent_file = 'users.php'; |
|
36 |
||
16 | 37 |
require_once ABSPATH . 'wp-admin/admin-header.php'; |
19 | 38 |
|
0 | 39 |
echo '<div class="wrap">'; |
40 |
confirm_delete_users( $_POST['allusers'] ); |
|
41 |
echo '</div>'; |
|
19 | 42 |
|
16 | 43 |
require_once ABSPATH . 'wp-admin/admin-footer.php'; |
5 | 44 |
} else { |
0 | 45 |
wp_redirect( network_admin_url( 'users.php' ) ); |
46 |
} |
|
16 | 47 |
exit; |
0 | 48 |
|
49 |
case 'allusers': |
|
9 | 50 |
if ( ! current_user_can( 'manage_network_users' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
51 |
wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 ); |
9 | 52 |
} |
0 | 53 |
|
18 | 54 |
if ( isset( $_POST['action'] ) && isset( $_POST['allusers'] ) ) { |
0 | 55 |
check_admin_referer( 'bulk-users-network' ); |
56 |
||
18 | 57 |
$doaction = $_POST['action']; |
0 | 58 |
$userfunction = ''; |
59 |
||
5 | 60 |
foreach ( (array) $_POST['allusers'] as $user_id ) { |
9 | 61 |
if ( ! empty( $user_id ) ) { |
0 | 62 |
switch ( $doaction ) { |
63 |
case 'delete': |
|
9 | 64 |
if ( ! current_user_can( 'delete_users' ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
65 |
wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 ); |
9 | 66 |
} |
19 | 67 |
|
68 |
// Used in the HTML title tag. |
|
9 | 69 |
$title = __( 'Users' ); |
0 | 70 |
$parent_file = 'users.php'; |
19 | 71 |
|
16 | 72 |
require_once ABSPATH . 'wp-admin/admin-header.php'; |
19 | 73 |
|
0 | 74 |
echo '<div class="wrap">'; |
75 |
confirm_delete_users( $_POST['allusers'] ); |
|
76 |
echo '</div>'; |
|
19 | 77 |
|
16 | 78 |
require_once ABSPATH . 'wp-admin/admin-footer.php'; |
79 |
exit; |
|
0 | 80 |
|
81 |
case 'spam': |
|
5 | 82 |
$user = get_userdata( $user_id ); |
9 | 83 |
if ( is_super_admin( $user->ID ) ) { |
16 | 84 |
wp_die( |
85 |
sprintf( |
|
86 |
/* translators: %s: User login. */ |
|
87 |
__( 'Warning! User cannot be modified. The user %s is a network administrator.' ), |
|
88 |
esc_html( $user->user_login ) |
|
89 |
) |
|
90 |
); |
|
9 | 91 |
} |
0 | 92 |
|
93 |
$userfunction = 'all_spam'; |
|
9 | 94 |
$blogs = get_blogs_of_user( $user_id, true ); |
16 | 95 |
|
5 | 96 |
foreach ( (array) $blogs as $details ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
97 |
if ( ! is_main_site( $details->userblog_id ) ) { // Main site is not a spam! |
0 | 98 |
update_blog_status( $details->userblog_id, 'spam', '1' ); |
9 | 99 |
} |
0 | 100 |
} |
16 | 101 |
|
102 |
$user_data = $user->to_array(); |
|
103 |
$user_data['spam'] = '1'; |
|
104 |
||
105 |
wp_update_user( $user_data ); |
|
9 | 106 |
break; |
0 | 107 |
|
108 |
case 'notspam': |
|
16 | 109 |
$user = get_userdata( $user_id ); |
110 |
||
0 | 111 |
$userfunction = 'all_notspam'; |
9 | 112 |
$blogs = get_blogs_of_user( $user_id, true ); |
16 | 113 |
|
9 | 114 |
foreach ( (array) $blogs as $details ) { |
0 | 115 |
update_blog_status( $details->userblog_id, 'spam', '0' ); |
9 | 116 |
} |
0 | 117 |
|
16 | 118 |
$user_data = $user->to_array(); |
119 |
$user_data['spam'] = '0'; |
|
120 |
||
121 |
wp_update_user( $user_data ); |
|
9 | 122 |
break; |
0 | 123 |
} |
124 |
} |
|
125 |
} |
|
126 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
127 |
if ( ! in_array( $doaction, array( 'delete', 'spam', 'notspam' ), true ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
128 |
$sendback = wp_get_referer(); |
16 | 129 |
$user_ids = (array) $_POST['allusers']; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
130 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
131 |
/** This action is documented in wp-admin/network/site-themes.php */ |
16 | 132 |
$sendback = apply_filters( 'handle_network_bulk_actions-' . get_current_screen()->id, $sendback, $doaction, $user_ids ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
133 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
134 |
wp_safe_redirect( $sendback ); |
16 | 135 |
exit; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
136 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
137 |
|
9 | 138 |
wp_safe_redirect( |
139 |
add_query_arg( |
|
140 |
array( |
|
141 |
'updated' => 'true', |
|
142 |
'action' => $userfunction, |
|
143 |
), |
|
144 |
wp_get_referer() |
|
145 |
) |
|
146 |
); |
|
0 | 147 |
} else { |
148 |
$location = network_admin_url( 'users.php' ); |
|
149 |
||
9 | 150 |
if ( ! empty( $_REQUEST['paged'] ) ) { |
0 | 151 |
$location = add_query_arg( 'paged', (int) $_REQUEST['paged'], $location ); |
9 | 152 |
} |
0 | 153 |
wp_redirect( $location ); |
154 |
} |
|
16 | 155 |
exit; |
0 | 156 |
|
157 |
case 'dodelete': |
|
158 |
check_admin_referer( 'ms-users-delete' ); |
|
9 | 159 |
if ( ! ( current_user_can( 'manage_network_users' ) && current_user_can( 'delete_users' ) ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
160 |
wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 ); |
9 | 161 |
} |
0 | 162 |
|
163 |
if ( ! empty( $_POST['blog'] ) && is_array( $_POST['blog'] ) ) { |
|
164 |
foreach ( $_POST['blog'] as $id => $users ) { |
|
165 |
foreach ( $users as $blogid => $user_id ) { |
|
9 | 166 |
if ( ! current_user_can( 'delete_user', $id ) ) { |
0 | 167 |
continue; |
9 | 168 |
} |
0 | 169 |
|
16 | 170 |
if ( ! empty( $_POST['delete'] ) && 'reassign' === $_POST['delete'][ $blogid ][ $id ] ) { |
171 |
remove_user_from_blog( $id, $blogid, (int) $user_id ); |
|
9 | 172 |
} else { |
0 | 173 |
remove_user_from_blog( $id, $blogid ); |
9 | 174 |
} |
0 | 175 |
} |
176 |
} |
|
177 |
} |
|
16 | 178 |
|
0 | 179 |
$i = 0; |
16 | 180 |
|
9 | 181 |
if ( is_array( $_POST['user'] ) && ! empty( $_POST['user'] ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
182 |
foreach ( $_POST['user'] as $id ) { |
9 | 183 |
if ( ! current_user_can( 'delete_user', $id ) ) { |
0 | 184 |
continue; |
9 | 185 |
} |
0 | 186 |
wpmu_delete_user( $id ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
187 |
++$i; |
0 | 188 |
} |
9 | 189 |
} |
0 | 190 |
|
16 | 191 |
if ( 1 === $i ) { |
0 | 192 |
$deletefunction = 'delete'; |
9 | 193 |
} else { |
0 | 194 |
$deletefunction = 'all_delete'; |
9 | 195 |
} |
0 | 196 |
|
9 | 197 |
wp_redirect( |
198 |
add_query_arg( |
|
199 |
array( |
|
200 |
'updated' => 'true', |
|
201 |
'action' => $deletefunction, |
|
202 |
), |
|
203 |
network_admin_url( 'users.php' ) |
|
204 |
) |
|
205 |
); |
|
16 | 206 |
exit; |
0 | 207 |
} |
208 |
} |
|
209 |
||
9 | 210 |
$wp_list_table = _get_list_table( 'WP_MS_Users_List_Table' ); |
211 |
$pagenum = $wp_list_table->get_pagenum(); |
|
0 | 212 |
$wp_list_table->prepare_items(); |
213 |
$total_pages = $wp_list_table->get_pagination_arg( 'total_pages' ); |
|
214 |
||
215 |
if ( $pagenum > $total_pages && $total_pages > 0 ) { |
|
216 |
wp_redirect( add_query_arg( 'paged', $total_pages ) ); |
|
217 |
exit; |
|
218 |
} |
|
19 | 219 |
|
220 |
// Used in the HTML title tag. |
|
9 | 221 |
$title = __( 'Users' ); |
0 | 222 |
$parent_file = 'users.php'; |
223 |
||
5 | 224 |
add_screen_option( 'per_page' ); |
0 | 225 |
|
9 | 226 |
get_current_screen()->add_help_tab( |
227 |
array( |
|
228 |
'id' => 'overview', |
|
229 |
'title' => __( 'Overview' ), |
|
230 |
'content' => |
|
231 |
'<p>' . __( 'This table shows all users across the network and the sites to which they are assigned.' ) . '</p>' . |
|
232 |
'<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>' . |
|
233 |
'<p>' . __( 'You can also go to the user’s profile page by clicking on the individual username.' ) . '</p>' . |
|
234 |
'<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>' . |
|
235 |
'<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>' . |
|
236 |
'<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>', |
|
237 |
) |
|
238 |
); |
|
0 | 239 |
|
240 |
get_current_screen()->set_help_sidebar( |
|
9 | 241 |
'<p><strong>' . __( 'For more information:' ) . '</strong></p>' . |
242 |
'<p>' . __( '<a href="https://codex.wordpress.org/Network_Admin_Users_Screen">Documentation on Network Users</a>' ) . '</p>' . |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
243 |
'<p>' . __( '<a href="https://wordpress.org/support/forum/multisite/">Support forums</a>' ) . '</p>' |
0 | 244 |
); |
245 |
||
9 | 246 |
get_current_screen()->set_screen_reader_content( |
247 |
array( |
|
248 |
'heading_views' => __( 'Filter users list' ), |
|
249 |
'heading_pagination' => __( 'Users list navigation' ), |
|
250 |
'heading_list' => __( 'Users list' ), |
|
251 |
) |
|
252 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
253 |
|
16 | 254 |
require_once ABSPATH . 'wp-admin/admin-header.php'; |
0 | 255 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
256 |
if ( isset( $_REQUEST['updated'] ) && 'true' === $_REQUEST['updated'] && ! empty( $_REQUEST['action'] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
257 |
$message = ''; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
258 |
switch ( $_REQUEST['action'] ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
259 |
case 'delete': |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
260 |
$message = __( 'User deleted.' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
261 |
break; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
262 |
case 'all_spam': |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
263 |
$message = __( 'Users marked as spam.' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
264 |
break; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
265 |
case 'all_notspam': |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
266 |
$message = __( 'Users removed from spam.' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
267 |
break; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
268 |
case 'all_delete': |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
269 |
$message = __( 'Users deleted.' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
270 |
break; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
271 |
case 'add': |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
272 |
$message = __( 'User added.' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
273 |
break; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
274 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
275 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
276 |
wp_admin_notice( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
277 |
$message, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
278 |
array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
279 |
'type' => 'success', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
280 |
'dismissible' => true, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
281 |
'id' => 'message', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
282 |
) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
283 |
); |
0 | 284 |
} |
9 | 285 |
?> |
0 | 286 |
<div class="wrap"> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
287 |
<h1 class="wp-heading-inline"><?php esc_html_e( 'Users' ); ?></h1> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
288 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
289 |
<?php |
9 | 290 |
if ( current_user_can( 'create_users' ) ) : |
291 |
?> |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
292 |
<a href="<?php echo esc_url( network_admin_url( 'user-new.php' ) ); ?>" class="page-title-action"><?php echo esc_html__( 'Add User' ); ?></a> |
18 | 293 |
<?php |
0 | 294 |
endif; |
295 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
296 |
if ( strlen( $usersearch ) ) { |
18 | 297 |
echo '<span class="subtitle">'; |
298 |
printf( |
|
299 |
/* translators: %s: Search query. */ |
|
300 |
__( 'Search results for: %s' ), |
|
301 |
'<strong>' . esc_html( $usersearch ) . '</strong>' |
|
302 |
); |
|
303 |
echo '</span>'; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
304 |
} |
0 | 305 |
?> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
306 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
307 |
<hr class="wp-header-end"> |
0 | 308 |
|
309 |
<?php $wp_list_table->views(); ?> |
|
310 |
||
5 | 311 |
<form method="get" class="search-form"> |
0 | 312 |
<?php $wp_list_table->search_box( __( 'Search Users' ), 'all-user' ); ?> |
313 |
</form> |
|
314 |
||
5 | 315 |
<form id="form-user-list" action="users.php?action=allusers" method="post"> |
0 | 316 |
<?php $wp_list_table->display(); ?> |
317 |
</form> |
|
318 |
</div> |
|
319 |
||
16 | 320 |
<?php require_once ABSPATH . 'wp-admin/admin-footer.php'; ?> |