mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
Themes: Enhance filtering options for allowed themes on a network.
* Move the legacy `allowed_themes` filter to `WP_Theme::get_allowed_on_network()`, where it will continue to filter themes allowed on the network. * Add `network_allowed_themes` filter to `WP_Theme::get_allowed()` and pass `$blog_id` to provide context. * Add `site_allowed_themes` filter to `WP_Theme::get_allowed_on_site()` and pass `$blog_id` to provide context. Props pauldewouters, lamosty, michalzuber, dmsnell, johnnypea, rob. Fixes #28436. git-svn-id: https://develop.svn.wordpress.org/trunk@36366 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
<?php
|
||||
if ( is_multisite() ) :
|
||||
/**
|
||||
* Tests specific to the filtering of `WP_Theme::get_allowed()` and related functions.
|
||||
*
|
||||
* @group themes
|
||||
* @group multisite
|
||||
*/
|
||||
class Tests_WP_Theme_Get_Allowed_Filters extends WP_UnitTestCase {
|
||||
/**
|
||||
@@ -10,6 +12,19 @@ class Tests_WP_Theme_Get_Allowed_Filters extends WP_UnitTestCase {
|
||||
*/
|
||||
protected $default_allowed;
|
||||
|
||||
protected $filter_network_allowed_themes_args;
|
||||
|
||||
public function test_network_allowed_themes_filter_sends_blog_id() {
|
||||
$blog_id = 1;
|
||||
|
||||
add_filter( 'network_allowed_themes', array( $this, 'filter_network_allowed_themes' ), 10, 2 );
|
||||
WP_Theme::get_allowed( $blog_id );
|
||||
remove_filter( 'network_allowed_themes', array( $this, 'filter_network_allowed_themes' ) );
|
||||
|
||||
$this->assertEquals( 2, count( $this->filter_network_allowed_themes_args ) );
|
||||
$this->assertEquals( $blog_id, $this->filter_network_allowed_themes_args[1] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the `allowed_themes` filter, which filters themes allowed on a network.
|
||||
*/
|
||||
@@ -27,9 +42,58 @@ class Tests_WP_Theme_Get_Allowed_Filters extends WP_UnitTestCase {
|
||||
$this->assertEquals( $expected, $allowed );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the `network_allowed_themes` filter, which filters allowed themes on the network and provides `$blog_id`.
|
||||
*/
|
||||
public function test_wp_theme_get_allowed_with_network_allowed_themes_filter() {
|
||||
$blog_id = 1;
|
||||
|
||||
$this->default_allowed = WP_Theme::get_allowed( $blog_id );
|
||||
|
||||
add_filter( 'network_allowed_themes', array( $this, 'filter_network_allowed_themes' ), 10, 2 );
|
||||
$allowed = WP_Theme::get_allowed( $blog_id );
|
||||
remove_filter( 'network_allowed_themes', array( $this, 'filter_network_allowed_themes' ), 10 );
|
||||
|
||||
$expected = $this->default_allowed + array( 'network-allowed-theme' => true );
|
||||
|
||||
$this->assertEquals( $expected, $allowed );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the `site_allowed_themes` filter, which filters allowed themes for a site and provides `$blog_id`.
|
||||
*/
|
||||
public function test_wp_theme_get_allowed_with_site_allowed_themes_filter() {
|
||||
$blog_id = 1;
|
||||
|
||||
$this->default_allowed = WP_Theme::get_allowed( $blog_id );
|
||||
|
||||
add_filter( 'site_allowed_themes', array( $this, 'filter_site_allowed_themes' ), 10, 2 );
|
||||
$allowed = WP_Theme::get_allowed( $blog_id );
|
||||
remove_filter( 'site_allowed_themes', array( $this, 'filter_site_allowed_themes' ), 10 );
|
||||
|
||||
$expected = $this->default_allowed + array( 'site-allowed-theme' => true );
|
||||
|
||||
$this->assertEquals( $expected, $allowed );
|
||||
}
|
||||
|
||||
public function filter_allowed_themes( $allowed_themes ) {
|
||||
$allowed_themes['allow-on-network'] = true;
|
||||
|
||||
return $allowed_themes;
|
||||
}
|
||||
}
|
||||
|
||||
public function filter_network_allowed_themes( $allowed_themes, $blog_id ) {
|
||||
$this->filter_network_allowed_themes_args = func_get_args();
|
||||
|
||||
$allowed_themes['network-allowed-theme'] = true;
|
||||
|
||||
return $allowed_themes;
|
||||
}
|
||||
|
||||
public function filter_site_allowed_themes( $allowed_themes, $blog_id ) {
|
||||
$allowed_themes['site-allowed-theme'] = true;
|
||||
|
||||
return $allowed_themes;
|
||||
}
|
||||
}
|
||||
endif;
|
||||
Reference in New Issue
Block a user