Site icon Hip-Hop Website Design and Development

How do I flush the rules after saving settings using the Settings API?

I’m using the Settings API to allow the user to toggle the has_archive option on some custom post types. When the user turns archives on or off, I want to flush the rewrite rules. If I had written the saving function myself, I could just call flush_rewrite_rules() and be done with it, but the Settings API takes care of the saving for me. Is there a hook somewhere that I can use?

Chosen Solution @Stephen Harris

add_action('admin_init', 'my_plugin_register_settings');
function my_plugin_register_settings() {
    if (delete_transient('my_plugin_flush_rules')) flush_rewrite_rules();
    register_setting('my_plugin', 'my_plugin_settings', 'my_plugin_sanitize');
    // add_settings_section(), add_settings_field(),...
}

function my_plugin_sanitize($input) {
    set_transient('my_plugin_flush_rules', true);
    return $input;
}