'Wordpress Customizer "customize_save_after" hook -- how to know which control was updated?
I've been able to tap into the "customize_save_after" hook, but as far as I can tell, this gets fired whenever the "Publish" button is clicked, regardless of which control was updated.
Wondering if it's possible to know which control was modified/updated when the user clicks "Publish"?
Am also aware of customize_save_{$id_base} hook, and am tapping into that as well. And that also gets fired when the user clicks "Publish". However, if you call get_theme_mod('control_name') inside this hook, it returns the old value (not the new saved value).
Any ideas would be appreciated.
EDIT: Think I found a way to do this, but it doesn't seem intuitive and is definitely not the home run. Still would love to hear better ideas.
You can hook onto the 'customize_save_response':
add_action( 'customize_save_response', 'customize_save_response_action', 10, 2 );
And then in the function that fires on that hook, I believe the ajax $response gets returned, and in that array, under "setting_validities", I'm seeing the name of the control(s) that were modified.
function customize_save_response_action( $response, $manager ){
foreach($response["setting_validities"] as $key=>$value) {
// Error logging the $key gets me the name of the controls
// that were updated
error_log($key);
}
return $response;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
