Make WordPress Core

Changeset 39240


Ignore:
Timestamp:
11/15/2016 07:15:20 AM (8 years ago)
Author:
peterwilsoncc
Message:

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.

Location:
trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-customize-manager.php

    r39237 r39240  
    34923492                'frame_button' => __( 'Choose Video' ),
    34933493            ),
    3494             'active_callback' => 'is_front_page',
     3494            'active_callback' => 'is_header_video_active',
    34953495        ) ) );
    34963496
  • trunk/src/wp-includes/theme.php

    r39231 r39240  
    14011401 */
    14021402function 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() ) ) {
    14041404        return true;
    14051405    }
    14061406
    14071407    return false;
     1408}
     1409
     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 */
     1417function 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. Returns the value
     1436     *                         of the theme setting for the `custom-header`'s `video-active-callback`.
     1437     *                         If no callback is set, the default value is that of `is_front_page()`.
     1438     */
     1439    return apply_filters( 'is_header_video_active', $show_video );
    14081440}
    14091441
     
    14431475    echo $custom_header;
    14441476
    1445     if ( is_front_page() && ( has_header_video() || is_customize_preview() ) ) {
     1477    if ( is_header_video_active() && ( has_header_video() || is_customize_preview() ) ) {
    14461478        wp_enqueue_script( 'wp-custom-header' );
    14471479        wp_localize_script( 'wp-custom-header', '_wpCustomHeaderSettings', get_header_video_settings() );
     
    20592091                'admin-preview-callback' => '',
    20602092                'video' => false,
     2093                'video-active-callback' => 'is_front_page',
    20612094            );
    20622095
     
    23202353                break;
    23212354            $support = get_theme_support( 'custom-header' );
    2322             if ( $support[0]['wp-head-callback'] )
     2355            if ( isset( $support[0]['wp-head-callback'] ) ) {
    23232356                remove_action( 'wp_head', $support[0]['wp-head-callback'] );
    2324             remove_action( 'admin_menu', array( $GLOBALS['custom_image_header'], 'init' ) );
    2325             unset( $GLOBALS['custom_image_header'] );
     2357            }
     2358            if ( isset( $GLOBALS['custom_image_header'] ) ) {
     2359                remove_action( 'admin_menu', array( $GLOBALS['custom_image_header'], 'init' ) );
     2360                unset( $GLOBALS['custom_image_header'] );
     2361            }
    23262362            break;
    23272363
Note: See TracChangeset for help on using the changeset viewer.