Make WordPress Core

#27780 closed defect (bug) (fixed)

Widget Customizer: Before and after widget check!

Reported by: jetonr Owned by: nacin
Milestone: 3.9 Priority: normal
Severity: minor Version: 3.9
Component: Customize Keywords: has-patch
Focuses: Cc:


Do a check for before and after if they are set because themes with registered sidebars where before_widget and after_widget is empty "" causes
Uncaught TypeError: Cannot read property 'replace' of undefined from

Attachments (1)

27780.patch (817 bytes) - added by ocean90 20 months ago.

Download all attachments as: .zip

Change History (11)

#1 @SergeyBiryukov
20 months ago

  • Milestone changed from Awaiting Review to 3.9
  • Version set to trunk

#2 @westonruter
20 months ago

@jetonr: How are you able to have a registered sidebar without a before_widget and after_widget provided? The register_sidebar() function provides defaults for these if you do not supply them. How are you registering your sidebars?

#3 @SergeyBiryukov
20 months ago

Could not reproduce neither by setting before_widget and after_widget to an empty string, nor by omitting them completely.

I was, however, able to get a similar error by setting them to false. Although it's not a valid value, I'm wondering if there are themes that do the same. A search through a copy of the repository did not produce any results.

#4 @jetonr
20 months ago

Hi @westonruter and @SergeyBiryukov this is the code that registers the sidebar and I it is registered with 'widgets_init' hook!

        'name' 		=> 'Home Widget Area',
	'id' 		=> 'home_page',
        'description'   => 'Add Multiple Home Widgets to this Area',
        'before_title'  => '',
        'after_title'   => '',
        'before_widget' => '',
        'after_widget'  => ''
Last edited 20 months ago by jetonr (previous) (diff)

#5 @ocean90
20 months ago

  • Keywords needs-patch added

Confirmed, happens only if all 4 args are empty.

20 months ago

#6 follow-up: @ocean90
20 months ago

  • Component changed from Widgets to Appearance
  • Keywords has-patch added; needs-patch removed
  • Severity changed from normal to minor

27780.patch just ignores such widgets for the highlighting. Another idea is to add a dummy wrapper around the widget, but that could break themes.

#7 @nacin
20 months ago

I like that approach. Can I get a confirmation?

#8 @jetonr
20 months ago

@nacin I tested the patch from @ocean90 with my theme and the error is gone. Widget Customizer works good even if all 4 args are empty!

Last edited 20 months ago by jetonr (previous) (diff)

#9 in reply to: ↑ 6 @westonruter
20 months ago

Replying to ocean90:

27780.patch just ignores such widgets for the highlighting. Another idea is to add a dummy wrapper around the widget, but that could break themes.

Yes, this is a good approach. I had thought the problem was with the first replace not the second one, so I was considering something like:

( sidebar.before_widget || '' ).replace( '%1$s', '' ).replace( '%2$s', '' )

But it seems clear that the issue isn't that sidebar.before_widget is not defined, but rather that the class attribute is undefined/missing on the emptyWidget widget template (since there is no container element). So, good on you ocean90.

#10 @nacin
20 months ago

  • Owner set to nacin
  • Resolution set to fixed
  • Status changed from new to closed

In 28100:

Customizer: Account for a sidebar with no container to which classes can be added.

props ocean90.
fixes #27780.

Note: See TracTickets for help on using tickets.