Rewrite Rule conflict causing 404 errors.

Hi there,

I've tried to resolve this issue many times before, but I've decided to drop it and pass this issue on to you.

According to the WordPress rewrite flushing guidelines, the Rewrite Rules should only be flushed once, as it's a heavy operation. The Domain Mapping plugin abides to this very well. Kudos!

However, it also is required to only do this on PHP shutdown. As other plugins or themes might add rules or endpoints in the meantime, or flush at shutdown themselves.
This will result in removing all rules prior to the latest flush.
Therefore I've added an extra note in the WordPress Codex "Usage", hoping other authors might catch this.

It should be executed either on the 'shutdown' hook, or on plugin/theme (de)activation.

Unfortunately, Domain Mapping is affected by this "standard". Since it's flushing on 'init'. The plugin order, among other factors, might "sometimes" not affect users. But other times, it will. Like within my Network.

To resolve all conflicts with other themes/plugins doing it right, and at the same time other themes/plugins doing it wrong, the following adjustment has to be made.

// @ domain-mapping\classes\Domainmap\Module\Cdsso.php - Line 357 ~ 364
function _flush_rewrite_rules(){
	$key =  domain_map::FLUSHED_REWRITE_RULES . get_current_blog_id();
	if( !get_site_option( $key ) ){
		add_action( 'shutdown', 'flush_rewrite_rules' ); // Was: flush_rewrite_rules();
		update_site_option( $key , true);
	}
}

I've applied this fix myself already, and within one reload on the Home Blog, all errors were gone and I was able to log in successfully without "re-saving the Permalink settings".

I hope this helps! Let me know if you require any more information, I'd love to contribute :slight_smile:.