By default, customized sent the below payload when the Save & Publish button is clicked.


Is there a way i can extend the payload to include custom data to be posted?

Refereence: https://github.com/WordPress/WordPress/blob/master/wp-admin/js/customize-controls.js#L3425

  • What kind of data and where do you get it from (static?) and what are you going to do with it? Is it meant for all control sections? The more relevant info you give, it's more likely that someone can point you in the right direction ;-) – birgire Jun 3 '16 at 11:32
  • I need to pass a unique id which will be used control settings I.e $wp_customizet->add_settings(). I want the control settings to be unique by appending the ID that will be POSTed by customizer appended to the ID. – Collizo4sky Jun 3 '16 at 12:18
  • If you go and bother the whole wordpress universe, the minimum you should do is have a more coherent question than "I want to do something with the customizer". What have you tried that didn't work? – Mark Kaplun Jun 3 '16 at 13:29
  • I have tried all tricks possible. Trust me I know my onions. If only the customizer triggers event say after saving is completed, I could have listen to the event and pass in the ID via Ajax post. – Collizo4sky Jun 3 '16 at 13:55
  • well, customizer do trigger an event after save, customize_save_after – Mark Kaplun Jun 3 '16 at 15:29

You can monkeypatch the wp.customize.previewer.query method:

add_action( 'customize_controls_enqueue_scripts', function () {
    wp_add_inline_script( 'customize-controls', '(function ( api ) {
        api.bind( "ready", function () {
            var _query = api.previewer.query;

            api.previewer.query = function () {
                var query = _query.call( this );
                query.foo = "bar";
                return query;
    })( wp.customize );'

This will ensure the script runs immediately after customize-controls.js in the markup - note that wp_add_inline_script will wrap your JS within <script /> tags, no need to do it yourself.

| improve this answer | |
  • Hey @TheDeadMedic, you rock. This fixed my problem. Thanks so much. – Collizo4sky Jun 4 '16 at 0:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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