From d3226f60412589fc5beb928ae2998757d6793be2 Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Fri, 9 Jun 2017 19:28:12 +0000 Subject: [PATCH] Media: Restrict appending `loop` parameter to Vimeo URLs specifically and not all external URLs in Video widget (via shortcode). Fixes issue where Video widgets embedding external files fail to get recognized due to the presence of the `loop` param after the video filename, even though it has a recognized extension. Regardless, the `loop` param is only present to fix a Vimeo issue in ME.js 2.x. Props timmydcrawford. Amends [40640]. See #39686, #39994. Fixes #40977. git-svn-id: https://develop.svn.wordpress.org/trunk@40892 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/media.php | 6 ++++- .../widgets/class-wp-widget-media-video.php | 6 +---- tests/phpunit/tests/media.php | 25 +++++++++++++++++++ 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index a7239297ab..76cc0c11c9 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -2556,7 +2556,11 @@ function wp_video_shortcode( $attr, $content = '' ) { } 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']; + $vimeo_src = 'https://' . $parsed_vimeo_url['host'] . $parsed_vimeo_url['path']; + + // Add loop param for mejs bug - see #40977, not needed after #39686. + $loop = $atts['loop'] ? '1' : '0'; + $atts['src'] = add_query_arg( 'loop', $loop, $vimeo_src ); } } diff --git a/src/wp-includes/widgets/class-wp-widget-media-video.php b/src/wp-includes/widgets/class-wp-widget-media-video.php index dd90bfac6b..f05928f636 100644 --- a/src/wp-includes/widgets/class-wp-widget-media-video.php +++ b/src/wp-includes/widgets/class-wp-widget-media-video.php @@ -115,13 +115,9 @@ class WP_Widget_Media_Video extends WP_Widget_Media { $attachment = get_post( $instance['attachment_id'] ); } + $src = $instance['url']; if ( $attachment ) { $src = wp_get_attachment_url( $attachment->ID ); - } else { - - // Manually add the loop query argument. - $loop = $instance['loop'] ? '1' : '0'; - $src = empty( $instance['url'] ) ? $instance['url'] : add_query_arg( 'loop', $loop, $instance['url'] ); } if ( empty( $src ) ) { diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php index 4eccd25fb5..c3e4014a8c 100644 --- a/tests/phpunit/tests/media.php +++ b/tests/phpunit/tests/media.php @@ -760,6 +760,31 @@ VIDEO; $this->assertNotContains( 'blah=meh', $actual ); } + /** + * @ticket 40977 + * @depends test_video_shortcode_body + */ + function test_wp_video_shortcode_vimeo_adds_loop() { + $actual = wp_video_shortcode( array( + 'src' => 'http://vimeo.com/190372437', + ) ); + + $this->assertContains( 'src="https://vimeo.com/190372437?loop=0', $actual ); + } + + /** + * @ticket 40977 + * @depends test_video_shortcode_body + */ + function test_wp_video_shortcode_vimeo_force_adds_loop_true() { + $actual = wp_video_shortcode( array( + 'src' => 'http://vimeo.com/190372437', + 'loop' => true, + ) ); + + $this->assertContains( 'src="https://vimeo.com/190372437?loop=1', $actual ); + } + /** * Test [video] shortcode processing *