0

I'm stuck all day trying to refresh the customizer screen after the settings has been saved. And this is driving me nuts.

I need this solution because i've hooked a function into the customize_save_after hook to process some data after the save. And i want a refresh on the preview with wp.customize.previewer.refresh(); after the things are saved.

I've already tried to set a trigger on the save button to run this refresh method when clicked, but it fires simultaneously with the save event, and i get a refresh, but no changes on the preview ultil i reload manually the page. I've used a timer to trigger the refresh after x secs, it works, the changes are displayed on the preview, but i want to trigger automatically when the settings are saved.

Here what i've done so far:

jQuery(document).ready(function($) {
    $('.save').click(function(event) {
        setTimeout(
          function() {
            wp.customize.previewer.refresh();
        }, 4000);
    });
});

Can anyone help me? Thanks!

  • can you explain why you want to do such a thing? The point of the customizer is that it shows thing exactly as they will be when you save the settings and if you need to do refresh after save, it is an indication you might not correctly write the code for it – Mark Kaplun Nov 25 '16 at 5:22
  • I have a class that process the input data and store it on DB. Its a kind of sanitize. I've looked at selective refresh, the new feature of WP, and that's what i need, but i'm looking for a workaround, since many people may not have WP on latest version. – Felipe Rodrigues Nov 25 '16 at 5:51
  • 1
    Selective refresh has been around since 4.5, so if users aren't on that version yet that would be concerning. There is a saved event that fires on wp.customize and that is what I think you're looking for, but yeah, if you could expound about your specific use case then a better answer can be provided. – Weston Ruter Nov 25 '16 at 6:02
  • @Weston Ruter I was digging on the customize-base.js and saw this action and i've playing with it and window.wp.customize since i've discovered. I have done a good progress, and i'm about to resolve this issue. – Felipe Rodrigues Nov 25 '16 at 6:10
1

Did it with the window.wp.customize.bind() method. Hope this helps someone else.

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.