diff --git a/src/wp-admin/network/site-new.php b/src/wp-admin/network/site-new.php index 7882d0e378..4dd36392d4 100644 --- a/src/wp-admin/network/site-new.php +++ b/src/wp-admin/network/site-new.php @@ -65,10 +65,14 @@ if ( isset($_REQUEST['action']) && 'add-site' == $_REQUEST['action'] ) { ); // Handle translation install for the new site. - if ( ! empty( $_POST['WPLANG'] ) && wp_can_install_language_pack() ) { - $language = wp_download_language_pack( wp_unslash( $_POST['WPLANG'] ) ); - if ( $language ) { - $meta['WPLANG'] = $language; + if ( isset( $_POST['WPLANG'] ) ) { + if ( '' === $_POST['WPLANG'] ) { + $meta['WPLANG'] = ''; // en_US + } elseif ( wp_can_install_language_pack() ) { + $language = wp_download_language_pack( wp_unslash( $_POST['WPLANG'] ) ); + if ( $language ) { + $meta['WPLANG'] = $language; + } } } diff --git a/src/wp-includes/ms-functions.php b/src/wp-includes/ms-functions.php index 113f37f284..ca8176124f 100644 --- a/src/wp-includes/ms-functions.php +++ b/src/wp-includes/ms-functions.php @@ -1092,7 +1092,10 @@ function wpmu_create_user( $user_name, $password, $email ) { * @return int|WP_Error Returns WP_Error object on failure, int $blog_id on success */ function wpmu_create_blog( $domain, $path, $title, $user_id, $meta = array(), $site_id = 1 ) { - $defaults = array( 'public' => 0 ); + $defaults = array( + 'public' => 0, + 'WPLANG' => get_site_option( 'WPLANG' ), + ); $meta = wp_parse_args( $meta, $defaults ); $domain = preg_replace( '/\s+/', '', sanitize_user( $domain, true ) ); @@ -1130,7 +1133,6 @@ function wpmu_create_blog( $domain, $path, $title, $user_id, $meta = array(), $s update_option( $key, $value ); } - add_option( 'WPLANG', get_site_option( 'WPLANG' ) ); update_option( 'blog_public', (int) $meta['public'] ); if ( ! is_super_admin( $user_id ) && ! get_user_meta( $user_id, 'primary_blog', true ) ) diff --git a/tests/phpunit/tests/multisite/site.php b/tests/phpunit/tests/multisite/site.php index e944197f7b..f6215e940e 100644 --- a/tests/phpunit/tests/multisite/site.php +++ b/tests/phpunit/tests/multisite/site.php @@ -926,6 +926,52 @@ class Tests_Multisite_Site extends WP_UnitTestCase { ); } + /** + * @ticket 36918 + */ + function test_new_blog_locale() { + $current_site = get_current_site(); + + add_filter( 'sanitize_option_WPLANG', array( $this, 'filter_allow_unavailable_languages' ), 10, 3 ); + update_site_option( 'WPLANG', 'de_DE' ); + remove_filter( 'sanitize_option_WPLANG', array( $this, 'filter_allow_unavailable_languages' ), 10 ); + + // No locale, use default locale. + add_filter( 'sanitize_option_WPLANG', array( $this, 'filter_allow_unavailable_languages' ), 10, 3 ); + $blog_id = wpmu_create_blog( $current_site->domain, '/de-de/', 'New Blog', get_current_user_id() ); + remove_filter( 'sanitize_option_WPLANG', array( $this, 'filter_allow_unavailable_languages' ), 10 ); + + $this->assertNotWPError( $blog_id ); + $this->assertSame( 'de_DE', get_blog_option( $blog_id, 'WPLANG' ) ); + + // Custom locale. + add_filter( 'sanitize_option_WPLANG', array( $this, 'filter_allow_unavailable_languages' ), 10, 3 ); + $blog_id = wpmu_create_blog( $current_site->domain, '/es-es/', 'New Blog', get_current_user_id(), array( 'WPLANG' => 'es_ES' ) ); + remove_filter( 'sanitize_option_WPLANG', array( $this, 'filter_allow_unavailable_languages' ), 10 ); + + $this->assertNotWPError( $blog_id ); + $this->assertSame( 'es_ES', get_blog_option( $blog_id, 'WPLANG' ) ); + + // en_US locale. + add_filter( 'sanitize_option_WPLANG', array( $this, 'filter_allow_unavailable_languages' ), 10, 3 ); + $blog_id = wpmu_create_blog( $current_site->domain, '/en-us/', 'New Blog', get_current_user_id(), array( 'WPLANG' => '' ) ); + remove_filter( 'sanitize_option_WPLANG', array( $this, 'filter_allow_unavailable_languages' ), 10 ); + + $this->assertNotWPError( $blog_id ); + $this->assertSame( '', get_blog_option( $blog_id, 'WPLANG' ) ); + } + + /** + * Allows to set the WPLANG option to any language. + * + * @param string $value The sanitized option value. + * @param string $option The option name. + * @param string $original_value The original value passed to the function. + * @return string The orginal value. + */ + function filter_allow_unavailable_languages( $value, $option, $original_value ) { + return $original_value; + } } endif;