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_left = get_upload_space_available();
30 $file_size = filesize( $file['tmp_name'] );
31 if ( $space_left < $file_size )
32 $file['error'] = sprintf( __( 'Not enough space to upload. %1$s KB needed.' ), number_format( ($file_size - $space_left) /1024 ) );
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 ) );
35 if ( upload_is_user_over_quota( false ) ) {
36 $file['error'] = __( 'You have used your space quota. Please delete files before uploading.' );
38 if ( $file['error'] != '0' && !isset($_POST['html-upload']) )
39 wp_die( $file['error'] . ' <a href="javascript:history.go(-1)">' . __( 'Back' ) . '</a>' );
43 add_filter( 'wp_handle_upload_prefilter', 'check_upload_size' );
50 * @param int $blog_id Blog ID
51 * @param bool $drop True if blog's table should be dropped. Default is false.
54 function wpmu_delete_blog( $blog_id, $drop = false ) {
55 global $wpdb, $current_site;
58 if ( get_current_blog_id() != $blog_id ) {
60 switch_to_blog( $blog_id );
63 $blog = get_blog_details( $blog_id );
65 do_action( 'delete_blog', $blog_id, $drop );
67 $users = get_users( array( 'blog_id' => $blog_id, 'fields' => 'ids' ) );
69 // Remove users from this blog.
70 if ( ! empty( $users ) ) {
71 foreach ( $users as $user_id ) {
72 remove_user_from_blog( $user_id, $blog_id );
76 update_blog_status( $blog_id, 'deleted', 1 );
78 // Don't destroy the initial, main, or root blog.
79 if ( $drop && ( 1 == $blog_id || is_main_site( $blog_id ) || ( $blog->path == $current_site->path && $blog->domain == $current_site->domain ) ) )
83 $drop_tables = apply_filters( 'wpmu_drop_tables', $wpdb->tables( 'blog' ), $blog_id );
85 foreach ( (array) $drop_tables as $table ) {
86 $wpdb->query( "DROP TABLE IF EXISTS `$table`" );
89 $wpdb->delete( $wpdb->blogs, array( 'blog_id' => $blog_id ) );
91 $uploads = wp_upload_dir();
92 $dir = apply_filters( 'wpmu_delete_blog_upload_dir', $uploads['basedir'], $blog_id );
93 $dir = rtrim( $dir, DIRECTORY_SEPARATOR );
98 while ( $index < count( $stack ) ) {
99 # Get indexed directory from stack
100 $dir = $stack[$index];
102 $dh = @opendir( $dir );
104 while ( ( $file = @readdir( $dh ) ) !== false ) {
105 if ( $file == '.' || $file == '..' )
108 if ( @is_dir( $dir . DIRECTORY_SEPARATOR . $file ) )
109 $stack[] = $dir . DIRECTORY_SEPARATOR . $file;
110 else if ( @is_file( $dir . DIRECTORY_SEPARATOR . $file ) )
111 @unlink( $dir . DIRECTORY_SEPARATOR . $file );
118 $stack = array_reverse( $stack ); // Last added dirs are deepest
119 foreach( (array) $stack as $dir ) {
120 if ( $dir != $top_dir)
124 clean_blog_cache( $blog );
128 restore_current_blog();
131 // @todo Merge with wp_delete_user() ?
132 function wpmu_delete_user( $id ) {
136 $user = new WP_User( $id );
138 if ( !$user->exists() )
141 do_action( 'wpmu_delete_user', $id );
143 $blogs = get_blogs_of_user( $id );
145 if ( ! empty( $blogs ) ) {
146 foreach ( $blogs as $blog ) {
147 switch_to_blog( $blog->userblog_id );
148 remove_user_from_blog( $id, $blog->userblog_id );
150 $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d", $id ) );
151 foreach ( (array) $post_ids as $post_id ) {
152 wp_delete_post( $post_id );
156 $link_ids = $wpdb->get_col( $wpdb->prepare( "SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $id ) );
159 foreach ( $link_ids as $link_id )
160 wp_delete_link( $link_id );
163 restore_current_blog();
167 $meta = $wpdb->get_col( $wpdb->prepare( "SELECT umeta_id FROM $wpdb->usermeta WHERE user_id = %d", $id ) );
168 foreach ( $meta as $mid )
169 delete_metadata_by_mid( 'user', $mid );
171 $wpdb->delete( $wpdb->users, array( 'ID' => $id ) );
173 clean_user_cache( $user );
175 // allow for commit transaction
176 do_action( 'deleted_user', $id );
181 function update_option_new_admin_email( $old_value, $value ) {
182 $email = get_option( 'admin_email' );
183 if ( $value == get_option( 'admin_email' ) || !is_email( $value ) )
186 $hash = md5( $value. time() .mt_rand() );
187 $new_admin_email = array(
191 update_option( 'adminhash', $new_admin_email );
193 $content = apply_filters( 'new_admin_email_content', __( "Dear user,
195 You recently requested to have the administration email address on
197 If this is correct, please click on the following link to change it:
200 You can safely ignore and delete this email if you do not want to
203 This email has been sent to ###EMAIL###
206 All at ###SITENAME###
207 ###SITEURL### "), $new_admin_email );
209 $content = str_replace( '###ADMIN_URL###', esc_url( admin_url( 'options.php?adminhash='.$hash ) ), $content );
210 $content = str_replace( '###EMAIL###', $value, $content );
211 $content = str_replace( '###SITENAME###', get_site_option( 'site_name' ), $content );
212 $content = str_replace( '###SITEURL###', network_home_url(), $content );
214 wp_mail( $value, sprintf( __( '[%s] New Admin Email Address' ), get_option( 'blogname' ) ), $content );
216 add_action( 'update_option_new_admin_email', 'update_option_new_admin_email', 10, 2 );
217 add_action( 'add_option_new_admin_email', 'update_option_new_admin_email', 10, 2 );
219 function send_confirmation_on_profile_email() {
220 global $errors, $wpdb;
221 $current_user = wp_get_current_user();
222 if ( ! is_object($errors) )
223 $errors = new WP_Error();
225 if ( $current_user->ID != $_POST['user_id'] )
228 if ( $current_user->user_email != $_POST['email'] ) {
229 if ( !is_email( $_POST['email'] ) ) {
230 $errors->add( 'user_email', __( "<strong>ERROR</strong>: The email address isn’t correct." ), array( 'form-field' => 'email' ) );
234 if ( $wpdb->get_var( $wpdb->prepare( "SELECT user_email FROM {$wpdb->users} WHERE user_email=%s", $_POST['email'] ) ) ) {
235 $errors->add( 'user_email', __( "<strong>ERROR</strong>: The email address is already used." ), array( 'form-field' => 'email' ) );
236 delete_option( $current_user->ID . '_new_email' );
240 $hash = md5( $_POST['email'] . time() . mt_rand() );
241 $new_user_email = array(
243 'newemail' => $_POST['email']
245 update_option( $current_user->ID . '_new_email', $new_user_email );
247 $content = apply_filters( 'new_user_email_content', __( "Dear user,
249 You recently requested to have the email address on your account changed.
250 If this is correct, please click on the following link to change it:
253 You can safely ignore and delete this email if you do not want to
256 This email has been sent to ###EMAIL###
259 All at ###SITENAME###
260 ###SITEURL###" ), $new_user_email );
262 $content = str_replace( '###ADMIN_URL###', esc_url( admin_url( 'profile.php?newuseremail='.$hash ) ), $content );
263 $content = str_replace( '###EMAIL###', $_POST['email'], $content);
264 $content = str_replace( '###SITENAME###', get_site_option( 'site_name' ), $content );
265 $content = str_replace( '###SITEURL###', network_home_url(), $content );
267 wp_mail( $_POST['email'], sprintf( __( '[%s] New Email Address' ), get_option( 'blogname' ) ), $content );
268 $_POST['email'] = $current_user->user_email;
271 add_action( 'personal_options_update', 'send_confirmation_on_profile_email' );
273 function new_user_email_admin_notice() {
274 if ( strpos( $_SERVER['PHP_SELF'], 'profile.php' ) && isset( $_GET['updated'] ) && $email = get_option( get_current_user_id() . '_new_email' ) )
275 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>";
277 add_action( 'admin_notices', 'new_user_email_admin_notice' );
280 * Check whether a blog has used its allotted upload space.
284 * @param bool $echo Optional. If $echo is set and the quota is exceeded, a warning message is echoed. Default is true.
287 function upload_is_user_over_quota( $echo = true ) {
288 if ( get_site_option( 'upload_space_check_disabled' ) )
291 $space_allowed = get_space_allowed();
292 if ( empty( $space_allowed ) || !is_numeric( $space_allowed ) )
293 $space_allowed = 10; // Default space allowed is 10 MB
295 $space_used = get_space_used();
297 if ( ( $space_allowed - $space_used ) < 0 ) {
299 _e( 'Sorry, you have used your space allocation. Please delete some files to upload more files.' );
307 * Displays the amount of disk space used by the current blog. Not used in core.
311 function display_space_usage() {
312 $space_allowed = get_space_allowed();
313 $space_used = get_space_used();
315 $percent_used = ( $space_used / $space_allowed ) * 100;
317 if ( $space_allowed > 1000 ) {
318 $space = number_format( $space_allowed / 1024 );
319 /* translators: Gigabytes */
320 $space .= __( 'GB' );
322 $space = number_format( $space_allowed );
323 /* translators: Megabytes */
324 $space .= __( 'MB' );
327 <strong><?php printf( __( 'Used: %1$s%% of %2$s' ), number_format( $percent_used ), $space ); ?></strong>
332 * Get the remaining upload space for this blog.
335 * @uses upload_is_user_over_quota()
336 * @uses get_space_allowed()
337 * @uses get_upload_space_available()
339 * @param int $size Current max size in bytes
340 * @return int Max size in bytes
342 function fix_import_form_size( $size ) {
343 if ( upload_is_user_over_quota( false ) == true )
346 $available = get_upload_space_available();
347 return min( $size, $available );
350 // Edit blog upload space setting on Edit Blog page
351 function upload_space_setting( $id ) {
352 switch_to_blog( $id );
353 $quota = get_option( 'blog_upload_space' );
354 restore_current_blog();
361 <th><?php _e( 'Site Upload Space Quota '); ?></th>
362 <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>
366 add_action( 'wpmueditblogaction', 'upload_space_setting' );
368 function update_user_status( $id, $pref, $value, $deprecated = null ) {
371 if ( null !== $deprecated )
372 _deprecated_argument( __FUNCTION__, '3.1' );
374 $wpdb->update( $wpdb->users, array( sanitize_key( $pref ) => $value ), array( 'ID' => $id ) );
376 $user = new WP_User( $id );
377 clean_user_cache( $user );
379 if ( $pref == 'spam' ) {
381 do_action( 'make_spam_user', $id );
383 do_action( 'make_ham_user', $id );
389 function refresh_user_details( $id ) {
392 if ( !$user = get_userdata( $id ) )
395 clean_user_cache( $user );
400 function format_code_lang( $code = '' ) {
401 $code = strtolower( substr( $code, 0, 2 ) );
403 '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',
404 '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',
405 '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',
406 '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',
407 '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',
408 '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',
409 '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',
410 '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',
411 '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',
412 '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',
413 've' => 'Venda', 'vi' => 'Vietnamese', 'vo' => 'Volapük', 'cy' => 'Welsh','wa' => 'Walloon','wo' => 'Wolof', 'xh' => 'Xhosa', 'yi' => 'Yiddish', 'yo' => 'Yoruba', 'za' => 'Zhuang; Chuang', 'zu' => 'Zulu' );
414 $lang_codes = apply_filters( 'lang_codes', $lang_codes, $code );
415 return strtr( $code, $lang_codes );
418 function sync_category_tag_slugs( $term, $taxonomy ) {
419 if ( global_terms_enabled() && ( $taxonomy == 'category' || $taxonomy == 'post_tag' ) ) {
420 if ( is_object( $term ) ) {
421 $term->slug = sanitize_title( $term->name );
423 $term['slug'] = sanitize_title( $term['name'] );
428 add_filter( 'get_term', 'sync_category_tag_slugs', 10, 2 );
430 function _access_denied_splash() {
431 if ( ! is_user_logged_in() || is_network_admin() )
434 $blogs = get_blogs_of_user( get_current_user_id() );
436 if ( wp_list_filter( $blogs, array( 'userblog_id' => get_current_blog_id() ) ) )
439 $blog_name = get_bloginfo( 'name' );
441 if ( empty( $blogs ) )
442 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 ) );
444 $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>';
445 $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>';
447 $output .= '<h3>' . __('Your Sites') . '</h3>';
448 $output .= '<table>';
450 foreach ( $blogs as $blog ) {
452 $output .= "<td valign='top'>";
453 $output .= "{$blog->blogname}";
455 $output .= "<td valign='top'>";
456 $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>" ;
460 $output .= '</table>';
464 add_action( 'admin_page_access_denied', '_access_denied_splash', 99 );
466 function check_import_new_users( $permission ) {
467 if ( !is_super_admin() )
471 add_filter( 'import_allow_create_users', 'check_import_new_users' );
472 // See "import_allow_fetch_attachments" and "import_attachment_size_limit" filters too.
474 function mu_dropdown_languages( $lang_files = array(), $current = '' ) {
478 foreach ( (array) $lang_files as $val ) {
479 $code_lang = basename( $val, '.mo' );
481 if ( $code_lang == 'en_US' ) { // American English
483 $ae = __( 'American English' );
484 $output[$ae] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . $ae . '</option>';
485 } elseif ( $code_lang == 'en_GB' ) { // British English
487 $be = __( 'British English' );
488 $output[$be] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . $be . '</option>';
490 $translated = format_code_lang( $code_lang );
491 $output[$translated] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . esc_html ( $translated ) . '</option>';
496 if ( $flag === false ) // WordPress english
497 $output[] = '<option value=""' . selected( $current, '', false ) . '>' . __( 'English' ) . "</option>";
500 uksort( $output, 'strnatcasecmp' );
502 $output = apply_filters( 'mu_dropdown_languages', $output, $lang_files, $current );
503 echo implode( "\n\t", $output );
506 /* Warn the admin if SECRET SALT information is missing from wp-config.php */
507 function secret_salt_warning() {
508 if ( !is_super_admin() )
510 $secret_keys = array( 'AUTH_KEY', 'SECURE_AUTH_KEY', 'LOGGED_IN_KEY', 'NONCE_KEY', 'AUTH_SALT', 'SECURE_AUTH_SALT', 'LOGGED_IN_SALT', 'NONCE_SALT' );
512 foreach( $secret_keys as $key ) {
513 if ( ! defined( $key ) )
514 $out .= "define( '$key', '" . esc_html( wp_generate_password( 64, true, true ) ) . "' );<br />";
517 $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.' );
518 $msg .= '<br/>' . __( "Before the line <code>/* That's all, stop editing! Happy blogging. */</code> please add this code:" );
519 $msg .= "<br/><br/><code>$out</code>";
521 echo "<div class='update-nag'>$msg</div>";
524 add_action( 'network_admin_notices', 'secret_salt_warning' );
526 function site_admin_notice() {
527 global $wp_db_version;
528 if ( !is_super_admin() )
530 if ( get_site_option( 'wpmu_upgrade_site' ) != $wp_db_version )
531 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>";
533 add_action( 'admin_notices', 'site_admin_notice' );
534 add_action( 'network_admin_notices', 'site_admin_notice' );
536 function avoid_blog_page_permalink_collision( $data, $postarr ) {
537 if ( is_subdomain_install() )
539 if ( $data['post_type'] != 'page' )
541 if ( !isset( $data['post_name'] ) || $data['post_name'] == '' )
543 if ( !is_main_site() )
546 $post_name = $data['post_name'];
548 while( $c < 10 && get_id_from_blogname( $post_name ) ) {
549 $post_name .= mt_rand( 1, 10 );
552 if ( $post_name != $data['post_name'] ) {
553 $data['post_name'] = $post_name;
557 add_filter( 'wp_insert_post_data', 'avoid_blog_page_permalink_collision', 10, 2 );
559 function choose_primary_blog() {
561 <table class="form-table">
563 <?php /* translators: My sites label */ ?>
564 <th scope="row"><?php _e( 'Primary Site' ); ?></th>
567 $all_blogs = get_blogs_of_user( get_current_user_id() );
568 $primary_blog = get_user_meta( get_current_user_id(), 'primary_blog', true );
569 if ( count( $all_blogs ) > 1 ) {
572 <select name="primary_blog">
573 <?php foreach( (array) $all_blogs as $blog ) {
574 if ( $primary_blog == $blog->userblog_id )
576 ?><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
581 $blog = array_shift( $all_blogs );
582 update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id );
584 } elseif ( count( $all_blogs ) == 1 ) {
585 $blog = array_shift( $all_blogs );
587 if ( $primary_blog != $blog->userblog_id ) // Set the primary blog again if it's out of sync with blog list.
588 update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id );
595 <?php if ( in_array( get_site_option( 'registration' ), array( 'all', 'blog' ) ) ) : ?>
597 <th scope="row" colspan="2" class="th-full">
598 <a href="<?php echo apply_filters( 'wp_signup_location', network_site_url( 'wp-signup.php' ) ); ?>"><?php _e( 'Create a New Site' ); ?></a>
607 * Grants super admin privileges.
610 * @param int $user_id
612 function grant_super_admin( $user_id ) {
613 global $super_admins;
615 // If global super_admins override is defined, there is nothing to do here.
616 if ( isset($super_admins) )
619 do_action( 'grant_super_admin', $user_id );
621 // Directly fetch site_admins instead of using get_super_admins()
622 $super_admins = get_site_option( 'site_admins', array( 'admin' ) );
624 $user = get_userdata( $user_id );
625 if ( $user && ! in_array( $user->user_login, $super_admins ) ) {
626 $super_admins[] = $user->user_login;
627 update_site_option( 'site_admins' , $super_admins );
628 do_action( 'granted_super_admin', $user_id );
635 * Revokes super admin privileges.
638 * @param int $user_id
640 function revoke_super_admin( $user_id ) {
641 global $super_admins;
643 // If global super_admins override is defined, there is nothing to do here.
644 if ( isset($super_admins) )
647 do_action( 'revoke_super_admin', $user_id );
649 // Directly fetch site_admins instead of using get_super_admins()
650 $super_admins = get_site_option( 'site_admins', array( 'admin' ) );
652 $user = get_userdata( $user_id );
653 if ( $user && $user->user_email != get_site_option( 'admin_email' ) ) {
654 if ( false !== ( $key = array_search( $user->user_login, $super_admins ) ) ) {
655 unset( $super_admins[$key] );
656 update_site_option( 'site_admins', $super_admins );
657 do_action( 'revoked_super_admin', $user_id );
665 * Whether or not we can edit this network from this page
667 * By default editing of network is restricted to the Network Admin for that site_id this allows for this to be overridden
670 * @param integer $site_id The network/site id to check.
672 function can_edit_network( $site_id ) {
675 if ($site_id == $wpdb->siteid )
680 return apply_filters( 'can_edit_network', $result, $site_id );
684 * Thickbox image paths for Network Admin.
689 function _thickbox_path_admin_subfolder() {
691 <script type="text/javascript">
693 var tb_pathToImage = "../../wp-includes/js/thickbox/loadingAnimation.gif";