wordpress: detecting rewrite rules flush
<p>I have my own plugin that, on activation, adds some rewrite rules which map url's to single page applications.</p>

<p>Now, I lose the rules once in a while, after some other plugin updates or maybe another process that triggers <code>flush_rewrite_rules</code> in Wordpress.</p>

<p>The problem is, I do not know when, how or why it happens. And by whom.</p>

<p>So I have searched globally in my WP files and come up with the following actions that trigger a refresh</p>

<p><code>
        add_action( 'woocommerce_settings_saved',          array( $this, 'load' ) );
        add_action( 'woocommerce_attribute_added',         array( $this, 'load' ) );
        add_action( 'woocommerce_attribute_updated',       array( $this, 'load' ) );
        add_action( 'woocommerce_attribute_deleted',       array( $this, 'load' ) );
        add_action( 'wp_install',                          array( $this, 'load' ) );
        add_action( 'after_db_upgrade',                    array( $this, 'load' ) );
        add_action( 'after_switch_theme',                    array( $this, 'load' ) );
</code></p>

<p>When one of those actions are triggered, I reload my rules.
That works, when one of those triggers.
So probably, once in a while another one triggers that I can't find.
Or maybe the flush happens after the action triggers, rendering my load useless.</p>

<p>So, is there a better way to hook into a flush so that I can add my own rules there automatically?
Now we figure it out a couple of days later when someone complains that the app is not working and I have to load the rules again.</p>

<p>Any suggestions are appreciated.</p>

<p>Cheers</p>