Hook if somebody saves plugin options?

Although I don’t agree with your purpose, here the action hooks you may use (you have not shown us what you are using to save the options, so I can not say which one is better).

If you use add_option to save options:

add_option_{option_name}: Runs after a the option with name “option_name” has been added using add_option() function. For example, for the option with name “foo”:

add_action('add_option_foo', function( $option_name, $option_value ) {
     //....
}, 10, 2);

add_option: Runs before an option gets added to the database. Example:

add_action('add_option', function( $option_name, $option_value ) {
     //....
}, 10, 2);

added_option: Runs after an option has been added. Example:

add_action('added_option', function( $option_name, $option_value ) {
     //....
}, 10, 2);

There are also analog actions for delete_option(): delete_option_{option_name}, delete_option and deleted_option

If you use update_option to save options:

(update_option can be used also to save/create new options)

update_option_{option_name}: Runs after the option with name “option_name” has been updated. For example, for the option with name “foo”:

add_action('update_option_foo', function( $old_value, $value ) {
     //....
}, 10, 2);

update_option: Runs before an option gets updated. Example:

add_action('update_option', function( $option_name, $old_value, $value ) {
     //....
}, 10, 3);

updated_option: Runs after an an option has been updated. Example:

add_action('updated_option', function( $option_name, $old_value, $value ) {
     //....
}, 10, 3);

Leave a Comment