Which to use to execute code during the saving of a plugin settings page?

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;
}

Leave a Comment