I'm writing a plugin with a settings/option page and I want some php code to be executed whenever someone saves the settings on that page and that page alone. Which actions do I need to hook into to accomplish this?
Tell me more
×
WordPress Answers is a question and answer site for
WordPress developers and administrators. It's 100% free, no registration required.
|
If you're using Settings API, then you should use a sanitize callback:
The myth is that the This is the sample code:
|
|||
|
|
|
There is a pre-update filter, applied just after the sanitize filter. It's called pre_update_option_optionname and takes the new and old values of the option as parameters. Use it like this:
The benefit of using this is that the intent is clearer, and you don't have to manually get the old option value (if you need it) since it's passed in for you. This filter is specific to a field, so if you want it to run once when saving options, just add it to only one field. |
||||
|
|