Run function AFTER theme options are saved?

Weird question, how can I run a custom function AFTER my theme settings are saved? I see that the register_settings() function has a sanitize callback, but that runs before the settings are changed. I need something to run after they’re saved. Is there an action or filter I can use to do that?

EDIT –

Read More

SO I have this setting I made:

add_settings_section(
    'kjd_body_background_settings_section', // ID hook name
    null, // label
    null, // function name
    'kjd_body_background_settings' // page name
);


    add_settings_field(
        'kjd_body_background_colors', // ID hook name
        null, //label
        null, //callback
        'kjd_body_background_settings', // page name
        'kjd_body_background_settings_section' // parent section 
);

and this function:

function kjd_update_stylesheet( $oldvalue, $_newvalue ){
   echo 'updated!';
   die();
}
add_action('update_options_kjd_body_background_settings','kjd_update_stylesheet',10, 2);

//add_action('update_options_kjd_body_background_colors','kjd_update_stylesheet',10, 2);

Related posts

1 comment

  1. Use the filter update_option_{$option}. It runs after a successful saving.

    $option is the name of your option, and you get the old and the new value as parameters.

    From wp-includes/option.php:

    do_action( "update_option_{$option}", $oldvalue, $_newvalue );
    

    Use it like this for an option wpse_themesettings:

    add_action( 'update_option_wpse_themesettings', 'wpse_check_settings', 10, 2 );
    
    function wpse_check_settings( $old_value, $new_value )
    {
        // do something
    }
    

Comments are closed.