I am working with redux framework and need to save theme option values to a file right before it is saved in DB. Is there a way to intercept


right before it saves data in DB?

3 Answers 3


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);
  • Very good point.
    – cybmeta
    Commented Mar 18, 2015 at 8:37

There is a filter exactly for that: pre_update_option_{option_name}. If the is option is, for example, names myoption, you could use somthing like this:

add_filter( 'pre_update_option_myoption', function( $new_value, $old_value ) {

   //Do something before returning the new value to be saved in database

   return $new_value;

}, 10, 2);

Referene: pre_update_option_(option_name)

It would be useful a general pre_update_option for all options, but as far I know such filter doesn't exist.

You asked about someting to use right before the option is saved to DB but you may be also interested in update_option_{option_name} action. This action is fired right after the option has been saved. Please, note that update_option_{option_name} is an action while pre_update_option_{option_name} is a filter, both are intented for different things. Basically (very basically), actions are intended to perform tasks and don't return values; filters return values and they are intented to work with or modify data (although there is nothing that stop you to perform tasks in filters).


Lead dev of Redux here. You can use one of our filters to match your needs:

"redux/validate/{$this->args['opt_name']}/defaults" - Only on resetting defaults

"redux/validate/{$this->args['opt_name']}/defaults_section" - Only on resetting one section

"redux/options/{$this->args['opt_name']}/import" - Only on import

"redux/validate/{$this->args['opt_name']}/before_validation" - before validation

"redux/options/{$this->args['opt_name']}/validate" - after validation

  • hehehhe, was just thinking about you dovy , we got to talk talk bud github.com/reduxframework/kirki/issues/208
    – Benn
    Commented Apr 24, 2015 at 20:59
  • bloating the code with entire framework to do something which is a one liner? just a no-no Commented May 22, 2018 at 4:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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