• Resolved franktcmarketing

    (@franktcmarketing)


    Can’t seem to prompt the user to “Login to View” protected content. I have restricted content text with a link to the login page. Want them to click the link on whatever post I have restricted, and then redirect back to the post once logged in.<br>
    I found the option to have the login form to “Refresh active Page” but that just takes them back ( or refreshes )the login page.<br>

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @franktcmarketing

    Does the Login link have the redirect_to in the URL parameter?

    Regards,

    Thread Starter franktcmarketing

    (@franktcmarketing)

    Did not 🙁
    I just wrote or actually used the editors link.
    So it would have looked more like the straight page link.
    website/login

    Thread Starter franktcmarketing

    (@franktcmarketing)

    OK, I looked that up and have it working but will have to enter new message& login link for each protected page and Post.
    I have:
    https://MYWEBSITE/members/login/?redirect_to=https://MYWEBSITE/members/members-area/
    Granted that would still get them logged in and they can find what ever post they were on and not have to login again.
    I can certainly add Custom Restrict message & Link for each new post.
    Like:
    https://MYWEBSITE/members/login/?redirect_to=https://MYWEBSITE/members/New-Post
    However if you can share a link format that would work in the Global Default Message that would not specify a link/page to send them back to but would send them back to whatever page they cam from??

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @franktcmarketing

    Sorry for the late response.’

    Could you please try this code snippet to redirect users back to previous visited page?

    // Login Referrer
    add_action("um_after_login_fields", function(){
        if( isset( $_SERVER['HTTP_REFERER'] ) || isset( $_POST['redirect_to'] ) ){
    
            if( isset( $_POST['redirect_to'] ) ){
                $redirect_to = $_POST['redirect_to'];
            }else{
                $redirect_to = $_SERVER['HTTP_REFERER'];
            }
            echo "<input type='hidden' name='redirect_to' value='".esc_attr( $redirect_to )."'>";
        }
    });

    You can add the code snippet to your theme’s function.php file or use Code Snippet plugin.

    Feel free to re-open this thread by changing the topic status to “Not Resolved” so we can get back to you.

    Regards,

    • This reply was modified 4 years, 3 months ago by Champ Camba.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Cant get user/login to redirect back to protected post.’ is closed to new replies.