[wp-trac] [WordPress Trac] #44923: Filter .children class on nested comments list
WordPress Trac
noreply at wordpress.org
Sat Nov 1 06:28:05 UTC 2025
#44923: Filter .children class on nested comments list
------------------------------------+------------------------------
Reporter: greenshady | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Comments | Version:
Severity: normal | Resolution:
Keywords: has-patch dev-feedback | Focuses: css
------------------------------------+------------------------------
Comment (by dmsnell):
This comment doesn’t speak to the value or tradeoffs involve in creating
this new filter, but I can propose one suggestion to avoid further HTML
escaping issues, and that is to create the opening tag using the Tag
Processor.
{{{#!php
<?php
if ( 'div' === $args['style'] ) {
return;
}
$class_names = apply_filters( 'comment_list_sublist_class', $classes,
$args, $depth );
$html = 'ol' === $args['style'] ? '<ol>' : '<ul>';
if ( ! $class_names ) {
return $html;
}
$processor = new WP_HTML_Tag_Processor( $html );
$processor->next_token();
foreach ( $class_names as $class_name ) {
$processor->add_class( $class_name );
}
return $processor->get_updated_html();
}}}
This can also work, of course, if the filter output is a list of strings,
but the array form is convenient and avoids syntax particulars about
separating CSS class names (something explored in
[https://github.com/WordPress/wordpress-develop/pull/10043 wordpress
/wordpress-develop#10043] and in #63694)
--
Ticket URL: <https://core.trac.wordpress.org/ticket/44923#comment:10>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list