Make WordPress Core

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's profile 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)

class-wp-customize-manager.diff (669 bytes) - added by Collizo4sky 6 years ago.
class-wp-customize-manager.2.diff (669 bytes) - added by Collizo4sky 6 years ago.
44976.patch (1.8 KB) - added by mukesh27 6 years ago.
New working patch with thee new functions.
44976.2.patch (1.8 KB) - added by mukesh27 6 years ago.
Updated patch. change array_search to in_array

Download all attachments as: .zip

Change History (21)

#1 @Collizo4sky
6 years ago

Couldn't find how to remove the duplicate patch. So here we are. Two similar patch.

#2 follow-up: @mukesh27
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 @Collizo4sky
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 @mukesh27
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' );

@mukesh27
6 years ago

New working patch with thee new functions.

#5 @mukesh27
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 @Collizo4sky
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.

@mukesh27
6 years ago

Updated patch. change array_search to in_array

This ticket was mentioned in Slack in #core by mukeshpanchal27. View the logs.


6 years ago

#8 @Collizo4sky
6 years ago

@westonruter please look into this trac.

#9 @westonruter
6 years ago

What's the use case?

#10 @Collizo4sky
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.

Last edited 6 years ago by Collizo4sky (previous) (diff)

#11 @westonruter
6 years ago

Can't you just unhook the action that registers the type in the first place?

#12 @Collizo4sky
6 years ago

That won’t work because the action callback also have other code feature in it.

#13 @mukesh27
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.

Last edited 6 years ago by mukesh27 (previous) (diff)

#14 @SergeyBiryukov
6 years ago

  • Focuses accessibility removed

#15 @pento
5 years ago

  • Version trunk deleted

#16 @Collizo4sky
5 years ago

@westonruter any news or decision about this ticket?

#17 @westonruter
5 years ago

@Collizo4sky No, no news. Sorry.

Note: See TracTickets for help on using tickets.