0

I am developing a Wordpress plugin and need to ad a rewrite url using add_rewrite_rule().

That does work. But what happens when my plugin is deleted? Does Wordpress cleanup the htaccess or do I need to do that? How can I remove a url which was added using add_rewrite_rule()?

2
  • Hi Alexander, welcome on WPSE. Are you talking about add_rewrite_rule as by default there is no such thing as add_rewrite_url in WordPress.
    – kraftner
    Commented Mar 9, 2015 at 10:33
  • Hi kraftner, yes I meant add_rewrite_rule() Commented Mar 9, 2015 at 10:36

1 Answer 1

1

Let me say beforehand that when using add_rewrite_rule() nothing is written to the htaccess file. Rewrite rules are stored in the database and handled by WordPress internally on PHP level.

TL;DR: Rewrite rules do persist after plugin deletion, but probably not the way you'd expect it.

When using add_rewrite_rule these rules are added in the options table in the database. You then need to flush the rewrite rules via flush_rewrite_rules() (Visiting Settings > Permalinks and saving does the same) for them to come in effect.

Similarly when you remove your plugin that added the rewrite rules they stay in effect until the next flushing of the rewrite rules. So yes they persist, but they will disappear at some random point later on when the rewrite rules are flushed.

1
  • thanks for the answer, and can I somehow remove the rewrites my plugin created? Commented Mar 9, 2015 at 15:11

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.