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 administration functions. |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
* @subpackage Multisite |
|
7 |
* @since 3.0.0 |
|
8 |
*/ |
|
9 |
||
10 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
11 |
* Determines whether uploaded file exceeds space quota. |
0 | 12 |
* |
13 |
* @since 3.0.0 |
|
14 |
* |
|
19 | 15 |
* @param array $file An element from the `$_FILES` array for a given file. |
16 |
* @return array The `$_FILES` array element with 'error' key set if file exceeds quota. 'error' is empty otherwise. |
|
0 | 17 |
*/ |
18 |
function check_upload_size( $file ) { |
|
9 | 19 |
if ( get_site_option( 'upload_space_check_disabled' ) ) { |
0 | 20 |
return $file; |
9 | 21 |
} |
0 | 22 |
|
19 | 23 |
if ( $file['error'] > 0 ) { // There's already an error. |
0 | 24 |
return $file; |
9 | 25 |
} |
0 | 26 |
|
9 | 27 |
if ( defined( 'WP_IMPORTING' ) ) { |
0 | 28 |
return $file; |
9 | 29 |
} |
0 | 30 |
|
31 |
$space_left = get_upload_space_available(); |
|
32 |
||
33 |
$file_size = filesize( $file['tmp_name'] ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
34 |
if ( $space_left < $file_size ) { |
16 | 35 |
/* translators: %s: Required disk space in kilobytes. */ |
9 | 36 |
$file['error'] = sprintf( __( 'Not enough space to upload. %s KB needed.' ), number_format( ( $file_size - $space_left ) / KB_IN_BYTES ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
37 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
38 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
39 |
if ( $file_size > ( KB_IN_BYTES * get_site_option( 'fileupload_maxk', 1500 ) ) ) { |
16 | 40 |
/* translators: %s: Maximum allowed file size in kilobytes. */ |
9 | 41 |
$file['error'] = sprintf( __( 'This file is too big. Files must be less than %s KB in size.' ), get_site_option( 'fileupload_maxk', 1500 ) ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
42 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
43 |
|
0 | 44 |
if ( upload_is_user_over_quota( false ) ) { |
45 |
$file['error'] = __( 'You have used your space quota. Please delete files before uploading.' ); |
|
46 |
} |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
47 |
|
19 | 48 |
if ( $file['error'] > 0 && ! isset( $_POST['html-upload'] ) && ! wp_doing_ajax() ) { |
0 | 49 |
wp_die( $file['error'] . ' <a href="javascript:history.go(-1)">' . __( 'Back' ) . '</a>' ); |
5 | 50 |
} |
0 | 51 |
|
52 |
return $file; |
|
53 |
} |
|
54 |
||
55 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
56 |
* Deletes a site. |
0 | 57 |
* |
58 |
* @since 3.0.0 |
|
9 | 59 |
* @since 5.1.0 Use wp_delete_site() internally to delete the site row from the database. |
0 | 60 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
61 |
* @param int $blog_id Site ID. |
16 | 62 |
* @param bool $drop True if site's database tables should be dropped. Default false. |
0 | 63 |
*/ |
64 |
function wpmu_delete_blog( $blog_id, $drop = false ) { |
|
19 | 65 |
$blog_id = (int) $blog_id; |
66 |
||
0 | 67 |
$switch = false; |
19 | 68 |
if ( get_current_blog_id() !== $blog_id ) { |
0 | 69 |
$switch = true; |
70 |
switch_to_blog( $blog_id ); |
|
71 |
} |
|
72 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
73 |
$blog = get_site( $blog_id ); |
0 | 74 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
75 |
$current_network = get_network(); |
5 | 76 |
|
77 |
// If a full blog object is not available, do not destroy anything. |
|
78 |
if ( $drop && ! $blog ) { |
|
79 |
$drop = false; |
|
80 |
} |
|
81 |
||
0 | 82 |
// Don't destroy the initial, main, or root blog. |
19 | 83 |
if ( $drop |
84 |
&& ( 1 === $blog_id || is_main_site( $blog_id ) |
|
85 |
|| ( $blog->path === $current_network->path && $blog->domain === $current_network->domain ) ) |
|
86 |
) { |
|
0 | 87 |
$drop = false; |
5 | 88 |
} |
89 |
||
90 |
$upload_path = trim( get_option( 'upload_path' ) ); |
|
91 |
||
92 |
// If ms_files_rewriting is enabled and upload_path is empty, wp_upload_dir is not reliable. |
|
93 |
if ( $drop && get_site_option( 'ms_files_rewriting' ) && empty( $upload_path ) ) { |
|
94 |
$drop = false; |
|
95 |
} |
|
0 | 96 |
|
97 |
if ( $drop ) { |
|
9 | 98 |
wp_delete_site( $blog_id ); |
99 |
} else { |
|
100 |
/** This action is documented in wp-includes/ms-blogs.php */ |
|
101 |
do_action_deprecated( 'delete_blog', array( $blog_id, false ), '5.1.0' ); |
|
5 | 102 |
|
9 | 103 |
$users = get_users( |
104 |
array( |
|
105 |
'blog_id' => $blog_id, |
|
106 |
'fields' => 'ids', |
|
107 |
) |
|
108 |
); |
|
0 | 109 |
|
9 | 110 |
// Remove users from this blog. |
111 |
if ( ! empty( $users ) ) { |
|
112 |
foreach ( $users as $user_id ) { |
|
113 |
remove_user_from_blog( $user_id, $blog_id ); |
|
114 |
} |
|
0 | 115 |
} |
116 |
||
9 | 117 |
update_blog_status( $blog_id, 'deleted', 1 ); |
0 | 118 |
|
9 | 119 |
/** This action is documented in wp-includes/ms-blogs.php */ |
120 |
do_action_deprecated( 'deleted_blog', array( $blog_id, false ), '5.1.0' ); |
|
0 | 121 |
} |
122 |
||
9 | 123 |
if ( $switch ) { |
0 | 124 |
restore_current_blog(); |
9 | 125 |
} |
0 | 126 |
} |
127 |
||
5 | 128 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
129 |
* Deletes a user and all of their posts from the network. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
130 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
131 |
* This function: |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
132 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
133 |
* - Deletes all posts (of all post types) authored by the user on all sites on the network |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
134 |
* - Deletes all links owned by the user on all sites on the network |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
135 |
* - Removes the user from all sites on the network |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
136 |
* - Deletes the user from the database |
5 | 137 |
* |
138 |
* @since 3.0.0 |
|
139 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
140 |
* @global wpdb $wpdb WordPress database abstraction object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
141 |
* |
5 | 142 |
* @param int $id The user ID. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
143 |
* @return bool True if the user was deleted, false otherwise. |
5 | 144 |
*/ |
0 | 145 |
function wpmu_delete_user( $id ) { |
146 |
global $wpdb; |
|
147 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
148 |
if ( ! is_numeric( $id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
149 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
150 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
151 |
|
9 | 152 |
$id = (int) $id; |
0 | 153 |
$user = new WP_User( $id ); |
154 |
||
9 | 155 |
if ( ! $user->exists() ) { |
0 | 156 |
return false; |
9 | 157 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
158 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
159 |
// Global super-administrators are protected, and cannot be deleted. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
160 |
$_super_admins = get_super_admins(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
161 |
if ( in_array( $user->user_login, $_super_admins, true ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
162 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
163 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
164 |
|
0 | 165 |
/** |
166 |
* Fires before a user is deleted from the network. |
|
167 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
168 |
* @since MU (3.0.0) |
16 | 169 |
* @since 5.5.0 Added the `$user` parameter. |
0 | 170 |
* |
16 | 171 |
* @param int $id ID of the user about to be deleted from the network. |
172 |
* @param WP_User $user WP_User object of the user about to be deleted from the network. |
|
0 | 173 |
*/ |
16 | 174 |
do_action( 'wpmu_delete_user', $id, $user ); |
0 | 175 |
|
176 |
$blogs = get_blogs_of_user( $id ); |
|
177 |
||
178 |
if ( ! empty( $blogs ) ) { |
|
179 |
foreach ( $blogs as $blog ) { |
|
180 |
switch_to_blog( $blog->userblog_id ); |
|
181 |
remove_user_from_blog( $id, $blog->userblog_id ); |
|
182 |
||
183 |
$post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d", $id ) ); |
|
184 |
foreach ( (array) $post_ids as $post_id ) { |
|
185 |
wp_delete_post( $post_id ); |
|
186 |
} |
|
187 |
||
16 | 188 |
// Clean links. |
0 | 189 |
$link_ids = $wpdb->get_col( $wpdb->prepare( "SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $id ) ); |
190 |
||
191 |
if ( $link_ids ) { |
|
9 | 192 |
foreach ( $link_ids as $link_id ) { |
0 | 193 |
wp_delete_link( $link_id ); |
9 | 194 |
} |
0 | 195 |
} |
196 |
||
197 |
restore_current_blog(); |
|
198 |
} |
|
199 |
} |
|
200 |
||
201 |
$meta = $wpdb->get_col( $wpdb->prepare( "SELECT umeta_id FROM $wpdb->usermeta WHERE user_id = %d", $id ) ); |
|
9 | 202 |
foreach ( $meta as $mid ) { |
0 | 203 |
delete_metadata_by_mid( 'user', $mid ); |
9 | 204 |
} |
0 | 205 |
|
206 |
$wpdb->delete( $wpdb->users, array( 'ID' => $id ) ); |
|
207 |
||
208 |
clean_user_cache( $user ); |
|
209 |
||
5 | 210 |
/** This action is documented in wp-admin/includes/user.php */ |
16 | 211 |
do_action( 'deleted_user', $id, null, $user ); |
0 | 212 |
|
213 |
return true; |
|
214 |
} |
|
215 |
||
5 | 216 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
217 |
* Checks whether a site has used its allotted upload space. |
5 | 218 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
219 |
* @since MU (3.0.0) |
0 | 220 |
* |
19 | 221 |
* @param bool $display_message Optional. If set to true and the quota is exceeded, |
222 |
* a warning message is displayed. Default true. |
|
5 | 223 |
* @return bool True if user is over upload space quota, otherwise false. |
0 | 224 |
*/ |
19 | 225 |
function upload_is_user_over_quota( $display_message = true ) { |
9 | 226 |
if ( get_site_option( 'upload_space_check_disabled' ) ) { |
0 | 227 |
return false; |
9 | 228 |
} |
0 | 229 |
|
230 |
$space_allowed = get_space_allowed(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
231 |
if ( ! is_numeric( $space_allowed ) ) { |
16 | 232 |
$space_allowed = 10; // Default space allowed is 10 MB. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
233 |
} |
0 | 234 |
$space_used = get_space_used(); |
235 |
||
236 |
if ( ( $space_allowed - $space_used ) < 0 ) { |
|
19 | 237 |
if ( $display_message ) { |
9 | 238 |
printf( |
16 | 239 |
/* translators: %s: Allowed space allocation. */ |
9 | 240 |
__( 'Sorry, you have used your space allocation of %s. Please delete some files to upload more files.' ), |
241 |
size_format( $space_allowed * MB_IN_BYTES ) |
|
242 |
); |
|
243 |
} |
|
0 | 244 |
return true; |
245 |
} else { |
|
246 |
return false; |
|
247 |
} |
|
248 |
} |
|
249 |
||
250 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
251 |
* Displays the amount of disk space used by the current site. Not used in core. |
0 | 252 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
253 |
* @since MU (3.0.0) |
0 | 254 |
*/ |
255 |
function display_space_usage() { |
|
256 |
$space_allowed = get_space_allowed(); |
|
9 | 257 |
$space_used = get_space_used(); |
0 | 258 |
|
259 |
$percent_used = ( $space_used / $space_allowed ) * 100; |
|
260 |
||
16 | 261 |
$space = size_format( $space_allowed * MB_IN_BYTES ); |
0 | 262 |
?> |
9 | 263 |
<strong> |
264 |
<?php |
|
16 | 265 |
/* translators: Storage space that's been used. 1: Percentage of used space, 2: Total space allowed in megabytes or gigabytes. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
266 |
printf( __( 'Used: %1$s%% of %2$s' ), number_format( $percent_used ), $space ); |
9 | 267 |
?> |
268 |
</strong> |
|
0 | 269 |
<?php |
270 |
} |
|
271 |
||
272 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
273 |
* Gets the remaining upload space for this site. |
0 | 274 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
275 |
* @since MU (3.0.0) |
0 | 276 |
* |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
277 |
* @param int $size Current max size in bytes. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
278 |
* @return int Max size in bytes. |
0 | 279 |
*/ |
280 |
function fix_import_form_size( $size ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
281 |
if ( upload_is_user_over_quota( false ) ) { |
0 | 282 |
return 0; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
283 |
} |
0 | 284 |
$available = get_upload_space_available(); |
285 |
return min( $size, $available ); |
|
286 |
} |
|
287 |
||
5 | 288 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
289 |
* Displays the site upload space quota setting form on the Edit Site Settings screen. |
5 | 290 |
* |
291 |
* @since 3.0.0 |
|
292 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
293 |
* @param int $id The ID of the site to display the setting for. |
5 | 294 |
*/ |
0 | 295 |
function upload_space_setting( $id ) { |
296 |
switch_to_blog( $id ); |
|
297 |
$quota = get_option( 'blog_upload_space' ); |
|
298 |
restore_current_blog(); |
|
299 |
||
9 | 300 |
if ( ! $quota ) { |
0 | 301 |
$quota = ''; |
9 | 302 |
} |
0 | 303 |
|
304 |
?> |
|
305 |
<tr> |
|
5 | 306 |
<th><label for="blog-upload-space-number"><?php _e( 'Site Upload Space Quota' ); ?></label></th> |
307 |
<td> |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
308 |
<input type="number" step="1" min="0" style="width: 100px" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
309 |
name="option[blog_upload_space]" id="blog-upload-space-number" |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
310 |
aria-describedby="blog-upload-space-desc" value="<?php echo esc_attr( $quota ); ?>" /> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
311 |
<span id="blog-upload-space-desc"><span class="screen-reader-text"> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
312 |
<?php |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
313 |
/* translators: Hidden accessibility text. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
314 |
_e( 'Size in megabytes' ); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
315 |
?> |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
316 |
</span> <?php _e( 'MB (Leave blank for network default)' ); ?></span> |
5 | 317 |
</td> |
0 | 318 |
</tr> |
319 |
<?php |
|
320 |
} |
|
321 |
||
5 | 322 |
/** |
323 |
* Cleans the user cache for a specific user. |
|
324 |
* |
|
325 |
* @since 3.0.0 |
|
326 |
* |
|
327 |
* @param int $id The user ID. |
|
18 | 328 |
* @return int|false The ID of the refreshed user or false if the user does not exist. |
5 | 329 |
*/ |
0 | 330 |
function refresh_user_details( $id ) { |
331 |
$id = (int) $id; |
|
332 |
||
16 | 333 |
$user = get_userdata( $id ); |
334 |
if ( ! $user ) { |
|
0 | 335 |
return false; |
9 | 336 |
} |
0 | 337 |
|
338 |
clean_user_cache( $user ); |
|
339 |
||
340 |
return $id; |
|
341 |
} |
|
342 |
||
5 | 343 |
/** |
344 |
* Returns the language for a language code. |
|
345 |
* |
|
346 |
* @since 3.0.0 |
|
347 |
* |
|
348 |
* @param string $code Optional. The two-letter language code. Default empty. |
|
349 |
* @return string The language corresponding to $code if it exists. If it does not exist, |
|
350 |
* then the first two letters of $code is returned. |
|
351 |
*/ |
|
0 | 352 |
function format_code_lang( $code = '' ) { |
9 | 353 |
$code = strtolower( substr( $code, 0, 2 ) ); |
0 | 354 |
$lang_codes = array( |
9 | 355 |
'aa' => 'Afar', |
356 |
'ab' => 'Abkhazian', |
|
357 |
'af' => 'Afrikaans', |
|
358 |
'ak' => 'Akan', |
|
359 |
'sq' => 'Albanian', |
|
360 |
'am' => 'Amharic', |
|
361 |
'ar' => 'Arabic', |
|
362 |
'an' => 'Aragonese', |
|
363 |
'hy' => 'Armenian', |
|
364 |
'as' => 'Assamese', |
|
365 |
'av' => 'Avaric', |
|
366 |
'ae' => 'Avestan', |
|
367 |
'ay' => 'Aymara', |
|
368 |
'az' => 'Azerbaijani', |
|
369 |
'ba' => 'Bashkir', |
|
370 |
'bm' => 'Bambara', |
|
371 |
'eu' => 'Basque', |
|
372 |
'be' => 'Belarusian', |
|
373 |
'bn' => 'Bengali', |
|
374 |
'bh' => 'Bihari', |
|
375 |
'bi' => 'Bislama', |
|
376 |
'bs' => 'Bosnian', |
|
377 |
'br' => 'Breton', |
|
378 |
'bg' => 'Bulgarian', |
|
379 |
'my' => 'Burmese', |
|
380 |
'ca' => 'Catalan; Valencian', |
|
381 |
'ch' => 'Chamorro', |
|
382 |
'ce' => 'Chechen', |
|
383 |
'zh' => 'Chinese', |
|
384 |
'cu' => 'Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church Slavonic', |
|
385 |
'cv' => 'Chuvash', |
|
386 |
'kw' => 'Cornish', |
|
387 |
'co' => 'Corsican', |
|
388 |
'cr' => 'Cree', |
|
389 |
'cs' => 'Czech', |
|
390 |
'da' => 'Danish', |
|
391 |
'dv' => 'Divehi; Dhivehi; Maldivian', |
|
392 |
'nl' => 'Dutch; Flemish', |
|
393 |
'dz' => 'Dzongkha', |
|
394 |
'en' => 'English', |
|
395 |
'eo' => 'Esperanto', |
|
396 |
'et' => 'Estonian', |
|
397 |
'ee' => 'Ewe', |
|
398 |
'fo' => 'Faroese', |
|
399 |
'fj' => 'Fijjian', |
|
400 |
'fi' => 'Finnish', |
|
401 |
'fr' => 'French', |
|
402 |
'fy' => 'Western Frisian', |
|
403 |
'ff' => 'Fulah', |
|
404 |
'ka' => 'Georgian', |
|
405 |
'de' => 'German', |
|
406 |
'gd' => 'Gaelic; Scottish Gaelic', |
|
407 |
'ga' => 'Irish', |
|
408 |
'gl' => 'Galician', |
|
409 |
'gv' => 'Manx', |
|
410 |
'el' => 'Greek, Modern', |
|
411 |
'gn' => 'Guarani', |
|
412 |
'gu' => 'Gujarati', |
|
413 |
'ht' => 'Haitian; Haitian Creole', |
|
414 |
'ha' => 'Hausa', |
|
415 |
'he' => 'Hebrew', |
|
416 |
'hz' => 'Herero', |
|
417 |
'hi' => 'Hindi', |
|
418 |
'ho' => 'Hiri Motu', |
|
419 |
'hu' => 'Hungarian', |
|
420 |
'ig' => 'Igbo', |
|
421 |
'is' => 'Icelandic', |
|
422 |
'io' => 'Ido', |
|
423 |
'ii' => 'Sichuan Yi', |
|
424 |
'iu' => 'Inuktitut', |
|
425 |
'ie' => 'Interlingue', |
|
426 |
'ia' => 'Interlingua (International Auxiliary Language Association)', |
|
427 |
'id' => 'Indonesian', |
|
428 |
'ik' => 'Inupiaq', |
|
429 |
'it' => 'Italian', |
|
430 |
'jv' => 'Javanese', |
|
431 |
'ja' => 'Japanese', |
|
432 |
'kl' => 'Kalaallisut; Greenlandic', |
|
433 |
'kn' => 'Kannada', |
|
434 |
'ks' => 'Kashmiri', |
|
435 |
'kr' => 'Kanuri', |
|
436 |
'kk' => 'Kazakh', |
|
437 |
'km' => 'Central Khmer', |
|
438 |
'ki' => 'Kikuyu; Gikuyu', |
|
439 |
'rw' => 'Kinyarwanda', |
|
440 |
'ky' => 'Kirghiz; Kyrgyz', |
|
441 |
'kv' => 'Komi', |
|
442 |
'kg' => 'Kongo', |
|
443 |
'ko' => 'Korean', |
|
444 |
'kj' => 'Kuanyama; Kwanyama', |
|
445 |
'ku' => 'Kurdish', |
|
446 |
'lo' => 'Lao', |
|
447 |
'la' => 'Latin', |
|
448 |
'lv' => 'Latvian', |
|
449 |
'li' => 'Limburgan; Limburger; Limburgish', |
|
450 |
'ln' => 'Lingala', |
|
451 |
'lt' => 'Lithuanian', |
|
452 |
'lb' => 'Luxembourgish; Letzeburgesch', |
|
453 |
'lu' => 'Luba-Katanga', |
|
454 |
'lg' => 'Ganda', |
|
455 |
'mk' => 'Macedonian', |
|
456 |
'mh' => 'Marshallese', |
|
457 |
'ml' => 'Malayalam', |
|
458 |
'mi' => 'Maori', |
|
459 |
'mr' => 'Marathi', |
|
460 |
'ms' => 'Malay', |
|
461 |
'mg' => 'Malagasy', |
|
462 |
'mt' => 'Maltese', |
|
463 |
'mo' => 'Moldavian', |
|
464 |
'mn' => 'Mongolian', |
|
465 |
'na' => 'Nauru', |
|
466 |
'nv' => 'Navajo; Navaho', |
|
467 |
'nr' => 'Ndebele, South; South Ndebele', |
|
468 |
'nd' => 'Ndebele, North; North Ndebele', |
|
469 |
'ng' => 'Ndonga', |
|
470 |
'ne' => 'Nepali', |
|
471 |
'nn' => 'Norwegian Nynorsk; Nynorsk, Norwegian', |
|
472 |
'nb' => 'Bokmål, Norwegian, Norwegian Bokmål', |
|
473 |
'no' => 'Norwegian', |
|
474 |
'ny' => 'Chichewa; Chewa; Nyanja', |
|
475 |
'oc' => 'Occitan, Provençal', |
|
476 |
'oj' => 'Ojibwa', |
|
477 |
'or' => 'Oriya', |
|
478 |
'om' => 'Oromo', |
|
479 |
'os' => 'Ossetian; Ossetic', |
|
480 |
'pa' => 'Panjabi; Punjabi', |
|
481 |
'fa' => 'Persian', |
|
482 |
'pi' => 'Pali', |
|
483 |
'pl' => 'Polish', |
|
484 |
'pt' => 'Portuguese', |
|
485 |
'ps' => 'Pushto', |
|
486 |
'qu' => 'Quechua', |
|
487 |
'rm' => 'Romansh', |
|
488 |
'ro' => 'Romanian', |
|
489 |
'rn' => 'Rundi', |
|
490 |
'ru' => 'Russian', |
|
491 |
'sg' => 'Sango', |
|
492 |
'sa' => 'Sanskrit', |
|
493 |
'sr' => 'Serbian', |
|
494 |
'hr' => 'Croatian', |
|
495 |
'si' => 'Sinhala; Sinhalese', |
|
496 |
'sk' => 'Slovak', |
|
497 |
'sl' => 'Slovenian', |
|
498 |
'se' => 'Northern Sami', |
|
499 |
'sm' => 'Samoan', |
|
500 |
'sn' => 'Shona', |
|
501 |
'sd' => 'Sindhi', |
|
502 |
'so' => 'Somali', |
|
503 |
'st' => 'Sotho, Southern', |
|
504 |
'es' => 'Spanish; Castilian', |
|
505 |
'sc' => 'Sardinian', |
|
506 |
'ss' => 'Swati', |
|
507 |
'su' => 'Sundanese', |
|
508 |
'sw' => 'Swahili', |
|
509 |
'sv' => 'Swedish', |
|
510 |
'ty' => 'Tahitian', |
|
511 |
'ta' => 'Tamil', |
|
512 |
'tt' => 'Tatar', |
|
513 |
'te' => 'Telugu', |
|
514 |
'tg' => 'Tajik', |
|
515 |
'tl' => 'Tagalog', |
|
516 |
'th' => 'Thai', |
|
517 |
'bo' => 'Tibetan', |
|
518 |
'ti' => 'Tigrinya', |
|
519 |
'to' => 'Tonga (Tonga Islands)', |
|
520 |
'tn' => 'Tswana', |
|
521 |
'ts' => 'Tsonga', |
|
522 |
'tk' => 'Turkmen', |
|
523 |
'tr' => 'Turkish', |
|
524 |
'tw' => 'Twi', |
|
525 |
'ug' => 'Uighur; Uyghur', |
|
526 |
'uk' => 'Ukrainian', |
|
527 |
'ur' => 'Urdu', |
|
528 |
'uz' => 'Uzbek', |
|
529 |
've' => 'Venda', |
|
530 |
'vi' => 'Vietnamese', |
|
531 |
'vo' => 'Volapük', |
|
532 |
'cy' => 'Welsh', |
|
533 |
'wa' => 'Walloon', |
|
534 |
'wo' => 'Wolof', |
|
535 |
'xh' => 'Xhosa', |
|
536 |
'yi' => 'Yiddish', |
|
537 |
'yo' => 'Yoruba', |
|
538 |
'za' => 'Zhuang; Chuang', |
|
539 |
'zu' => 'Zulu', |
|
540 |
); |
|
0 | 541 |
|
542 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
543 |
* Filters the language codes. |
0 | 544 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
545 |
* @since MU (3.0.0) |
0 | 546 |
* |
9 | 547 |
* @param string[] $lang_codes Array of key/value pairs of language codes where key is the short version. |
548 |
* @param string $code A two-letter designation of the language. |
|
0 | 549 |
*/ |
550 |
$lang_codes = apply_filters( 'lang_codes', $lang_codes, $code ); |
|
551 |
return strtr( $code, $lang_codes ); |
|
552 |
} |
|
553 |
||
5 | 554 |
/** |
555 |
* Displays an access denied message when a user tries to view a site's dashboard they |
|
556 |
* do not have access to. |
|
557 |
* |
|
558 |
* @since 3.2.0 |
|
559 |
* @access private |
|
560 |
*/ |
|
0 | 561 |
function _access_denied_splash() { |
9 | 562 |
if ( ! is_user_logged_in() || is_network_admin() ) { |
0 | 563 |
return; |
9 | 564 |
} |
0 | 565 |
|
566 |
$blogs = get_blogs_of_user( get_current_user_id() ); |
|
567 |
||
9 | 568 |
if ( wp_list_filter( $blogs, array( 'userblog_id' => get_current_blog_id() ) ) ) { |
0 | 569 |
return; |
9 | 570 |
} |
0 | 571 |
|
572 |
$blog_name = get_bloginfo( 'name' ); |
|
573 |
||
9 | 574 |
if ( empty( $blogs ) ) { |
16 | 575 |
wp_die( |
576 |
sprintf( |
|
577 |
/* translators: 1: Site title. */ |
|
578 |
__( 'You attempted to access the "%1$s" dashboard, but you do not currently have privileges on this site. If you believe you should be able to access the "%1$s" dashboard, please contact your network administrator.' ), |
|
579 |
$blog_name |
|
580 |
), |
|
581 |
403 |
|
582 |
); |
|
9 | 583 |
} |
0 | 584 |
|
16 | 585 |
$output = '<p>' . sprintf( |
586 |
/* translators: 1: Site title. */ |
|
587 |
__( 'You attempted to access the "%1$s" dashboard, but you do not currently have privileges on this site. If you believe you should be able to access the "%1$s" dashboard, please contact your network administrator.' ), |
|
588 |
$blog_name |
|
589 |
) . '</p>'; |
|
0 | 590 |
$output .= '<p>' . __( 'If you reached this screen by accident and meant to visit one of your own sites, here are some shortcuts to help you find your way.' ) . '</p>'; |
591 |
||
9 | 592 |
$output .= '<h3>' . __( 'Your Sites' ) . '</h3>'; |
0 | 593 |
$output .= '<table>'; |
594 |
||
595 |
foreach ( $blogs as $blog ) { |
|
5 | 596 |
$output .= '<tr>'; |
597 |
$output .= "<td>{$blog->blogname}</td>"; |
|
598 |
$output .= '<td><a href="' . esc_url( get_admin_url( $blog->userblog_id ) ) . '">' . __( 'Visit Dashboard' ) . '</a> | ' . |
|
9 | 599 |
'<a href="' . esc_url( get_home_url( $blog->userblog_id ) ) . '">' . __( 'View Site' ) . '</a></td>'; |
5 | 600 |
$output .= '</tr>'; |
0 | 601 |
} |
5 | 602 |
|
0 | 603 |
$output .= '</table>'; |
604 |
||
5 | 605 |
wp_die( $output, 403 ); |
0 | 606 |
} |
607 |
||
5 | 608 |
/** |
609 |
* Checks if the current user has permissions to import new users. |
|
610 |
* |
|
611 |
* @since 3.0.0 |
|
612 |
* |
|
613 |
* @param string $permission A permission to be checked. Currently not used. |
|
614 |
* @return bool True if the user has proper permissions, false if they do not. |
|
615 |
*/ |
|
0 | 616 |
function check_import_new_users( $permission ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
617 |
if ( ! current_user_can( 'manage_network_users' ) ) { |
0 | 618 |
return false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
619 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
620 |
|
0 | 621 |
return true; |
622 |
} |
|
623 |
// See "import_allow_fetch_attachments" and "import_attachment_size_limit" filters too. |
|
624 |
||
5 | 625 |
/** |
626 |
* Generates and displays a drop-down of available languages. |
|
627 |
* |
|
628 |
* @since 3.0.0 |
|
629 |
* |
|
9 | 630 |
* @param string[] $lang_files Optional. An array of the language files. Default empty array. |
631 |
* @param string $current Optional. The current language code. Default empty. |
|
5 | 632 |
*/ |
0 | 633 |
function mu_dropdown_languages( $lang_files = array(), $current = '' ) { |
9 | 634 |
$flag = false; |
0 | 635 |
$output = array(); |
636 |
||
637 |
foreach ( (array) $lang_files as $val ) { |
|
638 |
$code_lang = basename( $val, '.mo' ); |
|
639 |
||
16 | 640 |
if ( 'en_US' === $code_lang ) { // American English. |
9 | 641 |
$flag = true; |
642 |
$ae = __( 'American English' ); |
|
643 |
$output[ $ae ] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . $ae . '</option>'; |
|
16 | 644 |
} elseif ( 'en_GB' === $code_lang ) { // British English. |
9 | 645 |
$flag = true; |
646 |
$be = __( 'British English' ); |
|
647 |
$output[ $be ] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . $be . '</option>'; |
|
0 | 648 |
} else { |
9 | 649 |
$translated = format_code_lang( $code_lang ); |
650 |
$output[ $translated ] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . esc_html( $translated ) . '</option>'; |
|
0 | 651 |
} |
652 |
} |
|
653 |
||
16 | 654 |
if ( false === $flag ) { // WordPress English. |
9 | 655 |
$output[] = '<option value=""' . selected( $current, '', false ) . '>' . __( 'English' ) . '</option>'; |
656 |
} |
|
0 | 657 |
|
16 | 658 |
// Order by name. |
0 | 659 |
uksort( $output, 'strnatcasecmp' ); |
5 | 660 |
|
0 | 661 |
/** |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
662 |
* Filters the languages available in the dropdown. |
0 | 663 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
664 |
* @since MU (3.0.0) |
0 | 665 |
* |
9 | 666 |
* @param string[] $output Array of HTML output for the dropdown. |
667 |
* @param string[] $lang_files Array of available language files. |
|
668 |
* @param string $current The current language code. |
|
0 | 669 |
*/ |
670 |
$output = apply_filters( 'mu_dropdown_languages', $output, $lang_files, $current ); |
|
5 | 671 |
|
0 | 672 |
echo implode( "\n\t", $output ); |
673 |
} |
|
674 |
||
5 | 675 |
/** |
676 |
* Displays an admin notice to upgrade all sites after a core upgrade. |
|
677 |
* |
|
678 |
* @since 3.0.0 |
|
679 |
* |
|
16 | 680 |
* @global int $wp_db_version WordPress database version. |
19 | 681 |
* @global string $pagenow The filename of the current screen. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
682 |
* |
18 | 683 |
* @return void|false Void on success. False if the current user is not a super admin. |
5 | 684 |
*/ |
0 | 685 |
function site_admin_notice() { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
686 |
global $wp_db_version, $pagenow; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
687 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
688 |
if ( ! current_user_can( 'upgrade_network' ) ) { |
0 | 689 |
return false; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
690 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
691 |
|
16 | 692 |
if ( 'upgrade.php' === $pagenow ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
693 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
694 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
695 |
|
19 | 696 |
if ( (int) get_site_option( 'wpmu_upgrade_site' ) !== $wp_db_version ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
697 |
$upgrade_network_message = sprintf( |
16 | 698 |
/* translators: %s: URL to Upgrade Network screen. */ |
699 |
__( 'Thank you for Updating! Please visit the <a href="%s">Upgrade Network</a> page to update all your sites.' ), |
|
700 |
esc_url( network_admin_url( 'upgrade.php' ) ) |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
701 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
702 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
703 |
wp_admin_notice( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
704 |
$upgrade_network_message, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
705 |
array( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
706 |
'type' => 'warning', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
707 |
'additional_classes' => array( 'update-nag', 'inline' ), |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
708 |
'paragraph_wrap' => false, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
709 |
) |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
710 |
); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
711 |
} |
0 | 712 |
} |
713 |
||
5 | 714 |
/** |
715 |
* Avoids a collision between a site slug and a permalink slug. |
|
716 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
717 |
* In a subdirectory installation this will make sure that a site and a post do not use the |
5 | 718 |
* same subdirectory by checking for a site with the same name as a new post. |
719 |
* |
|
720 |
* @since 3.0.0 |
|
721 |
* |
|
722 |
* @param array $data An array of post data. |
|
723 |
* @param array $postarr An array of posts. Not currently used. |
|
724 |
* @return array The new array of post data after checking for collisions. |
|
725 |
*/ |
|
0 | 726 |
function avoid_blog_page_permalink_collision( $data, $postarr ) { |
9 | 727 |
if ( is_subdomain_install() ) { |
0 | 728 |
return $data; |
9 | 729 |
} |
16 | 730 |
if ( 'page' !== $data['post_type'] ) { |
0 | 731 |
return $data; |
9 | 732 |
} |
16 | 733 |
if ( ! isset( $data['post_name'] ) || '' === $data['post_name'] ) { |
0 | 734 |
return $data; |
9 | 735 |
} |
736 |
if ( ! is_main_site() ) { |
|
0 | 737 |
return $data; |
9 | 738 |
} |
19 | 739 |
if ( isset( $data['post_parent'] ) && $data['post_parent'] ) { |
740 |
return $data; |
|
741 |
} |
|
0 | 742 |
|
743 |
$post_name = $data['post_name']; |
|
9 | 744 |
$c = 0; |
19 | 745 |
|
9 | 746 |
while ( $c < 10 && get_id_from_blogname( $post_name ) ) { |
0 | 747 |
$post_name .= mt_rand( 1, 10 ); |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
748 |
++$c; |
0 | 749 |
} |
19 | 750 |
|
751 |
if ( $post_name !== $data['post_name'] ) { |
|
0 | 752 |
$data['post_name'] = $post_name; |
753 |
} |
|
19 | 754 |
|
0 | 755 |
return $data; |
756 |
} |
|
757 |
||
5 | 758 |
/** |
759 |
* Handles the display of choosing a user's primary site. |
|
760 |
* |
|
761 |
* This displays the user's primary site and allows the user to choose |
|
762 |
* which site is primary. |
|
763 |
* |
|
764 |
* @since 3.0.0 |
|
765 |
*/ |
|
0 | 766 |
function choose_primary_blog() { |
767 |
?> |
|
9 | 768 |
<table class="form-table" role="presentation"> |
0 | 769 |
<tr> |
16 | 770 |
<?php /* translators: My Sites label. */ ?> |
5 | 771 |
<th scope="row"><label for="primary_blog"><?php _e( 'Primary Site' ); ?></label></th> |
0 | 772 |
<td> |
773 |
<?php |
|
9 | 774 |
$all_blogs = get_blogs_of_user( get_current_user_id() ); |
19 | 775 |
$primary_blog = (int) get_user_meta( get_current_user_id(), 'primary_blog', true ); |
0 | 776 |
if ( count( $all_blogs ) > 1 ) { |
777 |
$found = false; |
|
778 |
?> |
|
5 | 779 |
<select name="primary_blog" id="primary_blog"> |
9 | 780 |
<?php |
781 |
foreach ( (array) $all_blogs as $blog ) { |
|
19 | 782 |
if ( $blog->userblog_id === $primary_blog ) { |
0 | 783 |
$found = true; |
9 | 784 |
} |
785 |
?> |
|
786 |
<option value="<?php echo $blog->userblog_id; ?>"<?php selected( $primary_blog, $blog->userblog_id ); ?>><?php echo esc_url( get_home_url( $blog->userblog_id ) ); ?></option> |
|
787 |
<?php |
|
788 |
} |
|
789 |
?> |
|
0 | 790 |
</select> |
791 |
<?php |
|
9 | 792 |
if ( ! $found ) { |
5 | 793 |
$blog = reset( $all_blogs ); |
0 | 794 |
update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id ); |
795 |
} |
|
19 | 796 |
} elseif ( 1 === count( $all_blogs ) ) { |
5 | 797 |
$blog = reset( $all_blogs ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
798 |
echo esc_url( get_home_url( $blog->userblog_id ) ); |
19 | 799 |
if ( $blog->userblog_id !== $primary_blog ) { // Set the primary blog again if it's out of sync with blog list. |
0 | 800 |
update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id ); |
9 | 801 |
} |
0 | 802 |
} else { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
803 |
_e( 'Not available' ); |
0 | 804 |
} |
805 |
?> |
|
806 |
</td> |
|
807 |
</tr> |
|
808 |
</table> |
|
809 |
<?php |
|
810 |
} |
|
811 |
||
812 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
813 |
* Determines whether or not this network from this page can be edited. |
0 | 814 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
815 |
* By default editing of network is restricted to the Network Admin for that `$network_id`. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
816 |
* This function allows for this to be overridden. |
0 | 817 |
* |
818 |
* @since 3.1.0 |
|
5 | 819 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
820 |
* @param int $network_id The network ID to check. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
821 |
* @return bool True if network can be edited, false otherwise. |
0 | 822 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
823 |
function can_edit_network( $network_id ) { |
19 | 824 |
if ( get_current_network_id() === (int) $network_id ) { |
0 | 825 |
$result = true; |
9 | 826 |
} else { |
0 | 827 |
$result = false; |
9 | 828 |
} |
0 | 829 |
|
830 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
831 |
* Filters whether this network can be edited from this page. |
0 | 832 |
* |
833 |
* @since 3.1.0 |
|
834 |
* |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
835 |
* @param bool $result Whether the network can be edited from this page. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
836 |
* @param int $network_id The network ID to check. |
0 | 837 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
838 |
return apply_filters( 'can_edit_network', $result, $network_id ); |
0 | 839 |
} |
840 |
||
841 |
/** |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
842 |
* Prints thickbox image paths for Network Admin. |
0 | 843 |
* |
844 |
* @since 3.1.0 |
|
5 | 845 |
* |
0 | 846 |
* @access private |
847 |
*/ |
|
848 |
function _thickbox_path_admin_subfolder() { |
|
9 | 849 |
?> |
0 | 850 |
<script type="text/javascript"> |
18 | 851 |
var tb_pathToImage = "<?php echo esc_js( includes_url( 'js/thickbox/loadingAnimation.gif', 'relative' ) ); ?>"; |
0 | 852 |
</script> |
9 | 853 |
<?php |
0 | 854 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
855 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
856 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
857 |
* @param array $users |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
858 |
* @return bool |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
859 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
860 |
function confirm_delete_users( $users ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
861 |
$current_user = wp_get_current_user(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
862 |
if ( ! is_array( $users ) || empty( $users ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
863 |
return false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
864 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
865 |
?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
866 |
<h1><?php esc_html_e( 'Users' ); ?></h1> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
867 |
|
16 | 868 |
<?php if ( 1 === count( $users ) ) : ?> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
869 |
<p><?php _e( 'You have chosen to delete the user from all networks and sites.' ); ?></p> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
870 |
<?php else : ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
871 |
<p><?php _e( 'You have chosen to delete the following users from all networks and sites.' ); ?></p> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
872 |
<?php endif; ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
873 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
874 |
<form action="users.php?action=dodelete" method="post"> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
875 |
<input type="hidden" name="dodelete" /> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
876 |
<?php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
877 |
wp_nonce_field( 'ms-users-delete' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
878 |
$site_admins = get_super_admins(); |
9 | 879 |
$admin_out = '<option value="' . esc_attr( $current_user->ID ) . '">' . $current_user->user_login . '</option>'; |
880 |
?> |
|
881 |
<table class="form-table" role="presentation"> |
|
882 |
<?php |
|
16 | 883 |
$allusers = (array) $_POST['allusers']; |
884 |
foreach ( $allusers as $user_id ) { |
|
19 | 885 |
if ( '' !== $user_id && '0' !== $user_id ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
886 |
$delete_user = get_userdata( $user_id ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
887 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
888 |
if ( ! current_user_can( 'delete_user', $delete_user->ID ) ) { |
16 | 889 |
wp_die( |
890 |
sprintf( |
|
891 |
/* translators: %s: User login. */ |
|
892 |
__( 'Warning! User %s cannot be deleted.' ), |
|
893 |
$delete_user->user_login |
|
894 |
) |
|
895 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
896 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
897 |
|
16 | 898 |
if ( in_array( $delete_user->user_login, $site_admins, true ) ) { |
899 |
wp_die( |
|
900 |
sprintf( |
|
901 |
/* translators: %s: User login. */ |
|
902 |
__( 'Warning! User cannot be deleted. The user %s is a network administrator.' ), |
|
903 |
'<em>' . $delete_user->user_login . '</em>' |
|
904 |
) |
|
905 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
906 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
907 |
?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
908 |
<tr> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
909 |
<th scope="row"><?php echo $delete_user->user_login; ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
910 |
<?php echo '<input type="hidden" name="user[]" value="' . esc_attr( $user_id ) . '" />' . "\n"; ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
911 |
</th> |
9 | 912 |
<?php |
913 |
$blogs = get_blogs_of_user( $user_id, true ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
914 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
915 |
if ( ! empty( $blogs ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
916 |
?> |
9 | 917 |
<td><fieldset><p><legend> |
918 |
<?php |
|
919 |
printf( |
|
16 | 920 |
/* translators: %s: User login. */ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
921 |
__( 'What should be done with content owned by %s?' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
922 |
'<em>' . $delete_user->user_login . '</em>' |
9 | 923 |
); |
924 |
?> |
|
925 |
</legend></p> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
926 |
<?php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
927 |
foreach ( (array) $blogs as $key => $details ) { |
9 | 928 |
$blog_users = get_users( |
929 |
array( |
|
930 |
'blog_id' => $details->userblog_id, |
|
931 |
'fields' => array( 'ID', 'user_login' ), |
|
932 |
) |
|
933 |
); |
|
16 | 934 |
|
9 | 935 |
if ( is_array( $blog_users ) && ! empty( $blog_users ) ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
936 |
$user_site = "<a href='" . esc_url( get_home_url( $details->userblog_id ) ) . "'>{$details->blogname}</a>"; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
937 |
$user_dropdown = '<label for="reassign_user" class="screen-reader-text">' . |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
938 |
/* translators: Hidden accessibility text. */ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
939 |
__( 'Select a user' ) . |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
940 |
'</label>'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
941 |
$user_dropdown .= "<select name='blog[$user_id][$key]' id='reassign_user'>"; |
9 | 942 |
$user_list = ''; |
16 | 943 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
944 |
foreach ( $blog_users as $user ) { |
16 | 945 |
if ( ! in_array( (int) $user->ID, $allusers, true ) ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
946 |
$user_list .= "<option value='{$user->ID}'>{$user->user_login}</option>"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
947 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
948 |
} |
16 | 949 |
|
950 |
if ( '' === $user_list ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
951 |
$user_list = $admin_out; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
952 |
} |
16 | 953 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
954 |
$user_dropdown .= $user_list; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
955 |
$user_dropdown .= "</select>\n"; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
956 |
?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
957 |
<ul style="list-style:none;"> |
16 | 958 |
<li> |
959 |
<?php |
|
960 |
/* translators: %s: Link to user's site. */ |
|
961 |
printf( __( 'Site: %s' ), $user_site ); |
|
962 |
?> |
|
963 |
</li> |
|
9 | 964 |
<li><label><input type="radio" id="delete_option0" name="delete[<?php echo $details->userblog_id . '][' . $delete_user->ID; ?>]" value="delete" checked="checked" /> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
965 |
<?php _e( 'Delete all content.' ); ?></label></li> |
9 | 966 |
<li><label><input type="radio" id="delete_option1" name="delete[<?php echo $details->userblog_id . '][' . $delete_user->ID; ?>]" value="reassign" /> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
967 |
<?php _e( 'Attribute all content to:' ); ?></label> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
968 |
<?php echo $user_dropdown; ?></li> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
969 |
</ul> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
970 |
<?php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
971 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
972 |
} |
9 | 973 |
echo '</fieldset></td></tr>'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
974 |
} else { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
975 |
?> |
9 | 976 |
<td><p><?php _e( 'User has no sites or content and will be deleted.' ); ?></p></td> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
977 |
<?php } ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
978 |
</tr> |
9 | 979 |
<?php |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
980 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
981 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
982 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
983 |
?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
984 |
</table> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
985 |
<?php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
986 |
/** This action is documented in wp-admin/users.php */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
987 |
do_action( 'delete_user_form', $current_user, $allusers ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
988 |
|
16 | 989 |
if ( 1 === count( $users ) ) : |
9 | 990 |
?> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
991 |
<p><?php _e( 'Once you hit “Confirm Deletion”, the user will be permanently removed.' ); ?></p> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
992 |
<?php else : ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
993 |
<p><?php _e( 'Once you hit “Confirm Deletion”, these users will be permanently removed.' ); ?></p> |
9 | 994 |
<?php |
995 |
endif; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
996 |
|
9 | 997 |
submit_button( __( 'Confirm Deletion' ), 'primary' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
998 |
?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
999 |
</form> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1000 |
<?php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1001 |
return true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1002 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1003 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1004 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1005 |
* Prints JavaScript in the header on the Network Settings screen. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1006 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1007 |
* @since 4.1.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1008 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1009 |
function network_settings_add_js() { |
9 | 1010 |
?> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1011 |
<script type="text/javascript"> |
19 | 1012 |
jQuery( function($) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1013 |
var languageSelect = $( '#WPLANG' ); |
18 | 1014 |
$( 'form' ).on( 'submit', function() { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1015 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1016 |
* Don't show a spinner for English and installed languages, |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1017 |
* as there is nothing to download. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1018 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1019 |
if ( ! languageSelect.find( 'option:selected' ).data( 'installed' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1020 |
$( '#submit', this ).after( '<span class="spinner language-install-spinner is-active" />' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1021 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1022 |
}); |
19 | 1023 |
} ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1024 |
</script> |
9 | 1025 |
<?php |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1026 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1027 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1028 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1029 |
* Outputs the HTML for a network's "Edit Site" tabular interface. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1030 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1031 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1032 |
* |
19 | 1033 |
* @global string $pagenow The filename of the current screen. |
18 | 1034 |
* |
16 | 1035 |
* @param array $args { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1036 |
* Optional. Array or string of Query parameters. Default empty array. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1037 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1038 |
* @type int $blog_id The site ID. Default is the current site. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1039 |
* @type array $links The tabs to include with (label|url|cap) keys. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1040 |
* @type string $selected The ID of the selected link. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1041 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1042 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1043 |
function network_edit_site_nav( $args = array() ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1044 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1045 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1046 |
* Filters the links that appear on site-editing network pages. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1047 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1048 |
* Default links: 'site-info', 'site-users', 'site-themes', and 'site-settings'. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1049 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1050 |
* @since 4.6.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1051 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1052 |
* @param array $links { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1053 |
* An array of link data representing individual network admin pages. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1054 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1055 |
* @type array $link_slug { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1056 |
* An array of information about the individual link to a page. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1057 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1058 |
* $type string $label Label to use for the link. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1059 |
* $type string $url URL, relative to `network_admin_url()` to use for the link. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1060 |
* $type string $cap Capability required to see the link. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1061 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1062 |
* } |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1063 |
*/ |
9 | 1064 |
$links = apply_filters( |
1065 |
'network_edit_site_nav_links', |
|
1066 |
array( |
|
1067 |
'site-info' => array( |
|
1068 |
'label' => __( 'Info' ), |
|
1069 |
'url' => 'site-info.php', |
|
1070 |
'cap' => 'manage_sites', |
|
1071 |
), |
|
1072 |
'site-users' => array( |
|
1073 |
'label' => __( 'Users' ), |
|
1074 |
'url' => 'site-users.php', |
|
1075 |
'cap' => 'manage_sites', |
|
1076 |
), |
|
1077 |
'site-themes' => array( |
|
1078 |
'label' => __( 'Themes' ), |
|
1079 |
'url' => 'site-themes.php', |
|
1080 |
'cap' => 'manage_sites', |
|
1081 |
), |
|
1082 |
'site-settings' => array( |
|
1083 |
'label' => __( 'Settings' ), |
|
1084 |
'url' => 'site-settings.php', |
|
1085 |
'cap' => 'manage_sites', |
|
1086 |
), |
|
1087 |
) |
|
1088 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1089 |
|
16 | 1090 |
// Parse arguments. |
1091 |
$parsed_args = wp_parse_args( |
|
9 | 1092 |
$args, |
1093 |
array( |
|
1094 |
'blog_id' => isset( $_GET['blog_id'] ) ? (int) $_GET['blog_id'] : 0, |
|
1095 |
'links' => $links, |
|
1096 |
'selected' => 'site-info', |
|
1097 |
) |
|
1098 |
); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1099 |
|
16 | 1100 |
// Setup the links array. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1101 |
$screen_links = array(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1102 |
|
16 | 1103 |
// Loop through tabs. |
1104 |
foreach ( $parsed_args['links'] as $link_id => $link ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1105 |
|
16 | 1106 |
// Skip link if user can't access. |
1107 |
if ( ! current_user_can( $link['cap'], $parsed_args['blog_id'] ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1108 |
continue; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1109 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1110 |
|
16 | 1111 |
// Link classes. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1112 |
$classes = array( 'nav-tab' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1113 |
|
9 | 1114 |
// Aria-current attribute. |
1115 |
$aria_current = ''; |
|
1116 |
||
16 | 1117 |
// Selected is set by the parent OR assumed by the $pagenow global. |
1118 |
if ( $parsed_args['selected'] === $link_id || $link['url'] === $GLOBALS['pagenow'] ) { |
|
9 | 1119 |
$classes[] = 'nav-tab-active'; |
1120 |
$aria_current = ' aria-current="page"'; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1121 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1122 |
|
16 | 1123 |
// Escape each class. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1124 |
$esc_classes = implode( ' ', $classes ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1125 |
|
16 | 1126 |
// Get the URL for this link. |
1127 |
$url = add_query_arg( array( 'id' => $parsed_args['blog_id'] ), network_admin_url( $link['url'] ) ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1128 |
|
16 | 1129 |
// Add link to nav links. |
9 | 1130 |
$screen_links[ $link_id ] = '<a href="' . esc_url( $url ) . '" id="' . esc_attr( $link_id ) . '" class="' . $esc_classes . '"' . $aria_current . '>' . esc_html( $link['label'] ) . '</a>'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1131 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1132 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1133 |
// All done! |
9 | 1134 |
echo '<nav class="nav-tab-wrapper wp-clearfix" aria-label="' . esc_attr__( 'Secondary menu' ) . '">'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1135 |
echo implode( '', $screen_links ); |
9 | 1136 |
echo '</nav>'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1137 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1138 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1139 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1140 |
* Returns the arguments for the help tab on the Edit Site screens. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1141 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1142 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1143 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1144 |
* @return array Help tab arguments. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1145 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1146 |
function get_site_screen_help_tab_args() { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1147 |
return array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1148 |
'id' => 'overview', |
9 | 1149 |
'title' => __( 'Overview' ), |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1150 |
'content' => |
9 | 1151 |
'<p>' . __( 'The menu is for editing information specific to individual sites, particularly if the admin area of a site is unavailable.' ) . '</p>' . |
1152 |
'<p>' . __( '<strong>Info</strong> — The site URL is rarely edited as this can cause the site to not work properly. The Registered date and Last Updated date are displayed. Network admins can mark a site as archived, spam, deleted and mature, to remove from public listings or disable.' ) . '</p>' . |
|
1153 |
'<p>' . __( '<strong>Users</strong> — This displays the users associated with this site. You can also change their role, reset their password, or remove them from the site. Removing the user from the site does not remove the user from the network.' ) . '</p>' . |
|
16 | 1154 |
'<p>' . sprintf( |
1155 |
/* translators: %s: URL to Network Themes screen. */ |
|
1156 |
__( '<strong>Themes</strong> — This area shows themes that are not already enabled across the network. Enabling a theme in this menu makes it accessible to this site. It does not activate the theme, but allows it to show in the site’s Appearance menu. To enable a theme for the entire network, see the <a href="%s">Network Themes</a> screen.' ), |
|
1157 |
network_admin_url( 'themes.php' ) |
|
1158 |
) . '</p>' . |
|
9 | 1159 |
'<p>' . __( '<strong>Settings</strong> — This page shows a list of all settings associated with this site. Some are created by WordPress and others are created by plugins you activate. Note that some fields are grayed out and say Serialized Data. You cannot modify these values due to the way the setting is stored in the database.' ) . '</p>', |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1160 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1161 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1162 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1163 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1164 |
* Returns the content for the help sidebar on the Edit Site screens. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1165 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1166 |
* @since 4.9.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1167 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1168 |
* @return string Help sidebar content. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1169 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1170 |
function get_site_screen_help_sidebar_content() { |
9 | 1171 |
return '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1172 |
'<p>' . __( '<a href="https://developer.wordpress.org/advanced-administration/multisite/admin/#network-admin-sites-screen">Documentation on Site Management</a>' ) . '</p>' . |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
1173 |
'<p>' . __( '<a href="https://wordpress.org/support/forum/multisite/">Support forums</a>' ) . '</p>'; |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1174 |
} |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1175 |
|
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1176 |
/** |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1177 |
* Stop execution if the role can not be assigned by the current user. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1178 |
* |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1179 |
* @since 6.8.0 |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1180 |
* |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1181 |
* @param string $role Role the user is attempting to assign. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1182 |
*/ |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1183 |
function wp_ensure_editable_role( $role ) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1184 |
$roles = get_editable_roles(); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1185 |
if ( ! isset( $roles[ $role ] ) ) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1186 |
wp_die( __( 'Sorry, you are not allowed to give users that role.' ), 403 ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1187 |
} |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
1188 |
} |