Skip to content

Commit 1c69513

Browse files
committed
Media: Add muted property for video elements.
This change allows for the muted property to be used in video elements which solves for content that wishes to `autoPlay` when a page is viewed. Adding `muted` to video elements adhears to the requirements browsers have to honor `autoPlay` functionality. Props prokium, peterwilsoncc, costdev, johnbillion, Benouare. Fixes #54788. git-svn-id: https://develop.svn.wordpress.org/trunk@54128 602fd350-edb4-49c9-b593-d223f7449a82
1 parent bb20a18 commit 1c69513

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/wp-includes/media.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3219,6 +3219,7 @@ function wp_get_video_extensions() {
32193219
* @type string $poster The 'poster' attribute for the `<video>` element. Default empty.
32203220
* @type string $loop The 'loop' attribute for the `<video>` element. Default empty.
32213221
* @type string $autoplay The 'autoplay' attribute for the `<video>` element. Default empty.
3222+
* @type string $muted The 'muted' attribute for the `<video>` element. Default false.
32223223
* @type string $preload The 'preload' attribute for the `<video>` element.
32233224
* Default 'metadata'.
32243225
* @type string $class The 'class' attribute for the `<video>` element.
@@ -3263,6 +3264,7 @@ function wp_video_shortcode( $attr, $content = '' ) {
32633264
'poster' => '',
32643265
'loop' => '',
32653266
'autoplay' => '',
3267+
'muted' => 'false',
32663268
'preload' => 'metadata',
32673269
'width' => 640,
32683270
'height' => 360,
@@ -3390,11 +3392,12 @@ function wp_video_shortcode( $attr, $content = '' ) {
33903392
'poster' => esc_url( $atts['poster'] ),
33913393
'loop' => wp_validate_boolean( $atts['loop'] ),
33923394
'autoplay' => wp_validate_boolean( $atts['autoplay'] ),
3395+
'muted' => wp_validate_boolean( $atts['muted'] ),
33933396
'preload' => $atts['preload'],
33943397
);
33953398

33963399
// These ones should just be omitted altogether if they are blank.
3397-
foreach ( array( 'poster', 'loop', 'autoplay', 'preload' ) as $a ) {
3400+
foreach ( array( 'poster', 'loop', 'autoplay', 'preload', 'muted' ) as $a ) {
33983401
if ( empty( $html_atts[ $a ] ) ) {
33993402
unset( $html_atts[ $a ] );
34003403
}

tests/phpunit/tests/media.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,7 @@ public function test_wp_video_shortcode_with_bad_attr() {
10231023

10241024
/**
10251025
* @ticket 35367
1026+
* @ticket 54788
10261027
* @depends test_video_shortcode_body
10271028
*/
10281029
public function test_wp_video_shortcode_attributes() {
@@ -1035,6 +1036,7 @@ public function test_wp_video_shortcode_attributes() {
10351036
$this->assertStringContainsString( 'src="https://example.com/foo.mp4', $actual );
10361037
$this->assertStringNotContainsString( 'loop', $actual );
10371038
$this->assertStringNotContainsString( 'autoplay', $actual );
1039+
$this->assertStringNotContainsString( 'muted', $actual );
10381040
$this->assertStringContainsString( 'preload="metadata"', $actual );
10391041
$this->assertStringContainsString( 'width="640"', $actual );
10401042
$this->assertStringContainsString( 'height="360"', $actual );
@@ -1046,6 +1048,7 @@ public function test_wp_video_shortcode_attributes() {
10461048
'poster' => 'https://example.com/foo.png',
10471049
'loop' => true,
10481050
'autoplay' => true,
1051+
'muted' => true,
10491052
'preload' => true,
10501053
'width' => 123,
10511054
'height' => 456,
@@ -1057,6 +1060,7 @@ public function test_wp_video_shortcode_attributes() {
10571060
$this->assertStringContainsString( 'poster="https://example.com/foo.png', $actual );
10581061
$this->assertStringContainsString( 'loop="1"', $actual );
10591062
$this->assertStringContainsString( 'autoplay="1"', $actual );
1063+
$this->assertStringContainsString( 'muted', $actual );
10601064
$this->assertStringContainsString( 'preload="1"', $actual );
10611065
$this->assertStringContainsString( 'width="123"', $actual );
10621066
$this->assertStringContainsString( 'height="456"', $actual );

0 commit comments

Comments
 (0)