Ticket #6348: 6348.01.patch
File 6348.01.patch, 5.4 KB (added by , 10 years ago) |
---|
-
src/bp-core/bp-core-template-loader.php
diff --git src/bp-core/bp-core-template-loader.php src/bp-core/bp-core-template-loader.php index 47d48fd..9fd45a4 100644
function bp_get_template_part( $slug, $name = null ) { 68 68 } 69 69 70 70 /** 71 * Get a restrained BuddyPress template part for display. 72 * 73 * @since BuddyPress (2.3.0) 74 * 75 * @see bp_get_template_part() for the description of parameters and returned value 76 */ 77 function bp_get_restrained_template_part( $slug, $name = null ) { 78 // Restrain to BP Legacy 79 add_filter( 'bp_is_theme_compat_restrained', '__return_true' ); 80 81 $restrained_template_part = bp_get_template_part( $slug, $name ); 82 83 // Stop restraining to BP Legacy 84 remove_filter( 'bp_is_theme_compat_restrained', '__return_true' ); 85 86 // Return the restrained template part 87 return $restrained_template_part; 88 } 89 90 /** 71 91 * Retrieve the name of the highest priority template file that exists. 72 92 * 73 93 * Searches in the STYLESHEETPATH before TEMPLATEPATH so that themes which … … function bp_locate_template( $template_names, $load = false, $require_once = tru 127 147 128 148 // Maybe load the template if one was located 129 149 $use_themes = defined( 'WP_USE_THEMES' ) && WP_USE_THEMES; 130 $doing_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; 131 if ( ( $use_themes || $doing_ajax ) && ( true == $load ) && ! empty( $located ) ) { 150 if ( ( $use_themes || is_admin() ) && ( true == $load ) && ! empty( $located ) ) { 132 151 load_template( $located, $require_once ); 133 152 } 134 153 … … function bp_get_template_stack() { 222 241 do { 223 242 foreach( (array) current( $wp_filter[$tag] ) as $the_ ) { 224 243 if ( ! is_null( $the_['function'] ) ) { 244 245 // Restrict to theme compat dir if needed 246 if ( bp_is_theme_compat_restrained() && 'bp_get_theme_compat_dir' !== $the_['function'] ) { 247 continue; 248 } 249 225 250 $args[1] = $stack; 226 251 $stack[] = call_user_func_array( $the_['function'], array_slice( $args, 1, (int) $the_['accepted_args'] ) ); 227 252 } -
src/bp-core/bp-core-theme-compatibility.php
diff --git src/bp-core/bp-core-theme-compatibility.php src/bp-core/bp-core-theme-compatibility.php index d88c27a..7311e0d 100644
function bp_get_theme_compat_version() { 224 224 } 225 225 226 226 /** 227 * Toggle function to allow BuddyPress core to restrict Theme Compat 228 * to the legacy one when needed (eg: Administration screens) 229 * 230 * @since BuddyPress (2.3.0) 231 * 232 * @return bool True to restrict to BP Legacy, false otherwise 233 */ 234 function bp_is_theme_compat_restrained() { 235 return apply_filters( 'bp_is_theme_compat_restrained', false ); 236 } 237 238 /** 227 239 * Get the absolute path of the theme package being used. 228 240 * 229 241 * or set manually. Tricky theme authors can override the default and include … … function bp_get_theme_compat_version() { 236 248 * @return string The absolute path of the theme package currently in use. 237 249 */ 238 250 function bp_get_theme_compat_dir() { 251 /** 252 * Restrict to BP Legacy if needed 253 */ 254 if ( bp_is_theme_compat_restrained() && 'legacy' !== bp_get_theme_compat_id() ) { 255 return false; 256 } 239 257 240 258 /** 241 259 * Filters the absolute path of the theme package being used. … … function bp_get_theme_compat_dir() { 261 279 * @return string URL of the theme package currently in use. 262 280 */ 263 281 function bp_get_theme_compat_url() { 282 /** 283 * Restrict to BP Legacy if needed 284 */ 285 if ( bp_is_theme_compat_restrained() && 'legacy' !== bp_get_theme_compat_id() ) { 286 return false; 287 } 264 288 265 289 /** 266 290 * Filters the URL of the theme package being used. -
tests/phpunit/testcases/core/template/theme-compat.php
diff --git tests/phpunit/testcases/core/template/theme-compat.php tests/phpunit/testcases/core/template/theme-compat.php index e69de29..600c814 100644
1 <?php 2 /** 3 * @group theme_compat 4 */ 5 class BP_Tests_BP_Attachement_Avatar_TestCases extends BP_UnitTestCase { 6 protected $displayed_user; 7 8 public function template_dir() { 9 return buddypress()->themes_dir . '/template-pack-test'; 10 } 11 12 public function setUp() { 13 parent::setUp(); 14 bp_register_template_stack( array( $this, 'template_dir' ), 13 ); 15 } 16 17 public function tearDown() { 18 parent::tearDown(); 19 bp_deregister_template_stack( array( $this, 'template_dir' ), 13 ); 20 } 21 22 /** 23 * @group bp_get_template_stack 24 */ 25 public function test_bp_get_template_stack_not_restrained() { 26 $stack = bp_get_template_stack(); 27 $root_dirs = array(); 28 29 foreach ( $stack as $template_dir ) { 30 $root_dir = array_pop( explode( '/', $template_dir ) ); 31 32 if ( 'template-pack-test' === $root_dir || 'bp-legacy' === $root_dir ) { 33 $root_dirs[] = $root_dir; 34 } 35 } 36 37 $this->assertFalse( count( $root_dirs ) === 1 ); 38 $this->assertContains( 'template-pack-test', $root_dirs ); 39 } 40 41 /** 42 * @group bp_get_template_stack 43 */ 44 public function test_bp_get_template_stack_restrained() { 45 add_filter( 'bp_is_theme_compat_restrained', '__return_true' ); 46 $stack = bp_get_template_stack(); 47 remove_filter( 'bp_is_theme_compat_restrained', '__return_true' ); 48 49 $root_dirs = array(); 50 51 foreach ( $stack as $template_dir ) { 52 $root_dir = array_pop( explode( '/', $template_dir ) ); 53 54 if ( 'template-pack-test' === $root_dir || 'bp-legacy' === $root_dir ) { 55 $root_dirs[] = $root_dir; 56 } 57 } 58 59 $this->assertTrue( count( $root_dirs ) === 1 ); 60 $this->assertContains( 'bp-legacy', $root_dirs ); 61 } 62 }