The customize_save WordPress action fires once the theme has switched in the Customizer, but before settings have been saved.
Usage
add_action('customize_save', 'my_custom_function'); function my_custom_function($manager) { // your custom code here }
Parameters
$manager
(WP_Customize_Manager) – The WP_Customize_Manager instance.
More information
See WordPress Developer Resources: customize_save
Examples
Log a message when the theme is switched
Log a message to a custom log file when the theme is switched in the Customizer.
add_action('customize_save', 'log_theme_switch'); function log_theme_switch($manager) { error_log("Theme switched in the Customizer.", 3, "/path/to/custom.log"); }
Send an email notification on theme switch
Send an email notification to the admin when the theme is switched in the Customizer.
add_action('customize_save', 'send_theme_switch_email'); function send_theme_switch_email($manager) { $admin_email = get_option('admin_email'); wp_mail($admin_email, 'Theme Switched', 'A theme has been switched in the Customizer.'); }
Update a custom option on theme switch
Update a custom option in the database when the theme is switched in the Customizer.
add_action('customize_save', 'update_custom_option'); function update_custom_option($manager) { update_option('my_custom_option', 'Theme switched in the Customizer'); }
Perform a custom action when switching to a specific theme
Perform a custom action only when switching to a specific theme in the Customizer.
add_action('customize_save', 'custom_action_for_specific_theme'); function custom_action_for_specific_theme($manager) { if ('my_theme_slug' === $manager->theme()->get_stylesheet()) { // your custom code here } }
Reset theme mod settings on theme switch
Reset all theme mod settings when the theme is switched in the Customizer.
add_action('customize_save', 'reset_theme_mods_on_switch'); function reset_theme_mods_on_switch($manager) { remove_theme_mods(); }