R
R
Rokis2015-11-13 15:24:08
PHP
Rokis, 2015-11-13 15:24:08

How to remove the redirect when there is a data entry error when registering Wordpress?

I have code that redirects to my modal window:

function redirect_reg_page() {  
    $reg_page  = home_url( '/#join_form' );  
    $page_viewed = basename($_SERVER['REQUEST_URI']);  
  
    if( $page_viewed == "wp-login.php?action=register" && $_SERVER['REQUEST_METHOD'] == 'GET') {  
        wp_redirect($reg_page);  
        exit;  
    }  
}  
add_action('init','redirect_reg_page');

In case of erroneous data entry in this modal window (registration) - it redirects to the standard registration page and an error message is displayed. How can I remove this redirect and why doesn't my redirect work in this situation?
The modal window itself has the following code:
<div class="popup">
            <p>Регистрация</p>
            <p>Пожалуйста заполните все поля</p>
      <form name="registerform" action="http://mysite.ru/wp-login.php?action=register" method="post" novalidate="novalidate">
  <div><p>
    <label for="user_login">Имя пользователя<br>
    <input id="firstname" type="text" name="user_login" value="" size="30"></label>
  </p></div>
  <div><p>
    <label for="user_email">E-mail<br>
    <input id="email" type="email" name="user_email" value="" size="30"></label>
  </p></div>
    <p id="reg_passmail">Пароль будет отправлен вам на e-mail.</p>
  <p class="submit"><input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="Регистрация"></p>
</form>
            
            <a class="close" href="#close"></a>
        </div>

The same situation with the entrance, with changing the password and getting the password. Please tell me how to fix? I'm trying to get rid of standard pages.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rokis, 2015-11-13
@Rokis

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;   
    }
}

R
Ravshan Abdulaev, 2015-11-13
@ravshanium

similar situation:
wordpress.stackexchange.com/questions/21765/redire...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question