Support » Plugins » Hacks » Go back two pages and refresh

Viewing 8 replies - 1 through 8 (of 8 total)
  • easy…

    add_action('init', 'rcp_login_form_fields_init');
    
    function rcp_login_form_fields_init(){
    
        if(!is_user_logged_in()) {
              auth_redirect();	//redirect to login page, this also handles redirecting
                                            // them back to the current page when they've logged-in
              exit;	//finished!
        }
    }

    if this isn’t what your after, have a look at how this is achieved, you might be able to replicate the wordpress function i.e.:
    /wp-includes/pluggable.php Line 742

    Thread Starter Wheelie111

    (@wheelie111)

    Hello Simon,

    Thanks for you swift reply!

    I tried your solution, I assume it was meant for functions.php, but the entire
    website stopped working after I placed it in there.

    Did I do something wrong?

    Yeah, I would place it in functions.php of your theme
    I just tried the code above and it just loop around.
    So we need to identify if the user is on a login page to break the redirect.
    Try this.

    add_action('init', 'rcp_login_form_fields_init');
    
    function rcp_login_form_fields_init(){
        if(!is_user_logged_in() && !rcp_login_form_fields_is_login_page()) {
              auth_redirect();	//redirect to login page, this also handles redirecting
                                            // them back to the current page when they've logged-in
              exit;	//finished!
        }
    }
    
    function rcp_login_form_fields_is_login_page() {
        return in_array($GLOBALS['pagenow'], array('wp-login.php', 'wp-register.php'));
    }

    see if this example gives you any joy.

    Thread Starter Wheelie111

    (@wheelie111)

    Hi,

    Thanks again but unfortunately it still crashes.
    Safari and Firefox give an error saying that the login page has too many redirects.

    Thats strange, I’m not getting that error anymore…?
    double check that you’ve added the extra function and clause in the if statement.

    if(!is_user_logged_in() && !rcp_login_form_fields_is_login_page())

    if there’s still no joy, debug it by putting the follow inside the rcp_login_form_fields_init function:

    var_dump(rcp_login_form_fields_is_login_page());
    exit;

    it should return true if the url is on wp-login.php or wp-register.php

    Thread Starter Wheelie111

    (@wheelie111)

    I must be doing something because it still crashes and burns with the same error. [ redacted, support is offered via the forum and not email or Skype. ]

    but just check first that the code you are amending is the right file.
    if you remove all the code we just added, are you still getting the issue.

    Thread Starter Wheelie111

    (@wheelie111)

    Thanks again Simon!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Go back two pages and refresh’ is closed to new replies.