Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

If you want instead of redirect to wp-login the user redirect to login page then use the following code. It will redirect user to login page where login form is present.

add_filter('site_url',  'wplogin_filter', 10, 3);
function wplogin_filter( $url, $path, $orig_scheme ){
    $old = array( "/(wp-login\.php)/");
    $new = array( "login/");
    return preg_replace( $old, $new, $url, 1);
}

add_action('init','possibly_redirect');
function possibly_redirect(){
    global $pagenow;
    if( 'wp-login.php' == $pagenow ){
        wp_redirect(site_url( $path = 'login'));
    exit();
    }
}

In login form ckeck the value of action. For login use wp_signon() function.

if(!isset($_REQUEST['action'])) { ?>
      <div>Login with the Email
        <form id="login-form" action="<?php echo $_SERVER['REQUEST_URI'] ?>" method="post">
          <table style="float: left;">
            <tr>
              <td><label>User Name</label></td>
              <td>
                <input type="text" name="user_name" id="user_name" placeholder="Enter your username">
              </td>
            </tr>
            <tr>
              <td><label>Password</label></td>
              <td>
                <input type="password" name="password" id="password" placeholder="Enter password"><br>
                <a href="<?php echo site_url('login/?action=lostpassword') ?> "> Forgot Your Password ? </a><br>
              </td>
            </tr>
            <tr>
              <td></td>
              <td><input type="submit" name="submit" id="login-submit" value="Login"></td>
            </tr>
          </table>
        </form>
<?php
}

For lost password. Create form in the same login page

if(isset($_REQUEST['action']) && 'lostpassword'== $_REQUEST['action'])
{
  ?>

  <div id="tab3_login" class="tab_content_login" >
   <p>Enter your username or email to reset your password.</p>
   <form method="post" action="<?php echo site_url('login/?action=tg_pwd_reset') ?>" class="wp-user-form">
    <div class="username">
      <label>Username or Email : </label>
      <input type="text" name="user_login" value="" size="20" id="user_login" />
      <?php toolTip('user_login', 'Username');?>
    </div>
    <input type="submit" name="user-submit" value="<?php _e('Reset my password'); ?>" class="user-submit" tabindex="1002" />
  </form>
</div>
<?php
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.