Multisite: Ensure wpmu_new_blog hook receives expected data in $meta.

Restores `public`, `archived`, `mature`, `spam`, `deleted`, `lang_id`, and `WPLANG` to the `$meta` data passed to `wpmu_new_blog`. This hook was deprecated in 5.1.0, but code using it still relies on this data.

Props david.binda, pbiron.
Fixes #46351.


git-svn-id: https://develop.svn.wordpress.org/trunk@44805 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jeremy Felt
2019-03-07 03:33:25 +00:00
parent 0cc536e173
commit 0d707e5da2
2 changed files with 99 additions and 10 deletions
+79
View File
@@ -12,6 +12,7 @@ if ( is_multisite() ) :
protected $suppress = false;
protected $site_status_hooks = array();
protected $wp_initialize_site_args = array();
protected $wp_initialize_site_meta = array();
protected static $network_ids;
protected static $site_ids;
protected static $uninitialized_site_id;
@@ -2348,6 +2349,84 @@ if ( is_multisite() ) :
// Set siteurl
update_option( 'siteurl', 'http://testsite1.example.org/test' );
}
/**
* Tests whether all expected meta are provided in deprecated `wpmu_new_blog` action.
*
* @dataProvider data_wpmu_new_blog_action_backward_commpatible
*
* @ticket 46351
*/
public function test_wpmu_new_blog_action_backward_compatible( $meta, $expected_meta ) {
// We are testing deprecated hook. Register it to expected deprecated notices.
$this->setExpectedDeprecated( 'wpmu_new_blog' );
add_action( 'wpmu_new_blog', array( $this, 'wpmu_new_blog_callback' ), 10, 6 );
wpmu_create_blog( 'testsite1.example.org', '/new-blog/', 'New Blog', get_current_user_id(), $meta, 1 );
$this->assertEquals( $expected_meta, $this->wp_initialize_site_meta );
$this->wp_initialize_site_meta = array();
}
/**
* Capture the $meta value passed to the wpmu_new_blog action and compare it.
*/
public function wpmu_new_blog_callback( $blog_id, $user_id, $domain, $path, $network_id, $meta ) {
$this->wp_initialize_site_meta = $meta;
}
public function data_wpmu_new_blog_action_backward_commpatible() {
return array(
'default values' => array(
array(
),
array(
'public' => 0, // `public` is one of the defaults metas in `wpmu_create_blog' function prior WordPress 5.1.0
'WPLANG' => 'en_US', // WPLANG is another default meta in `wpmu_create_blog` function prior WordPress 5.1.0.
),
),
'public site' => array(
array(
'public' => 1,
),
array(
'public' => 1,
'WPLANG' => 'en_US'
),
),
'all whitelisted' => array(
array(
'public' => -1,
'archived' => 0,
'mature' => 0,
'spam' => 0,
'deleted' => 0,
'lang_id' => 11,
),
array(
'public' => -1,
'WPLANG' => 'en_US',
'archived' => 0,
'mature' => 0,
'spam' => 0,
'deleted' => 0,
'lang_id' => 11,
),
),
'extra meta key' => array(
array(
'foo' => 'bar',
),
array(
'public' => 0,
'WPLANG' => 'en_US',
'foo' => 'bar',
),
),
);
}
}
endif;