'index.php?m=' . $wp_rewrite->preg_index(2) . $wp_rewrite->preg_index(1),
"date/(\d{4})" => 'index.php?year=' . $wp_rewrite->preg_index(1)
);
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules; //NOTE: You must add it to the start of the array, Else WP's greedy rules at the end of the array will eat the request
}
register_activation_hook( __FILE__, 'flush_rules_initiate' );
register_deactivation_hook( __FILE__, 'test_flush_rules' );
// add_action('init','test_flush_rules'); // for testing
function flush_rules_initiate() {
// Add the permalink override stuff
add_action('generate_rewrite_rules', 'test_add_rewrite_rules');
test_flush_rules();
}
function test_flush_rules(){
//Flush the rewrite rules so that the new rules from this plugin get added,
//This should only be done when the rewrite rules are changing, Ie. When this plugin is activated(Or Deactivated), For simplicity while developing using WP Rewrite, I flush the rules on every page load
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
?>