4

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

7

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.

2
  • Thanks, @Samuel Elh. Can you also take a look at wordpress.stackexchange.com/questions/230240/… and help me please? Jun 20, 2016 at 10:50
  • Just found that these actions don't trigger when you change them via the GUI. For example, changing the value of "Blog pages show at most" in Settings->Reading, doesn't fire "updated_option" or update_option_posts_per_page . Not sure if bug or intentional. Jul 21, 2016 at 17:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.