• Resolved meadows19

    (@meadows19)


    Hello,

    I’m having trouble with this excellent plugin, and I hope you can offer me some suggestions.

    I have two sites: https://staging.example.com/
    and https://www.example.com/members/

    I have a plugin that sends users an email link containing ?crfw_cart_hash=
    I want that link to go through, and have configured it as follows:

      // whitelist URL if query string contains 'parameter'
    
    if ( (isset($_GET['rcpga-invite-key']) || isset($_GET['crfw_cart_hash'])) ) 
      {
        $whitelist[] = site_url($_SERVER['REQUEST_URI']);
      }
    
      return $whitelist;
    }

    Now the problem is that it works fine on the staging site, but doesn’t work on the live site. On the live site, it sends me back to the login page.

    The link to the staging site looks like:
    https://staging.example.com/?crfw_cart_hash=bE&crfw_email=jimbob%2Bcart123%40gmail.com&crfw_action=checkout

    And the link to the live site looks like:
    https://www.example.com/members?crfw_cart_hash=y4&crfw_email=jimbob%2B999%40gmail.com&crfw_action=checkout

    I’ve tried putting a trailing slash after the word ‘members’ in this URL, but that doesn’t work either.

    Do you have any idea what could be wrong?

    Thanks for your help!

    • This topic was modified 8 years ago by meadows19.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter meadows19

    (@meadows19)

    see post below

    • This reply was modified 8 years ago by meadows19.
    Thread Starter meadows19

    (@meadows19)

    I tried it on the live site, with the Whitelist plugin disabled (email link works as expected) and enabled (link doesn’t work, and redirects to login page).

    The redirection traceroute is the exact same, except with the Whitelist plugin disabled, it stops here:

    301 Redirect
    https://www.example.com/members/gold/?crfw_cart_hash=y4&crfw_email=jimbob%2B999%40gmail.com&crfw_action=checkout&crfw_redirected=1

    but with the Whitelist plugin enabled, it adds one final step to the end:

    302 Redirect
    https://www.example.com/members/login/

    Plugin Author Kevin Vess

    (@kevinvess)

    I’m not sure why whitelisting the URL based on the existence of those query string parameters is only working on your staging site.

    I’m fairly certain the trailing slash is not the cause –?the site_url($_SERVER['REQUEST_URI']); line returns whatever the full URL is, regardless of trailing slashes.

    However, since your URL structures are different between your staging and live sites – maybe try the v_forcelogin_bypass filter instead?

    /**
     * Bypass Force Login to allow for exceptions.
     *
     * @return bool Whether to disable Force Login. Default false.
     */
    function my_forcelogin_bypass( $bypass ) {
      if ( isset($_GET['rcpga-invite-key']) || isset($_GET['crfw_cart_hash']) ) {
        $bypass = true;
      }
      return $bypass;
    }
    add_filter('v_forcelogin_bypass', 'my_forcelogin_bypass', 10, 1);
    Thread Starter meadows19

    (@meadows19)

    Thank you very much Kevin. Using the v_forcelogin_bypass as you suggested does seem to solve the problem!

    My last question is: I now have two separate plugins. The one you wrote above using v_forcelogin_bypass and another one using v_forcelogin_whitelist as follows:

    <?php
    
    function my_forcelogin_whitelist( $whitelist ) {
    
      // these pages can be accessed without logging in
    
      $whitelist[] = site_url( '/login/' );
      $whitelist[] = site_url( '/bronze/' );
      $whitelist[] = site_url( '/silver/' );
      $whitelist[] = site_url( '/gold/' );
    
      return $whitelist;
    }
    
    add_filter('v_forcelogin_whitelist', 'my_forcelogin_whitelist', 10, 1);

    Can I combine them both into a single plugin, and if so, do I just paste them into one file?

    Thanks again Kevin.

    Plugin Author Kevin Vess

    (@kevinvess)

    Great, I’m glad that worked!

    Can I combine them both into a single plugin, and if so, do I just paste them into one file?

    Yes, you may paste both filter codes into one plugin file, or you may add them to your theme’s functions.php file and not use a plugin at all. Totally up to you how you want to add these filters to your WordPress install.

    Be sure to rate and review my plugin to let others know how you like it.

    Thanks for using Force Login!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Problem with trailing slash?’ is closed to new replies.