Tell me more ×
WordPress Answers is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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