Make WordPress Core

Ticket #36918: 36918.patch

File 36918.patch, 4.1 KB (added by ocean90, 8 years ago)
  • src/wp-admin/network/site-new.php

     
    6565        );
    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        }
    7478
  • src/wp-includes/ms-functions.php

     
    10921092 * @return int|WP_Error Returns WP_Error object on failure, int $blog_id on success
    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
    10981101        $domain = preg_replace( '/\s+/', '', sanitize_user( $domain, true ) );
     
    11301133                        update_option( $key, $value );
    11311134        }
    11321135
    1133         add_option( 'WPLANG', get_site_option( 'WPLANG' ) );
    11341136        update_option( 'blog_public', (int) $meta['public'] );
    11351137
    11361138        if ( ! is_super_admin( $user_id ) && ! get_user_meta( $user_id, 'primary_blog', true ) )
  • tests/phpunit/tests/multisite/site.php

     
    926926                );
    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
    931977endif;