Remove rewrite rules generated by plugin during deactivation‎

I have a simple plugin like the following

add_action('generate_rewrite_rules', function ($wp_rewrite)
{
    $wp_rewrite->rules = xxx + $wp_rewrite->rules;
});

if (is_admin())
{
    register_activation_hook( __FILE__, function() {
        flush_rewrite_rules(FALSE);
    });

    register_deactivation_hook(__FILE__, function() {
        flush_rewrite_rules(FALSE);
    });
}

When I activate this plugin, the rewrite rule is being updated and in effect, cool! However, when I deactivate the plugin, the rewrite rule cannot be flushed automatically.

Read More

I need to manually flush by at the permalinks settings page.

So how to modify my plugin code so no manually flushing is needed during plugin deactivation?

Related posts

1 comment

  1. You’re adding your rewrite rules to $wp_rewrite->rules, but then not removing them before calling the flush during deactivation. Add code to your deactivation function to remove the stuff you added to $wp_rewrite->rules before calling flush_rewrite_rules().

Comments are closed.