Widgets: Normalize YouTube and Vimeo URLs in `video` shortcode (primarily for Video widget) to work around ME.js 2.22 bug.

Props timmydcrawford, jnylen0, westonruter.
See #32417, #39994.
Fixes #40866.


git-svn-id: https://develop.svn.wordpress.org/trunk@40847 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Weston Ruter 2017-05-26 23:09:42 +00:00
parent 31c9647279
commit 289965b097
2 changed files with 51 additions and 0 deletions

View File

@ -2546,6 +2546,20 @@ function wp_video_shortcode( $attr, $content = '' ) {
wp_enqueue_script( 'wp-mediaelement' );
}
// Mediaelement has issues with some URL formats for Vimeo and YouTube, so
// update the URL to prevent the ME.js player from breaking.
if ( 'mediaelement' === $library ) {
if ( $is_youtube ) {
// Remove `feature` query arg and force SSL - see #40866.
$atts['src'] = remove_query_arg( 'feature', $atts['src'] );
$atts['src'] = set_url_scheme( $atts['src'], 'https' );
} elseif ( $is_vimeo ) {
// Remove all query arguments and force SSL - see #40866.
$parsed_vimeo_url = wp_parse_url( $atts['src'] );
$atts['src'] = 'https://' . $parsed_vimeo_url['host'] . $parsed_vimeo_url['path'];
}
}
/**
* Filters the class attribute for the video shortcode output container.
*

View File

@ -723,6 +723,43 @@ VIDEO;
$this->assertContains( 'class="foobar"', $actual );
}
/**
* @ticket 40866
* @depends test_video_shortcode_body
*/
function test_wp_video_shortcode_youtube_remove_feature() {
$actual = wp_video_shortcode( array(
'src' => 'https://www.youtube.com/watch?v=i_cVJgIz_Cs&feature=youtu.be',
) );
$this->assertNotContains( 'feature=youtu.be', $actual );
}
/**
* @ticket 40866
* @depends test_video_shortcode_body
*/
function test_wp_video_shortcode_youtube_force_ssl() {
$actual = wp_video_shortcode( array(
'src' => 'http://www.youtube.com/watch?v=i_cVJgIz_Cs',
) );
$this->assertContains( 'src="https://www.youtube.com/watch?v=i_cVJgIz_Cs', $actual );
}
/**
* @ticket 40866
* @depends test_video_shortcode_body
*/
function test_wp_video_shortcode_vimeo_force_ssl_remove_query_args() {
$actual = wp_video_shortcode( array(
'src' => 'http://vimeo.com/190372437?blah=meh',
) );
$this->assertContains( 'src="https://vimeo.com/190372437', $actual );
$this->assertNotContains( 'blah=meh', $actual );
}
/**
* Test [video] shortcode processing
*