R
R
Rokis2015-11-14 11:39:20
PHP
Rokis, 2015-11-14 11:39:20

How to remove a redirect when there is a data entry error while logging in to a Wordpress account?

I have code that redirects to my modal window:

function redirect_login_page() {  
  $login_page  = home_url( '/#login_form' );  
    $page_viewed = basename($_SERVER['REQUEST_URI']);  
  
    if( $page_viewed == "wp-login.php" && $_SERVER['REQUEST_METHOD'] == 'GET') {  
        wp_redirect($login_page);  
        exit;  
    }  
}  
add_action('init','redirect_login_page');

In case of erroneous data entry in this modal window (Login to account) - it redirects to the standard wp-login.php login page and an error message is displayed. How to remove this redirect and leave everything in my modal window.
Window code:
<div class="popup">
            <p>Добро пожаловать!</p>
            <?php  /* Панель входа на сайт */
global $user_ID, $user_identity;
get_currentuserinfo();
if (!$user_ID): ?>
      <form name="loginform" action="<?php echo get_settings('siteurl'); ?>/wp-login.php" method="post">
      <div><p>Логин<br /><input type="text" id="login" name="log" value="" size="30" /></p></div>
      <div><p>Пароль<br /> <input type="password" id="password" name="pwd" value="" size="30" /></p></div>
      <input type="hidden" name="rememberme" value="forever" />
      <input type="submit" name="submit" value="Войти &raquo;" />
      <input type="hidden" name="redirect_to" value="<?php echo $_SERVER['REQUEST_URI']; ?>"/>
    </form>  
<?php else: ?>
  Добро пожаловать, <?php echo $user_identity; ?>
    <a href="<?php echo wp_logout_url( get_permalink() ); ?>">Выйти</a>
<?php endif; ?>
            

            <a class="close" href="#close"></a>
        </div>

There is a code that fixes registration, but I can’t figure out which variables to replace so that it works for logging in, changing a password, getting a password:
add_action('register_post', 'binda_register_fail_redirect', 99, 3);

function binda_register_fail_redirect( $sanitized_user_login, $user_email, $errors ){
    //this line is copied from register_new_user function of wp-login.php
    $errors = apply_filters( 'registration_errors', $errors, $sanitized_user_login, $user_email );
    //this if check is copied from register_new_user function of wp-login.php
    if ( $errors->get_error_code() ){
        //setup your custom URL for redirection
        $redirect_url = get_bloginfo('url') . '/registrace';
        //add error codes to custom redirection URL one by one
        foreach ( $errors->errors as $e => $m ){
            $redirect_url = add_query_arg( $e, '1', $redirect_url );    
        }
        //add finally, redirect to your custom page with all errors in attributes
        wp_redirect( $redirect_url );
        exit;   
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Chesnokov, 2015-11-18
@Rokis

wordpress.stackexchange.com/a/105224

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question