Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

SchwarzwaldFalke on "add_rewrite_rule if permalinks are disabled"

$
0
0

Hi,

I'm working on a simple wordpress plugin for my university, which uses some rewrite rules. Currently I try to rewrite all requests to wp-login.php to a post with a custom post type. This is absolutly easy with directly adding the rewrite rule to the .htaccess file, but I have some problems with the Rewrite API of WordPress.

So what I'm currently doing is the following:

In the constructor of my plugin:

add_action( 'init', array( 'Fum_Redirect', 'redirect_wp_login' ) );

The called function:

$page = get_page_by_title( 'Title', OBJECT, 'fum_post' );
$ID   = $page->ID;
add_rewrite_rule( 'wp-login\.php.*$', '?p=' . $ID, 'top' );
flush_rewrite_rules();

I know that it's bad practice to call flush_rewrite_rules(); on each reload, it's just for testing.

First problem:
If I disable permalinks (set to "Standard"), WordPress clears the complete .htaccess file. It does NOT add my rewrite_rule, so wp_login is not redirected.

Second problem:
WordPress seems to ignore the flush_rewrite_rules() in my function, it does not change the .htaccess file if I change the parameters of my add_rewrite_rule call.
But if I change the permastructure in the dashboard, it adds my new rewrite rule.

Maybe I missunderstand something in the Rewrite API, hopefully you can tell me what's the problem!

Best Regards,
Chris


Viewing all articles
Browse latest Browse all 8245

Trending Articles