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?

link|improve this question

feedback

1 Answer

up vote 2 down vote accepted

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;
}
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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