WordPress.org

Make WordPress Core

Opened 4 years ago

Last modified 7 weeks ago

#32471 new defect (bug)

There is no proper way to flush rewrite rules at plugin network de-activation

Reported by: Chouby Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.0
Component: Rewrite Rules Keywords:
Focuses: multisite Cc:

Description

It is considered as best practice for a plugin modifying rewrite rules to flush them at activation and de-activation: http://codex.wordpress.org/Function_Reference/flush_rewrite_rules

Plugins should then handle this at network activation and de-activation too. Following a comment from @nacin on #14170, we can find a way to handle this properly at network activation. We can even make something which scales using for example the plugin proper network activation from @scribu as a basis.

However the only proposal I found to handle the network de-activation is:

foreach ($wpdb->get_col("SELECT blog_id FROM $wpdb->blogs") as $blog_id) {
	switch_to_blog($blog_id);
	flush_rewrite_rules();
	restore_current_blog();
}

Apart from the fact that it does not scale, it would mess the rewrite rules of all blogs. I am aware of #20171 but fixing it with the proposed patch is not sufficient as other plugins may modify the rewrite rules and we then face the fact that $wp_rewrite->extra_rules_top is shared accross blogs.

So the only way I foresee as a potential solution is that the network de-activation is not handled at network level but that each blog runs its own individual de-activation process - in a similar way as @nacin proposed for the activation as indeed, with the current architecture, we must never mix switch_to_blog() and flush_rewrite_rules().

Unless I miss something, it seems that there is currently no way for a plugin to properly flush rewrite rules at network de-activation.

Change History (1)

#1 @RavanH
4 years ago

Hi Frédéric - just for reference: our discussion on https://polylang.wordpress.com/2015/06/10/polylang-1-7-6-and-multisite/#comments about the possibility of switch_to_blog + delete_option(‘rewrite_rules’)

@all - any insights or warnings about possible problems with this approach are appreciated because I too am hoping to find a proper solution for network deactivation rewrite flushing!

Note: See TracTickets for help on using tickets.