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 ) {
56 global $wpdb, $current_site;
59 if ( $blog_id != $wpdb->blogid ) {
61 switch_to_blog( $blog_id );
62 $blog = get_blog_details( $blog_id );
64 $blog = $GLOBALS['current_blog'];
67 do_action( 'delete_blog', $blog_id, $drop );
69 $users = get_users( array( 'blog_id' => $blog_id, 'fields' => 'ids' ) );
71 // Remove users from this blog.
72 if ( ! empty( $users ) ) {
73 foreach ( $users as $user_id ) {
74 remove_user_from_blog( $user_id, $blog_id );
78 update_blog_status( $blog_id, 'deleted', 1 );
80 // Don't destroy the initial, main, or root blog.
81 if ( $drop && ( 1 == $blog_id || is_main_site( $blog_id ) || ( $blog->path == $current_site->path && $blog->domain == $current_site->domain ) ) )
86 $drop_tables = apply_filters( 'wpmu_drop_tables', $wpdb->tables( 'blog' ) );
88 foreach ( (array) $drop_tables as $table ) {
89 $wpdb->query( "DROP TABLE IF EXISTS `$table`" );
92 $wpdb->delete( $wpdb->blogs, array( 'blog_id' => $blog_id ) );
94 $dir = apply_filters( 'wpmu_delete_blog_upload_dir', WP_CONTENT_DIR . "/blogs.dir/{$blog_id}/files/", $blog_id );
95 $dir = rtrim( $dir, DIRECTORY_SEPARATOR );
100 while ( $index < count( $stack ) ) {
101 # Get indexed directory from stack
102 $dir = $stack[$index];
104 $dh = @opendir( $dir );
106 while ( ( $file = @readdir( $dh ) ) !== false ) {
107 if ( $file == '.' || $file == '..' )
110 if ( @is_dir( $dir . DIRECTORY_SEPARATOR . $file ) )
111 $stack[] = $dir . DIRECTORY_SEPARATOR . $file;
112 else if ( @is_file( $dir . DIRECTORY_SEPARATOR . $file ) )
113 @unlink( $dir . DIRECTORY_SEPARATOR . $file );
119 $stack = array_reverse( $stack ); // Last added dirs are deepest
120 foreach( (array) $stack as $dir ) {
121 if ( $dir != $top_dir)
127 restore_current_blog();
130 // @todo Merge with wp_delete_user() ?
131 function wpmu_delete_user( $id ) {
135 $user = new WP_User( $id );
137 do_action( 'wpmu_delete_user', $id );
139 $blogs = get_blogs_of_user( $id );
141 if ( ! empty( $blogs ) ) {
142 foreach ( $blogs as $blog ) {
143 switch_to_blog( $blog->userblog_id );
144 remove_user_from_blog( $id, $blog->userblog_id );
146 $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d", $id ) );
147 foreach ( (array) $post_ids as $post_id ) {
148 wp_delete_post( $post_id );
152 $link_ids = $wpdb->get_col( $wpdb->prepare( "SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $id ) );
155 foreach ( $link_ids as $link_id )
156 wp_delete_link( $link_id );
159 restore_current_blog();
163 $meta = $wpdb->get_col( $wpdb->prepare( "SELECT umeta_id FROM $wpdb->usermeta WHERE user_id = %d", $id ) );
164 foreach ( $meta as $mid )
165 delete_metadata_by_mid( 'user', $mid );
167 $wpdb->delete( $wpdb->users, array( 'ID' => $id ) );
169 clean_user_cache( $user );
171 // allow for commit transaction
172 do_action( 'deleted_user', $id );
177 function update_option_new_admin_email( $old_value, $value ) {
178 $email = get_option( 'admin_email' );
179 if ( $value == get_option( 'admin_email' ) || !is_email( $value ) )
182 $hash = md5( $value. time() .mt_rand() );
183 $new_admin_email = array(
187 update_option( 'adminhash', $new_admin_email );
189 $content = apply_filters( 'new_admin_email_content', __( "Dear user,
191 You recently requested to have the administration email address on
193 If this is correct, please click on the following link to change it:
196 You can safely ignore and delete this email if you do not want to
199 This email has been sent to ###EMAIL###
202 All at ###SITENAME###
203 ###SITEURL### "), $new_admin_email );
205 $content = str_replace( '###ADMIN_URL###', esc_url( admin_url( 'options.php?adminhash='.$hash ) ), $content );
206 $content = str_replace( '###EMAIL###', $value, $content );
207 $content = str_replace( '###SITENAME###', get_site_option( 'site_name' ), $content );
208 $content = str_replace( '###SITEURL###', network_home_url(), $content );
210 wp_mail( $value, sprintf( __( '[%s] New Admin Email Address' ), get_option( 'blogname' ) ), $content );
212 add_action( 'update_option_new_admin_email', 'update_option_new_admin_email', 10, 2 );
213 add_action( 'add_option_new_admin_email', 'update_option_new_admin_email', 10, 2 );
215 function send_confirmation_on_profile_email() {
216 global $errors, $wpdb;
217 $current_user = wp_get_current_user();
218 if ( ! is_object($errors) )
219 $errors = new WP_Error();
221 if ( $current_user->ID != $_POST['user_id'] )
224 if ( $current_user->user_email != $_POST['email'] ) {
225 if ( !is_email( $_POST['email'] ) ) {
226 $errors->add( 'user_email', __( "<strong>ERROR</strong>: The e-mail address isn't correct." ), array( 'form-field' => 'email' ) );
230 if ( $wpdb->get_var( $wpdb->prepare( "SELECT user_email FROM {$wpdb->users} WHERE user_email=%s", $_POST['email'] ) ) ) {
231 $errors->add( 'user_email', __( "<strong>ERROR</strong>: The e-mail address is already used." ), array( 'form-field' => 'email' ) );
232 delete_option( $current_user->ID . '_new_email' );
236 $hash = md5( $_POST['email'] . time() . mt_rand() );
237 $new_user_email = array(
239 'newemail' => $_POST['email']
241 update_option( $current_user->ID . '_new_email', $new_user_email );
243 $content = apply_filters( 'new_user_email_content', __( "Dear user,
245 You recently requested to have the email address on your account changed.
246 If this is correct, please click on the following link to change it:
249 You can safely ignore and delete this email if you do not want to
252 This email has been sent to ###EMAIL###
255 All at ###SITENAME###
256 ###SITEURL###" ), $new_user_email );
258 $content = str_replace( '###ADMIN_URL###', esc_url( admin_url( 'profile.php?newuseremail='.$hash ) ), $content );
259 $content = str_replace( '###EMAIL###', $_POST['email'], $content);
260 $content = str_replace( '###SITENAME###', get_site_option( 'site_name' ), $content );
261 $content = str_replace( '###SITEURL###', network_home_url(), $content );
263 wp_mail( $_POST['email'], sprintf( __( '[%s] New Email Address' ), get_option( 'blogname' ) ), $content );
264 $_POST['email'] = $current_user->user_email;
267 add_action( 'personal_options_update', 'send_confirmation_on_profile_email' );
269 function new_user_email_admin_notice() {
270 if ( strpos( $_SERVER['PHP_SELF'], 'profile.php' ) && isset( $_GET['updated'] ) && $email = get_option( get_current_user_id() . '_new_email' ) )
271 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>";
273 add_action( 'admin_notices', 'new_user_email_admin_notice' );
276 * Determines if there is any upload space left in the current blog's quota.
279 * @return bool True if space is available, false otherwise.
281 function is_upload_space_available() {
282 if ( get_site_option( 'upload_space_check_disabled' ) )
285 if ( !( $space_allowed = get_upload_space_available() ) )
294 * @return int of upload size limit in bytes
296 function upload_size_limit_filter( $size ) {
297 $fileupload_maxk = 1024 * get_site_option( 'fileupload_maxk', 1500 );
298 if ( get_site_option( 'upload_space_check_disabled' ) )
299 return min( $size, $fileupload_maxk );
301 return min( $size, $fileupload_maxk, get_upload_space_available() );
304 * Determines if there is any upload space left in the current blog's quota.
306 * @return int of upload space available in bytes
308 function get_upload_space_available() {
309 $space_allowed = get_space_allowed() * 1024 * 1024;
310 if ( get_site_option( 'upload_space_check_disabled' ) )
311 return $space_allowed;
313 $dir_name = trailingslashit( BLOGUPLOADDIR );
314 if ( !( is_dir( $dir_name) && is_readable( $dir_name ) ) )
315 return $space_allowed;
317 $dir = dir( $dir_name );
320 while ( $file = $dir->read() ) {
321 if ( $file != '.' && $file != '..' ) {
322 if ( is_dir( $dir_name . $file) ) {
323 $size += get_dirsize( $dir_name . $file );
325 $size += filesize( $dir_name . $file );
331 if ( ( $space_allowed - $size ) <= 0 )
334 return $space_allowed - $size;
338 * Returns the upload quota for the current blog.
342 function get_space_allowed() {
343 $space_allowed = get_option( 'blog_upload_space' );
345 if ( ! is_numeric( $space_allowed ) )
346 $space_allowed = get_site_option( 'blog_upload_space' );
348 if ( empty( $space_allowed ) || ! is_numeric( $space_allowed ) )
351 return $space_allowed;
354 function display_space_usage() {
355 $space = get_space_allowed();
356 $used = get_dirsize( BLOGUPLOADDIR ) / 1024 / 1024;
358 $percentused = ( $used / $space ) * 100;
360 if ( $space > 1000 ) {
361 $space = number_format( $space / 1024 );
362 /* translators: Gigabytes */
363 $space .= __( 'GB' );
365 /* translators: Megabytes */
366 $space .= __( 'MB' );
369 <strong><?php printf( __( 'Used: %1s%% of %2s' ), number_format( $percentused ), $space ); ?></strong>
373 // Edit blog upload space setting on Edit Blog page
374 function upload_space_setting( $id ) {
375 $quota = get_blog_option( $id, 'blog_upload_space' );
381 <th><?php _e( 'Site Upload Space Quota '); ?></th>
382 <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>
386 add_action( 'wpmueditblogaction', 'upload_space_setting' );
388 function update_user_status( $id, $pref, $value, $deprecated = null ) {
391 if ( null !== $deprecated )
392 _deprecated_argument( __FUNCTION__, '3.1' );
394 $wpdb->update( $wpdb->users, array( $pref => $value ), array( 'ID' => $id ) );
396 $user = new WP_User( $id );
397 clean_user_cache( $user );
399 if ( $pref == 'spam' ) {
401 do_action( 'make_spam_user', $id );
403 do_action( 'make_ham_user', $id );
409 function refresh_user_details( $id ) {
412 if ( !$user = get_userdata( $id ) )
415 clean_user_cache( $user );
420 function format_code_lang( $code = '' ) {
421 $code = strtolower( substr( $code, 0, 2 ) );
423 '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',
424 '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',
425 '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',
426 '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',
427 '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',
428 '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',
429 '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',
430 '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',
431 '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',
432 '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',
433 've' => 'Venda', 'vi' => 'Vietnamese', 'vo' => 'Volapük', 'cy' => 'Welsh','wa' => 'Walloon','wo' => 'Wolof', 'xh' => 'Xhosa', 'yi' => 'Yiddish', 'yo' => 'Yoruba', 'za' => 'Zhuang; Chuang', 'zu' => 'Zulu' );
434 $lang_codes = apply_filters( 'lang_codes', $lang_codes, $code );
435 return strtr( $code, $lang_codes );
438 function sync_category_tag_slugs( $term, $taxonomy ) {
439 if ( global_terms_enabled() && ( $taxonomy == 'category' || $taxonomy == 'post_tag' ) ) {
440 if ( is_object( $term ) ) {
441 $term->slug = sanitize_title( $term->name );
443 $term['slug'] = sanitize_title( $term['name'] );
448 add_filter( 'get_term', 'sync_category_tag_slugs', 10, 2 );
450 function _access_denied_splash() {
451 if ( ! is_user_logged_in() || is_network_admin() )
454 $blogs = get_blogs_of_user( get_current_user_id() );
456 if ( wp_list_filter( $blogs, array( 'userblog_id' => get_current_blog_id() ) ) )
459 $blog_name = get_bloginfo( 'name' );
461 if ( empty( $blogs ) )
462 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 ) );
464 $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>';
465 $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>';
467 $output .= '<h3>' . __('Your Sites') . '</h3>';
468 $output .= '<table>';
470 foreach ( $blogs as $blog ) {
472 $output .= "<td valign='top'>";
473 $output .= "{$blog->blogname}";
475 $output .= "<td valign='top'>";
476 $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>" ;
480 $output .= '</table>';
484 add_action( 'admin_page_access_denied', '_access_denied_splash', 99 );
486 function check_import_new_users( $permission ) {
487 if ( !is_super_admin() )
491 add_filter( 'import_allow_create_users', 'check_import_new_users' );
492 // See "import_allow_fetch_attachments" and "import_attachment_size_limit" filters too.
494 function mu_dropdown_languages( $lang_files = array(), $current = '' ) {
498 foreach ( (array) $lang_files as $val ) {
499 $code_lang = basename( $val, '.mo' );
501 if ( $code_lang == 'en_US' ) { // American English
503 $ae = __( 'American English' );
504 $output[$ae] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . $ae . '</option>';
505 } elseif ( $code_lang == 'en_GB' ) { // British English
507 $be = __( 'British English' );
508 $output[$be] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . $be . '</option>';
510 $translated = format_code_lang( $code_lang );
511 $output[$translated] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . esc_html ( $translated ) . '</option>';
516 if ( $flag === false ) // WordPress english
517 $output[] = '<option value=""' . selected( $current, '', false ) . '>' . __( 'English' ) . "</option>";
520 uksort( $output, 'strnatcasecmp' );
522 $output = apply_filters( 'mu_dropdown_languages', $output, $lang_files, $current );
523 echo implode( "\n\t", $output );
526 /* Warn the admin if SECRET SALT information is missing from wp-config.php */
527 function secret_salt_warning() {
528 if ( !is_super_admin() )
530 $secret_keys = array( 'AUTH_KEY', 'SECURE_AUTH_KEY', 'LOGGED_IN_KEY', 'NONCE_KEY', 'AUTH_SALT', 'SECURE_AUTH_SALT', 'LOGGED_IN_SALT', 'NONCE_SALT' );
532 foreach( $secret_keys as $key ) {
533 if ( ! defined( $key ) )
534 $out .= "define( '$key', '" . esc_html( wp_generate_password( 64, true, true ) ) . "' );<br />";
537 $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.' );
538 $msg .= '<br/>' . __( "Before the line <code>/* That's all, stop editing! Happy blogging. */</code> please add this code:" );
539 $msg .= "<br/><br/><code>$out</code>";
541 echo "<div class='update-nag'>$msg</div>";
544 add_action( 'network_admin_notices', 'secret_salt_warning' );
546 function site_admin_notice() {
547 global $wp_db_version;
548 if ( !is_super_admin() )
550 if ( get_site_option( 'wpmu_upgrade_site' ) != $wp_db_version )
551 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>";
553 add_action( 'admin_notices', 'site_admin_notice' );
554 add_action( 'network_admin_notices', 'site_admin_notice' );
556 function avoid_blog_page_permalink_collision( $data, $postarr ) {
557 if ( is_subdomain_install() )
559 if ( $data['post_type'] != 'page' )
561 if ( !isset( $data['post_name'] ) || $data['post_name'] == '' )
563 if ( !is_main_site() )
566 $post_name = $data['post_name'];
568 while( $c < 10 && get_id_from_blogname( $post_name ) ) {
569 $post_name .= mt_rand( 1, 10 );
572 if ( $post_name != $data['post_name'] ) {
573 $data['post_name'] = $post_name;
577 add_filter( 'wp_insert_post_data', 'avoid_blog_page_permalink_collision', 10, 2 );
579 function choose_primary_blog() {
581 <table class="form-table">
583 <?php /* translators: My sites label */ ?>
584 <th scope="row"><?php _e( 'Primary Site' ); ?></th>
587 $all_blogs = get_blogs_of_user( get_current_user_id() );
588 $primary_blog = get_user_meta( get_current_user_id(), 'primary_blog', true );
589 if ( count( $all_blogs ) > 1 ) {
592 <select name="primary_blog">
593 <?php foreach( (array) $all_blogs as $blog ) {
594 if ( $primary_blog == $blog->userblog_id )
596 ?><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
601 $blog = array_shift( $all_blogs );
602 update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id );
604 } elseif ( count( $all_blogs ) == 1 ) {
605 $blog = array_shift( $all_blogs );
607 if ( $primary_blog != $blog->userblog_id ) // Set the primary blog again if it's out of sync with blog list.
608 update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id );
615 <?php if ( in_array( get_site_option( 'registration' ), array( 'all', 'blog' ) ) ) : ?>
617 <th scope="row" colspan="2" class="th-full">
618 <a href="<?php echo apply_filters( 'wp_signup_location', network_home_url( 'wp-signup.php' ) ); ?>"><?php _e( 'Create a New Site' ); ?></a>
626 function ms_deprecated_blogs_file() {
627 if ( ! is_super_admin() )
629 if ( ! file_exists( WP_CONTENT_DIR . '/blogs.php' ) )
631 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>';
633 add_action( 'network_admin_notices', 'ms_deprecated_blogs_file' );
636 * Grants super admin privileges.
639 * @param int $user_id
641 function grant_super_admin( $user_id ) {
642 global $super_admins;
644 // If global super_admins override is defined, there is nothing to do here.
645 if ( isset($super_admins) )
648 do_action( 'grant_super_admin', $user_id );
650 // Directly fetch site_admins instead of using get_super_admins()
651 $super_admins = get_site_option( 'site_admins', array( 'admin' ) );
653 $user = new WP_User( $user_id );
654 if ( ! in_array( $user->user_login, $super_admins ) ) {
655 $super_admins[] = $user->user_login;
656 update_site_option( 'site_admins' , $super_admins );
657 do_action( 'granted_super_admin', $user_id );
664 * Revokes super admin privileges.
667 * @param int $user_id
669 function revoke_super_admin( $user_id ) {
670 global $super_admins;
672 // If global super_admins override is defined, there is nothing to do here.
673 if ( isset($super_admins) )
676 do_action( 'revoke_super_admin', $user_id );
678 // Directly fetch site_admins instead of using get_super_admins()
679 $super_admins = get_site_option( 'site_admins', array( 'admin' ) );
681 $user = new WP_User( $user_id );
682 if ( $user->user_email != get_site_option( 'admin_email' ) ) {
683 if ( false !== ( $key = array_search( $user->user_login, $super_admins ) ) ) {
684 unset( $super_admins[$key] );
685 update_site_option( 'site_admins', $super_admins );
686 do_action( 'revoked_super_admin', $user_id );
694 * Whether or not we can edit this network from this page
696 * By default editing of network is restricted to the Network Admin for that site_id this allows for this to be overridden
699 * @param integer $site_id The network/site id to check.
701 function can_edit_network( $site_id ) {
704 if ($site_id == $wpdb->siteid )
709 return apply_filters( 'can_edit_network', $result, $site_id );
713 * Thickbox image paths for Network Admin.
718 function _thickbox_path_admin_subfolder() {
720 <script type="text/javascript">
722 var tb_pathToImage = "../../wp-includes/js/thickbox/loadingAnimation.gif";
723 var tb_closeImage = "../../wp-includes/js/thickbox/tb-close.png";
730 * Whether or not we have a large network.
732 * The default criteria for a large network is either more than 10,000 users or more than 10,000 sites.
733 * Plugins can alter this criteria using the 'wp_is_large_network' filter.
736 * @param string $using 'sites or 'users'. Default is 'sites'.
737 * @return bool True if the network meets the criteria for large. False otherwise.
739 function wp_is_large_network( $using = 'sites' ) {
740 if ( 'users' == $using ) {
741 $count = get_user_count();
742 return apply_filters( 'wp_is_large_network', $count > 10000, 'users', $count );
745 $count = get_blog_count();
746 return apply_filters( 'wp_is_large_network', $count > 10000, 'sites', $count );