Changeset 59987
- Timestamp:
- 03/16/2025 06:49:39 PM (5 weeks ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/media.php
r59955 r59987 3346 3346 * 3347 3347 * @since 3.6.0 3348 * @since 6.8.0 Added the 'muted' attribute. 3348 3349 * 3349 3350 * @param array $attr { … … 3353 3354 * @type string $loop The 'loop' attribute for the `<audio>` element. Default empty. 3354 3355 * @type string $autoplay The 'autoplay' attribute for the `<audio>` element. Default empty. 3356 * @type string $muted The 'muted' attribute for the `<audio>` element. Default 'false'. 3355 3357 * @type string $preload The 'preload' attribute for the `<audio>` element. Default 'none'. 3356 3358 * @type string $class The 'class' attribute for the `<audio>` element. Default 'wp-audio-shortcode'. … … 3391 3393 'loop' => '', 3392 3394 'autoplay' => '', 3395 'muted' => 'false', 3393 3396 'preload' => 'none', 3394 3397 'class' => 'wp-audio-shortcode', … … 3470 3473 'loop' => wp_validate_boolean( $atts['loop'] ), 3471 3474 'autoplay' => wp_validate_boolean( $atts['autoplay'] ), 3475 'muted' => wp_validate_boolean( $atts['muted'] ), 3472 3476 'preload' => $atts['preload'], 3473 3477 'style' => $atts['style'], … … 3475 3479 3476 3480 // These ones should just be omitted altogether if they are blank. 3477 foreach ( array( 'loop', 'autoplay', 'preload' ) as $a ) {3481 foreach ( array( 'loop', 'autoplay', 'preload', 'muted' ) as $a ) { 3478 3482 if ( empty( $html_atts[ $a ] ) ) { 3479 3483 unset( $html_atts[ $a ] ); … … 3483 3487 $attr_strings = array(); 3484 3488 3485 foreach ( $html_atts as $k => $v ) { 3486 $attr_strings[] = $k . '="' . esc_attr( $v ) . '"'; 3489 foreach ( $html_atts as $attribute_name => $attribute_value ) { 3490 if ( in_array( $attribute_name, array( 'loop', 'autoplay', 'muted' ), true ) && true === $attribute_value ) { 3491 // Add boolean attributes without a value. 3492 $attr_strings[] = esc_attr( $attribute_name ); 3493 } elseif ( 'preload' === $attribute_name && ! empty( $attribute_value ) ) { 3494 // Handle the preload attribute with specific allowed values. 3495 $allowed_preload_values = array( 'none', 'metadata', 'auto' ); 3496 if ( in_array( $attribute_value, $allowed_preload_values, true ) ) { 3497 $attr_strings[] = sprintf( '%s="%s"', esc_attr( $attribute_name ), esc_attr( $attribute_value ) ); 3498 } 3499 } else { 3500 // For other attributes, include the value. 3501 $attr_strings[] = sprintf( '%s="%s"', esc_attr( $attribute_name ), esc_attr( $attribute_value ) ); 3502 } 3487 3503 } 3488 3504 -
trunk/tests/phpunit/tests/media.php
r59954 r59987 942 942 $this->assertStringNotContainsString( 'loop', $actual ); 943 943 $this->assertStringNotContainsString( 'autoplay', $actual ); 944 $this->assertStringNotContainsString( 'muted', $actual ); 944 945 $this->assertStringContainsString( 'preload="none"', $actual ); 945 946 $this->assertStringContainsString( 'class="wp-audio-shortcode"', $actual ); … … 951 952 'loop' => true, 952 953 'autoplay' => true, 953 'preload' => true, 954 'muted' => true, 955 'preload' => 'none', 954 956 'class' => 'foobar', 955 957 'style' => 'padding:0;', … … 958 960 959 961 $this->assertStringContainsString( 'src="https://example.com/foo.mp3', $actual ); 960 $this->assertStringContainsString( 'loop="1"', $actual ); 961 $this->assertStringContainsString( 'autoplay="1"', $actual ); 962 $this->assertStringContainsString( 'preload="1"', $actual ); 962 $this->assertStringContainsString( 'loop', $actual ); 963 $this->assertStringContainsString( 'autoplay', $actual ); 964 $this->assertStringContainsString( 'muted', $actual ); 965 $this->assertStringContainsString( 'preload="none"', $actual ); 963 966 $this->assertStringContainsString( 'class="foobar"', $actual ); 964 967 $this->assertStringContainsString( 'style="padding:0;"', $actual ); -
trunk/tests/phpunit/tests/widgets/wpWidgetMediaAudio.php
r52248 r59987 273 273 // Custom attributes. 274 274 $this->assertStringContainsString( 'preload="auto"', $output ); 275 $this->assertStringContainsString( 'loop ="1"', $output );275 $this->assertStringContainsString( 'loop', $output ); 276 276 } 277 277
Note: See TracChangeset
for help on using the changeset viewer.