33 if ( $file_size > ( 1024 * get_site_option( 'fileupload_maxk', 1500 ) ) ) |
33 if ( $file_size > ( 1024 * get_site_option( 'fileupload_maxk', 1500 ) ) ) |
34 $file['error'] = sprintf(__('This file is too big. Files must be less than %1$s KB in size.'), get_site_option( 'fileupload_maxk', 1500 ) ); |
34 $file['error'] = sprintf(__('This file is too big. Files must be less than %1$s KB in size.'), get_site_option( 'fileupload_maxk', 1500 ) ); |
35 if ( upload_is_user_over_quota( false ) ) { |
35 if ( upload_is_user_over_quota( false ) ) { |
36 $file['error'] = __( 'You have used your space quota. Please delete files before uploading.' ); |
36 $file['error'] = __( 'You have used your space quota. Please delete files before uploading.' ); |
37 } |
37 } |
38 if ( $file['error'] != '0' && !isset($_POST['html-upload']) ) |
38 if ( $file['error'] != '0' && ! isset( $_POST['html-upload'] ) && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) { |
39 wp_die( $file['error'] . ' <a href="javascript:history.go(-1)">' . __( 'Back' ) . '</a>' ); |
39 wp_die( $file['error'] . ' <a href="javascript:history.go(-1)">' . __( 'Back' ) . '</a>' ); |
|
40 } |
40 |
41 |
41 return $file; |
42 return $file; |
42 } |
43 } |
43 add_filter( 'wp_handle_upload_prefilter', 'check_upload_size' ); |
44 add_filter( 'wp_handle_upload_prefilter', 'check_upload_size' ); |
44 |
45 |
45 /** |
46 /** |
46 * Delete a blog |
47 * Delete a blog. |
47 * |
48 * |
48 * @since 3.0.0 |
49 * @since 3.0.0 |
49 * |
50 * |
50 * @param int $blog_id Blog ID |
51 * @param int $blog_id Blog ID. |
51 * @param bool $drop True if blog's table should be dropped. Default is false. |
52 * @param bool $drop True if blog's table should be dropped. Default is false. |
52 * @return void |
|
53 */ |
53 */ |
54 function wpmu_delete_blog( $blog_id, $drop = false ) { |
54 function wpmu_delete_blog( $blog_id, $drop = false ) { |
55 global $wpdb, $current_site; |
55 global $wpdb; |
56 |
56 |
57 $switch = false; |
57 $switch = false; |
58 if ( get_current_blog_id() != $blog_id ) { |
58 if ( get_current_blog_id() != $blog_id ) { |
59 $switch = true; |
59 $switch = true; |
60 switch_to_blog( $blog_id ); |
60 switch_to_blog( $blog_id ); |
80 } |
80 } |
81 } |
81 } |
82 |
82 |
83 update_blog_status( $blog_id, 'deleted', 1 ); |
83 update_blog_status( $blog_id, 'deleted', 1 ); |
84 |
84 |
|
85 $current_site = get_current_site(); |
|
86 |
|
87 // If a full blog object is not available, do not destroy anything. |
|
88 if ( $drop && ! $blog ) { |
|
89 $drop = false; |
|
90 } |
|
91 |
85 // Don't destroy the initial, main, or root blog. |
92 // Don't destroy the initial, main, or root blog. |
86 if ( $drop && ( 1 == $blog_id || is_main_site( $blog_id ) || ( $blog->path == $current_site->path && $blog->domain == $current_site->domain ) ) ) |
93 if ( $drop && ( 1 == $blog_id || is_main_site( $blog_id ) || ( $blog->path == $current_site->path && $blog->domain == $current_site->domain ) ) ) { |
87 $drop = false; |
94 $drop = false; |
|
95 } |
|
96 |
|
97 $upload_path = trim( get_option( 'upload_path' ) ); |
|
98 |
|
99 // If ms_files_rewriting is enabled and upload_path is empty, wp_upload_dir is not reliable. |
|
100 if ( $drop && get_site_option( 'ms_files_rewriting' ) && empty( $upload_path ) ) { |
|
101 $drop = false; |
|
102 } |
88 |
103 |
89 if ( $drop ) { |
104 if ( $drop ) { |
|
105 $uploads = wp_upload_dir(); |
|
106 |
90 $tables = $wpdb->tables( 'blog' ); |
107 $tables = $wpdb->tables( 'blog' ); |
91 /** |
108 /** |
92 * Filter the tables to drop when the blog is deleted. |
109 * Filter the tables to drop when the blog is deleted. |
93 * |
110 * |
94 * @since MU |
111 * @since MU |
118 $top_dir = $dir; |
134 $top_dir = $dir; |
119 $stack = array($dir); |
135 $stack = array($dir); |
120 $index = 0; |
136 $index = 0; |
121 |
137 |
122 while ( $index < count( $stack ) ) { |
138 while ( $index < count( $stack ) ) { |
123 # Get indexed directory from stack |
139 // Get indexed directory from stack |
124 $dir = $stack[$index]; |
140 $dir = $stack[$index]; |
125 |
141 |
126 $dh = @opendir( $dir ); |
142 $dh = @opendir( $dir ); |
127 if ( $dh ) { |
143 if ( $dh ) { |
128 while ( ( $file = @readdir( $dh ) ) !== false ) { |
144 while ( ( $file = @readdir( $dh ) ) !== false ) { |
129 if ( $file == '.' || $file == '..' ) |
145 if ( $file == '.' || $file == '..' ) |
130 continue; |
146 continue; |
131 |
147 |
132 if ( @is_dir( $dir . DIRECTORY_SEPARATOR . $file ) ) |
148 if ( @is_dir( $dir . DIRECTORY_SEPARATOR . $file ) ) { |
133 $stack[] = $dir . DIRECTORY_SEPARATOR . $file; |
149 $stack[] = $dir . DIRECTORY_SEPARATOR . $file; |
134 else if ( @is_file( $dir . DIRECTORY_SEPARATOR . $file ) ) |
150 } elseif ( @is_file( $dir . DIRECTORY_SEPARATOR . $file ) ) { |
135 @unlink( $dir . DIRECTORY_SEPARATOR . $file ); |
151 @unlink( $dir . DIRECTORY_SEPARATOR . $file ); |
|
152 } |
136 } |
153 } |
137 @closedir( $dh ); |
154 @closedir( $dh ); |
138 } |
155 } |
139 $index++; |
156 $index++; |
140 } |
157 } |
200 |
226 |
201 $wpdb->delete( $wpdb->users, array( 'ID' => $id ) ); |
227 $wpdb->delete( $wpdb->users, array( 'ID' => $id ) ); |
202 |
228 |
203 clean_user_cache( $user ); |
229 clean_user_cache( $user ); |
204 |
230 |
205 /** |
231 /** This action is documented in wp-admin/includes/user.php */ |
206 * Fires after the user is deleted from the network. |
|
207 * |
|
208 * @since 2.8.0 |
|
209 * |
|
210 * @param int $id ID of the user that was deleted from the network. |
|
211 */ |
|
212 do_action( 'deleted_user', $id ); |
232 do_action( 'deleted_user', $id ); |
213 |
233 |
214 return true; |
234 return true; |
215 } |
235 } |
216 |
236 |
|
237 /** |
|
238 * Sends an email when a site administrator email address is changed. |
|
239 * |
|
240 * @since 3.0.0 |
|
241 * |
|
242 * @param string $old_value The old email address. Not currently used. |
|
243 * @param string $value The new email address. |
|
244 */ |
217 function update_option_new_admin_email( $old_value, $value ) { |
245 function update_option_new_admin_email( $old_value, $value ) { |
218 $email = get_option( 'admin_email' ); |
|
219 if ( $value == get_option( 'admin_email' ) || !is_email( $value ) ) |
246 if ( $value == get_option( 'admin_email' ) || !is_email( $value ) ) |
220 return; |
247 return; |
221 |
248 |
222 $hash = md5( $value. time() .mt_rand() ); |
249 $hash = md5( $value. time() .mt_rand() ); |
223 $new_admin_email = array( |
250 $new_admin_email = array( |
224 'hash' => $hash, |
251 'hash' => $hash, |
225 'newemail' => $value |
252 'newemail' => $value |
226 ); |
253 ); |
227 update_option( 'adminhash', $new_admin_email ); |
254 update_option( 'adminhash', $new_admin_email ); |
228 |
255 |
229 $email_text = __( 'Dear user, |
256 $email_text = __( 'Howdy ###USERNAME###, |
230 |
257 |
231 You recently requested to have the administration email address on |
258 You recently requested to have the administration email address on |
232 your site changed. |
259 your site changed. |
|
260 |
233 If this is correct, please click on the following link to change it: |
261 If this is correct, please click on the following link to change it: |
234 ###ADMIN_URL### |
262 ###ADMIN_URL### |
235 |
263 |
236 You can safely ignore and delete this email if you do not want to |
264 You can safely ignore and delete this email if you do not want to |
237 take this action. |
265 take this action. |
244 |
272 |
245 /** |
273 /** |
246 * Filter the email text sent when the site admin email is changed. |
274 * Filter the email text sent when the site admin email is changed. |
247 * |
275 * |
248 * The following strings have a special meaning and will get replaced dynamically: |
276 * The following strings have a special meaning and will get replaced dynamically: |
249 * ###ADMIN_URL### The link to click on to confirm the email change. Required otherwise this functunalty is will break. |
277 * ###USERNAME### The current user's username. |
|
278 * ###ADMIN_URL### The link to click on to confirm the email change. |
250 * ###EMAIL### The new email. |
279 * ###EMAIL### The new email. |
251 * ###SITENAME### The name of the site. |
280 * ###SITENAME### The name of the site. |
252 * ###SITEURL### The URL to the site. |
281 * ###SITEURL### The URL to the site. |
253 * |
282 * |
254 * @since MU |
283 * @since MU |
256 * @param string $email_text Text in the email. |
285 * @param string $email_text Text in the email. |
257 * @param string $new_admin_email New admin email that the current administration email was changed to. |
286 * @param string $new_admin_email New admin email that the current administration email was changed to. |
258 */ |
287 */ |
259 $content = apply_filters( 'new_admin_email_content', $email_text, $new_admin_email ); |
288 $content = apply_filters( 'new_admin_email_content', $email_text, $new_admin_email ); |
260 |
289 |
|
290 $content = str_replace( '###USERNAME###', $current_user->user_login, $content ); |
261 $content = str_replace( '###ADMIN_URL###', esc_url( admin_url( 'options.php?adminhash='.$hash ) ), $content ); |
291 $content = str_replace( '###ADMIN_URL###', esc_url( admin_url( 'options.php?adminhash='.$hash ) ), $content ); |
262 $content = str_replace( '###EMAIL###', $value, $content ); |
292 $content = str_replace( '###EMAIL###', $value, $content ); |
263 $content = str_replace( '###SITENAME###', get_site_option( 'site_name' ), $content ); |
293 $content = str_replace( '###SITENAME###', get_site_option( 'site_name' ), $content ); |
264 $content = str_replace( '###SITEURL###', network_home_url(), $content ); |
294 $content = str_replace( '###SITEURL###', network_home_url(), $content ); |
265 |
295 |
266 wp_mail( $value, sprintf( __( '[%s] New Admin Email Address' ), get_option( 'blogname' ) ), $content ); |
296 wp_mail( $value, sprintf( __( '[%s] New Admin Email Address' ), wp_specialchars_decode( get_option( 'blogname' ) ) ), $content ); |
267 } |
297 } |
268 add_action( 'update_option_new_admin_email', 'update_option_new_admin_email', 10, 2 ); |
298 add_action( 'update_option_new_admin_email', 'update_option_new_admin_email', 10, 2 ); |
269 add_action( 'add_option_new_admin_email', 'update_option_new_admin_email', 10, 2 ); |
299 add_action( 'add_option_new_admin_email', 'update_option_new_admin_email', 10, 2 ); |
270 |
300 |
|
301 /** |
|
302 * Sends an email when an email address change is requested. |
|
303 * |
|
304 * @since 3.0.0 |
|
305 * |
|
306 * @global object $errors WP_Error object. |
|
307 * @global object $wpdb WordPress database object. |
|
308 */ |
271 function send_confirmation_on_profile_email() { |
309 function send_confirmation_on_profile_email() { |
272 global $errors, $wpdb; |
310 global $errors, $wpdb; |
273 $current_user = wp_get_current_user(); |
311 $current_user = wp_get_current_user(); |
274 if ( ! is_object($errors) ) |
312 if ( ! is_object($errors) ) |
275 $errors = new WP_Error(); |
313 $errors = new WP_Error(); |
294 'hash' => $hash, |
332 'hash' => $hash, |
295 'newemail' => $_POST['email'] |
333 'newemail' => $_POST['email'] |
296 ); |
334 ); |
297 update_option( $current_user->ID . '_new_email', $new_user_email ); |
335 update_option( $current_user->ID . '_new_email', $new_user_email ); |
298 |
336 |
299 $email_text = __( 'Dear user, |
337 $email_text = __( 'Howdy ###USERNAME###, |
300 |
338 |
301 You recently requested to have the email address on your account changed. |
339 You recently requested to have the email address on your account changed. |
|
340 |
302 If this is correct, please click on the following link to change it: |
341 If this is correct, please click on the following link to change it: |
303 ###ADMIN_URL### |
342 ###ADMIN_URL### |
304 |
343 |
305 You can safely ignore and delete this email if you do not want to |
344 You can safely ignore and delete this email if you do not want to |
306 take this action. |
345 take this action. |
313 |
352 |
314 /** |
353 /** |
315 * Filter the email text sent when a user changes emails. |
354 * Filter the email text sent when a user changes emails. |
316 * |
355 * |
317 * The following strings have a special meaning and will get replaced dynamically: |
356 * The following strings have a special meaning and will get replaced dynamically: |
318 * ###ADMIN_URL### The link to click on to confirm the email change. Required otherwise this functunalty is will break. |
357 * ###USERNAME### The current user's username. |
319 * ###EMAIL### The new email. |
358 * ###ADMIN_URL### The link to click on to confirm the email change. |
320 * ###SITENAME### The name of the site. |
359 * ###EMAIL### The new email. |
321 * ###SITEURL### The URL to the site. |
360 * ###SITENAME### The name of the site. |
|
361 * ###SITEURL### The URL to the site. |
322 * |
362 * |
323 * @since MU |
363 * @since MU |
324 * |
364 * |
325 * @param string $email_text Text in the email. |
365 * @param string $email_text Text in the email. |
326 * @param string $new_user_email New user email that the current user has changed to. |
366 * @param string $new_user_email New user email that the current user has changed to. |
327 */ |
367 */ |
328 $content = apply_filters( 'new_user_email_content', $email_text, $new_user_email ); |
368 $content = apply_filters( 'new_user_email_content', $email_text, $new_user_email ); |
329 |
369 |
|
370 $content = str_replace( '###USERNAME###', $current_user->user_login, $content ); |
330 $content = str_replace( '###ADMIN_URL###', esc_url( admin_url( 'profile.php?newuseremail='.$hash ) ), $content ); |
371 $content = str_replace( '###ADMIN_URL###', esc_url( admin_url( 'profile.php?newuseremail='.$hash ) ), $content ); |
331 $content = str_replace( '###EMAIL###', $_POST['email'], $content); |
372 $content = str_replace( '###EMAIL###', $_POST['email'], $content); |
332 $content = str_replace( '###SITENAME###', get_site_option( 'site_name' ), $content ); |
373 $content = str_replace( '###SITENAME###', get_site_option( 'site_name' ), $content ); |
333 $content = str_replace( '###SITEURL###', network_home_url(), $content ); |
374 $content = str_replace( '###SITEURL###', network_home_url(), $content ); |
334 |
375 |
335 wp_mail( $_POST['email'], sprintf( __( '[%s] New Email Address' ), get_option( 'blogname' ) ), $content ); |
376 wp_mail( $_POST['email'], sprintf( __( '[%s] New Email Address' ), wp_specialchars_decode( get_option( 'blogname' ) ) ), $content ); |
336 $_POST['email'] = $current_user->user_email; |
377 $_POST['email'] = $current_user->user_email; |
337 } |
378 } |
338 } |
379 } |
339 add_action( 'personal_options_update', 'send_confirmation_on_profile_email' ); |
380 add_action( 'personal_options_update', 'send_confirmation_on_profile_email' ); |
340 |
381 |
|
382 /** |
|
383 * Adds an admin notice alerting the user to check for confirmation email |
|
384 * after email address change. |
|
385 * |
|
386 * @since 3.0.0 |
|
387 */ |
341 function new_user_email_admin_notice() { |
388 function new_user_email_admin_notice() { |
342 if ( strpos( $_SERVER['PHP_SELF'], 'profile.php' ) && isset( $_GET['updated'] ) && $email = get_option( get_current_user_id() . '_new_email' ) ) |
389 if ( strpos( $_SERVER['PHP_SELF'], 'profile.php' ) && isset( $_GET['updated'] ) && $email = get_option( get_current_user_id() . '_new_email' ) ) |
343 echo "<div class='update-nag'>" . sprintf( __( "Your email address has not been updated yet. Please check your inbox at %s for a confirmation email." ), $email['newemail'] ) . "</div>"; |
390 echo "<div class='update-nag'>" . sprintf( __( "Your email address has not been updated yet. Please check your inbox at %s for a confirmation email." ), $email['newemail'] ) . "</div>"; |
344 } |
391 } |
345 add_action( 'admin_notices', 'new_user_email_admin_notice' ); |
392 add_action( 'admin_notices', 'new_user_email_admin_notice' ); |
413 |
457 |
414 $available = get_upload_space_available(); |
458 $available = get_upload_space_available(); |
415 return min( $size, $available ); |
459 return min( $size, $available ); |
416 } |
460 } |
417 |
461 |
418 // Edit blog upload space setting on Edit Blog page |
462 /** |
|
463 * Displays the edit blog upload space setting form on the Edit Blog screen. |
|
464 * |
|
465 * @since 3.0.0 |
|
466 * |
|
467 * @param int $id The ID of the blog to display the setting for. |
|
468 */ |
419 function upload_space_setting( $id ) { |
469 function upload_space_setting( $id ) { |
420 switch_to_blog( $id ); |
470 switch_to_blog( $id ); |
421 $quota = get_option( 'blog_upload_space' ); |
471 $quota = get_option( 'blog_upload_space' ); |
422 restore_current_blog(); |
472 restore_current_blog(); |
423 |
473 |
424 if ( !$quota ) |
474 if ( !$quota ) |
425 $quota = ''; |
475 $quota = ''; |
426 |
476 |
427 ?> |
477 ?> |
428 <tr> |
478 <tr> |
429 <th><?php _e( 'Site Upload Space Quota '); ?></th> |
479 <th><label for="blog-upload-space-number"><?php _e( 'Site Upload Space Quota' ); ?></label></th> |
430 <td><input type="number" step="1" min="0" style="width: 100px" name="option[blog_upload_space]" value="<?php echo $quota; ?>" /> <?php _e( 'MB (Leave blank for network default)' ); ?></td> |
480 <td> |
|
481 <input type="number" step="1" min="0" style="width: 100px" name="option[blog_upload_space]" id="blog-upload-space-number" aria-describedby="blog-upload-space-desc" value="<?php echo $quota; ?>" /> |
|
482 <span id="blog-upload-space-desc"><span class="screen-reader-text"><?php _e( 'Size in megabytes' ); ?></span> <?php _e( 'MB (Leave blank for network default)' ); ?></span> |
|
483 </td> |
431 </tr> |
484 </tr> |
432 <?php |
485 <?php |
433 } |
486 } |
434 add_action( 'wpmueditblogaction', 'upload_space_setting' ); |
487 add_action( 'wpmueditblogaction', 'upload_space_setting' ); |
435 |
488 |
|
489 /** |
|
490 * Update the status of a user in the database. |
|
491 * |
|
492 * Used in core to mark a user as spam or "ham" (not spam) in Multisite. |
|
493 * |
|
494 * @since 3.0.0 |
|
495 * |
|
496 * @param int $id The user ID. |
|
497 * @param string $pref The column in the wp_users table to update the user's status |
|
498 * in (presumably user_status, spam, or deleted). |
|
499 * @param int $value The new status for the user. |
|
500 * @param null $deprecated Deprecated as of 3.0.2 and should not be used. |
|
501 * @return int The initially passed $value. |
|
502 */ |
436 function update_user_status( $id, $pref, $value, $deprecated = null ) { |
503 function update_user_status( $id, $pref, $value, $deprecated = null ) { |
437 global $wpdb; |
504 global $wpdb; |
438 |
505 |
439 if ( null !== $deprecated ) |
506 if ( null !== $deprecated ) |
440 _deprecated_argument( __FUNCTION__, '3.1' ); |
507 _deprecated_argument( __FUNCTION__, '3.1' ); |
478 clean_user_cache( $user ); |
553 clean_user_cache( $user ); |
479 |
554 |
480 return $id; |
555 return $id; |
481 } |
556 } |
482 |
557 |
|
558 /** |
|
559 * Returns the language for a language code. |
|
560 * |
|
561 * @since 3.0.0 |
|
562 * |
|
563 * @param string $code Optional. The two-letter language code. Default empty. |
|
564 * @return string The language corresponding to $code if it exists. If it does not exist, |
|
565 * then the first two letters of $code is returned. |
|
566 */ |
483 function format_code_lang( $code = '' ) { |
567 function format_code_lang( $code = '' ) { |
484 $code = strtolower( substr( $code, 0, 2 ) ); |
568 $code = strtolower( substr( $code, 0, 2 ) ); |
485 $lang_codes = array( |
569 $lang_codes = array( |
486 'aa' => 'Afar', 'ab' => 'Abkhazian', 'af' => 'Afrikaans', 'ak' => 'Akan', 'sq' => 'Albanian', 'am' => 'Amharic', 'ar' => 'Arabic', 'an' => 'Aragonese', 'hy' => 'Armenian', 'as' => 'Assamese', 'av' => 'Avaric', 'ae' => 'Avestan', 'ay' => 'Aymara', 'az' => 'Azerbaijani', 'ba' => 'Bashkir', 'bm' => 'Bambara', 'eu' => 'Basque', 'be' => 'Belarusian', 'bn' => 'Bengali', |
570 'aa' => 'Afar', 'ab' => 'Abkhazian', 'af' => 'Afrikaans', 'ak' => 'Akan', 'sq' => 'Albanian', 'am' => 'Amharic', 'ar' => 'Arabic', 'an' => 'Aragonese', 'hy' => 'Armenian', 'as' => 'Assamese', 'av' => 'Avaric', 'ae' => 'Avestan', 'ay' => 'Aymara', 'az' => 'Azerbaijani', 'ba' => 'Bashkir', 'bm' => 'Bambara', 'eu' => 'Basque', 'be' => 'Belarusian', 'bn' => 'Bengali', |
487 'bh' => 'Bihari', 'bi' => 'Bislama', 'bs' => 'Bosnian', 'br' => 'Breton', 'bg' => 'Bulgarian', 'my' => 'Burmese', 'ca' => 'Catalan; Valencian', 'ch' => 'Chamorro', 'ce' => 'Chechen', 'zh' => 'Chinese', 'cu' => 'Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church Slavonic', 'cv' => 'Chuvash', 'kw' => 'Cornish', 'co' => 'Corsican', 'cr' => 'Cree', |
571 'bh' => 'Bihari', 'bi' => 'Bislama', 'bs' => 'Bosnian', 'br' => 'Breton', 'bg' => 'Bulgarian', 'my' => 'Burmese', 'ca' => 'Catalan; Valencian', 'ch' => 'Chamorro', 'ce' => 'Chechen', 'zh' => 'Chinese', 'cu' => 'Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church Slavonic', 'cv' => 'Chuvash', 'kw' => 'Cornish', 'co' => 'Corsican', 'cr' => 'Cree', |
505 */ |
589 */ |
506 $lang_codes = apply_filters( 'lang_codes', $lang_codes, $code ); |
590 $lang_codes = apply_filters( 'lang_codes', $lang_codes, $code ); |
507 return strtr( $code, $lang_codes ); |
591 return strtr( $code, $lang_codes ); |
508 } |
592 } |
509 |
593 |
|
594 /** |
|
595 * Synchronize category and post tag slugs when global terms are enabled. |
|
596 * |
|
597 * @since 3.0.0 |
|
598 * |
|
599 * @param object $term The term. |
|
600 * @param string $taxonomy The taxonomy for $term. Should be 'category' or 'post_tag', as these are |
|
601 * the only taxonomies which are processed by this function; anything else |
|
602 * will be returned untouched. |
|
603 * @return object|array Returns `$term`, after filtering the 'slug' field with {@see sanitize_title()} |
|
604 * if $taxonomy is 'category' or 'post_tag'. |
|
605 */ |
510 function sync_category_tag_slugs( $term, $taxonomy ) { |
606 function sync_category_tag_slugs( $term, $taxonomy ) { |
511 if ( global_terms_enabled() && ( $taxonomy == 'category' || $taxonomy == 'post_tag' ) ) { |
607 if ( global_terms_enabled() && ( $taxonomy == 'category' || $taxonomy == 'post_tag' ) ) { |
512 if ( is_object( $term ) ) { |
608 if ( is_object( $term ) ) { |
513 $term->slug = sanitize_title( $term->name ); |
609 $term->slug = sanitize_title( $term->name ); |
514 } else { |
610 } else { |
529 return; |
632 return; |
530 |
633 |
531 $blog_name = get_bloginfo( 'name' ); |
634 $blog_name = get_bloginfo( 'name' ); |
532 |
635 |
533 if ( empty( $blogs ) ) |
636 if ( empty( $blogs ) ) |
534 wp_die( sprintf( __( '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.' ), $blog_name ) ); |
637 wp_die( sprintf( __( '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.' ), $blog_name ), 403 ); |
535 |
638 |
536 $output = '<p>' . sprintf( __( '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.' ), $blog_name ) . '</p>'; |
639 $output = '<p>' . sprintf( __( '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.' ), $blog_name ) . '</p>'; |
537 $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>'; |
640 $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>'; |
538 |
641 |
539 $output .= '<h3>' . __('Your Sites') . '</h3>'; |
642 $output .= '<h3>' . __('Your Sites') . '</h3>'; |
540 $output .= '<table>'; |
643 $output .= '<table>'; |
541 |
644 |
542 foreach ( $blogs as $blog ) { |
645 foreach ( $blogs as $blog ) { |
543 $output .= "<tr>"; |
646 $output .= '<tr>'; |
544 $output .= "<td valign='top'>"; |
647 $output .= "<td>{$blog->blogname}</td>"; |
545 $output .= "{$blog->blogname}"; |
648 $output .= '<td><a href="' . esc_url( get_admin_url( $blog->userblog_id ) ) . '">' . __( 'Visit Dashboard' ) . '</a> | ' . |
546 $output .= "</td>"; |
649 '<a href="' . esc_url( get_home_url( $blog->userblog_id ) ). '">' . __( 'View Site' ) . '</a></td>'; |
547 $output .= "<td valign='top'>"; |
650 $output .= '</tr>'; |
548 $output .= "<a href='" . esc_url( get_admin_url( $blog->userblog_id ) ) . "'>" . __( 'Visit Dashboard' ) . "</a> | <a href='" . esc_url( get_home_url( $blog->userblog_id ) ). "'>" . __( 'View Site' ) . "</a>" ; |
651 } |
549 $output .= "</td>"; |
652 |
550 $output .= "</tr>"; |
|
551 } |
|
552 $output .= '</table>'; |
653 $output .= '</table>'; |
553 |
654 |
554 wp_die( $output ); |
655 wp_die( $output, 403 ); |
555 } |
656 } |
556 add_action( 'admin_page_access_denied', '_access_denied_splash', 99 ); |
657 add_action( 'admin_page_access_denied', '_access_denied_splash', 99 ); |
557 |
658 |
|
659 /** |
|
660 * Checks if the current user has permissions to import new users. |
|
661 * |
|
662 * @since 3.0.0 |
|
663 * |
|
664 * @param string $permission A permission to be checked. Currently not used. |
|
665 * @return bool True if the user has proper permissions, false if they do not. |
|
666 */ |
558 function check_import_new_users( $permission ) { |
667 function check_import_new_users( $permission ) { |
559 if ( !is_super_admin() ) |
668 if ( !is_super_admin() ) |
560 return false; |
669 return false; |
561 return true; |
670 return true; |
562 } |
671 } |
563 add_filter( 'import_allow_create_users', 'check_import_new_users' ); |
672 add_filter( 'import_allow_create_users', 'check_import_new_users' ); |
564 // See "import_allow_fetch_attachments" and "import_attachment_size_limit" filters too. |
673 // See "import_allow_fetch_attachments" and "import_attachment_size_limit" filters too. |
565 |
674 |
|
675 /** |
|
676 * Generates and displays a drop-down of available languages. |
|
677 * |
|
678 * @since 3.0.0 |
|
679 * |
|
680 * @param array $lang_files Optional. An array of the language files. Default empty array. |
|
681 * @param string $current Optional. The current language code. Default empty. |
|
682 */ |
566 function mu_dropdown_languages( $lang_files = array(), $current = '' ) { |
683 function mu_dropdown_languages( $lang_files = array(), $current = '' ) { |
567 $flag = false; |
684 $flag = false; |
568 $output = array(); |
685 $output = array(); |
569 |
686 |
570 foreach ( (array) $lang_files as $val ) { |
687 foreach ( (array) $lang_files as $val ) { |
588 if ( $flag === false ) // WordPress english |
705 if ( $flag === false ) // WordPress english |
589 $output[] = '<option value=""' . selected( $current, '', false ) . '>' . __( 'English' ) . "</option>"; |
706 $output[] = '<option value=""' . selected( $current, '', false ) . '>' . __( 'English' ) . "</option>"; |
590 |
707 |
591 // Order by name |
708 // Order by name |
592 uksort( $output, 'strnatcasecmp' ); |
709 uksort( $output, 'strnatcasecmp' ); |
|
710 |
593 /** |
711 /** |
594 * Filter the languages available in the dropdown. |
712 * Filter the languages available in the dropdown. |
595 * |
713 * |
596 * @since MU |
714 * @since MU |
597 * |
715 * |
598 * @param array $output HTML output of the dropdown. |
716 * @param array $output HTML output of the dropdown. |
599 * @param array $lang_files Available language files. |
717 * @param array $lang_files Available language files. |
600 * @param string $current The current language code. |
718 * @param string $current The current language code. |
601 */ |
719 */ |
602 $output = apply_filters( 'mu_dropdown_languages', $output, $lang_files, $current ); |
720 $output = apply_filters( 'mu_dropdown_languages', $output, $lang_files, $current ); |
|
721 |
603 echo implode( "\n\t", $output ); |
722 echo implode( "\n\t", $output ); |
604 } |
723 } |
605 |
724 |
|
725 /** |
|
726 * Displays an admin notice to upgrade all sites after a core upgrade. |
|
727 * |
|
728 * @since 3.0.0 |
|
729 * |
|
730 * @global int $wp_db_version The version number of the database. |
|
731 */ |
606 function site_admin_notice() { |
732 function site_admin_notice() { |
607 global $wp_db_version; |
733 global $wp_db_version; |
608 if ( !is_super_admin() ) |
734 if ( !is_super_admin() ) |
609 return false; |
735 return false; |
610 if ( get_site_option( 'wpmu_upgrade_site' ) != $wp_db_version ) |
736 if ( get_site_option( 'wpmu_upgrade_site' ) != $wp_db_version ) |
611 echo "<div class='update-nag'>" . sprintf( __( 'Thank you for Updating! Please visit the <a href="%s">Upgrade Network</a> page to update all your sites.' ), esc_url( network_admin_url( 'upgrade.php' ) ) ) . "</div>"; |
737 echo "<div class='update-nag'>" . sprintf( __( 'Thank you for Updating! Please visit the <a href="%s">Upgrade Network</a> page to update all your sites.' ), esc_url( network_admin_url( 'upgrade.php' ) ) ) . "</div>"; |
612 } |
738 } |
613 add_action( 'admin_notices', 'site_admin_notice' ); |
739 add_action( 'admin_notices', 'site_admin_notice' ); |
614 add_action( 'network_admin_notices', 'site_admin_notice' ); |
740 add_action( 'network_admin_notices', 'site_admin_notice' ); |
615 |
741 |
|
742 /** |
|
743 * Avoids a collision between a site slug and a permalink slug. |
|
744 * |
|
745 * In a subdirectory install this will make sure that a site and a post do not use the |
|
746 * same subdirectory by checking for a site with the same name as a new post. |
|
747 * |
|
748 * @since 3.0.0 |
|
749 * |
|
750 * @param array $data An array of post data. |
|
751 * @param array $postarr An array of posts. Not currently used. |
|
752 * @return array The new array of post data after checking for collisions. |
|
753 */ |
616 function avoid_blog_page_permalink_collision( $data, $postarr ) { |
754 function avoid_blog_page_permalink_collision( $data, $postarr ) { |
617 if ( is_subdomain_install() ) |
755 if ( is_subdomain_install() ) |
618 return $data; |
756 return $data; |
619 if ( $data['post_type'] != 'page' ) |
757 if ( $data['post_type'] != 'page' ) |
620 return $data; |
758 return $data; |
634 } |
772 } |
635 return $data; |
773 return $data; |
636 } |
774 } |
637 add_filter( 'wp_insert_post_data', 'avoid_blog_page_permalink_collision', 10, 2 ); |
775 add_filter( 'wp_insert_post_data', 'avoid_blog_page_permalink_collision', 10, 2 ); |
638 |
776 |
|
777 /** |
|
778 * Handles the display of choosing a user's primary site. |
|
779 * |
|
780 * This displays the user's primary site and allows the user to choose |
|
781 * which site is primary. |
|
782 * |
|
783 * @since 3.0.0 |
|
784 */ |
639 function choose_primary_blog() { |
785 function choose_primary_blog() { |
640 ?> |
786 ?> |
641 <table class="form-table"> |
787 <table class="form-table"> |
642 <tr> |
788 <tr> |
643 <?php /* translators: My sites label */ ?> |
789 <?php /* translators: My sites label */ ?> |
644 <th scope="row"><?php _e( 'Primary Site' ); ?></th> |
790 <th scope="row"><label for="primary_blog"><?php _e( 'Primary Site' ); ?></label></th> |
645 <td> |
791 <td> |
646 <?php |
792 <?php |
647 $all_blogs = get_blogs_of_user( get_current_user_id() ); |
793 $all_blogs = get_blogs_of_user( get_current_user_id() ); |
648 $primary_blog = get_user_meta( get_current_user_id(), 'primary_blog', true ); |
794 $primary_blog = get_user_meta( get_current_user_id(), 'primary_blog', true ); |
649 if ( count( $all_blogs ) > 1 ) { |
795 if ( count( $all_blogs ) > 1 ) { |
650 $found = false; |
796 $found = false; |
651 ?> |
797 ?> |
652 <select name="primary_blog"> |
798 <select name="primary_blog" id="primary_blog"> |
653 <?php foreach( (array) $all_blogs as $blog ) { |
799 <?php foreach( (array) $all_blogs as $blog ) { |
654 if ( $primary_blog == $blog->userblog_id ) |
800 if ( $primary_blog == $blog->userblog_id ) |
655 $found = true; |
801 $found = true; |
656 ?><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><?php |
802 ?><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><?php |
657 } ?> |
803 } ?> |
658 </select> |
804 </select> |
659 <?php |
805 <?php |
660 if ( !$found ) { |
806 if ( !$found ) { |
661 $blog = array_shift( $all_blogs ); |
807 $blog = reset( $all_blogs ); |
662 update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id ); |
808 update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id ); |
663 } |
809 } |
664 } elseif ( count( $all_blogs ) == 1 ) { |
810 } elseif ( count( $all_blogs ) == 1 ) { |
665 $blog = array_shift( $all_blogs ); |
811 $blog = reset( $all_blogs ); |
666 echo $blog->domain; |
812 echo $blog->domain; |
667 if ( $primary_blog != $blog->userblog_id ) // Set the primary blog again if it's out of sync with blog list. |
813 if ( $primary_blog != $blog->userblog_id ) // Set the primary blog again if it's out of sync with blog list. |
668 update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id ); |
814 update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id ); |
669 } else { |
815 } else { |
670 echo "N/A"; |
816 echo "N/A"; |
674 </tr> |
820 </tr> |
675 <?php if ( in_array( get_site_option( 'registration' ), array( 'all', 'blog' ) ) ) : ?> |
821 <?php if ( in_array( get_site_option( 'registration' ), array( 'all', 'blog' ) ) ) : ?> |
676 <tr> |
822 <tr> |
677 <th scope="row" colspan="2" class="th-full"> |
823 <th scope="row" colspan="2" class="th-full"> |
678 <?php |
824 <?php |
679 $signup_url = network_site_url( 'wp-signup.php' ); |
|
680 /** This filter is documented in wp-login.php */ |
825 /** This filter is documented in wp-login.php */ |
|
826 $sign_up_url = apply_filters( 'wp_signup_location', network_site_url( 'wp-signup.php' ) ); |
681 ?> |
827 ?> |
682 <a href="<?php echo apply_filters( 'wp_signup_location', $signup_url ); ?>"><?php _e( 'Create a New Site' ); ?></a> |
828 <a href="<?php echo esc_url( $sign_up_url ); ?>"><?php _e( 'Create a New Site' ); ?></a> |
683 </th> |
829 </th> |
684 </tr> |
830 </tr> |
685 <?php endif; ?> |
831 <?php endif; ?> |
686 </table> |
832 </table> |
687 <?php |
833 <?php |
689 |
835 |
690 /** |
836 /** |
691 * Grants Super Admin privileges. |
837 * Grants Super Admin privileges. |
692 * |
838 * |
693 * @since 3.0.0 |
839 * @since 3.0.0 |
|
840 * |
694 * @param int $user_id ID of the user to be granted Super Admin privileges. |
841 * @param int $user_id ID of the user to be granted Super Admin privileges. |
|
842 * @return bool True on success, false on failure. This can fail when the user is |
|
843 * already a super admin or when the `$super_admins` global is defined. |
695 */ |
844 */ |
696 function grant_super_admin( $user_id ) { |
845 function grant_super_admin( $user_id ) { |
697 global $super_admins; |
|
698 |
|
699 // If global super_admins override is defined, there is nothing to do here. |
846 // If global super_admins override is defined, there is nothing to do here. |
700 if ( isset( $super_admins ) ) |
847 if ( isset( $GLOBALS['super_admins'] ) ) { |
701 return false; |
848 return false; |
|
849 } |
702 |
850 |
703 /** |
851 /** |
704 * Fires before the user is granted Super Admin privileges. |
852 * Fires before the user is granted Super Admin privileges. |
705 * |
853 * |
706 * @since 3.0.0 |
854 * @since 3.0.0 |
732 |
880 |
733 /** |
881 /** |
734 * Revokes Super Admin privileges. |
882 * Revokes Super Admin privileges. |
735 * |
883 * |
736 * @since 3.0.0 |
884 * @since 3.0.0 |
|
885 * |
737 * @param int $user_id ID of the user Super Admin privileges to be revoked from. |
886 * @param int $user_id ID of the user Super Admin privileges to be revoked from. |
|
887 * @return bool True on success, false on failure. This can fail when the user's email |
|
888 * is the network admin email or when the `$super_admins` global is defined. |
738 */ |
889 */ |
739 function revoke_super_admin( $user_id ) { |
890 function revoke_super_admin( $user_id ) { |
740 global $super_admins; |
|
741 |
|
742 // If global super_admins override is defined, there is nothing to do here. |
891 // If global super_admins override is defined, there is nothing to do here. |
743 if ( isset( $super_admins ) ) |
892 if ( isset( $GLOBALS['super_admins'] ) ) { |
744 return false; |
893 return false; |
|
894 } |
745 |
895 |
746 /** |
896 /** |
747 * Fires before the user's Super Admin privileges are revoked. |
897 * Fires before the user's Super Admin privileges are revoked. |
748 * |
898 * |
749 * @since 3.0.0 |
899 * @since 3.0.0 |
754 |
904 |
755 // Directly fetch site_admins instead of using get_super_admins() |
905 // Directly fetch site_admins instead of using get_super_admins() |
756 $super_admins = get_site_option( 'site_admins', array( 'admin' ) ); |
906 $super_admins = get_site_option( 'site_admins', array( 'admin' ) ); |
757 |
907 |
758 $user = get_userdata( $user_id ); |
908 $user = get_userdata( $user_id ); |
759 if ( $user && $user->user_email != get_site_option( 'admin_email' ) ) { |
909 if ( $user && 0 !== strcasecmp( $user->user_email, get_site_option( 'admin_email' ) ) ) { |
760 if ( false !== ( $key = array_search( $user->user_login, $super_admins ) ) ) { |
910 if ( false !== ( $key = array_search( $user->user_login, $super_admins ) ) ) { |
761 unset( $super_admins[$key] ); |
911 unset( $super_admins[$key] ); |
762 update_site_option( 'site_admins', $super_admins ); |
912 update_site_option( 'site_admins', $super_admins ); |
763 |
913 |
764 /** |
914 /** |