I am creating a WordPress plugin which create pages (with get_header()
, get_footer()
and get_sidebar()
) for searching through an API.
Of course, I have defined some rules for URL rewriting like this:
function init() {
global $wp_rewrite;
add_rewrite_rule('my_plugin/(.+)/results?', 'index.php?my_plugin=results&data=$matches[1]', 'top');
...
$wp_rewrite->flush_rules();
}
This function is called with this line in the constructor of my plugin:
add_action('init', array(&$this, 'init'));
The plugin works perfectly but I need to activate manually URL rewriting in Settings > Permalinks in my Admin Dashboard. I need only to select one option: Day and name, Month and name, Numeric,… (whatever).
The problem is that when I install the plugin on a new WordPress with Permalinks disable (Default), I am getting always a 404 error. This will only work if I activate manually Permalinks.
(I know this is done by the .htaccess).
Is there is a way to bypass this or to activate automatically Permalinks through my plugin ?
Other good solution is welcome.
I hope my question is clear.
Thank you.
Whenever I create a plugin that needs permalinks enabled i check on the plugin activation and if its not set i display a message for the user:
I found the code.