Changeset 36366
- Timestamp:
- 01/20/2016 06:28:33 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-theme.php
r36250 r36366 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 or network. 1185 * Filter the array of themes allowed on the network. 1186 * 1187 * Site is provided as context so that a list of network allowed themes can 1188 * be filtered further. 1189 * 1190 * @since 4.5.0 1191 * 1192 * @param array $allowed_themes An array of theme stylesheet names. 1193 * @param int $blog_id ID of the site. 1194 */ 1195 $network = (array) apply_filters( 'network_allowed_themes', self::get_allowed_on_network(), $blog_id ); 1196 return $network + self::get_allowed_on_site( $blog_id ); 1197 } 1198 1199 /** 1200 * Returns array of stylesheet names of themes allowed on the network. 1201 * 1202 * @since 3.4.0 1203 * 1204 * @static 1205 * @access public 1206 * 1207 * @staticvar array $allowed_themes 1208 * 1209 * @return array Array of stylesheet names. 1210 */ 1211 public static function get_allowed_on_network() { 1212 static $allowed_themes; 1213 if ( ! isset( $allowed_themes ) ) { 1214 $allowed_themes = (array) get_site_option( 'allowedthemes' ); 1215 } 1216 1217 /** 1218 * Filter the array of themes allowed on the network. 1186 1219 * 1187 1220 * @since MU … … 1189 1222 * @param array $allowed_themes An array of theme stylesheet names. 1190 1223 */ 1191 $network = (array) apply_filters( 'allowed_themes', self::get_allowed_on_network() ); 1192 return $network + self::get_allowed_on_site( $blog_id ); 1193 } 1194 1195 /** 1196 * Returns array of stylesheet names of themes allowed on the network. 1224 $allowed_themes = apply_filters( 'allowed_themes', $allowed_themes ); 1225 1226 return $allowed_themes; 1227 } 1228 1229 /** 1230 * Returns array of stylesheet names of themes allowed on the site. 1197 1231 * 1198 1232 * @since 3.4.0 … … 1203 1237 * @staticvar array $allowed_themes 1204 1238 * 1205 * @return array Array of stylesheet names. 1206 */ 1207 public static function get_allowed_on_network() { 1208 static $allowed_themes; 1209 if ( ! isset( $allowed_themes ) ) 1210 $allowed_themes = (array) get_site_option( 'allowedthemes' ); 1211 return $allowed_themes; 1212 } 1213 1214 /** 1215 * Returns array of stylesheet names of themes allowed on the site. 1216 * 1217 * @since 3.4.0 1218 * 1219 * @static 1220 * @access public 1221 * 1222 * @staticvar array $allowed_themes 1223 * 1224 * @param int $blog_id Optional. Defaults to current blog. 1239 * @param int $blog_id Optional. ID of the site. Defaults to the current site. 1225 1240 * @return array Array of stylesheet names. 1226 1241 */ … … 1231 1246 $blog_id = get_current_blog_id(); 1232 1247 1233 if ( isset( $allowed_themes[ $blog_id ] ) ) 1234 return $allowed_themes[ $blog_id ]; 1248 if ( isset( $allowed_themes[ $blog_id ] ) ) { 1249 /** 1250 * Filter the array of themes allowed on the site. 1251 * 1252 * @since 4.5.0 1253 * 1254 * @param array $allowed_themes An array of theme stylesheet names. 1255 * @param int $blog_id ID of the site. Defaults to current site. 1256 */ 1257 return (array) apply_filters( 'site_allowed_themes', $allowed_themes[ $blog_id ], $blog_id ); 1258 } 1235 1259 1236 1260 $current = $blog_id == get_current_blog_id(); … … 1280 1304 } 1281 1305 1282 return (array) $allowed_themes[ $blog_id ]; 1306 /** This filter is documented in wp-includes/class-wp-theme.php */ 1307 return (array) apply_filters( 'site_allowed_themes', $allowed_themes[ $blog_id ], $blog_id ); 1283 1308 } 1284 1309 -
trunk/tests/phpunit/tests/theme/getAllowedFilters.php
r36350 r36366 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 { … … 10 12 */ 11 13 protected $default_allowed; 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 } 12 27 13 28 /** … … 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; … … 33 82 return $allowed_themes; 34 83 } 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 } 35 98 } 99 endif;
Note: See TracChangeset
for help on using the changeset viewer.