Wordpress?登录=失败

时间:2015-02-06 15:57:35

标签: php wordpress login

我已经在wordpress中创建了一个自定义登录页面,并将下面的代码添加到我的模板functions.php,以防止当有人输入错误的密码或空白字段时,自定义登录页面会重定向到wp-login页面。登记/> 问题是,如果有人输入了错误的凭据,然后重新输入了正确的信息,则自定义登录页面仍会在URL的末尾保留/?login=failed字符串。
例如,它应该类似于www.something.com/customlogin/ 但即使他们登录,它也会显示www.something.com/customlogin/?login=failed。你能告诉我是否与下面的代码有关。感谢

add_action( 'wp_login_failed', 'custom_login_failed' );
function custom_login_failed( $username )
   {
    $referrer = wp_get_referer();

    if ( $referrer && ! strstr($referrer, 'wp-login') && ! strstr($referrer,'wp-admin') )
    {
        wp_redirect( add_query_arg('login', 'failed', $referrer) );
        exit;
    }
}



add_filter( 'authenticate', 'custom_authenticate_username_password', 30, 3);
function custom_authenticate_username_password( $user, $username, $password )
{
    if ( is_a($user, 'WP_User') ) { return $user; }

    if ( empty($username) || empty($password) )
    {
        $error = new WP_Error();
        $user  = new WP_Error('authentication_failed', __('<strong>ERROR</strong>: Invalid username or incorrect password.'));

        return $error;
    }
}

更新

    

    <?php global $user_login;
    if(isset($_GET['login']) && $_GET['login'] == 'failed')
    {
        ?>
            <div class="aa_error">
                <p>Incorrect Password, Please Try again! If you have forgotten your password, please contact Sunday Capital and we will reset it manually. Thank You.</p>
            </div>
        <?php
    }
        if (is_user_logged_in()) {
            echo '<div class="aa_logout"> Welcome ', $user_login, '. <div class="aa_logout_user"><a id="wp-submit" href="', wp_logout_url( home_url() ), '" title="Logout">Click here to Log Out.</a></div></div>';
        } else {
             wp_login_form($args);

                  $args = array(
                            'echo'           => true,
                            'redirect'       => home_url('/account-access/'), 
                            'form_id'        => 'loginform',
                            'label_username' => __( 'Username' ),
                            'label_password' => __( 'Password' ),
                            'label_remember' => __( 'Remember Me' ),
                            'label_log_in'   => __( 'Log In' ),
                            'id_username'    => 'user_login',
                            'id_password'    => 'user_pass',
                            'id_remember'    => 'rememberme',
                            'id_submit'      => 'wp-submit',
                            'remember'       => true,
                            'value_username' => NULL,
                            'value_remember' => true
                            ); 
        }

    ?> 

</section>
<!-- /section -->

1 个答案:

答案 0 :(得分:0)

这是我在登录后删除/?login =失败字符串的解决方案。也许有人可以使用它。

<?php global $user_login;
if(isset($_GET['login']) && $_GET['login'] == 'failed')
    {
        $new_url = esc_url( remove_query_arg( 'login' ) );
            $login = array(
                'remember' => false,    
                'redirect' => $new_url,                         
                'label_username' => '',
                'label_password' => '',
                'id_username'    => 'user_login_failed',
                'id_password'    => 'user_pass_failed'
            );


     } else { 

            $login = array(
                'remember' => false,                                
                'label_username' => '',
                'label_password' => ''
            );
    } ?>
<?php wp_login_form($login); ?>