WordPress.org

Make WordPress Core

Opened 6 months ago

Last modified 6 months ago

#39184 new defect (bug)

Fatal error in child-theme customizer partials

Reported by: bastho Owned by:
Milestone: Awaiting Review 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:

  1. Making the render_callback attribute mandatory
  2. Dealing with a default callback in child themes

Change History (3)

#1 @celloexpressions
6 months ago

  • Keywords needs-patch added

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.

#2 @westonruter
6 months 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.

This ticket was mentioned in Slack in #core-customize by celloexpressions. View the logs.


6 months ago

Note: See TracTickets for help on using tickets.