Ticket #38172: 38172.7.diff
File 38172.7.diff, 26.8 KB (added by , 4 years ago) |
---|
-
src/wp-admin/css/customize-controls.css
583 583 display: block; 584 584 font-style: italic; 585 585 line-height: 18px; 586 margin-top: 0; 586 587 margin-bottom: 5px; 587 588 } 588 589 -
src/wp-content/themes/twentyfourteen/functions.php
409 409 $classes[] = 'group-blog'; 410 410 } 411 411 412 if ( get_header_image() ) {412 if ( get_header_image() || function_exists( 'has_header_video' ) && has_header_video() ) { 413 413 $classes[] = 'header-image'; 414 414 } elseif ( ! in_array( $GLOBALS['pagenow'], array( 'wp-activate.php', 'wp-signup.php' ) ) ) { 415 415 $classes[] = 'masthead-fixed'; -
src/wp-content/themes/twentyfourteen/header.php
32 32 33 33 <body <?php body_class(); ?>> 34 34 <div id="page" class="hfeed site"> 35 <?php if ( get_header_image() ) : ?> 35 <?php if ( function_exists( 'has_header_video' ) && has_header_video() ) : ?> 36 <div id="site-header"> 37 <?php the_header_video_tag(); ?> 38 </div> 39 <?php elseif ( get_header_image() ) : ?> 36 40 <div id="site-header"> 37 41 <a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"> 38 42 <img src="<?php header_image(); ?>" width="<?php echo get_custom_header()->width; ?>" height="<?php echo get_custom_header()->height; ?>" alt="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>"> -
src/wp-content/themes/twentyfourteen/inc/custom-header.php
40 40 'width' => 1260, 41 41 'height' => 240, 42 42 'flex-height' => true, 43 'video' => true, 43 44 'wp-head-callback' => 'twentyfourteen_header_style', 44 45 'admin-head-callback' => 'twentyfourteen_admin_header_style', 45 46 'admin-preview-callback' => 'twentyfourteen_admin_header_image', -
src/wp-content/themes/twentyfourteen/js/functions.js
103 103 104 104 if ( body.is( '.header-image' ) ) { 105 105 toolbarOffset = body.is( '.admin-bar' ) ? $( '#wpadminbar' ).height() : 0; 106 mastheadOffset = $( '# masthead' ).offset().top- toolbarOffset;106 mastheadOffset = $( '#site-header' ).height() - toolbarOffset; 107 107 108 108 _window.on( 'scroll.twentyfourteen', function() { 109 109 if ( _window.scrollTop() > mastheadOffset && mastheadHeight < 49 ) { … … 112 112 body.removeClass( 'masthead-fixed' ); 113 113 } 114 114 } ); 115 116 // Update masthead offset after a selective refresh. 117 if ( 'undefined' !== typeof wp && wp.customize && wp.customize.selectiveRefresh ) { 118 wp.customize.selectiveRefresh.bind( 'partial-content-rendered', function( placement ) { 119 mastheadOffset = $( '#site-header' ).height() - toolbarOffset; 120 } ); 121 } 115 122 } 116 123 } 117 124 -
src/wp-content/themes/twentyfourteen/style.css
88 88 video { 89 89 display: inline-block; 90 90 max-width: 100%; 91 height: auto; 91 92 } 92 93 93 94 html { … … 608 609 max-width: 100%; 609 610 } 610 611 612 #wp-custom-header-video video { 613 margin-bottom: -8px; 614 } 615 611 616 p > embed, 612 617 p > iframe, 613 618 p > object, -
src/wp-content/themes/twentyseventeen/assets/css/ie8.css
37 37 38 38 /* Site Branding */ 39 39 40 .has-header-image .custom-header-image img, 41 .has-header-image .custom-header-image video { 42 left: 0; 43 top: 0; 44 } 45 40 46 .site-title { 41 47 font-weight: bolder; 42 48 } -
src/wp-content/themes/twentyseventeen/components/header/header-image.php
14 14 $header_image = get_header_image(); 15 15 16 16 // Check if Custom Header image has been added. 17 if ( ! empty( $header_image ) ) : ?>17 if ( ! empty( $header_image ) ) : 18 18 19 <div class="custom-header-image" style="background-image: url(<?php echo esc_url( $header_image ); ?>)"></div>20 <?php get_template_part( 'components/header/site', 'branding' );?>19 // If yes, check if we're on the front page 20 if ( twentyseventeen_is_frontpage() ) : ?> 21 21 22 <?php // Output the full custom header - video and/or image fallback. ?> 23 <div class="custom-header-image"> 24 <?php the_custom_header(); ?> 25 </div> 26 <?php get_template_part( 'components/header/site', 'branding' ); ?> 27 28 <?php else : ?> 29 30 <?php // If we're not on the front page, only output the header image. ?> 31 <div class="custom-header-image"> 32 <img src="<?php echo esc_url( $header_image ); ?>"> 33 </div> 34 <?php get_template_part( 'components/header/site', 'branding' ); ?> 35 36 <?php endif; ?> 37 22 38 <?php else : ?> 39 23 40 <?php // Otherwise, show a blank header. ?> 24 41 <div class="custom-header-simple"> 25 42 <?php get_template_part( 'components/header/site', 'branding' ); ?> -
src/wp-content/themes/twentyseventeen/footer.php
14 14 15 15 ?> 16 16 17 </div><!-- #content -->17 </div><!-- #content --> 18 18 19 <footer id="colophon" class="site-footer" role="contentinfo">20 <div class="wrap">21 <?php22 get_template_part( 'components/footer/footer', 'widgets' );19 <footer id="colophon" class="site-footer" role="contentinfo"> 20 <div class="wrap"> 21 <?php 22 get_template_part( 'components/footer/footer', 'widgets' ); 23 23 24 if ( has_nav_menu( 'social' ) ) : ?>25 <nav class="social-navigation" role="navigation" aria-label="<?php _e( 'Footer Social Links Menu', 'twentyseventeen' ); ?>">26 <?php27 wp_nav_menu( array(28 'theme_location' => 'social',29 'menu_class' => 'social-links-menu',30 'depth' => 1,31 'link_before' => '<span class="screen-reader-text">',32 'link_after' => '</span>' . twentyseventeen_get_svg( array( 'icon' => 'chain' ) ),33 ) );34 ?>35 </nav><!-- .social-navigation -->36 <?php endif;24 if ( has_nav_menu( 'social' ) ) : ?> 25 <nav class="social-navigation" role="navigation" aria-label="<?php _e( 'Footer Social Links Menu', 'twentyseventeen' ); ?>"> 26 <?php 27 wp_nav_menu( array( 28 'theme_location' => 'social', 29 'menu_class' => 'social-links-menu', 30 'depth' => 1, 31 'link_before' => '<span class="screen-reader-text">', 32 'link_after' => '</span>' . twentyseventeen_get_svg( array( 'icon' => 'chain' ) ), 33 ) ); 34 ?> 35 </nav><!-- .social-navigation --> 36 <?php endif; 37 37 38 get_template_part( 'components/footer/site', 'info' ); 39 ?> 40 </div><!-- .wrap --> 41 </footer><!-- #colophon --> 38 get_template_part( 'components/footer/site', 'info' ); 39 ?> 40 </div><!-- .wrap --> 41 </footer><!-- #colophon --> 42 </div><!-- .site-content-contain --> 42 43 </div><!-- #page --> 43 44 <?php wp_footer(); ?> 44 45 -
src/wp-content/themes/twentyseventeen/header.php
49 49 endif; 50 50 ?> 51 51 52 <div id="content" class="site-content"> 52 <div class="site-content-contain"> 53 <div id="content" class="site-content"> -
src/wp-content/themes/twentyseventeen/inc/custom-header.php
39 39 'width' => 2000, 40 40 'height' => 1200, 41 41 'flex-height' => true, 42 'video' => true, 42 43 'wp-head-callback' => 'twentyseventeen_header_style', 43 44 ) ) ); 44 45 -
src/wp-content/themes/twentyseventeen/style.css
1287 1287 border-top: 1px solid #eee; 1288 1288 font-size: 16px; 1289 1289 font-size: 1rem; 1290 position: relative; 1290 1291 } 1291 1292 1292 1293 .navigation-top .wrap { … … 1528 1529 1529 1530 .site-branding { 1530 1531 padding: 1em 0; 1532 position: relative; 1531 1533 -webkit-transition: margin-bottom 0.2s; 1532 1534 transition: margin-bottom 0.2s; 1535 z-index: 3; 1533 1536 } 1534 1537 1535 1538 .site-branding a { … … 1622 1625 } 1623 1626 1624 1627 .custom-header-image { 1625 background-position: center center;1626 background-repeat: no-repeat;1627 -webkit-background-size: cover;1628 background-size: cover;1629 1628 bottom: 0; 1630 1629 left: 0; 1630 overflow: hidden; 1631 1631 position: absolute; 1632 1632 right: 0; 1633 1633 top: 0; 1634 width: 100%; 1634 1635 } 1635 1636 1636 1637 .custom-header-image:before { … … 1646 1647 left: 0; 1647 1648 position: absolute; 1648 1649 right: 0; 1650 z-index: 2; 1649 1651 } 1650 1652 1651 .has-header-image:not(.twentyseventeen-front-page):not(.home) .custom-header-image { 1652 background-position: center bottom; 1653 .has-header-image .custom-header-image img, 1654 .has-header-image .custom-header-image video, 1655 .has-header-image .custom-header-image iframe { 1656 position: fixed; 1657 height: auto; 1658 left: 50%; 1659 max-width: 1000%; 1660 min-height: 100%; 1661 min-width: 100%; 1662 min-width: 100vw; /* vw prevents 1px gap on left that 100% has */ 1663 width: auto; 1664 top: 50%; 1665 -ms-transform: translateX(-50%) translateY(-50%); 1666 -moz-transform: translateX(-50%) translateY(-50%); 1667 -webkit-transform: translateX(-50%) translateY(-50%); 1668 transform: translateX(-50%) translateY(-50%); 1653 1669 } 1654 1670 1671 .has-header-image:not(.twentyseventeen-front-page):not(.home) .custom-header-image img { 1672 bottom: 0; 1673 position: absolute; 1674 top: auto; 1675 -ms-transform: translateX(-50%) translateY(0); 1676 -moz-transform: translateX(-50%) translateY(0); 1677 -webkit-transform: translateX(-50%) translateY(0); 1678 transform: translateX(-50%) translateY(0); 1679 } 1680 1655 1681 body:not(.has-header-image) .custom-header-image { 1656 1682 padding: 5% 0; 1657 1683 } … … 1749 1775 ## Regular Content 1750 1776 --------------------------------------------------------------*/ 1751 1777 1778 .site-content-contain { 1779 background-color: #fff; 1780 position: relative; 1781 } 1782 1752 1783 .site-content { 1753 1784 padding: 2.5em 0 0; 1754 1785 } … … 2614 2645 # Media 2615 2646 --------------------------------------------------------------*/ 2616 2647 2617 img { 2648 img, 2649 video { 2618 2650 height: auto; /* Make sure images are scaled correctly. */ 2619 2651 max-width: 100%; /* Adhere to container width. */ 2620 2652 } … … 3258 3290 3259 3291 .has-header-image.twentyseventeen-front-page .custom-header, 3260 3292 .has-header-image.home.blog .custom-header { 3261 display: block;3262 3293 min-height: 0; 3263 3294 } 3264 3295 … … 3267 3298 position: relative; 3268 3299 } 3269 3300 3301 .twentyseventeen-front-page.has-header-image .custom-header-image, 3302 .home.blog.has-header-image .custom-header-image { 3303 height: 0; 3304 position: relative; 3305 } 3306 3270 3307 .has-header-image:not(.twentyseventeen-front-page):not(.home) .custom-header-image { 3271 3308 bottom: 0; 3272 3309 height: auto; … … 3276 3313 top: 0; 3277 3314 } 3278 3315 3279 .twentyseventeen-front-page.has-header-image .custom-header-image,3280 .home.blog.has-header-image .custom-header-image {3281 height: 0;3282 padding-top: 66%;3283 position: relative;3284 }3285 3286 3316 .custom-logo-link { 3287 3317 padding-right: 2em; 3288 3318 } … … 3554 3584 height: 1200px; 3555 3585 height: 100vh; 3556 3586 max-height: 100%; 3557 padding: 10% 0; 3587 overflow: hidden; 3588 /* padding: 10% 0; */ 3558 3589 } 3559 3590 3560 3591 .twentyseventeen-front-page.has-header-image .custom-header-image:before, … … 3901 3932 3902 3933 @media screen and ( min-width: 55em ) { 3903 3934 3904 .twentyseventeen-front-page.has-header-image .custom-header-image,3905 .home.blog.has-header-image .custom-header-image {3906 background-attachment: fixed;3907 }3908 3909 3935 .panel-image { 3910 3936 background-attachment: fixed; 3911 3937 } -
src/wp-includes/class-wp-customize-manager.php
3223 3223 3224 3224 /* Custom Header */ 3225 3225 3226 if ( current_theme_supports( 'custom-header', 'video' ) ) { 3227 $title = __( 'Header Visuals' ); 3228 $description = __( 'If you add a video, the image will be used as a fallback while the video loads.' ); 3229 $width = absint( get_theme_support( 'custom-header', 'width' ) ); 3230 $height = absint( get_theme_support( 'custom-header', 'height' ) ); 3231 if ( $width && $height ) { 3232 /* translators: %s: header size in pixels */ 3233 $control_description = sprintf( __( 'Upload your video in <code>.mp4</code> format and minimize its file size for best results. Your theme recommends dimensions of %s pixels.' ), 3234 sprintf( '<strong>%s × %s</strong>', $width, $height ) 3235 ); 3236 } elseif ( $width ) { 3237 /* translators: %s: header width in pixels */ 3238 $control_description = sprintf( __( 'Upload your video in <code>.mp4</code> format and minimize its file size for best results. Your theme recommends a width of %s pixels.' ), 3239 sprintf( '<strong>%s</strong>', $width ) 3240 ); 3241 } else { 3242 /* translators: %s: header height in pixels */ 3243 $control_description = sprintf( __( 'Upload your video in <code>.mp4</code> format and minimize its file size for best results. Your theme recommends a height of %s pixels.' ), 3244 sprintf( '<strong>%s</strong>', $height ) 3245 ); 3246 } 3247 } else { 3248 $title = __( 'Header Image' ); 3249 $description = ''; 3250 $control_description = ''; 3251 } 3252 3226 3253 $this->add_section( 'header_image', array( 3227 'title' => __( 'Header Image' ), 3254 'title' => $title, 3255 'description' => $description, 3228 3256 'theme_supports' => 'custom-header', 3229 3257 'priority' => 60, 3230 3258 ) ); 3231 3259 3260 $this->add_setting( 'header_video', array( 3261 'theme_supports' => array( 'custom-header', 'video' ), 3262 // 'transport' => 'postMessage', 3263 'sanitize_callback' => 'absint', 3264 'validate_callback' => array( $this, '_validate_header_video' ), 3265 ) ); 3266 3267 $this->add_setting( 'external_header_video', array( 3268 'theme_supports' => array( 'custom-header', 'video' ), 3269 // 'transport' => 'postMessage', 3270 'sanitize_callback' => 'esc_url', 3271 'validate_callback' => array( $this, '_validate_external_header_video' ), 3272 ) ); 3273 3232 3274 $this->add_setting( new WP_Customize_Filter_Setting( $this, 'header_image', array( 3233 3275 'default' => get_theme_support( 'custom-header', 'default-image' ), 3234 3276 'theme_supports' => 'custom-header', … … 3239 3281 'theme_supports' => 'custom-header', 3240 3282 ) ) ); 3241 3283 3284 $this->add_control( new WP_Customize_Media_Control( $this, 'header_video', array( 3285 'theme_supports' => array( 'custom-header', 'video' ), 3286 'label' => __( 'Header Video' ), 3287 'description' => $control_description, 3288 'section' => 'header_image', 3289 'mime_type' => 'video', 3290 ) ) ); 3291 3292 $this->add_control( 'external_header_video', array( 3293 'theme_supports' => array( 'custom-header', 'video' ), 3294 'type' => 'url', 3295 'description' => __( 'Or, enter a YouTube or Vimeo URL:' ), 3296 'section' => 'header_image', 3297 ) ); 3298 3242 3299 $this->add_control( new WP_Customize_Header_Image_Control( $this ) ); 3243 3300 3301 $this->selective_refresh->add_partial( 'header_video', array( 3302 'selector' => '#wp-custom-header', 3303 'render_callback' => 'the_custom_header', 3304 'settings' => array( 'header_video', 'external_header_video', 'header_image' ), // The image is used as a video fallback here. 3305 'container_inclusive' => true, 3306 ) ); 3307 3244 3308 /* Custom Background */ 3245 3309 3246 3310 $this->add_section( 'background_image', array( … … 3595 3659 } 3596 3660 3597 3661 /** 3662 * Callback for validating the header_video value. 3663 * 3664 * Ensures that the selected video is less than 8MB and provides an error message. 3665 * 3666 * @since 4.7.0 3667 * 3668 * @param WP_Error $validity 3669 * @param mixed $value 3670 * @return mixed 3671 */ 3672 public function _validate_header_video( $validity, $value ) { 3673 $video = get_attached_file( absint( $value ) ); 3674 if ( $video ) { 3675 $size = filesize( $video ); 3676 if ( 4 < $size / pow( 1024, 2 ) ) { // Check whether the size is larger than 4MB. 3677 $validity->add( 'size_too_large', __( 'This video file is too large to use as a header video. Try a shorter video or optimize the compression settings and re-upload. Or, upload your video to YouTube and link it with the option below.' ) ); 3678 } 3679 } 3680 return $validity; 3681 } 3682 3683 /** 3684 * Callback for validating the external_header_video value. 3685 * 3686 * Ensures that the provided URL is for YouTube or Vimeo. 3687 * 3688 * @since 4.7.0 3689 * 3690 * @param WP_Error $validity 3691 * @param mixed $value 3692 * @return mixed 3693 */ 3694 public function _validate_external_header_video( $validity, $value ) { 3695 $video = esc_url( $value ); 3696 if ( $video ) { 3697 if ( ! preg_match( '#^https?://(?:www\.)?(?:youtube\.com/watch|youtu\.be/)#', $video ) 3698 && ! preg_match( '#^https?://(.+\.)?vimeo\.com/.*#', $video ) ) { 3699 $validity->add( 'invalid_url', __( 'Please enter a valid YouTube or Vimeo video URL.' ) ); 3700 } 3701 } 3702 return $validity; 3703 } 3704 3705 /** 3598 3706 * Callback for rendering the custom logo, used in the custom_logo partial. 3599 3707 * 3600 3708 * This method exists because the partial object and context data are passed -
src/wp-includes/customize/class-wp-customize-header-image-control.php
166 166 $height = absint( get_theme_support( 'custom-header', 'height' ) ); 167 167 ?> 168 168 <div class="customize-control-content"> 169 <p class="customizer-section-intro"> 169 <?php if ( current_theme_supports( 'custom-header', 'video' ) ) { 170 echo '<span class="customize-control-title">' . $this->label . '</span>'; 171 } ?> 172 <p class="customizer-section-intro customize-control-description"> 170 173 <?php 171 if ( $width && $height ) { 174 if ( current_theme_supports( 'custom-header', 'video' ) ) { 175 _e( 'While you can crop images to your liking after clicking <strong>Add new image</strong>, we recommend matching the size of your video.' ); 176 } elseif ( $width && $height ) { 172 177 /* translators: %s: header size in pixels */ 173 178 printf( __( 'While you can crop images to your liking after clicking <strong>Add new image</strong>, your theme recommends a header size of %s pixels.' ), 174 179 sprintf( '<strong>%s × %s</strong>', $width, $height ) -
src/wp-includes/js/wp-custom-header.js
1 (function( window, settings ) { 2 //settings.videoUrl = 'https://www.youtube.com/watch?v=LSmgKRx5pBo'; 3 //settings.mimeType = 'video/x-youtube'; 4 5 function wpCustomHeader() { 6 var handlers = { 7 native: { 8 test: function( settings ) { 9 var video = document.createElement( 'video' ); 10 return video.canPlayType( settings.mimeType ); 11 }, 12 callback: nativeHandler 13 }, 14 youtube: { 15 test: function( settings ) { 16 return 'video/x-youtube' === settings.mimeType; 17 }, 18 callback: youtubeHandler 19 } 20 }; 21 22 function initialize() { 23 settings.container = document.getElementById( 'wp-custom-header' ); 24 25 if ( supportsVideo() ) { 26 for ( id in handlers ) { 27 var handler = handlers[ id ]; 28 29 if ( handlers.hasOwnProperty( id ) && handler.test( settings ) ) { 30 handler.callback( settings ); 31 break; 32 } 33 } 34 } 35 } 36 37 function supportsVideo() { 38 // @todo Check screen width, user agent, other environment variables, etc. 39 return true; 40 } 41 42 return { 43 handlers: handlers, 44 initialize: initialize, 45 supportsVideo: supportsVideo 46 } 47 } 48 49 function nativeHandler( settings ) { 50 var video = document.createElement( 'video' ); 51 52 video.id = 'wp-custom-header-video'; 53 video.autoplay = true; 54 video.loop = true; 55 video.muted = true; 56 video.poster = settings.posterUrl; 57 video.width = settings.width; 58 video.height = settings.height; 59 60 video.addEventListener( 'canplay', function() { 61 settings.container.innerHTML = ''; 62 settings.container.appendChild( video ); 63 }); 64 65 video.addEventListener( 'click', function() { 66 if ( video.paused ) { 67 video.play(); 68 } else { 69 video.pause(); 70 } 71 }); 72 73 video.src = settings.videoUrl; 74 video.load(); 75 } 76 77 function youtubeHandler( settings ) { 78 // @link http://stackoverflow.com/a/27728417 79 var VIDEO_ID_REGEX = /^.*(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/)|(?:(?:watch)?\?v(?:i)?=|\&v(?:i)?=))([^#\&\?]*).*/, 80 videoId = settings.videoUrl.match( VIDEO_ID_REGEX )[1]; 81 82 function loadVideo() { 83 YT.ready(function() { 84 var video = document.createElement( 'div' ); 85 video.id = 'wp-custom-header-video'; 86 settings.container.innerHTML = ''; 87 settings.container.appendChild( video ); 88 89 new YT.Player( video, { 90 height: settings.height, 91 width: settings.width, 92 videoId: videoId, 93 events: { 94 onReady: function( e ) { 95 e.target.mute(); 96 } 97 }, 98 playerVars: { 99 autoplay: 1, 100 controls: 0, 101 disablekb: 1, 102 fs: 0, 103 iv_load_policy: 3, 104 loop: 1, 105 modestbranding: 1, 106 //origin: '', 107 playsinline: 1, 108 rel: 0, 109 showinfo: 0 110 } 111 }); 112 }); 113 } 114 115 if ( 'YT' in window ) { 116 loadVideo(); 117 } else { 118 tag = document.createElement( 'script' ); 119 tag.src = 'https://www.youtube.com/player_api'; 120 tag.onload = function () { loadVideo(); }; 121 document.getElementsByTagName( 'head' )[0].appendChild( tag ); 122 } 123 } 124 125 window.wp = window.wp || {}; 126 window.wp.customHeader = new wpCustomHeader(); 127 document.addEventListener( 'DOMContentLoaded', window.wp.customHeader.initialize, false ); 128 129 })( window, window._wpCustomHeaderSettings || {} ); -
src/wp-includes/script-loader.php
479 479 $scripts->add( 'customize-nav-menus', "/wp-admin/js/customize-nav-menus$suffix.js", array( 'jquery', 'wp-backbone', 'customize-controls', 'accordion', 'nav-menu' ), false, 1 ); 480 480 $scripts->add( 'customize-preview-nav-menus', "/wp-includes/js/customize-preview-nav-menus$suffix.js", array( 'jquery', 'wp-util', 'customize-preview', 'customize-selective-refresh' ), false, 1 ); 481 481 482 $scripts->add( 'wp-custom-header', "/wp-includes/js/wp-custom-header$suffix.js", array(), false, 1 ); 483 482 484 $scripts->add( 'accordion', "/wp-admin/js/accordion$suffix.js", array( 'jquery' ), false, 1 ); 483 485 484 486 $scripts->add( 'shortcode', "/wp-includes/js/shortcode$suffix.js", array( 'underscore' ), false, 1 ); -
src/wp-includes/theme.php
1264 1264 'thumbnail_url' => '', 1265 1265 'width' => get_theme_support( 'custom-header', 'width' ), 1266 1266 'height' => get_theme_support( 'custom-header', 'height' ), 1267 'video' => get_theme_support( 'custom-header', 'video' ), 1267 1268 ); 1268 1269 return (object) wp_parse_args( $data, $default ); 1269 1270 } … … 1311 1312 } 1312 1313 1313 1314 /** 1315 * Check whether a header video is set or not. 1316 * 1317 * @since 4.7.0 1318 * 1319 * @see get_header_video_url() 1320 * 1321 * @return bool Whether a header video is set or not. 1322 */ 1323 function has_header_video() { 1324 return (bool) get_header_video_url(); 1325 } 1326 1327 /* Retrieve header video URL for custom header. 1328 * 1329 * Uses a local video if present, or falls back to an external video. Returns false if there is no video. 1330 * 1331 * @since 4.7.0 1332 * 1333 * @return string|false 1334 */ 1335 function get_header_video_url() { 1336 $id = absint( get_theme_mod( 'header_video' ) ); 1337 $url = esc_url( get_theme_mod( 'external_header_video' ) ); 1338 1339 if ( ! $id && ! $url ) { 1340 return false; 1341 } 1342 1343 if ( $id ) { 1344 // Get the file URL from the attachment ID. 1345 $url = wp_get_attachment_url( $id ); 1346 } 1347 1348 return esc_url_raw( set_url_scheme( $url ) ); 1349 } 1350 1351 /** 1352 * Display header video URL. 1353 * 1354 * @since 4.7.0 1355 */ 1356 function the_header_video_url() { 1357 $video = get_header_video_url(); 1358 if ( $video ) { 1359 echo esc_url( $video ); 1360 } 1361 } 1362 1363 /** 1364 * Display the video and image markup for a custom header. 1365 * 1366 * @since 4.7.0 1367 */ 1368 function the_custom_header() { 1369 $header = get_custom_header(); 1370 1371 printf( 1372 '<div id="wp-custom-header">%s</div>', 1373 get_header_image_tag() 1374 ); 1375 1376 if ( isset( $header->video ) && $header->video && has_header_video() ) { 1377 $video_url = get_header_video_url(); 1378 $video_type = wp_check_filetype( $video_url, wp_get_mime_types() ); 1379 1380 $settings = array( 1381 'mimeType' => '', 1382 'posterUrl' => get_header_image(), 1383 'videoUrl' => $video_url, 1384 'width' => absint( $header->width ), 1385 'height' => absint( $header->height ), 1386 ); 1387 1388 if ( preg_match( '#^https?://(?:www\.)?(?:youtube\.com/watch|youtu\.be/)#', $video_url ) ) { 1389 $settings['mimeType'] = 'video/x-youtube'; 1390 } elseif ( preg_match( '#^https?://(.+\.)?vimeo\.com/.*#', $video_url ) ) { 1391 $settings['mimeType'] = 'video/x-vimeo'; 1392 } elseif ( ! empty( $video_type['type'] ) ) { 1393 $settings['mimeType'] = $video_type['type']; 1394 } 1395 1396 wp_enqueue_script( 'wp-custom-header' ); 1397 wp_localize_script( 'wp-custom-header', '_wpCustomHeaderSettings', $settings ); 1398 } 1399 } 1400 1401 /** 1314 1402 * Retrieve background image for custom background. 1315 1403 * 1316 1404 * @since 3.0.0 … … 1706 1794 'wp-head-callback' => '', 1707 1795 'admin-head-callback' => '', 1708 1796 'admin-preview-callback' => '', 1797 'video' => false, 1709 1798 ); 1710 1799 1711 1800 $jit = isset( $args[0]['__jit'] );