i am having trouble getting any usable information or example of the update_option action hook. my aim is to compare both old and new value of my data, then send email to user for changes. below is the hook:
add_action('update_option', function( $option_name, $old_value, $value ) {
//....
}, 10, 3)
i have compied the code as is to test run but nothing happened. my question is what goes into $option_name, $old_value, $value? sorry am fairly new to php. any explanation with any example will be appreciated.
EDIT:
below is the full code. the idea is to compare the data if it has changed, then echo:
add_action('updated_option', function( $options, $old_value, $value ) {
$options = $options;
foreach ($options as $value) {
$value['id'] = $old_value;
$value['id'] = $value;
}
if($old_value == $value){
echo 'data is current';
else{
echo 'there has been changes';
}
}, 10, 3);
i still don't get anything.
//....
is just like that in your actual code, then nothing would happen. And the parameters are:$option_name
- the option name;$old_value
- the old option value;$value
- the new option value. See here.$options
is the option name and not the option value. If you just want to see if the option has been changed, thenadd_action( 'update_option_{your_option_name}', function(){ echo 'Option changed'; } );
would do it because if there were no changes, WordPress won't trigger theupdate_option_your_option_name
orupdated_option
hook.add_action( 'update_option_{'.$userID.'_interview_date}', function(){ echo 'Option changed'; } );
. i did that and nothing happened. if there's another way to achieve this i will be grateful.{
and}
).. but anyway, see my answer.