Skip to main content
One of two possibilities existed in your answer, when only one worked (update_option) in this case.
Source Link

theThe function add_optionupdate_option includes action hooks that you can use. For your case, the best is to use

Use add_option_update_option_{$option_key} as shown here:

function my_func($option, $value) {
  //this is called only when that particular option is addedupdated
  //$option has the option key & $value has the value array
}
add_action('add_option_testimonials_settings''update_option_testimonials_settings', 'my_func', 10, 2);

Though, if possible, you should directly insert inside the table & not use options. If not that, atleast try to use update_option in place of add_option otherwise you'll need regular cleanups of that table(maybe via a cron?). If you use update_option, the hook is similar update_option_{$option_key} & parameters are old value & new value

the function add_option includes action hooks that you can use. For your case, the best is to use add_option_{$option_key}

function my_func($option, $value) {
  //this is called only when that particular option is added
  //$option has the option key & $value has the value array
}
add_action('add_option_testimonials_settings', 'my_func', 10, 2);

Though, if possible, you should directly insert inside the table & not use options. If not that, atleast try to use update_option in place of add_option otherwise you'll need regular cleanups of that table(maybe via a cron?). If you use update_option, the hook is similar update_option_{$option_key} & parameters are old value & new value

The function update_option includes action hooks that you can use.

Use update_option_{$option_key} as shown here:

function my_func($option, $value) {
  //this is called only when that particular option is updated
  //$option has the option key & $value has the value array
}
add_action('update_option_testimonials_settings', 'my_func', 10, 2);
Source Link
Mridul Aggarwal
  • 6.7k
  • 1
  • 28
  • 25

the function add_option includes action hooks that you can use. For your case, the best is to use add_option_{$option_key}

function my_func($option, $value) {
  //this is called only when that particular option is added
  //$option has the option key & $value has the value array
}
add_action('add_option_testimonials_settings', 'my_func', 10, 2);

Though, if possible, you should directly insert inside the table & not use options. If not that, atleast try to use update_option in place of add_option otherwise you'll need regular cleanups of that table(maybe via a cron?). If you use update_option, the hook is similar update_option_{$option_key} & parameters are old value & new value