[wp-trac] [WordPress Trac] #60178: wp_video_shortcode() outputs invalid HTML
WordPress Trac
noreply at wordpress.org
Wed Jan 3 17:33:33 UTC 2024
#60178: wp_video_shortcode() outputs invalid HTML
---------------------------+------------------------------
Reporter: jongycastillo | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Media | Version:
Severity: normal | Resolution:
Keywords: needs-patch | Focuses:
---------------------------+------------------------------
Changes (by sabernhardt):
* keywords: => needs-patch
* version: 6.4.2 =>
* component: Shortcodes => Media
Comment:
The attribute values were "1" with WordPress 5.0 and possibly since 4.0
(r30185). Also, the
[https://core.trac.wordpress.org/browser/trunk/tests/phpunit/tests/media.php?rev=57019&marks=1072-1075#L1070
unit tests] have expected that since r36240.
The handbook still says to [https://developer.wordpress.org/coding-
standards/wordpress-coding-standards/html/#quotes use quotes for attribute
values], though the [https://core.trac.wordpress.org/browser/trunk/src/wp-
includes/comment-template.php?rev=56687&marks=2500-2502#L2500 comment
form] can print its attributes without values when the theme declares
support.
To pass validation, the shortcode's attributes simply could have values
that match the attribute:
{{{
foreach ( $html_atts as $k => $v ) {
if ( in_array( $k, array( 'loop', 'autoplay', 'muted' ),
true ) ) {
$attr_strings[] = $k . '="' . esc_attr( $k ) .
'"'; // could be changed to only $k later
} else {
$attr_strings[] = $k . '="' . esc_attr( $v ) .
'"';
}
}
}}}
Or instead of editing the `foreach` loop, the `$html_atts` array could set
the string values (similar to code proposed for the `controls` attribute
on #40590):
{{{
$html_atts = array(
'class' => $atts['class'],
'id' => sprintf( 'video-%d-%d', $post_id, $instance
),
'width' => absint( $atts['width'] ),
'height' => absint( $atts['height'] ),
'poster' => esc_url( $atts['poster'] ),
'loop' => ( wp_validate_boolean( $atts['loop'] ) ) ?
'loop' : '',
'autoplay' => ( wp_validate_boolean( $atts['autoplay'] ) )
? 'autoplay' : '',
'muted' => ( wp_validate_boolean( $atts['muted'] ) ) ?
'muted' : '',
'preload' => $atts['preload'],
);
}}}
Similar edits should be made for the audio shortcode too.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/60178#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list