Notice removed Canonical answer required by Rarst
    Bounty Ended with Adam's answer chosen by Rarst
3 deleted 1 character in body
source | link

Let's say you have a plugin which need to flush rewrite rules. You do it all properly with activation hook and adding flush late, so everything is smooth and compatible.

And then one fine day someone tries to run it on multisite.

Instead of a simple scenarios like:

  1. WordPress site is created
  2. Plugin is installed and activated

You now have nightmare scenarios like:

  1. Plugin is installed and network activated
  2. New WordPress site (or a hundred) in multisite is created

In theory it should just work, right? In practice it goes wrong in spectacular ways:

  • $wp_rewrite state can be from the wrong site
  • switch_to_blog() doesn't track rewrite state either
  • the “later” part might happen in different blog entirely
  • all those other plugins, you are supposed to placeplay nice with, might not be consistently enabled on different sites

For example you can see this issue how trying to do it right blows away permalinks on main site every time new site is created.

So how would plugin go about reliably flushing rewrite rules in multisite:

  1. When new site is created, for the site?
  2. When existing site is activated from inactive, for the site?
  3. When plugin is network activated, for every site?
  4. When plugin is network deactivated, for every site?
  5. Possibly in other scenarios, involving rewrite global context getting changed?

Let's say you have a plugin which need to flush rewrite rules. You do it all properly with activation hook and adding flush late, so everything is smooth and compatible.

And then one fine day someone tries to run it on multisite.

Instead of a simple scenarios like:

  1. WordPress site is created
  2. Plugin is installed and activated

You now have nightmare scenarios like:

  1. Plugin is installed and network activated
  2. New WordPress site (or a hundred) in multisite is created

In theory it should just work, right? In practice it goes wrong in spectacular ways:

  • $wp_rewrite state can be from the wrong site
  • switch_to_blog() doesn't track rewrite state either
  • the “later” part might happen in different blog entirely
  • all those other plugins, you are supposed to place nice with, might not be consistently enabled on different sites

For example you can see this issue how trying to do it right blows away permalinks on main site every time new site is created.

So how would plugin go about reliably flushing rewrite rules in multisite:

  1. When new site is created, for the site?
  2. When existing site is activated from inactive, for the site?
  3. When plugin is network activated, for every site?
  4. When plugin is network deactivated, for every site?
  5. Possibly in other scenarios, involving rewrite global context getting changed?

Let's say you have a plugin which need to flush rewrite rules. You do it all properly with activation hook and adding flush late, so everything is smooth and compatible.

And then one fine day someone tries to run it on multisite.

Instead of a simple scenarios like:

  1. WordPress site is created
  2. Plugin is installed and activated

You now have nightmare scenarios like:

  1. Plugin is installed and network activated
  2. New WordPress site (or a hundred) in multisite is created

In theory it should just work, right? In practice it goes wrong in spectacular ways:

  • $wp_rewrite state can be from the wrong site
  • switch_to_blog() doesn't track rewrite state either
  • the “later” part might happen in different blog entirely
  • all those other plugins, you are supposed to play nice with, might not be consistently enabled on different sites

For example you can see this issue how trying to do it right blows away permalinks on main site every time new site is created.

So how would plugin go about reliably flushing rewrite rules in multisite:

  1. When new site is created, for the site?
  2. When existing site is activated from inactive, for the site?
  3. When plugin is network activated, for every site?
  4. When plugin is network deactivated, for every site?
  5. Possibly in other scenarios, involving rewrite global context getting changed?
    Notice added Canonical answer required by Rarst
    Bounty Started worth 250 reputation by Rarst
    Tweeted twitter.com/#!/StackWordPress/status/597072710259310592
2 added 65 characters in body
source | link

Let's say you have a plugin which need to flush rewrite rules. You do it all properly with activation hook and adding flush late, so everything is smooth and compatible.

And then one fine day someone tries to run it on multisite.

Instead of a simple scenarios like:

  1. WordPress site is created
  2. Plugin is installed and activated

You now have nightmare scenarios like:

  1. Plugin is installed and network activated
  2. New WordPress site (or a hundred) in multisite is created

In theory it should just work, right? In practice it goes wrong in spectacular ways:

  • $wp_rewrite state can be from the wrong site
  • switch_to_blog() doesn't track rewrite state either
  • the “later” part might happen in different blog entirely
  • all those other plugins, you are supposed to place nice with, might not be consistently enabled on different sites

For example you can see this issue how trying to do it right blows away permalinks on main site every time new site is created.

So how would plugin go about reliably flushing rewrite rules in multisite:

  1. When new site is created, for the site?
  2. When existing site is activated from inactive, for the site?
  3. When plugin is network activated, for every site?
  4. When plugin is network deactivated, for every site?
  5. Possibly in other scenarios, involving rewrite global context getting changed?

Let's say you have a plugin which need to flush rewrite rules. You do it all properly with activation hook and adding flush late, so everything is smooth and compatible.

And then one fine day someone tries to run it on multisite.

Instead of a simple scenarios like:

  1. WordPress site is created
  2. Plugin is installed and activated

You now have nightmare scenarios like:

  1. Plugin is installed and network activated
  2. New WordPress site (or a hundred) in multisite is created

In theory it should just work, right? In practice it goes wrong in spectacular ways:

  • $wp_rewrite state can be from the wrong site
  • switch_to_blog() doesn't track rewrite state either
  • the “later” part might happen in different blog entirely
  • all those other plugins, you are supposed to place nice with, might not be consistently enabled on different sites

For example you can see this issue how trying to do it right blows away permalinks on main site every time new site is created.

So how would plugin go about reliably flushing rewrite rules in multisite:

  1. When new site is created, for the site?
  2. When plugin is network activated, for every site?
  3. When plugin is network deactivated, for every site?
  4. Possibly in other scenarios, involving rewrite global context getting changed?

Let's say you have a plugin which need to flush rewrite rules. You do it all properly with activation hook and adding flush late, so everything is smooth and compatible.

And then one fine day someone tries to run it on multisite.

Instead of a simple scenarios like:

  1. WordPress site is created
  2. Plugin is installed and activated

You now have nightmare scenarios like:

  1. Plugin is installed and network activated
  2. New WordPress site (or a hundred) in multisite is created

In theory it should just work, right? In practice it goes wrong in spectacular ways:

  • $wp_rewrite state can be from the wrong site
  • switch_to_blog() doesn't track rewrite state either
  • the “later” part might happen in different blog entirely
  • all those other plugins, you are supposed to place nice with, might not be consistently enabled on different sites

For example you can see this issue how trying to do it right blows away permalinks on main site every time new site is created.

So how would plugin go about reliably flushing rewrite rules in multisite:

  1. When new site is created, for the site?
  2. When existing site is activated from inactive, for the site?
  3. When plugin is network activated, for every site?
  4. When plugin is network deactivated, for every site?
  5. Possibly in other scenarios, involving rewrite global context getting changed?
1
source | link

How to reliably flush rewrite rules on multisite?

Let's say you have a plugin which need to flush rewrite rules. You do it all properly with activation hook and adding flush late, so everything is smooth and compatible.

And then one fine day someone tries to run it on multisite.

Instead of a simple scenarios like:

  1. WordPress site is created
  2. Plugin is installed and activated

You now have nightmare scenarios like:

  1. Plugin is installed and network activated
  2. New WordPress site (or a hundred) in multisite is created

In theory it should just work, right? In practice it goes wrong in spectacular ways:

  • $wp_rewrite state can be from the wrong site
  • switch_to_blog() doesn't track rewrite state either
  • the “later” part might happen in different blog entirely
  • all those other plugins, you are supposed to place nice with, might not be consistently enabled on different sites

For example you can see this issue how trying to do it right blows away permalinks on main site every time new site is created.

So how would plugin go about reliably flushing rewrite rules in multisite:

  1. When new site is created, for the site?
  2. When plugin is network activated, for every site?
  3. When plugin is network deactivated, for every site?
  4. Possibly in other scenarios, involving rewrite global context getting changed?