Using WordPress ‘customize_save_after’ PHP action

The customize_save_after WordPress PHP action fires after the Customize settings have been saved.

Usage

add_action('customize_save_after', 'your_custom_function');
function your_custom_function($manager) {
    // your custom code here
}

Parameters

  • $manager (WP_Customize_Manager): The instance of the WP_Customize_Manager class.

More information

See WordPress Developer Resources: customize_save_after

Examples

Log Saved Changes

Log the saved changes to a text file.

add_action('customize_save_after', 'log_saved_changes');
function log_saved_changes($manager) {
    $changes = $manager->changeset_data();
    $log_file = fopen('changes.log', 'a');
    fwrite($log_file, json_encode($changes) . PHP_EOL);
    fclose($log_file);
}

Send Notification Email

Send a notification email to the admin when Customize settings are saved.

add_action('customize_save_after', 'send_notification_email');
function send_notification_email($manager) {
    $to = get_option('admin_email');
    $subject = 'Customize Settings Saved';
    $message = 'The Customize settings have been updated on your WordPress site.';
    wp_mail($to, $subject, $message);
}

Update Site Title

Update the site title after Customize settings have been saved.

add_action('customize_save_after', 'update_site_title');
function update_site_title($manager) {
    $new_title = $manager->get_setting('blogname')->value();
    update_option('blogname', $new_title . ' - Updated');
}

Purge Cache

Purge the site cache after the Customize settings have been saved.

add_action('customize_save_after', 'purge_site_cache');
function purge_site_cache($manager) {
    if (function_exists('wp_cache_flush')) {
        wp_cache_flush();
    }
}

Save Changeset Data to Custom Table

Save the changeset data to a custom database table after the Customize settings have been saved.

add_action('customize_save_after', 'save_changeset_to_custom_table');
function save_changeset_to_custom_table($manager) {
    global $wpdb;
    $changeset_data = $manager->changeset_data();
    $table_name = $wpdb->prefix . 'custom_changeset_data';
    $wpdb->insert($table_name, array('changeset' => json_encode($changeset_data)));
}