[wp-trac] [WordPress Trac] #49588: Cannot remove <div class="textwidget custom-html-widget">

WordPress Trac noreply at wordpress.org
Sat Mar 7 18:22:28 UTC 2020


#49588: Cannot remove <div class="textwidget custom-html-widget">
-------------------------------------------------+-------------------------
 Reporter:  jasom                                |       Owner:  (none)
     Type:  feature request                      |      Status:  new
 Priority:  normal                               |   Milestone:  Awaiting
                                                 |  Review
Component:  Widgets                              |     Version:
 Severity:  minor                                |  Resolution:
 Keywords:  has-patch needs-testing needs-unit-  |     Focuses:
  tests                                          |
-------------------------------------------------+-------------------------
Changes (by sabernhardt):

 * keywords:   => has-patch needs-testing needs-unit-tests


Comment:

 @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).

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/49588#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list