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' ) );
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 do_action( 'wpmu_delete_user', $id );
140 $blogs = get_blogs_of_user( $id );
142 if ( ! empty( $blogs ) ) {
143 foreach ( $blogs as $blog ) {
144 switch_to_blog( $blog->userblog_id );
145 remove_user_from_blog( $id, $blog->userblog_id );
147 $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d", $id ) );
148 foreach ( (array) $post_ids as $post_id ) {
149 wp_delete_post( $post_id );
153 $link_ids = $wpdb->get_col( $wpdb->prepare( "SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $id ) );
156 foreach ( $link_ids as $link_id )
157 wp_delete_link( $link_id );
160 restore_current_blog();
164 $meta = $wpdb->get_col( $wpdb->prepare( "SELECT umeta_id FROM $wpdb->usermeta WHERE user_id = %d", $id ) );
165 foreach ( $meta as $mid )
166 delete_metadata_by_mid( 'user', $mid );
168 $wpdb->delete( $wpdb->users, array( 'ID' => $id ) );
170 clean_user_cache( $user );
172 // allow for commit transaction
173 do_action( 'deleted_user', $id );
178 function update_option_new_admin_email( $old_value, $value ) {
179 $email = get_option( 'admin_email' );
180 if ( $value == get_option( 'admin_email' ) || !is_email( $value ) )
183 $hash = md5( $value. time() .mt_rand() );
184 $new_admin_email = array(
188 update_option( 'adminhash', $new_admin_email );
190 $content = apply_filters( 'new_admin_email_content', __( "Dear user,
192 You recently requested to have the administration email address on
194 If this is correct, please click on the following link to change it:
197 You can safely ignore and delete this email if you do not want to
200 This email has been sent to ###EMAIL###
203 All at ###SITENAME###
204 ###SITEURL### "), $new_admin_email );
206 $content = str_replace( '###ADMIN_URL###', esc_url( admin_url( 'options.php?adminhash='.$hash ) ), $content );
207 $content = str_replace( '###EMAIL###', $value, $content );
208 $content = str_replace( '###SITENAME###', get_site_option( 'site_name' ), $content );
209 $content = str_replace( '###SITEURL###', network_home_url(), $content );
211 wp_mail( $value, sprintf( __( '[%s] New Admin Email Address' ), get_option( 'blogname' ) ), $content );
213 add_action( 'update_option_new_admin_email', 'update_option_new_admin_email', 10, 2 );
214 add_action( 'add_option_new_admin_email', 'update_option_new_admin_email', 10, 2 );
216 function send_confirmation_on_profile_email() {
217 global $errors, $wpdb;
218 $current_user = wp_get_current_user();
219 if ( ! is_object($errors) )
220 $errors = new WP_Error();
222 if ( $current_user->ID != $_POST['user_id'] )
225 if ( $current_user->user_email != $_POST['email'] ) {
226 if ( !is_email( $_POST['email'] ) ) {
227 $errors->add( 'user_email', __( "<strong>ERROR</strong>: The email address isn’t correct." ), array( 'form-field' => 'email' ) );
231 if ( $wpdb->get_var( $wpdb->prepare( "SELECT user_email FROM {$wpdb->users} WHERE user_email=%s", $_POST['email'] ) ) ) {
232 $errors->add( 'user_email', __( "<strong>ERROR</strong>: The email address is already used." ), array( 'form-field' => 'email' ) );
233 delete_option( $current_user->ID . '_new_email' );
237 $hash = md5( $_POST['email'] . time() . mt_rand() );
238 $new_user_email = array(
240 'newemail' => $_POST['email']
242 update_option( $current_user->ID . '_new_email', $new_user_email );
244 $content = apply_filters( 'new_user_email_content', __( "Dear user,
246 You recently requested to have the email address on your account changed.
247 If this is correct, please click on the following link to change it:
250 You can safely ignore and delete this email if you do not want to
253 This email has been sent to ###EMAIL###
256 All at ###SITENAME###
257 ###SITEURL###" ), $new_user_email );
259 $content = str_replace( '###ADMIN_URL###', esc_url( admin_url( 'profile.php?newuseremail='.$hash ) ), $content );
260 $content = str_replace( '###EMAIL###', $_POST['email'], $content);
261 $content = str_replace( '###SITENAME###', get_site_option( 'site_name' ), $content );
262 $content = str_replace( '###SITEURL###', network_home_url(), $content );
264 wp_mail( $_POST['email'], sprintf( __( '[%s] New Email Address' ), get_option( 'blogname' ) ), $content );
265 $_POST['email'] = $current_user->user_email;
268 add_action( 'personal_options_update', 'send_confirmation_on_profile_email' );
270 function new_user_email_admin_notice() {
271 if ( strpos( $_SERVER['PHP_SELF'], 'profile.php' ) && isset( $_GET['updated'] ) && $email = get_option( get_current_user_id() . '_new_email' ) )
272 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>";
274 add_action( 'admin_notices', 'new_user_email_admin_notice' );
277 * Check whether a blog has used its allotted upload space.
281 * @param bool $echo Optional. If $echo is set and the quota is exceeded, a warning message is echoed. Default is true.
284 function upload_is_user_over_quota( $echo = true ) {
285 if ( get_site_option( 'upload_space_check_disabled' ) )
288 $space_allowed = get_space_allowed();
289 if ( empty( $space_allowed ) || !is_numeric( $space_allowed ) )
290 $space_allowed = 10; // Default space allowed is 10 MB
292 $space_used = get_space_used();
294 if ( ( $space_allowed - $space_used ) < 0 ) {
296 _e( 'Sorry, you have used your space allocation. Please delete some files to upload more files.' );
304 * Displays the amount of disk space used by the current blog. Not used in core.
308 function display_space_usage() {
309 $space_allowed = get_space_allowed();
310 $space_used = get_space_used();
312 $percent_used = ( $space_used / $space_allowed ) * 100;
314 if ( $space_allowed > 1000 ) {
315 $space = number_format( $space_allowed / 1024 );
316 /* translators: Gigabytes */
317 $space .= __( 'GB' );
319 $space = number_format( $space_allowed );
320 /* translators: Megabytes */
321 $space .= __( 'MB' );
324 <strong><?php printf( __( 'Used: %1$s%% of %2$s' ), number_format( $percent_used ), $space ); ?></strong>
329 * Get the remaining upload space for this blog.
332 * @uses upload_is_user_over_quota()
333 * @uses get_space_allowed()
334 * @uses get_upload_space_available()
336 * @param int $size Current max size in bytes
337 * @return int Max size in bytes
339 function fix_import_form_size( $size ) {
340 if ( upload_is_user_over_quota( false ) == true )
343 $available = get_upload_space_available();
344 return min( $size, $available );
347 // Edit blog upload space setting on Edit Blog page
348 function upload_space_setting( $id ) {
349 switch_to_blog( $id );
350 $quota = get_option( 'blog_upload_space' );
351 restore_current_blog();
358 <th><?php _e( 'Site Upload Space Quota '); ?></th>
359 <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>
363 add_action( 'wpmueditblogaction', 'upload_space_setting' );
365 function update_user_status( $id, $pref, $value, $deprecated = null ) {
368 if ( null !== $deprecated )
369 _deprecated_argument( __FUNCTION__, '3.1' );
371 $wpdb->update( $wpdb->users, array( $pref => $value ), array( 'ID' => $id ) );
373 $user = new WP_User( $id );
374 clean_user_cache( $user );
376 if ( $pref == 'spam' ) {
378 do_action( 'make_spam_user', $id );
380 do_action( 'make_ham_user', $id );
386 function refresh_user_details( $id ) {
389 if ( !$user = get_userdata( $id ) )
392 clean_user_cache( $user );
397 function format_code_lang( $code = '' ) {
398 $code = strtolower( substr( $code, 0, 2 ) );
400 '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',
401 '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',
402 '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',
403 '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',
404 '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',
405 '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',
406 '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',
407 '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',
408 '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',
409 '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',
410 've' => 'Venda', 'vi' => 'Vietnamese', 'vo' => 'Volapük', 'cy' => 'Welsh','wa' => 'Walloon','wo' => 'Wolof', 'xh' => 'Xhosa', 'yi' => 'Yiddish', 'yo' => 'Yoruba', 'za' => 'Zhuang; Chuang', 'zu' => 'Zulu' );
411 $lang_codes = apply_filters( 'lang_codes', $lang_codes, $code );
412 return strtr( $code, $lang_codes );
415 function sync_category_tag_slugs( $term, $taxonomy ) {
416 if ( global_terms_enabled() && ( $taxonomy == 'category' || $taxonomy == 'post_tag' ) ) {
417 if ( is_object( $term ) ) {
418 $term->slug = sanitize_title( $term->name );
420 $term['slug'] = sanitize_title( $term['name'] );
425 add_filter( 'get_term', 'sync_category_tag_slugs', 10, 2 );
427 function _access_denied_splash() {
428 if ( ! is_user_logged_in() || is_network_admin() )
431 $blogs = get_blogs_of_user( get_current_user_id() );
433 if ( wp_list_filter( $blogs, array( 'userblog_id' => get_current_blog_id() ) ) )
436 $blog_name = get_bloginfo( 'name' );
438 if ( empty( $blogs ) )
439 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 ) );
441 $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>';
442 $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>';
444 $output .= '<h3>' . __('Your Sites') . '</h3>';
445 $output .= '<table>';
447 foreach ( $blogs as $blog ) {
449 $output .= "<td valign='top'>";
450 $output .= "{$blog->blogname}";
452 $output .= "<td valign='top'>";
453 $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>" ;
457 $output .= '</table>';
461 add_action( 'admin_page_access_denied', '_access_denied_splash', 99 );
463 function check_import_new_users( $permission ) {
464 if ( !is_super_admin() )
468 add_filter( 'import_allow_create_users', 'check_import_new_users' );
469 // See "import_allow_fetch_attachments" and "import_attachment_size_limit" filters too.
471 function mu_dropdown_languages( $lang_files = array(), $current = '' ) {
475 foreach ( (array) $lang_files as $val ) {
476 $code_lang = basename( $val, '.mo' );
478 if ( $code_lang == 'en_US' ) { // American English
480 $ae = __( 'American English' );
481 $output[$ae] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . $ae . '</option>';
482 } elseif ( $code_lang == 'en_GB' ) { // British English
484 $be = __( 'British English' );
485 $output[$be] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . $be . '</option>';
487 $translated = format_code_lang( $code_lang );
488 $output[$translated] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . esc_html ( $translated ) . '</option>';
493 if ( $flag === false ) // WordPress english
494 $output[] = '<option value=""' . selected( $current, '', false ) . '>' . __( 'English' ) . "</option>";
497 uksort( $output, 'strnatcasecmp' );
499 $output = apply_filters( 'mu_dropdown_languages', $output, $lang_files, $current );
500 echo implode( "\n\t", $output );
503 /* Warn the admin if SECRET SALT information is missing from wp-config.php */
504 function secret_salt_warning() {
505 if ( !is_super_admin() )
507 $secret_keys = array( 'AUTH_KEY', 'SECURE_AUTH_KEY', 'LOGGED_IN_KEY', 'NONCE_KEY', 'AUTH_SALT', 'SECURE_AUTH_SALT', 'LOGGED_IN_SALT', 'NONCE_SALT' );
509 foreach( $secret_keys as $key ) {
510 if ( ! defined( $key ) )
511 $out .= "define( '$key', '" . esc_html( wp_generate_password( 64, true, true ) ) . "' );<br />";
514 $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.' );
515 $msg .= '<br/>' . __( "Before the line <code>/* That's all, stop editing! Happy blogging. */</code> please add this code:" );
516 $msg .= "<br/><br/><code>$out</code>";
518 echo "<div class='update-nag'>$msg</div>";
521 add_action( 'network_admin_notices', 'secret_salt_warning' );
523 function site_admin_notice() {
524 global $wp_db_version;
525 if ( !is_super_admin() )
527 if ( get_site_option( 'wpmu_upgrade_site' ) != $wp_db_version )
528 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( network_admin_url( 'upgrade.php' ) ) ) . "</div>";
530 add_action( 'admin_notices', 'site_admin_notice' );
531 add_action( 'network_admin_notices', 'site_admin_notice' );
533 function avoid_blog_page_permalink_collision( $data, $postarr ) {
534 if ( is_subdomain_install() )
536 if ( $data['post_type'] != 'page' )
538 if ( !isset( $data['post_name'] ) || $data['post_name'] == '' )
540 if ( !is_main_site() )
543 $post_name = $data['post_name'];
545 while( $c < 10 && get_id_from_blogname( $post_name ) ) {
546 $post_name .= mt_rand( 1, 10 );
549 if ( $post_name != $data['post_name'] ) {
550 $data['post_name'] = $post_name;
554 add_filter( 'wp_insert_post_data', 'avoid_blog_page_permalink_collision', 10, 2 );
556 function choose_primary_blog() {
558 <table class="form-table">
560 <?php /* translators: My sites label */ ?>
561 <th scope="row"><?php _e( 'Primary Site' ); ?></th>
564 $all_blogs = get_blogs_of_user( get_current_user_id() );
565 $primary_blog = get_user_meta( get_current_user_id(), 'primary_blog', true );
566 if ( count( $all_blogs ) > 1 ) {
569 <select name="primary_blog">
570 <?php foreach( (array) $all_blogs as $blog ) {
571 if ( $primary_blog == $blog->userblog_id )
573 ?><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
578 $blog = array_shift( $all_blogs );
579 update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id );
581 } elseif ( count( $all_blogs ) == 1 ) {
582 $blog = array_shift( $all_blogs );
584 if ( $primary_blog != $blog->userblog_id ) // Set the primary blog again if it's out of sync with blog list.
585 update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id );
592 <?php if ( in_array( get_site_option( 'registration' ), array( 'all', 'blog' ) ) ) : ?>
594 <th scope="row" colspan="2" class="th-full">
595 <a href="<?php echo apply_filters( 'wp_signup_location', network_site_url( 'wp-signup.php' ) ); ?>"><?php _e( 'Create a New Site' ); ?></a>
604 * Grants super admin privileges.
607 * @param int $user_id
609 function grant_super_admin( $user_id ) {
610 global $super_admins;
612 // If global super_admins override is defined, there is nothing to do here.
613 if ( isset($super_admins) )
616 do_action( 'grant_super_admin', $user_id );
618 // Directly fetch site_admins instead of using get_super_admins()
619 $super_admins = get_site_option( 'site_admins', array( 'admin' ) );
621 $user = get_userdata( $user_id );
622 if ( $user && ! in_array( $user->user_login, $super_admins ) ) {
623 $super_admins[] = $user->user_login;
624 update_site_option( 'site_admins' , $super_admins );
625 do_action( 'granted_super_admin', $user_id );
632 * Revokes super admin privileges.
635 * @param int $user_id
637 function revoke_super_admin( $user_id ) {
638 global $super_admins;
640 // If global super_admins override is defined, there is nothing to do here.
641 if ( isset($super_admins) )
644 do_action( 'revoke_super_admin', $user_id );
646 // Directly fetch site_admins instead of using get_super_admins()
647 $super_admins = get_site_option( 'site_admins', array( 'admin' ) );
649 $user = get_userdata( $user_id );
650 if ( $user && $user->user_email != get_site_option( 'admin_email' ) ) {
651 if ( false !== ( $key = array_search( $user->user_login, $super_admins ) ) ) {
652 unset( $super_admins[$key] );
653 update_site_option( 'site_admins', $super_admins );
654 do_action( 'revoked_super_admin', $user_id );
662 * Whether or not we can edit this network from this page
664 * By default editing of network is restricted to the Network Admin for that site_id this allows for this to be overridden
667 * @param integer $site_id The network/site id to check.
669 function can_edit_network( $site_id ) {
672 if ($site_id == $wpdb->siteid )
677 return apply_filters( 'can_edit_network', $result, $site_id );
681 * Thickbox image paths for Network Admin.
686 function _thickbox_path_admin_subfolder() {
688 <script type="text/javascript">
690 var tb_pathToImage = "../../wp-includes/js/thickbox/loadingAnimation.gif";
697 * Whether or not we have a large network.
699 * The default criteria for a large network is either more than 10,000 users or more than 10,000 sites.
700 * Plugins can alter this criteria using the 'wp_is_large_network' filter.
703 * @param string $using 'sites or 'users'. Default is 'sites'.
704 * @return bool True if the network meets the criteria for large. False otherwise.
706 function wp_is_large_network( $using = 'sites' ) {
707 if ( 'users' == $using ) {
708 $count = get_user_count();
709 return apply_filters( 'wp_is_large_network', $count > 10000, 'users', $count );
712 $count = get_blog_count();
713 return apply_filters( 'wp_is_large_network', $count > 10000, 'sites', $count );