How to intercept update_option() before it saves data?

You might be better off using the update_option_ action instead. This will allow you to write to your file after the option has been updated (as apposed to before). If another plugin hooks into pre_update_option_ and alters the value after your plugin has saved it then you will have saved an incorrect value.

I would use:

add_action( 'update_option_myoption', function( $old_value, $new_value ) {
   //Do something with the new value
}, 10, 2);

Leave a Comment