• Resolved christinecoulon

    (@christinecoulon)


    Hey there,

    I’m having trouble with a redirect loop when trying to use the forgot password link.

    I have created a custom login page and set up a separate redirect to redirect wp-login.php to my custom login page which is working fine.

    When I disable the Force Login plugin on my site then my ‘Lost Password’ link works perfectly.

    Here are my urls:

    Login Page: https://printforge.co.za/harcourts/login
    Lost Password: https://printforge.co.za/harcourts/lost-password

    I’ve added the below code to my functions.php thinking it would fix the problem but it’s still not working. I’m not sure where I’m going wrong. Please help.

    function my_forcelogin_bypass( $bypass, $visited_url ) {
    
    	// Allow all single posts
      if ( is_single() ) {
        $bypass = true;
      }
    	
      // Allow these absolute URLs
      $allowed = array(
    	home_url( '/lost-password/' ),
      );
      if ( ! $bypass ) {
        $bypass = in_array( $visited_url, $allowed );
      }
    
      return $bypass;
    }
    add_filter( 'v_forcelogin_bypass', 'my_forcelogin_bypass', 10, 2 );

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Kevin Vess

    (@kevinvess)

    Hi, thanks for using Force Login!

    Since you’re using custom login and forgot password URLs, you’ll need to use the bypass filter to tell Force Login to allow visits to those pages.

    I recommend you try the following code with the is_page() conditional function:

    /**
     * Bypass Force Login to allow for exceptions.
     *
     * @param bool $bypass Whether to disable Force Login. Default false.
     * @return bool
     */
    function my_forcelogin_bypass( $bypass ) {
    
      // Allow custom login & lost-password pages
      if ( is_page( array( 18681, 'lost-password' ) ) ) {
        $bypass = true;
      }
    
      return $bypass;
    }
    add_filter( 'v_forcelogin_bypass', 'my_forcelogin_bypass' );

    Good luck!

    Thread Starter christinecoulon

    (@christinecoulon)

    Hi Kevin,

    Thanks so much for the quick response.

    I’ve added the suggested code to my functions.php but it’s still only redirecting me back to the login page: https://printforge.co.za/harcourts/login/?redirect_to=https%3A%2F%2Fprintforge.co.za%2Fharcourts%2Flost-password%2F

    Is there anything else I could try?

    Plugin Author Kevin Vess

    (@kevinvess)

    My example code used the page slug 'lost-password' but you can try using the page ID instead; like how I used the custom login page ID 18681 in the array of allowed pages.

    Unfortunately, I can’t really troubleshoot this without access to your website.

    I recommend you hire a web developer to help you customize this for your site.

    Good luck!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Force Login Redirect Loop for Forgot Password’ is closed to new replies.