Ticket #38738: 38738.3.diff
| File 38738.3.diff, 3.7 KB (added by , 9 years ago) |
|---|
-
src/wp-includes/theme.php
diff --git src/wp-includes/theme.php src/wp-includes/theme.php index bf1c55c..d6d4ce9 100644
function get_header_video_settings() { 1400 1400 * @return bool True if a custom header is set. False if not. 1401 1401 */ 1402 1402 function has_custom_header() { 1403 if ( has_header_image() || ( is_front_page() && has_header_video() ) ) {1403 if ( has_header_image() || ( has_header_video() && is_header_video_active() ) ) { 1404 1404 return true; 1405 1405 } 1406 1406 … … function has_custom_header() { 1408 1408 } 1409 1409 1410 1410 /** 1411 * Checks whether the custom header video is eligible to show on the current page. 1412 * 1413 * @since 4.7.0 1414 * 1415 * @return bool True if the custom header video should be shown. False if not. 1416 */ 1417 function is_header_video_active() { 1418 if ( ! get_theme_support( 'custom-header', 'video' ) ) { 1419 return false; 1420 } 1421 1422 $video_active_cb = get_theme_support( 'custom-header', 'video-active-callback' ); 1423 1424 if ( empty( $video_active_cb ) || ! is_callable( $video_active_cb ) ) { 1425 $show_video = true; 1426 } else { 1427 $show_video = call_user_func( $video_active_cb ); 1428 } 1429 1430 /** 1431 * Modify whether the custom header video is eligible to show on the current page. 1432 * 1433 * @since 4.7.0 1434 * 1435 * @param bool $show_video Whether the custom header video should be shown. Defaults to the value of the theme setting for the `custom-header`'s `video-active-callback`. If no callback is set, the default value is that of `is_front_page()`. 1436 */ 1437 return apply_filters( 'is_header_video_active', $show_video ); 1438 } 1439 1440 /** 1411 1441 * Retrieve the markup for a custom header. 1412 1442 * 1413 1443 * @since 4.7.0 … … function the_custom_header_markup() { 1436 1466 } 1437 1467 echo $custom_header; 1438 1468 1439 if ( has_header_video() && is_ front_page() ) {1469 if ( has_header_video() && is_header_video_active() ) { 1440 1470 wp_enqueue_script( 'wp-custom-header' ); 1441 1471 wp_localize_script( 'wp-custom-header', '_wpCustomHeaderSettings', get_header_video_settings() ); 1442 1472 } … … function add_theme_support( $feature ) { 2052 2082 'admin-head-callback' => '', 2053 2083 'admin-preview-callback' => '', 2054 2084 'video' => false, 2085 'video-active-callback' => 'is_front_page', 2055 2086 ); 2056 2087 2057 2088 $jit = isset( $args[0]['__jit'] ); -
tests/phpunit/tests/theme/support.php
diff --git tests/phpunit/tests/theme/support.php tests/phpunit/tests/theme/support.php index 648f031..0cd16a0 100644
class Tests_Theme_Support extends WP_UnitTestCase { 191 191 $this->assertEmpty( get_registered_nav_menus() ); 192 192 $this->assertFalse( current_theme_supports( 'menus' ) ); 193 193 } 194 195 /** 196 * @ticket 38738 197 */ 198 function test_video_header_callback() { 199 add_theme_support( 'custom-header', array( 200 'video' => true, 201 '__jit' => true, // Force refresh. 202 ) ); 203 204 $p = self::factory()->post->create( array( 205 'post_status' => 'publish', 206 ) ); 207 208 $this->go_to( home_url() ); 209 $this->assertTrue( is_header_video_active() ); 210 211 $this->go_to( get_permalink( $p ) ); 212 $this->assertSame( false, is_header_video_active() ); 213 214 /* 215 * Change callback to __return_true(). 216 * 217 * Support must be removed first, otherwise the previously set 218 * values will override the new values. 219 */ 220 remove_theme_support( 'custom-header' ); 221 add_theme_support( 'custom-header', array( 222 'video' => true, 223 'video-active-callback' => '__return_true', 224 '__jit' => true, // Force refresh. 225 ) ); 226 227 $this->assertTrue( is_header_video_active() ); 228 229 // Now check the filter works as expected. 230 add_filter( 'is_header_video_active', '__return_false' ); 231 $this->assertSame( false, is_header_video_active() ); 232 remove_filter( 'is_header_video_active', '__return_false' ); 233 } 194 234 }