Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#46377 closed defect (bug) (invalid)

Can't remove Customizer sections whose ID contains a hyphen.

Reported by: jeremybubbleup's profile jeremybubbleup Owned by: williampatton's profile williampatton
Milestone: Priority: normal
Severity: normal Version: 5.1
Component: Customize Keywords:
Focuses: Cc:

Description

On the $wp_customize object, passed via the 'customize_register' action, the get_section, get_panel, add_section, and add_panel functions allow strings that contain either hyphens, "-", or underscores, "_". However, when using the remove_section function, sections whose ID contains hyphens are not properly removed, and instead the entire Customizer is empty (no sections) and thus broken. No PHP errors or warnings are thrown in my case, and I can reliably reproduce the error and contrast it with sections added and removed in the exact same way but with IDs containing underscores instead of hyphens. Calling remove_section on a non-existent section, even one that contains hyphens, like 'bogus-fogus', does not reproduce the break; It only seems to happen when trying to remove sections which actually exist.

Change History (6)

#1 @williampatton
6 years ago

  • Severity changed from major to normal

Hey @jeremybubbleup,

Welcome to Trac! Could you share some code that you use to trigger this issue.

On my test install I am unable to recreate this using this code:

<?php
$wp_customize->add_section(
        'test-section',
        array(
                'title' => 'Test Section',
        )
);
$wp_customize->remove_section( 'test-section' );

The section is not there with this code, but if I comment out the remove_section call then the section appears in the customizer.

#2 @jeremybubbleup
6 years ago

Parent theme has this:

function fup20_customize_register($wp_customize) {	
	...
	$wp_customize->add_section('fup20-header', array(
		'title' => __('Header', 'fup20'),
	));	
	$wp_customize->add_setting(...);
	$wp_customize->add_control(...'section' => 'fup20-header'...);
	...
	$wp_customize->get_section('fup20-header')->priority = 60;
}
add_action('customize_register', 'fup20_customize_register');

and the child theme wants to remove that section:

function child_theme_customizer( $wp_customize ) {
	$wp_customize->remove_section('fup20-header');
}
add_action('customize_register', 'cci_lex_customizer', 100);

#3 @jeremybubbleup
6 years ago

I also have a script, enqueued inside customize_controls_enqueue_scripts, which uses wp.customize.bind in order to show and hide some settings conditionally. I will run some tests with dequeuing that script.

#4 @jeremybubbleup
6 years ago

After dequeuing the script, I was able to remove the section without the Customizer breaking. It seems that when the script went to bind settings, they weren't there (since the section was removed) and the JS failure caused the Customizer sections to disappear - I didn't dig deeper into the details of its rendering.

There is no apparent relationship to the ID having hyphens, as I originally thought. As it turns out, all of the sections with hyphens in their IDs had bound settings in the JS, and the sections without hyphens happened to not have bound settings. That coincidence led me down the wrong path originally.

#5 @williampatton
6 years ago

  • Owner set to williampatton
  • Status changed from new to accepted

Glad you were able to resolve the issue, any other problems you see that may be bugs feel free to open more tickets :)

#6 @williampatton
6 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from accepted to closed
Note: See TracTickets for help on using tickets.