Opened 6 years ago
Last modified 5 years ago
#44976 assigned enhancement
Proposal to add deregister_control_type(), deregister_panel_type() and deregister_section_type() methods to WP_Customize_Manager
Reported by: | Collizo4sky | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | |
Component: | Customize | Keywords: | has-patch needs-testing dev-feedback |
Focuses: | Cc: |
Description
Today was the time I wish I am able to remove a registered customizer control.
I also have a patch to implement a deregister_control_type()
Attachments (4)
Change History (21)
#2
follow-up:
↓ 3
@
6 years ago
- Keywords 2nd-opinion reporter-feedback added
- Severity changed from major to normal
@Collizo4sky, remove_control already remove the control for customizer so why we need other function for same functionality?
<?php public function remove_control( $id ) { unset( $this->controls[ $id ] ); }
#3
in reply to:
↑ 2
@
6 years ago
Replying to mukesh27:
remove_control() removes a control and not the control type. These are two different thing. Ask yourself, why do we have to register a control type when we already have add_control()
A control and control type are two different concept.
The former is what is shown on customizer and the latter is the php Class definition of the control.
@Collizo4sky, remove_control already remove the control for customizer so why we need other function for same functionality?
<?php public function remove_control( $id ) { unset( $this->controls[ $id ] ); }
#4
@
6 years ago
- Focuses accessibility added
- Keywords needs-testing dev-feedback added; 2nd-opinion reporter-feedback removed
@Collizo4sky, So you want to deregister control type not control.
I have tested your patch and found that it is not remove control type when i call below function in theme functions.php file.
$wp_customize->deregister_control_type( 'WP_Customize_Color_Control' );
i have checked your code and found that it's return notice when we try to deregister any controls. You can please try rewise patch that i have do and added two new functions to deregister panel and section also.
After applying patch you can check like below functions.
To deregister any control type add below function in customize_register
action like below
<?php function customize_deregister_control_type( $wp_customize ) { $wp_customize->deregister_control_type( 'WP_Customize_Color_Control' ); } add_action( 'customize_register', 'customize_deregister_control_type' );
To deregister any panel type add below function in customize_register
action like below
<?php function customize_deregister_panel_type( $wp_customize ) { $wp_customize->deregister_panel_type( 'WP_Customize_Themes_Panel' ); } add_action( 'customize_register', 'customize_deregister_panel_type' );
To deregister any section type add below function in customize_register
action like below
<?php function customize_deregister_section_type( $wp_customize ) { $wp_customize->deregister_section_type( 'WP_Customize_Section' ); } add_action( 'customize_register', 'customize_deregister_section_type' );
#5
@
6 years ago
- Summary changed from Proposal to add deregister_control_type() method to WP_Customize_Manager to Proposal to add deregister_control_type(), deregister_panel_type() and deregister_section_type() methods to WP_Customize_Manager
#6
@
6 years ago
You patch look great. Kindly change array_search to a simply in_array. Array_search is an overkill for something as simple as this.
I don’t have the time now otherwise I will do it myself when I am free.
Do that please.
This ticket was mentioned in Slack in #core by mukeshpanchal27. View the logs.
6 years ago
#10
@
6 years ago
If there is a way to register a control type, shouldn’t there be to deregister?
Currently working on a project where we have a need to remove totally from the customizer the js wp.template code of a custom control created by the active theme.
Without a way to deregister it, it will still be printed to customizer.
I hope that answers your question.
#13
@
6 years ago
@westonruter Yes that is one option to remove that core action. In core file this action add_action( 'wp_loaded', array( $this, 'wp_loaded' ) );
is added to register panel, section and control types but if we remove this action it will remove all core types like panel, section and control.
As per this ticket @Collizo4sky said that in core we need to add an option to remove any core type not all so any end user can remove core types as per there needs and it is good idea to add this feature in core. what is your thought on this?
When we remove wp_loaded
action then it show one notice Notice: Trying to get property 'title' of non-object in C:\wordpress-meta\wp-includes\class-wp-customize-nav-menus.php on line 446
so don't think it is good way to remove core action as it create errors in some code.
Couldn't find how to remove the duplicate patch. So here we are. Two similar patch.