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?
2 Answers
If you’re using Settings API, then you should use a sanitize callback:
register_setting( $option_group, $option_name, $sanitize_callback );
The myth is that the $sanitize_callback
actually is a filter for your options when it’s saved in the database. This is the place where you can do something with your custom code.
This is the sample code:
register_setting( 'wpse38180', 'wpse38180', 'sanitize_wpse38180' );
function sanitize_wpse38180( $options )
{
// Do anything you want
return $options;
}