I know queries about rewrite rules not working correctly are very common, but in my case I am actually unable to get rules to create in the first place. I need to create a plugin that will be loaded into a number of sites and provide some common functionality to each site. One of those functions it will provide is to create a rewrite rule common to those sites. At this point, I have whittled down the test example to the following:
Debian server running apache 2.4.x, php 5.6.3x, wordpress 4.9.4 using mysql database. The wordpress install is a clean unzipped copy of the source with no plugins enabled. It’s just been brought to the point of finishing the initial setup. The apache vhost is set up to AllowOverrides All, but the issue here isn’t even with .htaccess writing because I do see wordpress updating the .htaccess file to show the following (but never putting rules in it):
# BEGIN WordPress
# END WordPress
I created a plugin in wp-content/plugins/test-plugin/test-plugin.php.
After gradually pulling away pieces of code, I have it running only this code in the test plugin file now:
echo “test”; // Just to see that the function is being called
Obviously this is stupid code simply to try to isolate where the rewrite API is failing. When I load the index of the site, the code is running because I do see the “test” output as well as the var_dump() output. In all cases, however, the var_dump() output is an array with no values in it. Any variations of ordering the flush_rules (or not using it, etc) seems to have no effect.
I am also looking in the database and doing SELECT * FROM wp_options WHERE option_name = ‘rewrite_rules’. The row exists but the value of the option is never being populated.
I had initially tried to set this up on a site with existing code but now I am using a fresh naked install with only the above plugin included (and yes, it’s active) and I am just not getting these rules. Can someone tell me what I am missing here?
Read more here:: WordPress Rewrite API calls not creating new rules