The customize_save_response WordPress PHP filter modifies the response data for a successful customize_save Ajax request.
Usage
add_filter('customize_save_response', 'my_custom_function', 10, 2); function my_custom_function($response, $manager) { // your custom code here return $response; }
Parameters
$response
(array): Additional information passed back to the ‘saved’ event on wp.customize.$manager
(WP_Customize_Manager): WP_Customize_Manager instance.
More information
See WordPress Developer Resources: customize_save_response
Note: This filter does not apply if there was a nonce or authentication failure.
Examples
Add a custom message to the response
Add a custom message to be displayed upon saving changes in the Customizer.
add_filter('customize_save_response', 'add_custom_message', 10, 2); function add_custom_message($response, $manager) { $response['custom_message'] = 'Your changes have been saved successfully!'; return $response; }
Log the saved data
Log the data saved in the Customizer to a file.
add_filter('customize_save_response', 'log_saved_data', 10, 2); function log_saved_data($response, $manager) { error_log(print_r($response, true)); return $response; }
Add a timestamp to the response
Add a timestamp to the response to show when the Customizer settings were saved.
add_filter('customize_save_response', 'add_timestamp', 10, 2); function add_timestamp($response, $manager) { $response['timestamp'] = time(); return $response; }
Send a notification email upon save
Send an email notification to the admin when Customizer settings are saved.
add_filter('customize_save_response', 'send_notification_email', 10, 2); function send_notification_email($response, $manager) { $to = get_option('admin_email'); $subject = 'Customizer Settings Saved'; $message = 'The Customizer settings have been saved on your website.'; wp_mail($to, $subject, $message); return $response; }
Modify a specific setting value in the response
Modify a specific setting value in the response before it is passed back to the ‘saved’ event.
add_filter('customize_save_response', 'modify_setting_value', 10, 2); function modify_setting_value($response, $manager) { if (isset($response['changeset_data']['my_setting'])) { $response['changeset_data']['my_setting']['value'] = 'New Value'; } return $response; }