[wp-trac] [WordPress Trac] #44610: Update regex used for YouTube videos in class-wp-customize-manager.php::_validate_external_header_video()

WordPress Trac noreply at wordpress.org
Thu Jul 19 19:47:55 UTC 2018


#44610: Update regex used for YouTube videos in class-wp-customize-
manager.php::_validate_external_header_video()
-------------------------------------------------+-------------------------
 Reporter:  jepperask                            |       Owner:  (none)
     Type:  enhancement                          |      Status:  reopened
 Priority:  normal                               |   Milestone:
Component:  Customize                            |     Version:  4.9.7
 Severity:  normal                               |  Resolution:
 Keywords:  needs-testing 2nd-opinion needs-     |     Focuses:
  unit-tests                                     |
-------------------------------------------------+-------------------------
Changes (by jepperask):

 * keywords:   => needs-testing 2nd-opinion needs-unit-tests
 * status:  closed => reopened
 * resolution:  invalid =>


Comment:

 I've done some more digging and made it show the no-cookie version,
 however autoplay does not seem consistant.
 I'm new to this part of Wordpress - can i submit a pull-request for review
 and input from others somewhere?

 My changes are simply updating the regex (PHP) and adding an argument to
 the YT.Player initialization (JS). Resolving the 'host' argument is a bit
 clumsy, so I'd appreciate if someone would take over.

 Otherwise here comes a description of my changes:
 **wp-includes/class-wp-customize-manager.php:5664** - change function to:
 {{{#!php
 <?php
 public function _validate_external_header_video( $validity, $value ) {
         $video = esc_url_raw( $value );
         if ( $video ) {
                 if ( ! preg_match( '#^https?://(?:www\.)?(youtube|youtube-
 nocookie)\.com/(watch|embed|youtu\.be/)#', $video ) ) {
                         $validity->add( 'invalid_url', __( 'Please enter a
 valid YouTube URL.' ) );
                 }
         }
         return $validity;
 }
 }}}


 **wp-includes/theme.php:1402** - change line to:
 {{{#!php
 <?php
 if ( preg_match( '#^https?://(?:www\.)?(youtube|youtube-
 nocookie)\.com/(watch|embed|youtu\.be/)#', $video_url ) ) {
 }}}


 **wp-includes/js/wp-custom-header.js:394** - add "host" argument to
 YT.Player settings dictionary:
 {{{#!php
 <?php
 host: location.protocol + this.settings.videoUrl.indexOf("youtube-
 nocookie") !== -1 ? "//www.youtube-nocookie.com" : "//www.youtube.com",
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/44610#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list