• Resolved wpwebbiepro

    (@webbiepro777)


    Hi,

    Is there a way to remove a control?
    For example I’d like to remove the post status control.

    This is not working (but is working for other global controls and panels):

    function my_customize_register() {     
    global $wp_customize;
    
    $wp_customize->remove_control( 'post_status' ); // not working
    
    }
    add_action( 'customize_register', 'my_customize_register', 11);
    • This topic was modified 7 years, 11 months ago by wpwebbiepro.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Weston Ruter

    (@westonruter)

    Remember that controls in Customize Posts are created dynamically with JS. They will not have been created in PHP at this point.

    You can see here where the post status control gets added: https://github.com/xwp/wp-customize-posts/blob/0.8.5/js/customize-post-section.js#L280-L284

    Note that many of the controls are added conditionally based on whether or not a post feature is supported. Status doesn’t have a feature support, so it is added regardless.

    Maybe the quickest workaround for now is to add some JS to your plugin that depends on the customize-post-section script that short-circuits the function when it is called for a given post type:

    wp.customize.Posts.PostSection.prototype.addStatusControl = (function( originalAddControl ) {
        return function addStatusControl() {
            var section = this;
            if ( 'my_post_type_without_status' === section.params.post_type ) {
                return null;
            }
            return originalAddControl.call( section );
        };
    })( wp.customize.Posts.PostSection.prototype.addStatusControl )
    Thread Starter wpwebbiepro

    (@webbiepro777)

    Hi,

    Thanks for the help!!!
    Got this working with this code:

    // Add JS to customizer
    function print_customizer_js() {     
    ?>
    <script>
    jQuery(document).ready(function($) {
    wp.customize.Posts.PostSection.prototype.addStatusControl = (function( originalAddControl ) {
    return function addStatusControl() {
    var section = this;
    if (('page') || ('post') === section.params.post_type ) {
    return null;
    }
    return originalAddControl.call( section );
    };
    })( wp.customize.Posts.PostSection.prototype.addStatusControl )
    });
    </script>
    <?php
    }
    add_action('customize_controls_print_scripts', 'print_customizer_js');

    Now I’m trying to figure out how to disable certain custom post types the plugin is automatically showing. It shows Beaver Builder Templates and MailPoet unsubscribe page custom post types options (panels) in the customizer and I’d like to hide those. How can I do this? My goal is to only show the panels Posts and Pages.

    • This reply was modified 7 years, 11 months ago by wpwebbiepro.
    • This reply was modified 7 years, 11 months ago by wpwebbiepro.
    • This reply was modified 7 years, 11 months ago by wpwebbiepro.
    Plugin Author Weston Ruter

    (@westonruter)

    This code isn’t right:

    if (('page') || ('post') === section.params.post_type ) {

    If you want to disabler for posts and pages only, then do this:

    if ( 'page' === section.params.post_type || 'post' === section.params.post_type ) {

    To restrict the post types that are shown in the customizer, you can do something like this in a plugin:

    add_action( 'registered_post_type', function( $post_type, $post_type_obj ) {
        if ( 'post' !== $post_type && 'page' !== $post_type ) {
            $post_type_obj->show_in_customizer = false;
        }
    }, 10, 2 );
    • This reply was modified 7 years, 11 months ago by Weston Ruter.
    Thread Starter wpwebbiepro

    (@webbiepro777)

    Works great, thanks a lot again for helping out!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to unset / remove a control’ is closed to new replies.