mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-02 11:44:33 +00:00
Themes: Remove front page restriction from video header functions.
Adds a callback for determining when video headers should be displayed in themes supporting custom headers. By default, video headers are only displayed on the front page of a site. Theme authors may set a custom callback by passing `'video-active-callback' => 'mytheme_video_active_callback'` as an argument. The default callback is `is_front_page()`. This introduces the new function `is_header_video_active()` - returns `true` on pages that should display video headers. The return value can be filtered using the new filter of the same name. Props flixos90, bradyvercher, peterwilsoncc, joemcgill. Fixes #38738. git-svn-id: https://develop.svn.wordpress.org/trunk@39240 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
125
tests/phpunit/tests/theme/customHeader.php
Normal file
125
tests/phpunit/tests/theme/customHeader.php
Normal file
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
/**
|
||||
* @group themes
|
||||
*/
|
||||
class Tests_Theme_Custom_Header extends WP_UnitTestCase {
|
||||
|
||||
static $post;
|
||||
|
||||
public static function wpSetUpBeforeClass( $factory ) {
|
||||
self::$post = self::factory()->post->create( array(
|
||||
'post_status' => 'publish',
|
||||
) );
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
remove_theme_support( 'custom-header' );
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 38738
|
||||
*/
|
||||
function test_video_header_callback_front_page_from_front_page() {
|
||||
$this->_add_theme_support( array(
|
||||
'video' => true,
|
||||
) );
|
||||
|
||||
$this->go_to( home_url() );
|
||||
|
||||
$result = is_header_video_active();
|
||||
|
||||
$this->assertTrue( $result );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 38738
|
||||
*/
|
||||
function test_video_header_callback_front_page_from_elsewhere() {
|
||||
$this->_add_theme_support( array(
|
||||
'video' => true,
|
||||
) );
|
||||
|
||||
$this->go_to( get_permalink( self::$post ) );
|
||||
|
||||
$result = is_header_video_active();
|
||||
|
||||
$this->assertFalse( $result );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 38738
|
||||
*/
|
||||
function test_video_header_callback_globally_from_front_page() {
|
||||
$this->_add_theme_support( array(
|
||||
'video' => true,
|
||||
'video-active-callback' => '__return_true',
|
||||
) );
|
||||
|
||||
$this->go_to( home_url() );
|
||||
|
||||
$result = is_header_video_active();
|
||||
|
||||
$this->assertTrue( $result );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 38738
|
||||
*/
|
||||
function test_video_header_callback_globally_from_elsewhere() {
|
||||
$this->_add_theme_support( array(
|
||||
'video' => true,
|
||||
'video-active-callback' => '__return_true',
|
||||
) );
|
||||
|
||||
$this->go_to( get_permalink( self::$post ) );
|
||||
|
||||
$result = is_header_video_active();
|
||||
|
||||
$this->assertTrue( $result );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 38738
|
||||
*/
|
||||
function test_video_header_callback_globally_with_negative_filter() {
|
||||
$this->_add_theme_support( array(
|
||||
'video' => true,
|
||||
'video-active-callback' => '__return_true',
|
||||
) );
|
||||
|
||||
$this->go_to( get_permalink( self::$post ) );
|
||||
|
||||
add_filter( 'is_header_video_active', '__return_false' );
|
||||
$result = is_header_video_active();
|
||||
remove_filter( 'is_header_video_active', '__return_false' );
|
||||
|
||||
$this->assertFalse( $result );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds arguments directly to the $_wp_theme_features global. Calling
|
||||
* add_theme_support( 'custom-header' ) will poison subsequent tests since
|
||||
* it defines constants.
|
||||
*/
|
||||
function _add_theme_support( $args = array() ) {
|
||||
global $_wp_theme_features;
|
||||
|
||||
$_wp_theme_features['custom-header'][0] = wp_parse_args( $args, array(
|
||||
'default-image' => '',
|
||||
'random-default' => false,
|
||||
'width' => 0,
|
||||
'height' => 0,
|
||||
'flex-height' => false,
|
||||
'flex-width' => false,
|
||||
'default-text-color' => '',
|
||||
'header-text' => true,
|
||||
'uploads' => true,
|
||||
'wp-head-callback' => '',
|
||||
'admin-head-callback' => '',
|
||||
'admin-preview-callback' => '',
|
||||
'video' => false,
|
||||
'video-active-callback' => 'is_front_page',
|
||||
) );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user