A common problem with rewrite rules added in a theme is that there is no obvious hook on which you can flush the rewrite rules. The problem is getting harder when you update a theme with new code that includes new rewrite rules.
It seems like a good solution to the problem might be to detect if the rewrite rule exists and if it doesn’t to flush the rules. So how can I check if a rule already exists?
If I understand correctly then you can hook into the rewrite api/process and flush or manipulate the rules that way?
Read: Plugin Hooks on this page
http://codex.wordpress.org/Function_Reference/WP_Rewrite
Maybe something like:
// flush_rules() if our rules are not yet included
function my_flush_rules()
{
$rules = get_option( 'rewrite_rules' );
if ( ! isset( $rules['(project)/(\d*)$'] ) ) {
global $wp_rewrite; $wp_rewrite->flush_rules();
}
}
add_action( 'wp_loaded','my_flush_rules' );