• Resolved ayssono

    (@ayssono)


    Hello!

    I have that code activated, which I found here in the support forum:

    // Custom Registration URL
    function my_registration_page( $register_url ) {
        return site_url( '/login/', 'login' );
    }
    add_filter( 'register_url', 'my_registration_page', 10, 1 );
    
    // Custom Login URL
    function my_login_page( $login_url, $redirect ) {
        return site_url( '/login/?redirect_to=' . $redirect );
    }
    add_filter( 'login_url', 'my_login_page', 10, 2 );

    But since the last version 5.6.1. I have a problem. It always redirects again and again and again, but that worked fine before!

    The link looks like this, when Firefox stopped:
    https://DOMAIN/login/?redirect_to=https://DOMAIN/login/?redirect_to=https://DOMAIN/login/?redirect_to=https://DOMAIN/login/?redirect_to=https://DOMAIN/login/?redirect_to=https://DOMAIN/login/?redirect_to=https://DOMAIN/login/?redirect_to=https://DOMAIN/login/?redirect_to=https://DOMAIN/login/?redirect_to=https://DOMAIN/login/?redirect_to=https://DOMAIN/login/?redirect_to=https://DOMAIN/login/?redirect_to=https://DOMAIN/login/?redirect_to=https://DOMAIN/login/?redirect_to=https://DOMAIN/login/?redirect_to=https://DOMAIN/login/?redirect_to=https://DOMAIN/login/?redirect_to=https://DOMAIN/login/?redirect_to=https://DOMAIN/login/?redirect_to=https://DOMAIN/kasse/?add-to-cart=389

    Kind regards,

    Klaus

Viewing 12 replies - 1 through 12 (of 12 total)
  • Thread Starter ayssono

    (@ayssono)

    Hello!
    I checked it again, problem is since version 5.6 and 5.6.1 too.
    With version 5.5 there is no problem, it works fine.
    Kind regards,
    Klaus

    Plugin Author Kevin Vess

    (@kevinvess)

    Hi, thanks for using Force Login!

    I think I know why you’re getting a “too many redirects” error, and it has to do with your custom login page.

    I removed a condition in Force Login 5.6 which checks if you’re visiting the WP login screen because Force Login doesn’t actually run on the default WordPress login screen and hasn’t since version 5.0.

    However, since you’re using a custom page for your login screen–?you will need to tell Force Login to bypass that page.

    If a significant number of Force Login users rely on that condition, I might put the conditional back in. In the meantime, you may continue to use version 5.5 or add the following filter to your site:

    /**
     * Bypass Force Login to allow for exceptions.
     *
     * @param bool $bypass Whether to disable Force Login. Default false.
     * @param string $visited_url The visited URL.
     * @return bool
     */
    function my_forcelogin_bypass( $bypass, $visited_url ) {
      // Allow login screen
      if ( is_page('login') ) {
        $bypass = true;
      }
      return $bypass;
    }
    add_filter( 'v_forcelogin_bypass', 'my_forcelogin_bypass', 10, 2 );
    • This reply was modified 3 years, 5 months ago by Kevin Vess. Reason: Fixed code syntax
    Plugin Author Kevin Vess

    (@kevinvess)

    Also–?I don’t recommend using the /login URL for your custom page; as WordPress already uses that URL to redirect users to their default /wp-login.php URL.

    Plugin Author Kevin Vess

    (@kevinvess)

    Hi–

    Given the amount of feedback I’m getting about this issue, I’ve released a new version which will hopefully help with this issue.

    Thanks!

    Thread Starter ayssono

    (@ayssono)

    Hello!
    Thank you, but I still have the problem.

    My code:

    // Custom Registration URL
    function my_registration_page( $register_url ) {
        return site_url( '/logreg/', 'login' );
    }
    add_filter( 'register_url', 'my_registration_page', 10, 1 );
    
    // Custom Login URL
    function my_login_page( $login_url, $redirect ) {
        return site_url( '/logreg/?redirect_to=' . $redirect );
    }
    add_filter( 'login_url', 'my_login_page', 10, 2 );

    And the installed “Force Login” – version is 5.6.2.

    I still have:
    https://DOMAIN/logreg/?redirect_to=https://DOMAIN/logreg/?redirect_to=https://DOMAIN/logreg/?redirect_to=https://DOMAIN/logreg/?redirect_to=https://DOMAIN/logreg/?redirect_to=https://DOMAIN/logreg/?redirect_to=https://DOMAIN/logreg/?redirect_to=https://DOMAIN/logreg/?redirect_to=https://DOMAIN/logreg/?redirect_to=https://DOMAIN/logreg/?redirect_to=https://DOMAIN/logreg/?redirect_to=https://DOMAIN/logreg/?redirect_to=https://DOMAIN/logreg/?redirect_to=https://DOMAIN/logreg/?redirect_to=https://DOMAIN/logreg/?redirect_to=https://DOMAIN/logreg/?redirect_to=https://DOMAIN/logreg/?redirect_to=https://DOMAIN/logreg/?redirect_to=https://DOMAIN/logreg/?redirect_to=https://DOMAIN/kasse/

    Kind regards,

    Klaus

    Plugin Author Kevin Vess

    (@kevinvess)

    Hi–

    Force Login is a simple plugin, designed to work with the default WordPress login, lost-password, and register screens.

    Since you’re using a custom registration URL/process, you’ll need to use the v_forcelogin_bypass filter to allow Force Login to bypass your custom URLs.

    Please check out the FAQs for examples of how to add an exception for pages.

    You may also reference this Github issue about this topic:
    https://github.com/kevinvess/wp-force-login/issues/33

    Thanks!

    Thread Starter ayssono

    (@ayssono)

    Hi!

    So I have to use both filters or only the v_forcelogin_bypass?
    And if I have to use both filters, is the order of the filters important?

    // Custom Registration URL
    function my_registration_page( $register_url ) {
        return site_url( '/logreg/', 'login' );
    }
    add_filter( 'register_url', 'my_registration_page', 10, 1 );
    
    // Custom Login URL
    function my_login_page( $login_url, $redirect ) {
        return site_url( '/logreg/?redirect_to=' . $redirect );
    }
    add_filter( 'login_url', 'my_login_page', 10, 2 );
    
    /**
     * Bypass Force Login to allow for exceptions.
     *
     * @param bool $bypass Whether to disable Force Login. Default false.
     * @param string $visited_url The visited URL.
     * @return bool
     */
    function my_forcelogin_bypass( $bypass, $visited_url ) {
      // Allow all single posts
      if ( is_single() ) {
        $bypass = true;
      }
    
      // Allow these absolute URLs
      $allowed = array(
        home_url( '/logreg/' ),
      );
      if ( ! $bypass ) {
        $bypass = in_array( $visited_url, $allowed );
      }
    
      return $bypass;
    }
    add_filter( 'v_forcelogin_bypass', 'my_forcelogin_bypass', 10, 2 );

    Kind regards,

    Klaus

    Thread Starter ayssono

    (@ayssono)

    Hello!

    Ok, I made two plugins.

    Plugin ONE with this code:

    /**
     * Bypass Force Login to allow for exceptions.
     *
     * @param bool $bypass Whether to disable Force Login. Default false.
     * @param string $visited_url The visited URL.
     * @return bool
     */
    function my_forcelogin_bypass( $bypass, $visited_url ) {
      // Allow all single posts
      if ( is_single() ) {
        $bypass = true;
      }
    
      // Allow these absolute URLs
      $allowed = array(
        home_url( '/logreg/' ),
      );
      if ( ! $bypass ) {
        $bypass = in_array( $visited_url, $allowed );
      }
    
      return $bypass;
    }
    add_filter( 'v_forcelogin_bypass', 'my_forcelogin_bypass', 10, 2 );

    Plugin TWO with this code:

    // Custom Registration URL
    function my_registration_page( $register_url ) {
        return site_url( '/logreg/', 'login' );
    }
    add_filter( 'register_url', 'my_registration_page', 10, 1 );
    
    // Custom Login URL
    function my_login_page( $login_url, $redirect ) {
        return site_url( '/logreg/?redirect_to=' . $redirect );
    }
    add_filter( 'login_url', 'my_login_page', 10, 2 );

    Both activated, but I still have the same problem…

    Kind regards,

    Klaus

    Plugin Author Kevin Vess

    (@kevinvess)

    When you use the register_url filter, you are ensuring that anywhere the wp_registration_url() function is used,?it will return your custom registration URL instead. This does not affect Force Login.

    Force Login does not reference the wp_registration_url() function since the plugin does not run on the default WordPress login or registration screen.

    You’ll need to use the v_forcelogin_bypass filter to allow Force Login to bypass your custom registration URL.

    Also, I don’t recommend you copy the FAQ example code verbatim, unless you want to allow all single posts and the array of URLs to be publicly accessible.

    Plugin Author Kevin Vess

    (@kevinvess)

    First, I recommend you try coding the bypass code like this:

    /**
     * Bypass Force Login to allow for exceptions.
     *
     * @param bool $bypass Whether to disable Force Login. Default false.
     * @param string $visited_url The visited URL.
     * @return bool
     */
    function my_forcelogin_bypass( $bypass, $visited_url ) {
      // Allow these absolute URLs
      $allowed = array(
        wp_registration_url(),
      );
      if ( ! $bypass ) {
        $bypass = in_array( $visited_url, $allowed );
      }
    
      return $bypass;
    }
    add_filter( 'v_forcelogin_bypass', 'my_forcelogin_bypass', 10, 2 );

    Second, you’ll need to run some tests to confirm if your bypass code/plugin is actually running before we can make assumptions about where the issue is.

    Third, it appears your custom register_url and login_url are actually the same page URL. Therefore, you shouldn’t need the Force Login bypass filter because Force Login already bypasses the login_url page.

    It will be difficult for me to troubleshoot your code without access to your site and the hosting environment. I recommend you consult with a web developer and give them access to your site to troubleshoot your custom code/plugins.

    Good luck!

    Thread Starter ayssono

    (@ayssono)

    Hello!

    Ok, with the activated “Force Login” Plugin and the Bypass-Code you wrote in the thread with the custom page-url I can see that page now. That works fine.

    But if I use any other page, it doesn’t forward the user to this custom page-url, it forwards the user to the default login page.

    And I thought, that would work with the other code you wrote too. But I always get the forwarding-problem.

    Kind regards,

    Klaus ??

    • This reply was modified 3 years, 5 months ago by ayssono.
    Thread Starter ayssono

    (@ayssono)

    Hello!

    You can set the thread on RESOLVED.

    Because from your site, the BYPASS – Filter was the helpful code.
    For Login-Redirect I found another code.

    Thank you for your patience and help!

    Kind regards,

    Klaus

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Since 5.6.1: Problem with custom login page’ is closed to new replies.