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.

Built from https://develop.svn.wordpress.org/trunk@39240


git-svn-id: http://core.svn.wordpress.org/trunk@39180 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Peter Wilson 2016-11-15 07:16:33 +00:00
parent 0f5a44e093
commit 11998b4169
3 changed files with 43 additions and 7 deletions

View File

@ -3491,7 +3491,7 @@ final class WP_Customize_Manager {
'frame_title' => __( 'Select Video' ),
'frame_button' => __( 'Choose Video' ),
),
'active_callback' => 'is_front_page',
'active_callback' => 'is_header_video_active',
) ) );
$this->add_control( 'external_header_video', array(

View File

@ -1400,13 +1400,45 @@ function get_header_video_settings() {
* @return bool True if a custom header is set. False if not.
*/
function has_custom_header() {
if ( has_header_image() || ( is_front_page() && has_header_video() ) ) {
if ( has_header_image() || ( has_header_video() && is_header_video_active() ) ) {
return true;
}
return false;
}
/**
* Checks whether the custom header video is eligible to show on the current page.
*
* @since 4.7.0
*
* @return bool True if the custom header video should be shown. False if not.
*/
function is_header_video_active() {
if ( ! get_theme_support( 'custom-header', 'video' ) ) {
return false;
}
$video_active_cb = get_theme_support( 'custom-header', 'video-active-callback' );
if ( empty( $video_active_cb ) || ! is_callable( $video_active_cb ) ) {
$show_video = true;
} else {
$show_video = call_user_func( $video_active_cb );
}
/**
* Modify whether the custom header video is eligible to show on the current page.
*
* @since 4.7.0
*
* @param bool $show_video Whether the custom header video should be shown. Returns 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()`.
*/
return apply_filters( 'is_header_video_active', $show_video );
}
/**
* Retrieve the markup for a custom header.
*
@ -1442,7 +1474,7 @@ function the_custom_header_markup() {
echo $custom_header;
if ( is_front_page() && ( has_header_video() || is_customize_preview() ) ) {
if ( is_header_video_active() && ( has_header_video() || is_customize_preview() ) ) {
wp_enqueue_script( 'wp-custom-header' );
wp_localize_script( 'wp-custom-header', '_wpCustomHeaderSettings', get_header_video_settings() );
}
@ -2058,6 +2090,7 @@ function add_theme_support( $feature ) {
'admin-head-callback' => '',
'admin-preview-callback' => '',
'video' => false,
'video-active-callback' => 'is_front_page',
);
$jit = isset( $args[0]['__jit'] );
@ -2319,10 +2352,13 @@ function _remove_theme_support( $feature ) {
if ( ! did_action( 'wp_loaded' ) )
break;
$support = get_theme_support( 'custom-header' );
if ( $support[0]['wp-head-callback'] )
if ( isset( $support[0]['wp-head-callback'] ) ) {
remove_action( 'wp_head', $support[0]['wp-head-callback'] );
remove_action( 'admin_menu', array( $GLOBALS['custom_image_header'], 'init' ) );
unset( $GLOBALS['custom_image_header'] );
}
if ( isset( $GLOBALS['custom_image_header'] ) ) {
remove_action( 'admin_menu', array( $GLOBALS['custom_image_header'], 'init' ) );
unset( $GLOBALS['custom_image_header'] );
}
break;
case 'custom-background' :

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.7-beta3-39239';
$wp_version = '4.7-beta3-39240';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.