Make WordPress Core

Opened 4 years ago

Last modified 4 years ago

#49588 new feature request

Cannot remove <div class="textwidget custom-html-widget">

Reported by: jasom's profile jasom Owned by:
Milestone: Awaiting Review Priority: normal
Severity: minor Version:
Component: Widgets Keywords: has-patch needs-testing needs-unit-tests
Focuses: Cc:


I cannot remove wrapping class in html widget:

<div class="textwidget custom-html-widget">

It is defined here:

I think it is job for some apply_filters.

Do we really need another <div> wrap? There can be <div> wrap added by register_sidebar or using widget_text filter

Attachments (1)

49588.patch (2.3 KB) - added by sabernhardt 4 years ago.

Download all attachments as: .zip

Change History (4)

4 years ago

#1 @sabernhardt
4 years ago

  • Keywords has-patch needs-testing needs-unit-tests added

@jasom Thanks for the report!

Yes, that div is added for any Custom HTML widget, after the widget_custom_html_content filter.

Changesets [41115] and [41116] added classes to the HTML widget, but in different ways. I think the two would have been better as one change, without the extra div, to allow for empty before_widget and after_widget values:

$args['before_widget'] = preg_replace( '/(?<=\sclass=["\'])/', 'widget_text textwidget custom-html-widget ', $args['before_widget'] );

Adding a filter on the $args variable (similar to wp_nav_menu_args) could allow themes and plugins to set the before_widget and after_widget values for all Custom HTML widgets.

The patch here moves the div's classes into the replace function, and that function also uses the limit proposed in ticket:42998. The widget's unit test is updated (please check that), and the new filter probably should have unit tests as well (not yet included).

#2 @jasom
4 years ago

I have read your reactions on this topic and my question: Is any other action expected from my side?

Note: This is my first WP issue report.

#3 @sabernhardt
4 years ago

@jasom Good question!

Your report should be enough, assuming I correctly recognized the issue from the description. Of course, if you want to continue with the discussion or other aspects of the topic as the ticket progresses, you are very welcome :)

(I'm still rather new to WordPress Trac, too. This would be the first time I've helped create a filter, and the first time I've even edited a unit test.)

Note: See TracTickets for help on using tickets.