From 3018d9827c90b7513867d49df1b6336c9cd73808 Mon Sep 17 00:00:00 2001 From: Jeremy Felt Date: Wed, 20 Jan 2016 18:29:27 +0000 Subject: [PATCH] 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 --- wp-includes/class-wp-theme.php | 43 +++++++++++++++++++++++++++------- wp-includes/version.php | 2 +- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/wp-includes/class-wp-theme.php b/wp-includes/class-wp-theme.php index a2df384d0f..f680558ac0 100644 --- a/wp-includes/class-wp-theme.php +++ b/wp-includes/class-wp-theme.php @@ -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 ); } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index e054e36bc6..afce66e6df 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.