Make WordPress Core

Changeset 38655


Ignore:
Timestamp:
09/26/2016 06:38:32 PM (8 years ago)
Author:
ocean90
Message:

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.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/network/site-new.php

    r37914 r38655  
    6666
    6767    // Handle translation install for the new site.
    68     if ( ! empty( $_POST['WPLANG'] ) && wp_can_install_language_pack() ) {
    69         $language = wp_download_language_pack( wp_unslash( $_POST['WPLANG'] ) );
    70         if ( $language ) {
    71             $meta['WPLANG'] = $language;
     68    if ( isset( $_POST['WPLANG'] ) ) {
     69        if ( '' === $_POST['WPLANG'] ) {
     70            $meta['WPLANG'] = ''; // en_US
     71        } elseif ( wp_can_install_language_pack() ) {
     72            $language = wp_download_language_pack( wp_unslash( $_POST['WPLANG'] ) );
     73            if ( $language ) {
     74                $meta['WPLANG'] = $language;
     75            }
    7276        }
    7377    }
  • trunk/src/wp-includes/ms-functions.php

    r38636 r38655  
    10931093 */
    10941094function wpmu_create_blog( $domain, $path, $title, $user_id, $meta = array(), $site_id = 1 ) {
    1095     $defaults = array( 'public' => 0 );
     1095    $defaults = array(
     1096        'public' => 0,
     1097        'WPLANG' => get_site_option( 'WPLANG' ),
     1098    );
    10961099    $meta = wp_parse_args( $meta, $defaults );
    10971100
     
    11311134    }
    11321135
    1133     add_option( 'WPLANG', get_site_option( 'WPLANG' ) );
    11341136    update_option( 'blog_public', (int) $meta['public'] );
    11351137
  • trunk/tests/phpunit/tests/multisite/site.php

    r37665 r38655  
    927927    }
    928928
     929    /**
     930     * @ticket 36918
     931     */
     932    function test_new_blog_locale() {
     933        $current_site = get_current_site();
     934
     935        add_filter( 'sanitize_option_WPLANG', array( $this, 'filter_allow_unavailable_languages' ), 10, 3 );
     936        update_site_option( 'WPLANG', 'de_DE' );
     937        remove_filter( 'sanitize_option_WPLANG', array( $this, 'filter_allow_unavailable_languages' ), 10 );
     938
     939        // No locale, use default locale.
     940        add_filter( 'sanitize_option_WPLANG', array( $this, 'filter_allow_unavailable_languages' ), 10, 3 );
     941        $blog_id = wpmu_create_blog( $current_site->domain, '/de-de/', 'New Blog', get_current_user_id() );
     942        remove_filter( 'sanitize_option_WPLANG', array( $this, 'filter_allow_unavailable_languages' ), 10 );
     943
     944        $this->assertNotWPError( $blog_id );
     945        $this->assertSame( 'de_DE', get_blog_option( $blog_id, 'WPLANG' ) );
     946
     947        // Custom locale.
     948        add_filter( 'sanitize_option_WPLANG', array( $this, 'filter_allow_unavailable_languages' ), 10, 3 );
     949        $blog_id = wpmu_create_blog( $current_site->domain, '/es-es/', 'New Blog', get_current_user_id(), array( 'WPLANG' => 'es_ES' ) );
     950        remove_filter( 'sanitize_option_WPLANG', array( $this, 'filter_allow_unavailable_languages' ), 10 );
     951
     952        $this->assertNotWPError( $blog_id );
     953        $this->assertSame( 'es_ES', get_blog_option( $blog_id, 'WPLANG' ) );
     954
     955        // en_US locale.
     956        add_filter( 'sanitize_option_WPLANG', array( $this, 'filter_allow_unavailable_languages' ), 10, 3 );
     957        $blog_id = wpmu_create_blog( $current_site->domain, '/en-us/', 'New Blog', get_current_user_id(), array( 'WPLANG' => '' ) );
     958        remove_filter( 'sanitize_option_WPLANG', array( $this, 'filter_allow_unavailable_languages' ), 10 );
     959
     960        $this->assertNotWPError( $blog_id );
     961        $this->assertSame( '', get_blog_option( $blog_id, 'WPLANG' ) );
     962    }
     963
     964    /**
     965     * Allows to set the WPLANG option to any language.
     966     *
     967     * @param string $value          The sanitized option value.
     968     * @param string $option         The option name.
     969     * @param string $original_value The original value passed to the function.
     970     * @return string The orginal value.
     971     */
     972    function filter_allow_unavailable_languages( $value, $option, $original_value ) {
     973        return $original_value;
     974    }
    929975}
    930976
Note: See TracChangeset for help on using the changeset viewer.