3 * Multisite administration functions.
6 * @subpackage Multisite
11 * Determine if uploaded file exceeds space quota.
15 * @param array $file $_FILES array for a given file.
16 * @return array $_FILES array with 'error' key set if file exceeds quota. 'error' is empty otherwise.
18 function check_upload_size( $file ) {
19 if ( get_site_option( 'upload_space_check_disabled' ) )
22 if ( $file['error'] != '0' ) // there's already an error
25 if ( defined( 'WP_IMPORTING' ) )
28 $space_allowed = 1048576 * get_space_allowed();
29 $space_used = get_dirsize( BLOGUPLOADDIR );
30 $space_left = $space_allowed - $space_used;
31 $file_size = filesize( $file['tmp_name'] );
32 if ( $space_left < $file_size )
33 $file['error'] = sprintf( __( 'Not enough space to upload. %1$s KB needed.' ), number_format( ($file_size - $space_left) /1024 ) );
34 if ( $file_size > ( 1024 * get_site_option( 'fileupload_maxk', 1500 ) ) )
35 $file['error'] = sprintf(__('This file is too big. Files must be less than %1$s KB in size.'), get_site_option( 'fileupload_maxk', 1500 ) );
36 if ( upload_is_user_over_quota( false ) ) {
37 $file['error'] = __( 'You have used your space quota. Please delete files before uploading.' );
39 if ( $file['error'] != '0' && !isset($_POST['html-upload']) )
40 wp_die( $file['error'] . ' <a href="javascript:history.go(-1)">' . __( 'Back' ) . '</a>' );
44 add_filter( 'wp_handle_upload_prefilter', 'check_upload_size' );
51 * @param int $blog_id Blog ID
52 * @param bool $drop True if blog's table should be dropped. Default is false.
55 function wpmu_delete_blog( $blog_id, $drop = false ) {
59 if ( $blog_id != $wpdb->blogid ) {
61 switch_to_blog( $blog_id );
64 $blog_prefix = $wpdb->get_blog_prefix( $blog_id );
66 do_action( 'delete_blog', $blog_id, $drop );
68 $users = get_users_of_blog( $blog_id );
70 // Remove users from this blog.
71 if ( ! empty( $users ) ) {
72 foreach ( $users as $user ) {
73 remove_user_from_blog( $user->user_id, $blog_id) ;
77 update_blog_status( $blog_id, 'deleted', 1 );
80 if ( substr( $blog_prefix, -1 ) == '_' )
81 $blog_prefix = substr( $blog_prefix, 0, -1 ) . '\_';
83 $drop_tables = $wpdb->get_results( "SHOW TABLES LIKE '{$blog_prefix}%'", ARRAY_A );
84 $drop_tables = apply_filters( 'wpmu_drop_tables', $drop_tables );
86 reset( $drop_tables );
87 foreach ( (array) $drop_tables as $drop_table) {
88 $wpdb->query( "DROP TABLE IF EXISTS ". current( $drop_table ) ."" );
90 $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->blogs WHERE blog_id = %d", $blog_id ) );
91 $dir = apply_filters( 'wpmu_delete_blog_upload_dir', WP_CONTENT_DIR . "/blogs.dir/{$blog_id}/files/", $blog_id );
92 $dir = rtrim( $dir, DIRECTORY_SEPARATOR );
97 while ( $index < count( $stack ) ) {
98 # Get indexed directory from stack
99 $dir = $stack[$index];
101 $dh = @opendir( $dir );
103 while ( ( $file = @readdir( $dh ) ) !== false ) {
104 if ( $file == '.' || $file == '..' )
107 if ( @is_dir( $dir . DIRECTORY_SEPARATOR . $file ) )
108 $stack[] = $dir . DIRECTORY_SEPARATOR . $file;
109 else if ( @is_file( $dir . DIRECTORY_SEPARATOR . $file ) )
110 @unlink( $dir . DIRECTORY_SEPARATOR . $file );
116 $stack = array_reverse( $stack ); // Last added dirs are deepest
117 foreach( (array) $stack as $dir ) {
118 if ( $dir != $top_dir)
123 $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key = '{$blog_prefix}autosave_draft_ids'" );
124 $blogs = get_site_option( 'blog_list' );
125 if ( is_array( $blogs ) ) {
126 foreach ( $blogs as $n => $blog ) {
127 if ( $blog['blog_id'] == $blog_id )
130 update_site_option( 'blog_list', $blogs );
133 if ( $switch === true )
134 restore_current_blog();
137 // @todo Merge with wp_delete_user() ?
138 function wpmu_delete_user( $id ) {
143 do_action( 'wpmu_delete_user', $id );
145 $blogs = get_blogs_of_user( $id );
147 if ( ! empty( $blogs ) ) {
148 foreach ( $blogs as $blog ) {
149 switch_to_blog( $blog->userblog_id );
150 remove_user_from_blog( $id, $blog->userblog_id );
152 $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d", $id ) );
153 foreach ( (array) $post_ids as $post_id ) {
154 wp_delete_post( $post_id );
158 $link_ids = $wpdb->get_col( $wpdb->prepare( "SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $id ) );
161 foreach ( $link_ids as $link_id )
162 wp_delete_link( $link_id );
165 restore_current_blog();
169 $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->users WHERE ID = %d", $id ) );
170 $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE user_id = %d", $id ) );
172 clean_user_cache( $id );
174 // allow for commit transaction
175 do_action( 'deleted_user', $id );
180 function confirm_delete_users( $users ) {
181 $current_user = wp_get_current_user();
182 if ( !is_array( $users ) )
187 <h2><?php esc_html_e( 'Users' ); ?></h2>
188 <p><?php _e( 'Transfer or delete posts and links before deleting users.' ); ?></p>
189 <form action="ms-edit.php?action=dodelete" method="post">
190 <input type="hidden" name="dodelete" />
192 wp_nonce_field( 'ms-users-delete' );
193 $site_admins = get_super_admins();
194 $admin_out = "<option value='$current_user->ID'>$current_user->user_login</option>";
196 foreach ( ( $allusers = (array) $_POST['allusers'] ) as $key => $val ) {
197 if ( $val != '' && $val != '0' ) {
198 $delete_user = new WP_User( $val );
200 if ( in_array( $delete_user->user_login, $site_admins ) )
201 wp_die( sprintf( __( 'Warning! User cannot be deleted. The user %s is a network admnistrator.' ), $delete_user->user_login ) );
203 echo "<input type='hidden' name='user[]' value='{$val}'/>\n";
204 $blogs = get_blogs_of_user( $val, true );
206 if ( !empty( $blogs ) ) {
208 <br /><fieldset><p><legend><?php printf( __( "What should be done with posts and links owned by <em>%s</em>?" ), $delete_user->user_login ); ?></legend></p>
210 foreach ( (array) $blogs as $key => $details ) {
211 $blog_users = get_users_of_blog( $details->userblog_id );
212 if ( is_array( $blog_users ) && !empty( $blog_users ) ) {
213 $user_site = "<a href='" . esc_url( get_home_url( $details->userblog_id ) ) . "'>{$details->blogname}</a>";
214 $user_dropdown = "<select name='blog[$val][{$key}]'>";
216 foreach ( $blog_users as $user ) {
217 if ( $user->user_id != $val && !in_array( $user->user_id, $allusers ) )
218 $user_list .= "<option value='{$user->user_id}'>{$user->user_login}</option>";
220 if ( '' == $user_list )
221 $user_list = $admin_out;
222 $user_dropdown .= $user_list;
223 $user_dropdown .= "</select>\n";
225 <ul style="list-style:none;">
226 <li><?php printf( __( 'Site: %s' ), $user_site ); ?></li>
227 <li><label><input type="radio" id="delete_option0" name="delete[<?php echo $details->userblog_id . '][' . $delete_user->ID ?>]" value="delete" checked="checked" />
228 <?php _e( 'Delete all posts and links.' ); ?></label></li>
229 <li><label><input type="radio" id="delete_option1" name="delete[<?php echo $details->userblog_id . '][' . $delete_user->ID ?>]" value="reassign" />
230 <?php echo __( 'Attribute all posts and links to:' ) . '</label>' . $user_dropdown; ?></li>
240 <p class="submit"><input type="submit" class="button-secondary delete" value="<?php esc_attr_e( 'Confirm Deletion' ); ?>" /></p>
246 function wpmu_get_blog_allowedthemes( $blog_id = 0 ) {
247 $themes = get_themes();
250 switch_to_blog( $blog_id );
252 $blog_allowed_themes = get_option( 'allowedthemes' );
253 if ( !is_array( $blog_allowed_themes ) || empty( $blog_allowed_themes ) ) { // convert old allowed_themes to new allowedthemes
254 $blog_allowed_themes = get_option( 'allowed_themes' );
256 if ( is_array( $blog_allowed_themes ) ) {
257 foreach( (array) $themes as $key => $theme ) {
258 $theme_key = esc_html( $theme['Stylesheet'] );
259 if ( isset( $blog_allowed_themes[$key] ) == true ) {
260 $blog_allowedthemes[$theme_key] = 1;
263 $blog_allowed_themes = $blog_allowedthemes;
264 add_option( 'allowedthemes', $blog_allowed_themes );
265 delete_option( 'allowed_themes' );
270 restore_current_blog();
272 return $blog_allowed_themes;
275 function update_option_new_admin_email( $old_value, $value ) {
276 $email = get_option( 'admin_email' );
277 if ( $value == get_option( 'admin_email' ) || !is_email( $value ) )
280 $hash = md5( $value. time() .mt_rand() );
281 $new_admin_email = array(
285 update_option( 'adminhash', $new_admin_email );
287 $content = apply_filters( 'new_admin_email_content', __( "Dear user,
289 You recently requested to have the administration email address on
291 If this is correct, please click on the following link to change it:
294 You can safely ignore and delete this email if you do not want to
297 This email has been sent to ###EMAIL###
300 All at ###SITENAME###
301 ###SITEURL### "), $new_admin_email );
303 $content = str_replace( '###ADMIN_URL###', esc_url( admin_url( 'options.php?adminhash='.$hash ) ), $content );
304 $content = str_replace( '###EMAIL###', $value, $content );
305 $content = str_replace( '###SITENAME###', get_site_option( 'site_name' ), $content );
306 $content = str_replace( '###SITEURL###', network_home_url(), $content );
308 wp_mail( $value, sprintf( __( '[%s] New Admin Email Address' ), get_option( 'blogname' ) ), $content );
310 add_action( 'update_option_new_admin_email', 'update_option_new_admin_email', 10, 2 );
311 add_action( 'add_option_new_admin_email', 'update_option_new_admin_email', 10, 2 );
313 function send_confirmation_on_profile_email() {
314 global $errors, $wpdb;
315 $current_user = wp_get_current_user();
316 if ( ! is_object($errors) )
317 $errors = new WP_Error();
319 if ( $current_user->id != $_POST['user_id'] )
322 if ( $current_user->user_email != $_POST['email'] ) {
323 if ( !is_email( $_POST['email'] ) ) {
324 $errors->add( 'user_email', __( "<strong>ERROR</strong>: The e-mail address isn't correct." ), array( 'form-field' => 'email' ) );
328 if ( $wpdb->get_var( $wpdb->prepare( "SELECT user_email FROM {$wpdb->users} WHERE user_email=%s", $_POST['email'] ) ) ) {
329 $errors->add( 'user_email', __( "<strong>ERROR</strong>: The e-mail address is already used." ), array( 'form-field' => 'email' ) );
330 delete_option( $current_user->ID . '_new_email' );
334 $hash = md5( $_POST['email'] . time() . mt_rand() );
335 $new_user_email = array(
337 'newemail' => $_POST['email']
339 update_option( $current_user->ID . '_new_email', $new_user_email );
341 $content = apply_filters( 'new_user_email_content', __( "Dear user,
343 You recently requested to have the email address on your account changed.
344 If this is correct, please click on the following link to change it:
347 You can safely ignore and delete this email if you do not want to
350 This email has been sent to ###EMAIL###
353 All at ###SITENAME###
354 ###SITEURL###" ), $new_user_email );
356 $content = str_replace( '###ADMIN_URL###', esc_url( admin_url( 'profile.php?newuseremail='.$hash ) ), $content );
357 $content = str_replace( '###EMAIL###', $_POST['email'], $content);
358 $content = str_replace( '###SITENAME###', get_site_option( 'site_name' ), $content );
359 $content = str_replace( '###SITEURL###', network_home_url(), $content );
361 wp_mail( $_POST['email'], sprintf( __( '[%s] New Email Address' ), get_option( 'blogname' ) ), $content );
362 $_POST['email'] = $current_user->user_email;
365 add_action( 'personal_options_update', 'send_confirmation_on_profile_email' );
367 function new_user_email_admin_notice() {
368 if ( strpos( $_SERVER['PHP_SELF'], 'profile.php' ) && isset( $_GET['updated'] ) && $email = get_option( get_current_user_id() . '_new_email' ) )
369 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>";
371 add_action( 'admin_notices', 'new_user_email_admin_notice' );
373 function get_site_allowed_themes() {
374 $themes = get_themes();
375 $allowed_themes = get_site_option( 'allowedthemes' );
376 if ( !is_array( $allowed_themes ) || empty( $allowed_themes ) ) {
377 $allowed_themes = get_site_option( 'allowed_themes' ); // convert old allowed_themes format
378 if ( !is_array( $allowed_themes ) ) {
379 $allowed_themes = array();
381 foreach( (array) $themes as $key => $theme ) {
382 $theme_key = esc_html( $theme['Stylesheet'] );
383 if ( isset( $allowed_themes[ $key ] ) == true ) {
384 $allowedthemes[ $theme_key ] = 1;
387 $allowed_themes = $allowedthemes;
390 return $allowed_themes;
394 * Determines if there is any upload space left in the current blog's quota.
397 * @return bool True if space is available, false otherwise.
399 function is_upload_space_available() {
400 if ( get_site_option( 'upload_space_check_disabled' ) )
403 if ( !( $space_allowed = get_upload_space_available() ) )
412 * @return int of upload size limit in bytes
414 function upload_size_limit_filter( $size ) {
415 $fileupload_maxk = 1024 * get_site_option( 'fileupload_maxk', 1500 );
416 return min( $size, $fileupload_maxk, get_upload_space_available() );
419 * Determines if there is any upload space left in the current blog's quota.
421 * @return int of upload space available in bytes
423 function get_upload_space_available() {
424 $space_allowed = get_space_allowed() * 1024 * 1024;
425 if ( get_site_option( 'upload_space_check_disabled' ) )
426 return $space_allowed;
428 $dir_name = trailingslashit( BLOGUPLOADDIR );
429 if ( !( is_dir( $dir_name) && is_readable( $dir_name ) ) )
430 return $space_allowed;
432 $dir = dir( $dir_name );
435 while ( $file = $dir->read() ) {
436 if ( $file != '.' && $file != '..' ) {
437 if ( is_dir( $dir_name . $file) ) {
438 $size += get_dirsize( $dir_name . $file );
440 $size += filesize( $dir_name . $file );
446 if ( ( $space_allowed - $size ) <= 0 )
449 return $space_allowed - $size;
453 * Returns the upload quota for the current blog.
457 function get_space_allowed() {
458 $space_allowed = get_option( 'blog_upload_space' );
459 if ( $space_allowed == false )
460 $space_allowed = get_site_option( 'blog_upload_space' );
461 if ( empty( $space_allowed ) || !is_numeric( $space_allowed ) )
464 return $space_allowed;
467 function display_space_usage() {
468 $space = get_space_allowed();
469 $used = get_dirsize( BLOGUPLOADDIR ) / 1024 / 1024;
471 $percentused = ( $used / $space ) * 100;
473 if ( $space > 1000 ) {
474 $space = number_format( $space / 1024 );
475 /* translators: Gigabytes */
476 $space .= __( 'GB' );
478 /* translators: Megabytes */
479 $space .= __( 'MB' );
482 <strong><?php printf( __( 'Used: %1s%% of %2s' ), number_format( $percentused ), $space ); ?></strong>
486 // Display File upload quota on dashboard
487 function dashboard_quota() {
488 if ( get_site_option( 'upload_space_check_disabled' ) )
491 $quota = get_space_allowed();
492 $used = get_dirsize( BLOGUPLOADDIR ) / 1024 / 1024;
494 if ( $used > $quota )
495 $percentused = '100';
497 $percentused = ( $used / $quota ) * 100;
498 $used_color = ( $percentused < 70 ) ? ( ( $percentused >= 40 ) ? 'waiting' : 'approved' ) : 'spam';
499 $used = round( $used, 2 );
500 $percentused = number_format( $percentused );
503 <p class="sub musub"><?php _e( 'Storage Space' ); ?></p>
504 <div class="table table_content musubtable">
507 <td class="first b b-posts"><?php printf( __( '<a href="%1$s" title="Manage Uploads" class="musublink">%2$sMB</a>' ), esc_url( admin_url( 'upload.php' ) ), $quota ); ?></td>
508 <td class="t posts"><?php _e( 'Space Allowed' ); ?></td>
512 <div class="table table_discussion musubtable">
515 <td class="b b-comments"><?php printf( __( '<a href="%1$s" title="Manage Uploads" class="musublink">%2$sMB (%3$s%%)</a>' ), esc_url( admin_url( 'upload.php' ) ), $used, $percentused ); ?></td>
516 <td class="last t comments <?php echo $used_color;?>"><?php _e( 'Space Used' );?></td>
523 if ( current_user_can( 'edit_posts' ) )
524 add_action( 'activity_box_end', 'dashboard_quota' );
526 // Edit blog upload space setting on Edit Blog page
527 function upload_space_setting( $id ) {
528 $quota = get_blog_option( $id, 'blog_upload_space' );
534 <th><?php _e( 'Site Upload Space Quota '); ?></th>
535 <td><input type="text" size="3" name="option[blog_upload_space]" value="<?php echo $quota; ?>" /> <?php _e( 'MB (Leave blank for network default)' ); ?></td>
539 add_action( 'wpmueditblogaction', 'upload_space_setting' );
541 function update_user_status( $id, $pref, $value, $refresh = 1 ) {
544 $wpdb->update( $wpdb->users, array( $pref => $value ), array( 'ID' => $id ) );
547 refresh_user_details( $id );
549 if ( $pref == 'spam' ) {
551 do_action( 'make_spam_user', $id );
553 do_action( 'make_ham_user', $id );
559 function refresh_user_details( $id ) {
562 if ( !$user = get_userdata( $id ) )
565 clean_user_cache( $id );
570 function format_code_lang( $code = '' ) {
571 $code = strtolower( substr( $code, 0, 2 ) );
573 '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',
574 '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',
575 'cs' => 'Czech', 'da' => 'Danish', 'dv' => 'Divehi; Dhivehi; Maldivian', 'nl' => 'Dutch; Flemish', 'dz' => 'Dzongkha', 'en' => 'English', 'eo' => 'Esperanto', 'et' => 'Estonian', 'ee' => 'Ewe', 'fo' => 'Faroese', 'fj' => 'Fijjian', 'fi' => 'Finnish', 'fr' => 'French', 'fy' => 'Western Frisian', 'ff' => 'Fulah', 'ka' => 'Georgian', 'de' => 'German', 'gd' => 'Gaelic; Scottish Gaelic',
576 'ga' => 'Irish', 'gl' => 'Galician', 'gv' => 'Manx', 'el' => 'Greek, Modern', 'gn' => 'Guarani', 'gu' => 'Gujarati', 'ht' => 'Haitian; Haitian Creole', 'ha' => 'Hausa', 'he' => 'Hebrew', 'hz' => 'Herero', 'hi' => 'Hindi', 'ho' => 'Hiri Motu', 'hu' => 'Hungarian', 'ig' => 'Igbo', 'is' => 'Icelandic', 'io' => 'Ido', 'ii' => 'Sichuan Yi', 'iu' => 'Inuktitut', 'ie' => 'Interlingue',
577 'ia' => 'Interlingua (International Auxiliary Language Association)', 'id' => 'Indonesian', 'ik' => 'Inupiaq', 'it' => 'Italian', 'jv' => 'Javanese', 'ja' => 'Japanese', 'kl' => 'Kalaallisut; Greenlandic', 'kn' => 'Kannada', 'ks' => 'Kashmiri', 'kr' => 'Kanuri', 'kk' => 'Kazakh', 'km' => 'Central Khmer', 'ki' => 'Kikuyu; Gikuyu', 'rw' => 'Kinyarwanda', 'ky' => 'Kirghiz; Kyrgyz',
578 'kv' => 'Komi', 'kg' => 'Kongo', 'ko' => 'Korean', 'kj' => 'Kuanyama; Kwanyama', 'ku' => 'Kurdish', 'lo' => 'Lao', 'la' => 'Latin', 'lv' => 'Latvian', 'li' => 'Limburgan; Limburger; Limburgish', 'ln' => 'Lingala', 'lt' => 'Lithuanian', 'lb' => 'Luxembourgish; Letzeburgesch', 'lu' => 'Luba-Katanga', 'lg' => 'Ganda', 'mk' => 'Macedonian', 'mh' => 'Marshallese', 'ml' => 'Malayalam',
579 'mi' => 'Maori', 'mr' => 'Marathi', 'ms' => 'Malay', 'mg' => 'Malagasy', 'mt' => 'Maltese', 'mo' => 'Moldavian', 'mn' => 'Mongolian', 'na' => 'Nauru', 'nv' => 'Navajo; Navaho', 'nr' => 'Ndebele, South; South Ndebele', 'nd' => 'Ndebele, North; North Ndebele', 'ng' => 'Ndonga', 'ne' => 'Nepali', 'nn' => 'Norwegian Nynorsk; Nynorsk, Norwegian', 'nb' => 'Bokmål, Norwegian, Norwegian Bokmål',
580 'no' => 'Norwegian', 'ny' => 'Chichewa; Chewa; Nyanja', 'oc' => 'Occitan, Provençal', 'oj' => 'Ojibwa', 'or' => 'Oriya', 'om' => 'Oromo', 'os' => 'Ossetian; Ossetic', 'pa' => 'Panjabi; Punjabi', 'fa' => 'Persian', 'pi' => 'Pali', 'pl' => 'Polish', 'pt' => 'Portuguese', 'ps' => 'Pushto', 'qu' => 'Quechua', 'rm' => 'Romansh', 'ro' => 'Romanian', 'rn' => 'Rundi', 'ru' => 'Russian',
581 'sg' => 'Sango', 'sa' => 'Sanskrit', 'sr' => 'Serbian', 'hr' => 'Croatian', 'si' => 'Sinhala; Sinhalese', 'sk' => 'Slovak', 'sl' => 'Slovenian', 'se' => 'Northern Sami', 'sm' => 'Samoan', 'sn' => 'Shona', 'sd' => 'Sindhi', 'so' => 'Somali', 'st' => 'Sotho, Southern', 'es' => 'Spanish; Castilian', 'sc' => 'Sardinian', 'ss' => 'Swati', 'su' => 'Sundanese', 'sw' => 'Swahili',
582 'sv' => 'Swedish', 'ty' => 'Tahitian', 'ta' => 'Tamil', 'tt' => 'Tatar', 'te' => 'Telugu', 'tg' => 'Tajik', 'tl' => 'Tagalog', 'th' => 'Thai', 'bo' => 'Tibetan', 'ti' => 'Tigrinya', 'to' => 'Tonga (Tonga Islands)', 'tn' => 'Tswana', 'ts' => 'Tsonga', 'tk' => 'Turkmen', 'tr' => 'Turkish', 'tw' => 'Twi', 'ug' => 'Uighur; Uyghur', 'uk' => 'Ukrainian', 'ur' => 'Urdu', 'uz' => 'Uzbek',
583 've' => 'Venda', 'vi' => 'Vietnamese', 'vo' => 'Volapük', 'cy' => 'Welsh','wa' => 'Walloon','wo' => 'Wolof', 'xh' => 'Xhosa', 'yi' => 'Yiddish', 'yo' => 'Yoruba', 'za' => 'Zhuang; Chuang', 'zu' => 'Zulu' );
584 $lang_codes = apply_filters( 'lang_codes', $lang_codes, $code );
585 return strtr( $code, $lang_codes );
588 function sync_category_tag_slugs( $term, $taxonomy ) {
589 if ( global_terms_enabled() && ( $taxonomy == 'category' || $taxonomy == 'post_tag' ) ) {
590 if ( is_object( $term ) ) {
591 $term->slug = sanitize_title( $term->name );
593 $term['slug'] = sanitize_title( $term['name'] );
598 add_filter( 'get_term', 'sync_category_tag_slugs', 10, 2 );
600 function redirect_user_to_blog() {
602 if ( isset( $_GET['c'] ) )
603 $c = (int) $_GET['c'];
606 wp_die( __( "You don’t have permission to view this site. Please contact the system administrator." ) );
610 $blog = get_active_blog_for_user( get_current_user_id() );
611 $dashboard_blog = get_dashboard_blog();
612 if ( is_object( $blog ) ) {
613 wp_redirect( get_admin_url( $blog->blog_id, '?c=' . $c ) ); // redirect and count to 5, "just in case"
618 If the user is a member of only 1 blog and the user's primary_blog isn't set to that blog,
619 then update the primary_blog record to match the user's blog
621 $blogs = get_blogs_of_user( get_current_user_id() );
623 if ( !empty( $blogs ) ) {
624 foreach( $blogs as $blogid => $blog ) {
625 if ( $blogid != $dashboard_blog->blog_id && get_user_meta( get_current_user_id() , 'primary_blog', true ) == $dashboard_blog->blog_id ) {
626 update_user_meta( get_current_user_id(), 'primary_blog', $blogid );
630 $blog = get_blog_details( get_user_meta( get_current_user_id(), 'primary_blog', true ) );
631 wp_redirect( get_admin_url( $blog->blog_id, '?c=' . $c ) );
634 wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
636 add_action( 'admin_page_access_denied', 'redirect_user_to_blog', 99 );
638 function check_import_new_users( $permission ) {
639 if ( !is_super_admin() )
643 add_filter( 'import_allow_create_users', 'check_import_new_users' );
644 // See "import_allow_fetch_attachments" and "import_attachment_size_limit" filters too.
646 function mu_dropdown_languages( $lang_files = array(), $current = '' ) {
650 foreach ( (array) $lang_files as $val ) {
651 $code_lang = basename( $val, '.mo' );
653 if ( $code_lang == 'en_US' ) { // American English
655 $ae = __( 'American English' );
656 $output[$ae] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . $ae . '</option>';
657 } elseif ( $code_lang == 'en_GB' ) { // British English
659 $be = __( 'British English' );
660 $output[$be] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . $be . '</option>';
662 $translated = format_code_lang( $code_lang );
663 $output[$translated] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . esc_html ( $translated ) . '</option>';
668 if ( $flag === false ) // WordPress english
669 $output[] = '<option value=""' . selected( $current, '', false ) . '>' . __( 'English' ) . "</option>";
672 uksort( $output, 'strnatcasecmp' );
674 $output = apply_filters( 'mu_dropdown_languages', $output, $lang_files, $current );
675 echo implode( "\n\t", $output );
678 /* Warn the admin if SECRET SALT information is missing from wp-config.php */
679 function secret_salt_warning() {
680 if ( !is_super_admin() )
682 $secret_keys = array( 'AUTH_KEY', 'SECURE_AUTH_KEY', 'LOGGED_IN_KEY', 'NONCE_KEY', 'AUTH_SALT', 'SECURE_AUTH_SALT', 'LOGGED_IN_SALT', 'NONCE_SALT' );
684 foreach( $secret_keys as $key ) {
685 if ( ! defined( $key ) )
686 $out .= "define( '$key', '" . esc_html( wp_generate_password( 64, true, true ) ) . "' );<br />";
689 $msg = __( 'Warning! WordPress encrypts user cookies, but you must add the following lines to <strong>wp-config.php</strong> for it to be more secure.' );
690 $msg .= '<br/>' . __( "Before the line <code>/* That's all, stop editing! Happy blogging. */</code> please add this code:" );
691 $msg .= "<br/><br/><code>$out</code>";
693 echo "<div class='update-nag'>$msg</div>";
696 add_action( 'admin_notices', 'secret_salt_warning' );
698 function admin_notice_feed() {
699 global $current_screen;
700 if ( $current_screen->id != 'dashboard' )
703 if ( !empty( $_GET['feed_dismiss'] ) ) {
704 update_user_option( get_current_user_id(), 'admin_feed_dismiss', $_GET['feed_dismiss'], true );
708 $url = get_site_option( 'admin_notice_feed' );
712 $rss = fetch_feed( $url );
713 if ( ! is_wp_error( $rss ) && $item = $rss->get_item() ) {
714 $title = $item->get_title();
715 if ( md5( $title ) == get_user_option( 'admin_feed_dismiss' ) )
717 $msg = "<h3>" . esc_html( $title ) . "</h3>\n";
718 $content = $item->get_description();
719 $content = $content ? wp_html_excerpt( $content, 200 ) . ' … ' : '';
720 $link = esc_url( strip_tags( $item->get_link() ) );
721 $msg .= "<p>" . $content . "<a href='$link'>" . __( 'Read More' ) . "</a> <a href='index.php?feed_dismiss=" . md5( $title ) . "'>" . __( 'Dismiss' ) . "</a></p>";
722 echo "<div class='updated'>$msg</div>";
723 } elseif ( is_super_admin() ) {
724 printf( '<div class="update-nag">' . __( 'Your feed at %s is empty.' ) . '</div>', esc_html( $url ) );
727 add_action( 'admin_notices', 'admin_notice_feed' );
729 function site_admin_notice() {
730 global $wp_db_version;
731 if ( !is_super_admin() )
733 if ( get_site_option( 'wpmu_upgrade_site' ) != $wp_db_version )
734 echo "<div class='update-nag'>" . sprintf( __( 'Thank you for Updating! Please visit the <a href="%s">Update Network</a> page to update all your sites.' ), esc_url( admin_url( 'ms-upgrade-network.php' ) ) ) . "</div>";
736 add_action( 'admin_notices', 'site_admin_notice' );
738 function avoid_blog_page_permalink_collision( $data, $postarr ) {
739 if ( is_subdomain_install() )
741 if ( $data['post_type'] != 'page' )
743 if ( !isset( $data['post_name'] ) || $data['post_name'] == '' )
745 if ( !is_main_site() )
748 $post_name = $data['post_name'];
750 while( $c < 10 && get_id_from_blogname( $post_name ) ) {
751 $post_name .= mt_rand( 1, 10 );
754 if ( $post_name != $data['post_name'] ) {
755 $data['post_name'] = $post_name;
759 add_filter( 'wp_insert_post_data', 'avoid_blog_page_permalink_collision', 10, 2 );
761 function choose_primary_blog() {
763 <table class="form-table">
765 <?php /* translators: My sites label */ ?>
766 <th scope="row"><?php _e( 'Primary Site' ); ?></th>
769 $all_blogs = get_blogs_of_user( get_current_user_id() );
770 $primary_blog = get_user_meta( get_current_user_id(), 'primary_blog', true );
771 if ( count( $all_blogs ) > 1 ) {
774 <select name="primary_blog">
775 <?php foreach( (array) $all_blogs as $blog ) {
776 if ( $primary_blog == $blog->userblog_id )
778 ?><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
783 $blog = array_shift( $all_blogs );
784 update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id );
786 } elseif ( count( $all_blogs ) == 1 ) {
787 $blog = array_shift( $all_blogs );
789 if ( $primary_blog != $blog->userblog_id ) // Set the primary blog again if it's out of sync with blog list.
790 update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id );
797 <?php if ( in_array( get_site_option( 'registration' ), array( 'all', 'blog' ) ) ) : ?>
799 <th scope="row" colspan="2" class="th-full">
800 <a href="<?php echo apply_filters( 'wp_signup_location', network_home_url( 'wp-signup.php' ) ); ?>"><?php _e( 'Create a New Site' ); ?></a>
808 function show_post_thumbnail_warning() {
809 if ( ! is_super_admin() )
811 $mu_media_buttons = get_site_option( 'mu_media_buttons', array() );
812 if ( empty($mu_media_buttons['image']) && current_theme_supports( 'post-thumbnails' ) ) {
813 echo "<div class='update-nag'>" . sprintf( __( "Warning! The current theme supports Featured Images. You must enable image uploads on <a href='%s'>the options page</a> for it to work." ), esc_url( admin_url( 'ms-options.php' ) ) ) . "</div>";
816 add_action( 'admin_notices', 'show_post_thumbnail_warning' );
818 function ms_deprecated_blogs_file() {
819 if ( ! is_super_admin() )
821 if ( ! file_exists( WP_CONTENT_DIR . '/blogs.php' ) )
823 echo '<div class="update-nag">' . sprintf( __( 'The <code>%1$s</code> file is deprecated. Please remove it and update your server rewrite rules to use <code>%2$s</code> instead.' ), 'wp-content/blogs.php', 'wp-includes/ms-files.php' ) . '</div>';
825 add_action( 'admin_notices', 'ms_deprecated_blogs_file' );
828 * Outputs the notice message for multisite regarding activation of plugin page.
833 function _admin_notice_multisite_activate_plugins_page() {
834 $message = sprintf( __( 'The plugins page is not visible to normal users. It must be activated first. %s' ), '<a href="' . esc_url( admin_url( 'ms-options.php#menu' ) ) . '">' . __( 'Activate' ) . '</a>' );
835 echo "<div class='error'><p>$message</p></div>";
839 * Grants super admin privileges.
844 function grant_super_admin( $user_id ) {
845 global $super_admins;
847 // If global super_admins override is defined, there is nothing to do here.
848 if ( isset($super_admins) )
851 do_action( 'grant_super_admin', $user_id );
853 // Directly fetch site_admins instead of using get_super_admins()
854 $super_admins = get_site_option( 'site_admins', array( 'admin' ) );
856 $user = new WP_User( $user_id );
857 if ( ! in_array( $user->user_login, $super_admins ) ) {
858 $super_admins[] = $user->user_login;
859 update_site_option( 'site_admins' , $super_admins );
860 do_action( 'granted_super_admin', $user_id );
867 * Revokes super admin privileges.
872 function revoke_super_admin( $user_id ) {
873 global $super_admins;
875 // If global super_admins override is defined, there is nothing to do here.
876 if ( isset($super_admins) )
879 do_action( 'revoke_super_admin', $user_id );
881 // Directly fetch site_admins instead of using get_super_admins()
882 $super_admins = get_site_option( 'site_admins', array( 'admin' ) );
884 $user = new WP_User( $user_id );
885 if ( $user->user_email != get_site_option( 'admin_email' ) ) {
886 if ( false !== ( $key = array_search( $user->user_login, $super_admins ) ) ) {
887 unset( $super_admins[$key] );
888 update_site_option( 'site_admins', $super_admins );
889 do_action( 'revoked_super_admin', $user_id );