0

When you are using the wordpress customizer, if you don't make any changes to the settings, the wordpress customizer doesn't enable the publish button. And it shows like this:

enter image description here

And I want it to be displayed like this after I make a change from my custom customizer control which is an input not linked to the customizer:

enter image description here

How can I enable the disabled publish button from my custom control when I change something with it?

Thanks.

3
  • Hi . How do you disable the publish button? Jan 8, 2018 at 7:51
  • Sorry I wasn't clear I guess. I'll update the question now.
    – tpaksu
    Jan 8, 2018 at 7:51
  • It would be easier to debug if you could provide your custom control too.
    – ghoul
    Jan 8, 2018 at 17:56

3 Answers 3

2

Just set the saved state to false:

wp.customize.bind( 'ready', function() {
    wp.customize.state( 'saved' ).set( false );
} );
1
  • Thanks for your answer @Weston, you also commented on my bug report on wordpress.org yesterday :)
    – tpaksu
    Jan 9, 2018 at 6:03
0

Actually, triggering the change event of an linked input did the trick.

0

Without the a peek in your custom control, the exact solution can't be provided. But here you can try something like this in the customize-controls.js which should be enqueued like this:

function theme_name_panels_js() {
   wp_enqueue_script( 'theme_name-customize-controls', get_theme_file_uri( '/assets/js/customize-controls.js' ), array(), '1.0', true );
}
add_action( 'customize_controls_enqueue_scripts', 'theme_name_panels_js' );

In your customize-controls.js you can try this where 'radio-image' is the type of custom control and event is triggered on change of the radio button

( function( $, api ) {

api.controlConstructor['radio-image'] = api.Control.extend( {
    ready: function() {
        var control = this;

        $( 'input:radio', control.container ).change(
            function() {
                control.setting.set( $( this ).val() );
            }
        );
    }
} );
} )( jQuery, wp.customize );
1
  • Yes, you answered this like creating a link between the setting and the linkless input. And control.setting.set would trigger the live update event or so. The main thing that's triggering the publish button to get enabled is the change event itself I guess.
    – tpaksu
    Jan 8, 2018 at 18:51

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.