Do "customize_save" action hook after the settings are saved

  1. lemmonaid

    Hi guys,

    Just now I've stumbled uppon a certain "issue". I'm hooking a custom function onto "customize_save" hook that's being fired on saving customization options in Theme Customizer. This function of mine is basically regenerating CSS file with new settings.

    The issue here is that settings are not being applied immediately, only after secondary Theme Customizer save procedure. This is due to "customize_save" hook being executed BEFORE the customizer options are being actually saved.

    My question is if you could move this hook after the options saving or if you could create another new hook at that place that would be awesome.

    Thank you very much for considering.



    Posted: 2 years ago #
  2. Dovy Paukstys


    I'm having a similar issue. I ended up doing an admin-ajax hook and running javascript 2500 ms after they clicked save. Very much a hack. Wish it were different.

    Posted: 2 years ago #
  3. Dovy Paukstys



    Please add the following line to the the next release of WordPress.

    do_action( 'customize_save_after', $this );

    to line: 514 of class-wp-customize-manager.php

    The full function should look as follows:

    public function save() {
    		if ( ! $this->is_preview() )
    		check_ajax_referer( 'save-customize_' . $this->get_stylesheet(), 'nonce' );
    		// Do we have to switch themes?
    		if ( ! $this->is_theme_active() ) {
    			// Temporarily stop previewing the theme to allow switch_themes()
    			// to operate properly.
    			switch_theme( $this->get_stylesheet() );
    		do_action( 'customize_save', $this );
    		foreach ( $this->settings as $setting ) {
    		do_action( 'customize_save_after', $this );


    This will allow us to use a hook for after the settings from the customizer have been saved.

    Thank you!

    Posted: 2 years ago #
  4. Ryan Boren
    WordPress Dev

  5. lemmonaid

    Thanks Ryan!

    Just to let you know guys, I've manage to come up with a workaround that works perfectly fine for me:

    1. First I create a hidden field in customizer options and place it at the very end of my settings. Let's call it "my-last-setting".
    2. Then create a function that will process your saved customizer options. Call it "my_processing_function" for now.
    3. Finally hook the above function like this: add_action( 'customize_save_my-last-setting', 'my_processing_function' );

    This should work just fine I think. Although, it is kind of a "hack" too ;)

    Posted: 2 years ago #

RSS feed for this topic


You must log in to post.

  • Rating

    3 Votes
  • Status

    Good idea! We're working on it