4

Is there a way to retrieve all the registered customizer sections? I'm building out a custom customizer and don't want other plugin or themes who register custom sections to appear on this page.

I can remove all the default sections, but I can't predict which plugins or themes will register sections.

$wp_customize->remove_section( 'title_tagline' );

removes the default title_tagline section.

I can see all of the registered sections by doing print_r( $wp_customize );. I would just loop over that section and build an array to un-register, but I can't seem to access the array of registered sections due to it being protected.

Is there any other way to retreive registered sections?

2

Have you tried sections method? You can use $wp_customize->sections().

Example:

foreach ($wp_customize->sections() as $section_key => $section_object ) {
  echo $section_key . '<br />';
}
2

After digging around inside of some core files, I was actually able to get this resolved.

The following function will retrieve all registered sections in the customizer and loop over each to un-register them altogether.

This should run before registering any of your own custom sections, as to not remove your custom registered sections.

function eherman_remove_registered_customizer_sections() {
    // retrieve the sections array
    $registered_sections = $wp_customize->sections();
    // loop over and remove each section
    foreach( $registered_sections as $section ) {
       $wp_customize->remove_section( $section->id );
    }   
}

Not bad at all. Hopefully that helps others out as we move closer to a more powerful customizer!

Resources:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.