X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/38ca813a0e312e2768e5b9519f0415cd0aa84781..refs/tags/wordpress-3.4:/wp-admin/includes/ms.php diff --git a/wp-admin/includes/ms.php b/wp-admin/includes/ms.php index 98991ef6..a6828b2d 100644 --- a/wp-admin/includes/ms.php +++ b/wp-admin/includes/ms.php @@ -49,20 +49,21 @@ add_filter( 'wp_handle_upload_prefilter', 'check_upload_size' ); * @since 3.0.0 * * @param int $blog_id Blog ID - * @param bool $drop True if blog's table should be dropped. Default is false. + * @param bool $drop True if blog's table should be dropped. Default is false. * @return void */ function wpmu_delete_blog( $blog_id, $drop = false ) { - global $wpdb; + global $wpdb, $current_site; $switch = false; if ( $blog_id != $wpdb->blogid ) { $switch = true; switch_to_blog( $blog_id ); + $blog = get_blog_details( $blog_id ); + } else { + $blog = $GLOBALS['current_blog']; } - $blog_prefix = $wpdb->get_blog_prefix( $blog_id ); - do_action( 'delete_blog', $blog_id, $drop ); $users = get_users( array( 'blog_id' => $blog_id, 'fields' => 'ids' ) ); @@ -70,24 +71,26 @@ function wpmu_delete_blog( $blog_id, $drop = false ) { // Remove users from this blog. if ( ! empty( $users ) ) { foreach ( $users as $user_id ) { - remove_user_from_blog( $user_id, $blog_id) ; + remove_user_from_blog( $user_id, $blog_id ); } } update_blog_status( $blog_id, 'deleted', 1 ); + // Don't destroy the initial, main, or root blog. + if ( $drop && ( 1 == $blog_id || is_main_site( $blog_id ) || ( $blog->path == $current_site->path && $blog->domain == $current_site->domain ) ) ) + $drop = false; + if ( $drop ) { - if ( substr( $blog_prefix, -1 ) == '_' ) - $blog_prefix = substr( $blog_prefix, 0, -1 ) . '\_'; - $drop_tables = $wpdb->get_results( "SHOW TABLES LIKE '{$blog_prefix}%'", ARRAY_A ); - $drop_tables = apply_filters( 'wpmu_drop_tables', $drop_tables ); + $drop_tables = apply_filters( 'wpmu_drop_tables', $wpdb->tables( 'blog' ) ); - reset( $drop_tables ); - foreach ( (array) $drop_tables as $drop_table) { - $wpdb->query( "DROP TABLE IF EXISTS ". current( $drop_table ) ."" ); + foreach ( (array) $drop_tables as $table ) { + $wpdb->query( "DROP TABLE IF EXISTS `$table`" ); } - $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->blogs WHERE blog_id = %d", $blog_id ) ); + + $wpdb->delete( $wpdb->blogs, array( 'blog_id' => $blog_id ) ); + $dir = apply_filters( 'wpmu_delete_blog_upload_dir', WP_CONTENT_DIR . "/blogs.dir/{$blog_id}/files/", $blog_id ); $dir = rtrim( $dir, DIRECTORY_SEPARATOR ); $top_dir = $dir; @@ -113,24 +116,14 @@ function wpmu_delete_blog( $blog_id, $drop = false ) { $index++; } - $stack = array_reverse( $stack ); // Last added dirs are deepest + $stack = array_reverse( $stack ); // Last added dirs are deepest foreach( (array) $stack as $dir ) { if ( $dir != $top_dir) @rmdir( $dir ); } } - $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key = '{$blog_prefix}autosave_draft_ids'" ); - $blogs = get_site_option( 'blog_list' ); - if ( is_array( $blogs ) ) { - foreach ( $blogs as $n => $blog ) { - if ( $blog['blog_id'] == $blog_id ) - unset( $blogs[$n] ); - } - update_site_option( 'blog_list', $blogs ); - } - - if ( $switch === true ) + if ( $switch ) restore_current_blog(); } @@ -139,6 +132,7 @@ function wpmu_delete_user( $id ) { global $wpdb; $id = (int) $id; + $user = new WP_User( $id ); do_action( 'wpmu_delete_user', $id ); @@ -166,10 +160,13 @@ function wpmu_delete_user( $id ) { } } - $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->users WHERE ID = %d", $id ) ); - $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE user_id = %d", $id ) ); + $meta = $wpdb->get_col( $wpdb->prepare( "SELECT umeta_id FROM $wpdb->usermeta WHERE user_id = %d", $id ) ); + foreach ( $meta as $mid ) + delete_metadata_by_mid( 'user', $mid ); + + $wpdb->delete( $wpdb->users, array( 'ID' => $id ) ); - clean_user_cache( $id ); + clean_user_cache( $user ); // allow for commit transaction do_action( 'deleted_user', $id ); @@ -177,35 +174,6 @@ function wpmu_delete_user( $id ) { return true; } -function wpmu_get_blog_allowedthemes( $blog_id = 0 ) { - $themes = get_themes(); - - if ( $blog_id != 0 ) - switch_to_blog( $blog_id ); - - $blog_allowed_themes = get_option( 'allowedthemes' ); - if ( !is_array( $blog_allowed_themes ) || empty( $blog_allowed_themes ) ) { // convert old allowed_themes to new allowedthemes - $blog_allowed_themes = get_option( 'allowed_themes' ); - - if ( is_array( $blog_allowed_themes ) ) { - foreach( (array) $themes as $key => $theme ) { - $theme_key = esc_html( $theme['Stylesheet'] ); - if ( isset( $blog_allowed_themes[$key] ) == true ) { - $blog_allowedthemes[$theme_key] = 1; - } - } - $blog_allowed_themes = $blog_allowedthemes; - add_option( 'allowedthemes', $blog_allowed_themes ); - delete_option( 'allowed_themes' ); - } - } - - if ( $blog_id != 0 ) - restore_current_blog(); - - return $blog_allowed_themes; -} - function update_option_new_admin_email( $old_value, $value ) { $email = get_option( 'admin_email' ); if ( $value == get_option( 'admin_email' ) || !is_email( $value ) ) @@ -250,7 +218,7 @@ function send_confirmation_on_profile_email() { if ( ! is_object($errors) ) $errors = new WP_Error(); - if ( $current_user->id != $_POST['user_id'] ) + if ( $current_user->ID != $_POST['user_id'] ) return false; if ( $current_user->user_email != $_POST['email'] ) { @@ -304,26 +272,6 @@ function new_user_email_admin_notice() { } add_action( 'admin_notices', 'new_user_email_admin_notice' ); -function get_site_allowed_themes() { - $themes = get_themes(); - $allowed_themes = get_site_option( 'allowedthemes' ); - if ( !is_array( $allowed_themes ) || empty( $allowed_themes ) ) { - $allowed_themes = get_site_option( 'allowed_themes' ); // convert old allowed_themes format - if ( !is_array( $allowed_themes ) ) { - $allowed_themes = array(); - } else { - foreach( (array) $themes as $key => $theme ) { - $theme_key = esc_html( $theme['Stylesheet'] ); - if ( isset( $allowed_themes[ $key ] ) == true ) { - $allowedthemes[ $theme_key ] = 1; - } - } - $allowed_themes = $allowedthemes; - } - } - return $allowed_themes; -} - /** * Determines if there is any upload space left in the current blog's quota. * @@ -393,9 +341,11 @@ function get_upload_space_available() { */ function get_space_allowed() { $space_allowed = get_option( 'blog_upload_space' ); - if ( $space_allowed == false ) + + if ( ! is_numeric( $space_allowed ) ) $space_allowed = get_site_option( 'blog_upload_space' ); - if ( empty( $space_allowed ) || !is_numeric( $space_allowed ) ) + + if ( empty( $space_allowed ) || ! is_numeric( $space_allowed ) ) $space_allowed = 50; return $space_allowed; @@ -429,7 +379,7 @@ function upload_space_setting( $id ) { ?> - + update( $wpdb->users, array( $pref => $value ), array( 'ID' => $id ) ); - clean_user_cache( $id ); + $user = new WP_User( $id ); + clean_user_cache( $user ); if ( $pref == 'spam' ) { if ( $value == 1 ) @@ -461,7 +412,7 @@ function refresh_user_details( $id ) { if ( !$user = get_userdata( $id ) ) return false; - clean_user_cache( $id ); + clean_user_cache( $user ); return $id; } @@ -557,7 +508,7 @@ function mu_dropdown_languages( $lang_files = array(), $current = '' ) { $output[$be] = ''; } else { $translated = format_code_lang( $code_lang ); - $output[$translated] = ''; + $output[$translated] = ''; } } @@ -642,7 +593,7 @@ function choose_primary_blog() { userblog_id ) $found = true; - ?> +/** + * Whether or not we have a large network. + * + * The default criteria for a large network is either more than 10,000 users or more than 10,000 sites. + * Plugins can alter this criteria using the 'wp_is_large_network' filter. + * + * @since 3.3.0 + * @param string $using 'sites or 'users'. Default is 'sites'. + * @return bool True if the network meets the criteria for large. False otherwise. + */ +function wp_is_large_network( $using = 'sites' ) { + if ( 'users' == $using ) { + $count = get_user_count(); + return apply_filters( 'wp_is_large_network', $count > 10000, 'users', $count ); + } + + $count = get_blog_count(); + return apply_filters( 'wp_is_large_network', $count > 10000, 'sites', $count ); +}