1

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.

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?

1
  • Your code snippet doesn't seem to have anything to remove the added rewrite rules. Are you sure that the problem is that it's not flushing on deactivation?
    – Pat J
    Jun 24, 2013 at 18:12

1 Answer 1

2

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().

1
  • Yes you are right, I can loop thru the rewrite rules during deactivation to remove the rules and do a flush. I am thinking if this is the best method, since a lot of codes is needed..
    – Yoga
    Jun 25, 2013 at 15:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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