• My plugin sets rewrite rules using add_rewrite_rule, on plugin activation the rule works great.

    Often these rules stop working which seem to coincide with a WordPress update and/or a Yoast SEO plugin update.

    Is there any way to set the rewrite to not be flushed by another source, or is it possible to check via cron job in my plugin whether the rule exists, if not then set it again?

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    You can use ‘upgrader_process_complete’ action to do something after upgrades. Your callback is passed an instance of the upgrader object and an array of data about what was upgraded.

    You cannot prevent the rewrites from being flushed though, it shouldn’t be necessary AFAIK. Your add_rewrite_rule() is still considered when rewrites are flushed if your plugin is active. And if it were deactivated during upgrading, your activation hook should be triggered upon reactivation, so you’d be covered either way.

    Something about how you phrased your question gives me pause. Your add_rewrite_rule() calls should be made from the “init” action every time your plugin loads. Not only during activation. What you should only do during activation is call flush_rewrite_rules(). If this is what you are doing, I don’t know what is causing trouble, but something else flushing rules shouldn’t matter.

    You could use the above hook to flush rules again, but it shouldn’t be necessary. Flushing is time consuming and upgrades are prone to timing out as it is. Lets try to not make the problem worse ??

Viewing 1 replies (of 1 total)
  • The topic ‘Plugin rewrite rule flushed on plugin/wp update’ is closed to new replies.