From 11998b416959e9a12190ead9df8c04ea02294508 Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Tue, 15 Nov 2016 07:16:33 +0000 Subject: [PATCH] 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 --- wp-includes/class-wp-customize-manager.php | 2 +- wp-includes/theme.php | 46 +++++++++++++++++++--- wp-includes/version.php | 2 +- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/wp-includes/class-wp-customize-manager.php b/wp-includes/class-wp-customize-manager.php index 54c3f0eac1..1a9c1c5523 100644 --- a/wp-includes/class-wp-customize-manager.php +++ b/wp-includes/class-wp-customize-manager.php @@ -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( diff --git a/wp-includes/theme.php b/wp-includes/theme.php index 66e10b24e8..9ca52735cb 100644 --- a/wp-includes/theme.php +++ b/wp-includes/theme.php @@ -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' : diff --git a/wp-includes/version.php b/wp-includes/version.php index 1e8fdfa071..4be8f9a1bd 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.