Multisite: Allow to set the site language of a new site to English.
An empty string in `WPLANG` is used to define the site language as `en_US`. The `! empty()` check didn't catch this case so that `wpmu_create_blog()` fell back to the network setting. Fixes #36918. git-svn-id: https://develop.svn.wordpress.org/trunk@38655 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
fa48bfa1d2
commit
a1e9fbfc14
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 ) )
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user