Opened 11 years ago
Closed 11 years ago
#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: |
Description
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
customize-preview-widgets.min.js?ver=3.9-RC1:1
Attachments (1)
Change History (11)
#3
@
11 years 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
@
11 years ago
Hi @westonruter and @SergeyBiryukov this is the code that registers the sidebar and I it is registered with 'widgets_init' hook!
register_sidebar(array( 'name' => 'Home Widget Area', 'id' => 'home_page', 'description' => 'Add Multiple Home Widgets to this Area', 'before_title' => '', 'after_title' => '', 'before_widget' => '', 'after_widget' => '' ));
#6
follow-up:
↓ 9
@
11 years 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.
#8
@
11 years 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!
#9
in reply to:
↑ 6
@
11 years 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.
@jetonr: How are you able to have a registered sidebar without a
before_widget
andafter_widget
provided? Theregister_sidebar()
function provides defaults for these if you do not supply them. How are you registering your sidebars?