Ticket #38738: 38738.4.diff
| File 38738.4.diff, 4.0 KB (added by , 9 years ago) |
|---|
-
src/wp-includes/theme.php
diff --git src/wp-includes/theme.php src/wp-includes/theme.php index 865f851..9bf9bd0 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 * The container div will always be returned in the Customizer preview. … … function the_custom_header_markup() { 1442 1472 1443 1473 echo $custom_header; 1444 1474 1445 if ( is_ front_page() && ( has_header_video() || is_customize_preview() ) ) {1475 if ( is_header_video_active() && ( has_header_video() || is_customize_preview() ) ) { 1446 1476 wp_enqueue_script( 'wp-custom-header' ); 1447 1477 wp_localize_script( 'wp-custom-header', '_wpCustomHeaderSettings', get_header_video_settings() ); 1448 1478 } … … function add_theme_support( $feature ) { 2058 2088 'admin-head-callback' => '', 2059 2089 'admin-preview-callback' => '', 2060 2090 'video' => false, 2091 'video-active-callback' => 'is_front_page', 2061 2092 ); 2062 2093 2063 2094 $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..3b148f8 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 // Back up theme features global to avoid poisoning later tests. 200 global $_wp_theme_features; 201 $_wp_theme_features_backup = $_wp_theme_features; 202 203 add_theme_support( 'custom-header', array( 204 'video' => true, 205 '__jit' => true, // Force refresh. 206 ) ); 207 208 $p = self::factory()->post->create( array( 209 'post_status' => 'publish', 210 ) ); 211 212 $this->go_to( home_url() ); 213 $this->assertTrue( is_header_video_active() ); 214 215 $this->go_to( get_permalink( $p ) ); 216 $this->assertSame( false, is_header_video_active() ); 217 218 /* 219 * Change callback to __return_true(). 220 * 221 * Support must be removed first, otherwise the previously set 222 * values will override the new values. 223 */ 224 remove_theme_support( 'custom-header' ); 225 add_theme_support( 'custom-header', array( 226 'video' => true, 227 'video-active-callback' => '__return_true', 228 '__jit' => true, // Force refresh. 229 ) ); 230 231 $this->assertTrue( is_header_video_active() ); 232 233 // Now check the filter works as expected. 234 add_filter( 'is_header_video_active', '__return_false' ); 235 $this->assertSame( false, is_header_video_active() ); 236 remove_filter( 'is_header_video_active', '__return_false' ); 237 238 // Restore theme features global to initial state. 239 $_wp_theme_features = $_wp_theme_features_backup; 240 } 194 241 }