Ticket #28436: 28436.5.diff
File 28436.5.diff, 6.0 KB (added by , 9 years ago) |
---|
-
src/wp-includes/class-wp-theme.php
1177 1177 * @static 1178 1178 * @access public 1179 1179 * 1180 * @param int $blog_id Optional. Defaults to current blog.1180 * @param int $blog_id Optional. ID of the site. Defaults to the current site. 1181 1181 * @return array Array of stylesheet names. 1182 1182 */ 1183 1183 public static function get_allowed( $blog_id = null ) { 1184 1184 /** 1185 * Filter the array of themes allowed on the site ornetwork.1185 * Filter the array of themes allowed on the network. 1186 1186 * 1187 * @since MU1187 * @since 4.5.0 1188 1188 * 1189 1189 * @param array $allowed_themes An array of theme stylesheet names. 1190 * @param int $blog_id ID of the site. 1190 1191 */ 1191 $network = (array) apply_filters( ' allowed_themes', self::get_allowed_on_network());1192 $network = (array) apply_filters( 'network_allowed_themes', self::get_allowed_on_network(), $blog_id ); 1192 1193 return $network + self::get_allowed_on_site( $blog_id ); 1193 1194 } 1194 1195 … … 1206 1207 */ 1207 1208 public static function get_allowed_on_network() { 1208 1209 static $allowed_themes; 1209 if ( ! isset( $allowed_themes ) ) 1210 if ( ! isset( $allowed_themes ) ) { 1210 1211 $allowed_themes = (array) get_site_option( 'allowedthemes' ); 1212 } 1213 1214 /** 1215 * Filter the array of themes allowed on the network. 1216 * 1217 * @since MU 1218 * 1219 * @param array $allowed_themes An array of theme stylesheet names. 1220 */ 1221 $allowed_themes = apply_filters( 'allowed_themes', $allowed_themes ); 1222 1211 1223 return $allowed_themes; 1212 1224 } 1213 1225 … … 1221 1233 * 1222 1234 * @staticvar array $allowed_themes 1223 1235 * 1224 * @param int $blog_id Optional. Defaults to current blog.1236 * @param int $blog_id Optional. ID of the site. Defaults to the current site. 1225 1237 * @return array Array of stylesheet names. 1226 1238 */ 1227 1239 public static function get_allowed_on_site( $blog_id = null ) { … … 1230 1242 if ( ! $blog_id || ! is_multisite() ) 1231 1243 $blog_id = get_current_blog_id(); 1232 1244 1233 if ( isset( $allowed_themes[ $blog_id ] ) ) 1234 return $allowed_themes[ $blog_id ]; 1245 if ( isset( $allowed_themes[ $blog_id ] ) ) { 1246 /** 1247 * Filter the array of themes allowed on the site. 1248 * 1249 * @since 4.5.0 1250 * 1251 * @param array $allowed_themes An array of theme stylesheet names. 1252 * @param int $blog_id ID of the site. Defaults to current site. 1253 */ 1254 return (array) apply_filters( 'site_allowed_themes', $allowed_themes[ $blog_id ], $blog_id ); 1255 } 1235 1256 1236 1257 $current = $blog_id == get_current_blog_id(); 1237 1258 … … 1279 1300 } 1280 1301 } 1281 1302 1282 return (array) $allowed_themes[ $blog_id ]; 1303 /** This filter is documented in wp-includes/class-wp-theme.php */ 1304 return (array) apply_filters( 'site_allowed_themes', $allowed_themes[ $blog_id ], $blog_id ); 1283 1305 } 1284 1306 1285 1307 /** -
tests/phpunit/tests/theme/getAllowedFilters.php
1 1 <?php 2 if ( is_multisite() ) : 2 3 /** 3 4 * Tests specific to the filtering of `WP_Theme::get_allowed()` and related functions. 4 5 * 5 6 * @group themes 7 * @group multisite 6 8 */ 7 9 class Tests_WP_Theme_Get_Allowed_Filters extends WP_UnitTestCase { 8 10 /** … … 10 12 */ 11 13 protected $default_allowed; 12 14 15 protected $filter_network_allowed_themes_args; 16 17 public function test_network_allowed_themes_filter_sends_blog_id() { 18 $blog_id = 1; 19 20 add_filter( 'network_allowed_themes', array( $this, 'filter_network_allowed_themes' ), 10, 2 ); 21 WP_Theme::get_allowed( $blog_id ); 22 remove_filter( 'network_allowed_themes', array( $this, 'filter_network_allowed_themes' ) ); 23 24 $this->assertEquals( 2, count( $this->filter_network_allowed_themes_args ) ); 25 $this->assertEquals( $blog_id, $this->filter_network_allowed_themes_args[1] ); 26 } 27 13 28 /** 14 29 * Test the `allowed_themes` filter, which filters themes allowed on a network. 15 30 */ … … 27 42 $this->assertEquals( $expected, $allowed ); 28 43 } 29 44 45 /** 46 * Test the `network_allowed_themes` filter, which filters allowed themes on the network and provides `$blog_id`. 47 */ 48 public function test_wp_theme_get_allowed_with_network_allowed_themes_filter() { 49 $blog_id = 1; 50 51 $this->default_allowed = WP_Theme::get_allowed( $blog_id ); 52 53 add_filter( 'network_allowed_themes', array( $this, 'filter_network_allowed_themes' ), 10, 2 ); 54 $allowed = WP_Theme::get_allowed( $blog_id ); 55 remove_filter( 'network_allowed_themes', array( $this, 'filter_network_allowed_themes' ), 10 ); 56 57 $expected = $this->default_allowed + array( 'network-allowed-theme' => true ); 58 59 $this->assertEquals( $expected, $allowed ); 60 } 61 62 /** 63 * Test the `site_allowed_themes` filter, which filters allowed themes for a site and provides `$blog_id`. 64 */ 65 public function test_wp_theme_get_allowed_with_site_allowed_themes_filter() { 66 $blog_id = 1; 67 68 $this->default_allowed = WP_Theme::get_allowed( $blog_id ); 69 70 add_filter( 'site_allowed_themes', array( $this, 'filter_site_allowed_themes' ), 10, 2 ); 71 $allowed = WP_Theme::get_allowed( $blog_id ); 72 remove_filter( 'site_allowed_themes', array( $this, 'filter_site_allowed_themes' ), 10 ); 73 74 $expected = $this->default_allowed + array( 'site-allowed-theme' => true ); 75 76 $this->assertEquals( $expected, $allowed ); 77 } 78 30 79 public function filter_allowed_themes( $allowed_themes ) { 31 80 $allowed_themes['allow-on-network'] = true; 32 81 33 82 return $allowed_themes; 34 83 } 35 } 36 No newline at end of file 84 85 public function filter_network_allowed_themes( $allowed_themes, $blog_id ) { 86 $this->filter_network_allowed_themes_args = func_get_args(); 87 88 $allowed_themes['network-allowed-theme'] = true; 89 90 return $allowed_themes; 91 } 92 93 public function filter_site_allowed_themes( $allowed_themes, $blog_id ) { 94 $allowed_themes['site-allowed-theme'] = true; 95 96 return $allowed_themes; 97 } 98 } 99 endif; 100 No newline at end of file