Make WordPress Core

Ticket #38172: 38172.2.patch

File 38172.2.patch, 3.8 KB (added by davidakennedy, 7 years ago)

Revised patch for the theme API part of this. Worked on this along with @joshcummingsdesign

  • wp-includes/theme.php

     
    12641264                'thumbnail_url' => '',
    12651265                'width'         => get_theme_support( 'custom-header', 'width' ),
    12661266                'height'        => get_theme_support( 'custom-header', 'height' ),
     1267                'video'         => get_theme_support( 'custom-header', 'video' ),
    12671268        );
    12681269        return (object) wp_parse_args( $data, $default );
    12691270}
     
    13111312}
    13121313
    13131314/**
     1315 * Check whether a header video is set or not.
     1316 *
     1317 * @since 4.7.0
     1318 *
     1319 * @see get_header_video()
     1320 *
     1321 * @return bool Whether a header video is set or not.
     1322 */
     1323function has_header_video() {
     1324        return (bool) get_header_video();
     1325}
     1326
     1327/* Retrieve header video for custom header.
     1328*
     1329* @since 4.7.0
     1330*
     1331* @return string|false
     1332*/
     1333function get_header_video() {
     1334        $url = get_theme_mod( 'header_video' );
     1335
     1336        if ( 'remove-header' == $url )
     1337                return false;
     1338
     1339        if ( $url ) {
     1340                // We have an attachment ID, need the full URL
     1341                $url = wp_get_attachment_url( $url );
     1342        }
     1343
     1344        return esc_url_raw( set_url_scheme( $url ) );
     1345}
     1346
     1347/**
     1348 * Create video tag markup for a custom header video.
     1349 *
     1350 * @since 4.7.0
     1351 *
     1352 * @param array $attr Optional. Additional attributes for the image tag. Can be used
     1353 *                              to override the default attributes. Default empty.
     1354 * @return string HTML image element markup or empty string on failure.
     1355 */
     1356function get_header_video_tag( $attr = array() ) {
     1357        $header = get_custom_header();
     1358        $video = get_header_video();
     1359        $image = get_header_image();
     1360
     1361        if ( empty( $video ) ) {
     1362                return '';
     1363        }
     1364
     1365        $width = absint( $header->width );
     1366        $height = absint( $header->height );
     1367
     1368        $attr = wp_parse_args(
     1369                $attr,
     1370                array(
     1371                        'src' => get_header_video(),
     1372                        'width' => $width,
     1373                        'height' => $height,
     1374                        'controls' => '',
     1375                        'autoplay' => '',
     1376                        'loop' => '',
     1377                        'muted' => '',
     1378                )
     1379        );
     1380
     1381        // Use the header image as poster attribute.
     1382        if ( ! empty( $image ) ) {
     1383                $attr['poster'] = $header->url;
     1384        }
     1385
     1386        $attr = array_map( 'esc_attr', $attr );
     1387        $html = '<video';
     1388
     1389        foreach ( $attr as $name => $value ) {
     1390                $html .= ' ' . $name . '="' . $value . '"';
     1391        }
     1392
     1393        $html .= '></video>';
     1394
     1395        /**
     1396         * Filters the markup of header videos.
     1397         *
     1398         * @since 4.7.0
     1399         *
     1400         * @param string $html   The HTML image tag markup being filtered.
     1401         * @param object $header The custom header object returned by 'get_custom_header()'.
     1402         * @param array  $attr   Array of the attributes for the image tag.
     1403         */
     1404        return apply_filters( 'get_header_video_tag', $html, $header, $attr );
     1405}
     1406
     1407/**
     1408 * Display the video markup for a custom header video.
     1409 *
     1410 * @since 4.7.0
     1411 *
     1412 * @param array $attr Optional. Attributes for the image markup. Default empty.
     1413 */
     1414function the_header_video_tag( $attr = array() ) {
     1415        echo get_header_video_tag( $attr );
     1416}
     1417
     1418/**
     1419 * Display header video URL.
     1420 *
     1421 * @since 4.7.0
     1422 */
     1423function the_header_video() {
     1424        $video = get_header_video();
     1425        if ( $video ) {
     1426                echo esc_url( $video );
     1427        }
     1428}
     1429
     1430/**
     1431 * Display the video and image markup for a custom header.
     1432 *
     1433 * @since 4.7.0
     1434 */
     1435function the_custom_header() {
     1436        $video = get_header_video();
     1437        $image = get_header_image();
     1438
     1439        if ( ! empty( $video ) ) {
     1440                the_header_video_tag();
     1441        } elseif ( ! empty( $image ) ) {
     1442                the_header_image_tag();
     1443        }
     1444}
     1445
     1446/**
    13141447 * Retrieve background image for custom background.
    13151448 *
    13161449 * @since 3.0.0
     
    16231756                                'wp-head-callback' => '',
    16241757                                'admin-head-callback' => '',
    16251758                                'admin-preview-callback' => '',
     1759                                'video' => false,
    16261760                        );
    16271761
    16281762                        $jit = isset( $args[0]['__jit'] );
     
    20822216                return;
    20832217        }
    20842218
    2085         require_once ABSPATH . WPINC . '/class-wp-customize-manager.php'; 
     2219        require_once ABSPATH . WPINC . '/class-wp-customize-manager.php';
    20862220        $GLOBALS['wp_customize'] = new WP_Customize_Manager();
    20872221}
    20882222