Multisite: Use `get_network_option()` for language in `wpmu_create_blog()`.

Before this changeset, the language of a new site would always result in the language of the current network, regardless of the `$site_id` parameter passed that actually determines the network for the site. Now the correct `WPLANG` value is used in such cases.

Alongside this change, a few minor documentation changes around the function have been made to account for the current naming conventions of sites and networks.

Props spacedmonkey.
Fixes #40503.


git-svn-id: https://develop.svn.wordpress.org/trunk@41058 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Felix Arntz 2017-07-14 21:07:17 +00:00
parent e85f291a79
commit d18c6696c2
2 changed files with 42 additions and 5 deletions

View File

@ -1152,13 +1152,13 @@ function wpmu_create_user( $user_name, $password, $email ) {
* 'spam', 'deleted', or 'lang_id') the given site status(es) will be
* updated. Otherwise, keys and values will be used to set options for
* the new site. Default empty array.
* @param int $site_id Optional. Only relevant on multi-network installs.
* @return int|WP_Error Returns WP_Error object on failure, int $blog_id on success
* @param int $site_id Optional. Network ID. Only relevant on multi-network installs.
* @return int|WP_Error Returns WP_Error object on failure, the new site ID on success.
*/
function wpmu_create_blog( $domain, $path, $title, $user_id, $meta = array(), $site_id = 1 ) {
$defaults = array(
'public' => 0,
'WPLANG' => get_site_option( 'WPLANG' ),
'WPLANG' => get_network_option( $site_id, 'WPLANG' ),
);
$meta = wp_parse_args( $meta, $defaults );
@ -1208,11 +1208,11 @@ function wpmu_create_blog( $domain, $path, $title, $user_id, $meta = array(), $s
*
* @since MU
*
* @param int $blog_id Blog ID.
* @param int $blog_id Site ID.
* @param int $user_id User ID.
* @param string $domain Site domain.
* @param string $path Site path.
* @param int $site_id Site ID. Only relevant on multi-network installs.
* @param int $site_id Network ID. Only relevant on multi-network installs.
* @param array $meta Meta data. Used to set initial site options.
*/
do_action( 'wpmu_new_blog', $blog_id, $user_id, $domain, $path, $site_id, $meta );

View File

@ -10,6 +10,7 @@ if ( is_multisite() ) :
*/
class Tests_Multisite_Site extends WP_UnitTestCase {
protected $suppress = false;
protected static $network_ids;
function setUp() {
global $wpdb;
@ -23,6 +24,26 @@ class Tests_Multisite_Site extends WP_UnitTestCase {
parent::tearDown();
}
public static function wpSetUpBeforeClass( $factory ) {
self::$network_ids = array(
'make.wordpress.org/' => array( 'domain' => 'make.wordpress.org', 'path' => '/' ),
);
foreach ( self::$network_ids as &$id ) {
$id = $factory->network->create( $id );
}
unset( $id );
}
public static function wpTearDownAfterClass() {
global $wpdb;
foreach( self::$network_ids as $id ) {
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->sitemeta} WHERE site_id = %d", $id ) );
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->site} WHERE id= %d", $id ) );
}
}
function test_switch_restore_blog() {
global $_wp_switched_stack, $wpdb;
@ -980,6 +1001,22 @@ class Tests_Multisite_Site extends WP_UnitTestCase {
$this->assertSame( '', get_blog_option( $blog_id, 'WPLANG' ) );
}
/**
* @ticket 40503
*/
function test_different_network_language() {
$network = get_network( self::$network_ids['make.wordpress.org/'] );
add_filter( 'sanitize_option_WPLANG', array( $this, 'filter_allow_unavailable_languages' ), 10, 3 );
update_network_option( self::$network_ids['make.wordpress.org/'], 'WPLANG', 'wibble' );
$blog_id = wpmu_create_blog( $network->domain, '/de-de/', 'New Blog', get_current_user_id(), array(), $network->id );
remove_filter( 'sanitize_option_WPLANG', array( $this, 'filter_allow_unavailable_languages' ), 10 );
$this->assertSame( get_network_option( self::$network_ids['make.wordpress.org/'], 'WPLANG' ), get_blog_option( $blog_id, 'WPLANG' ) );
}
/**
* Allows to set the WPLANG option to any language.
*