Redirect after login in Wordpress

1

I created a new type of user with the buyer role in wordpress whenever a new user is registered the even receives two links, one to change the password and another that directs to a login screen, I'm having trouble in this part, the each user registered with the buyer role Wordpress sends these links, the login when clicks directs to login screen and when it is logged in it redirects to the subscriber panel where the profile changes and such, except that such buyer permission must be redirected to a specific URL which is the file responsible for sending that link so that I can change the redirect URL, or is there another solution? how could I do that?

    
asked by anonymous 10.01.2018 / 18:53

2 answers

1

In order to work, you have to send a parameter to the URL of the email as a URL to the example login: link

Remember to put the URL encoded . And put this code in the functions.php of your current theme.

add_action('login_form', 'redirect_after_login');
function redirect_after_login()
{
    global $redirect_to;
    if   (isset($_GET['url']))
    {
        $redirect_to =   $_GET['url'];
    }
}
    
11.01.2018 / 12:30
1

jQuery(document).ready(function($){
        $("#loginform").on('submit', function() {
            var input_data = $('#loginform').serialize();
            $.ajax({
                type: "POST",
                url: "<?php echo site_url('wp-login.php','login_post'); ?>",
                data: input_data,
                success: function(msg) {
                    var reg1 = /login_error/g;
                    if (reg1.test(msg)) {
                         $('#message').html("Usuário ou senha incorretos.");
                    } else {
                        window.location = "http://url-que-voce-deseja-enviar-o-usuario.com.br";
                    }
                }
            });
            return false;
        });
    });
    
11.01.2018 / 09:24