Opened 9 years ago
Closed 8 years ago
#39184 closed defect (bug) (invalid)
Fatal error in child-theme customizer partials
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.7 |
Component: | Customize | Keywords: | reporter-feedback |
Focuses: | Cc: |
Description
When calling wp_customize::selective_refresh::add_partial without render_callback attribute, like this:
<?php $wp_customize->selective_refresh->add_partial( 'setting_name', array( 'selector' => '#object-id', ) );
No error is return, everything works well.
But, when a child theme is created, the customizer crashes with error:
Fatal error: Cannot unset string offsets in [...]/wp-includes/class-wp-customize-widgets.php on line 1077
Simply adding a dummy renderer as:
<?php $wp_customize->selective_refresh->add_partial( 'setting_name', array( 'selector' => '#object-id', 'render_callback' => 'return_true', ) );
make it working every where.
Suggestions:
- Making the render_callback attribute mandatory
- Dealing with a default callback in child themes
Change History (4)
#2
@
9 years ago
- Keywords reporter-feedback added; needs-patch removed
@bastho I cannot reproduce the issue here. Note in your example also you have return_true
as the render_callback
but this is not defined and would cause a fatal error. I think you're looking for __return_true
.
Here is a complete example showing a child theme of Twenty Seventeen that has two new partials for the title and tagline, the first lacks a render_callback
while the second has it: https://gist.github.com/westonruter/cc0f17b18774c4d732778a27aeff232d
Please fork the child theme in that gist to bring it to a point where it exhibits the bug.
When I change the site title, the Ajax response returns with false
as the rendered partial which is exactly as expected.
Also, the render_callback
needn't be mandated because it can be supplied via the customize_partial_render
filter or via overriding WP_Customize_Partial::render_callback()
in a subclass.
I think
render_callback
should probably be required, at least based on the current construction of partials. Not sure whether returning true there would work well, though. I never noticed that this was broken in child themes until recently.It's hard to say what a default callback would look like. I was noticing a similar issue in child themes though.