Getting URL Variables with a Rewritten Page (Login Page)

Question

As part of a larger project, I am attempting all login activity to occur at the following address:

www.url.com/login

So, a link that should lead to a form that would allow a user to reset their password would be found at the following:

www.url.com/login?action=lostpassword

However, the wp-login.php is not reading this correctly, and when I go to the above address, I get the normal log-in form.

This is how I have it set up:

add_action( 'init', 'add_virtual_page_template' );
function add_virtual_page_template()
{
    global $wp, $wp_rewrite;

    $wp->add_query_var( 'template' );

    add_rewrite_endpoint( 'login', EP_PERMALINK | EP_PAGES );
    add_rewrite_rule( 'login/?', 'index.php?template=login', 'top' );

    add_rewrite_rule( 'login/?', 'index.php?template=login', 'top' );

    $wp_rewrite->flush_rules();
}

add_action( 'template_redirect', 'add_virtual_page_redirect' );
function add_virtual_page_redirect()
{
    global $wp;

    $queryvar = get_query_var('template');

    if ($queryvar && $queryvar == 'login')
    {
        include(site_url('wp-login.php'));
        exit();
    }

    if ($queryvar == 'mylogin')
    {
        include( get_stylesheet_directory() . '/page-login.php' );
        exit();
    }
}

What am I missing?

0
, William 8 years 2013-06-25T19:23:39-05:00 0 Answers 86 views 0

Leave an answer

Browse
Browse