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.

Built from https://develop.svn.wordpress.org/trunk@36366


git-svn-id: http://core.svn.wordpress.org/trunk@36333 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Jeremy Felt 2016-01-20 18:29:27 +00:00
parent 1e1d1375b0
commit 3018d9827c
2 changed files with 35 additions and 10 deletions

View File

@ -1177,18 +1177,22 @@ final class WP_Theme implements ArrayAccess {
* @static
* @access public
*
* @param int $blog_id Optional. Defaults to current blog.
* @param int $blog_id Optional. ID of the site. Defaults to the current site.
* @return array Array of stylesheet names.
*/
public static function get_allowed( $blog_id = null ) {
/**
* Filter the array of themes allowed on the site or network.
* Filter the array of themes allowed on the network.
*
* @since MU
* Site is provided as context so that a list of network allowed themes can
* be filtered further.
*
* @since 4.5.0
*
* @param array $allowed_themes An array of theme stylesheet names.
* @param int $blog_id ID of the site.
*/
$network = (array) apply_filters( 'allowed_themes', self::get_allowed_on_network() );
$network = (array) apply_filters( 'network_allowed_themes', self::get_allowed_on_network(), $blog_id );
return $network + self::get_allowed_on_site( $blog_id );
}
@ -1206,8 +1210,19 @@ final class WP_Theme implements ArrayAccess {
*/
public static function get_allowed_on_network() {
static $allowed_themes;
if ( ! isset( $allowed_themes ) )
if ( ! isset( $allowed_themes ) ) {
$allowed_themes = (array) get_site_option( 'allowedthemes' );
}
/**
* Filter the array of themes allowed on the network.
*
* @since MU
*
* @param array $allowed_themes An array of theme stylesheet names.
*/
$allowed_themes = apply_filters( 'allowed_themes', $allowed_themes );
return $allowed_themes;
}
@ -1221,7 +1236,7 @@ final class WP_Theme implements ArrayAccess {
*
* @staticvar array $allowed_themes
*
* @param int $blog_id Optional. Defaults to current blog.
* @param int $blog_id Optional. ID of the site. Defaults to the current site.
* @return array Array of stylesheet names.
*/
public static function get_allowed_on_site( $blog_id = null ) {
@ -1230,8 +1245,17 @@ final class WP_Theme implements ArrayAccess {
if ( ! $blog_id || ! is_multisite() )
$blog_id = get_current_blog_id();
if ( isset( $allowed_themes[ $blog_id ] ) )
return $allowed_themes[ $blog_id ];
if ( isset( $allowed_themes[ $blog_id ] ) ) {
/**
* Filter the array of themes allowed on the site.
*
* @since 4.5.0
*
* @param array $allowed_themes An array of theme stylesheet names.
* @param int $blog_id ID of the site. Defaults to current site.
*/
return (array) apply_filters( 'site_allowed_themes', $allowed_themes[ $blog_id ], $blog_id );
}
$current = $blog_id == get_current_blog_id();
@ -1279,7 +1303,8 @@ final class WP_Theme implements ArrayAccess {
}
}
return (array) $allowed_themes[ $blog_id ];
/** This filter is documented in wp-includes/class-wp-theme.php */
return (array) apply_filters( 'site_allowed_themes', $allowed_themes[ $blog_id ], $blog_id );
}
/**

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.5-alpha-36365';
$wp_version = '4.5-alpha-36366';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.