I've been plodding my way through creating a custom 'non_wp_rules' for the past day or so. Obviously, http://codex.wordpress.org/Function_Reference/WP_Rewrite has been a huge help.
I am able to to get the rewrite working as intended, but only by going to options-permalink.php and manually saving out the Permalinks options. At that point, my .htaccess file is updated, including my rule right after RewriteBase and before the first RewriteCond:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^find/(this)$ /addit.php?here=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
My question is how do I mimic the manual save step at options-permalink.php when saving my theme options to enable / disable the non-WordPress rewrite?
Here is my code in my theme's functions.php:
function ftc_flush_rewrites() {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
function ftc_add_rewrites() {
global $wp_rewrite;
$ftc_new_non_wp_rules = array(
'find/(this)' => '/addit.php?here=$1',
);
$wp_rewrite->non_wp_rules = $ftc_new_non_wp_rules + $wp_rewrite->non_wp_rules;
}
add_action('init', 'ftc_flush_rewrites');
add_action('generate_rewrite_rules', 'ftc_add_rewrites');
I understand that the $wp_rewrite->flush_rules(); in my ftc_flush_rewrites function is supposed to write to the .htaccess file with the implied 'hard' flush, but why is it not actually being written until I force it by a manual save at options-permalink.php?
Sorry this is such a long post! Just trying to be thorough. ;)