Tuesday, 28 May 2013

URL rewriting must be activated manually for my plugin

URL rewriting must be activated manually for my plugin

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.

No comments:

Post a Comment