1

As mentioned in my question my wigets and nav_menus are components, why not panels? What is the difference between a component and panel/section(I understand both are containers for controls)

Is it because both don't have controls and has different functionality from normal form controls?

I understand that I can create custom control, Can I also create custom component?

1
  • See my answer here for some info on how menus are set up inside the customiser. Commented Jan 22, 2018 at 12:18

1 Answer 1

0

A component in the Customizer is just a way for core to allow for plugins to determine whether or not the functionality is loaded. Functionality in the Customizer involves much more than just adding a panel. It also involves logic for previewing, enqueuing scripts, and so on. So there are components for widgets and nav menus in order to provide a way for a plugin to turn off all of a component's functionality, without having to know all of the hooks that a component integrates with. Read more on #33552 for why the filter was introduced. Both widgets and nav menus have panels, but they also have classes (WP_Customize_Widgets and WP_Customize_Nav_Menus respectively) which manage the registration of the panels and all of the other things the functionalities need. You can certainly create your own custom classes to organize your Customizer code in the same way. The Customize Posts plugin does this by hooking into the same filter to give plugins the opportunity to turn the functionality of if needed: https://github.com/xwp/wp-customize-posts/blob/9550566/php/class-customize-posts-plugin.php#L70-L71

1
  • Thank you for explanation. After seeing source code of the mentioned classes, it comes clear why components are needed.
    – Venkat
    Commented Jan 25, 2018 at 4:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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