Hook/notify when any option or setting is added or updated

I know about:

add_option_{option_name}
update_option_{option_name}

but these need specific option names. What I am looking for is a way to know if and when any option is changed (added or updated).

What I am really trying to avoid is running a query to find all option names, then running a loop through them to add both add_option_{option_name} and update_option_{option_name} for those options dynamically.
(If indeed this is the only way to do it, is this an alright way to do it?)

Any suggestions?

1 Answer
1

Looking at the sources (core files, wp-includes/option.php) you can always find your target hook tags:

add_action('added_option', 'wpse230212_callback_add', 10, 2);
add_action('updated_option', 'wpse230212_callback_update', 10, 3);

function wpse230212_callback_add( $option_name, $option_value ) {
    // do stuff on add_option
}

function wpse230212_callback_update( $option_name, $old_value, $option_value ) {
    // do stuff on update_option    
}

Hope that helps.

Leave a Comment