[wp-trac] [WordPress Trac] #61515: wp_audio_shortcode() outputs invalid HTML
WordPress Trac
noreply at wordpress.org
Thu Jun 27 04:20:13 UTC 2024
#61515: wp_audio_shortcode() outputs invalid HTML
--------------------------+-----------------------------
Reporter: shub07 | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Media | Version:
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
Did an audit of a website and found several invalid HTML for audio tags
that were output with wp_audio_shortcode(). The errors:
Bad value {{{1}}} for attribute loop on element audio
Bad value {{{1}}} for attribute autoplay on element audio
Bad value {{{1}}} for attribute muted on element audio
Based on documentation from Mozilla, all 3 are boolean attributes. Here is
an example of function usage that produced the HTML validation errors:
{{{#!php
<?php
echo wp_audio_shortcode( [
'src' => wp_get_attachment_url(9999),
'class' => 'my-custom-audio',
'poster' => '',
'loop' => 'true',
'autoplay' => 'true',
'muted' => 'true',
'height' => 1080,
'width' => 1920
] );
}}}
This part in {{{wp_audio_shortcode()}}} is the culprit:
{{{#!php
<?php
$attr_strings = array();
foreach ( $html_atts as $k => $v ) {
$attr_strings[] = $k . '="' . esc_attr( $v ) . '"';
}
}}}
Currently, we are using the filter to clean up these attributes like this:
{{{#!php
<?php
foreach ( $html_atts as $k => $v ) {
$attr_strings[] = $k . '="' . esc_attr( $v ) . '"';
if ( in_array( $k, array( 'loop', 'autoplay', 'muted' ),
true ) && true === $v ) {
$attr_strings[] = esc_attr( $k );
} else {
$attr_strings[] = $k . '="' . esc_attr( $v ) .
'"';
}
}
}}}
Similar to: https://core.trac.wordpress.org/ticket/60178
--
Ticket URL: <https://core.trac.wordpress.org/ticket/61515>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list