[wp-trac] [WordPress Trac] #31920: oEmbed: Support YouTube timestamps as hashes

WordPress Trac noreply at wordpress.org
Tue Apr 7 15:24:27 UTC 2015


#31920: oEmbed: Support YouTube timestamps as hashes
-----------------------------+----------------------------
 Reporter:  danielbachhuber  |      Owner:
     Type:  enhancement      |     Status:  new
 Priority:  normal           |  Milestone:  Future Release
Component:  Embeds           |    Version:
 Severity:  normal           |   Keywords:  needs-patch
  Focuses:                   |
-----------------------------+----------------------------
 YouTube can provide timestamps as a hash, which doesn't get properly
 processed by the oEmbed endpoint:
 `https://www.youtube.com/watch?v=8A6q6eGM_Aw#t=8m30s`

 Converting the hash to a proper query argument produces the expected
 behavior: `https://www.youtube.com/watch?v=8A6q6eGM_Aw&t=8m30s`

 Although it's a pain to maintain compatibility shims, including in core
 would reduce user confusion around oEmbed.

 {{{
 /**
  * Support YouTube timestamp as hash (e.g.
 https://www.youtube.com/watch?v=8A6q6eGM_Aw#t=8m30s)
  * by converting the hash to a query arg
  */
 add_filter( 'oembed_fetch_url', function( $provider, $url, $args ) {
         if ( false === stripos( $provider, 'www.youtube.com/oembed' ) ||
 false === stripos( $url, '#t=' ) ) {
                 return $provider;
         }
         $url = str_replace( '#t=', '&t=', $url );
         $provider = add_query_arg( 'url', rawurlencode( $url ), $provider
 );
         return $provider;
 }, 10, 3 );
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/31920>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list