• Resolved marlonsabala

    (@marlonsabala)


    Hi everyone,

    Let me start by saying this plugin has been really helpful to me. It is now a crucial part of how my site works.

    I have a problem though. Notice the following code:

    
    /**
     * Filter Force Login to allow exceptions for specific URLs.
     *
     * @return array An array of URLs. Must be absolute.
     */
    function my_forcelogin_whitelist( $whitelist ) {
      $whitelist[] = site_url( '/member/' );
      $whitelist[] = site_url( '/product/platinum-bundle/' );
      $whitelist[] = site_url( '/one-to-one-lessons/' );
      $whitelist[] = site_url( '/buy-weekly-lessons/' );
      $whitelist[] = site_url( '/buy-by-weekly-lessons/' );
      $whitelist[] = site_url( '/buy-packaged-lessons/' );
      $whitelist[] = site_url( '/quizzes/audio_test_quiz/' );
      $whitelist[] = site_url( '/babies/' );
      return $whitelist;
    }
    add_filter('v_forcelogin_whitelist', 'my_forcelogin_whitelist', 10, 1);

    everything was working quite well, but now some of those pages are blocked and some are not.
    The member page for example sends me to the login page.

    It doesn’t seem to be a caching issue as some new URLs can be added without this issue.

    Any ideas? I’m going a bit crazy with this.

    Thanks in advance,
    Marlon

    • This topic was modified 5 years, 11 months ago by marlonsabala.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Kevin Vess

    (@kevinvess)

    Hi– thanks for using Force Login!

    The issue is with your URL paths and how your web server handles loading these pages. Specifically, the use of a trailing slash.

    For example, your member page example links without a trailing slash /member but your whitelist code includes the trailing slash:

    $whitelist[] = site_url( '/member/' );

    If you include the trailing slash in the link, it works.

    Suggested Fixes

    Instead of updating your whitelist code to include URLs both with and without trailing slashes, I recommend at least one of the following:

    1. Use the v_forcelogin_bypass filter instead and the is_page() Conditional Tag to bypass Force Login for certain pages (see example below).
    2. Fix your web host configuration to dynamically add the trailing slash to WordPress URLs. Check that your htaccess file is properly configured and any redirect rules are listed before your default WP rule.
    /**
     * Bypass Force Login to allow for exceptions.
     *
     * @return bool Whether to disable Force Login. Default false.
     */
    function my_forcelogin_bypass( $bypass ) {
      // page slugs to allow public access
      $allowed = array(
        'member',
        'platinum-bundle',
        'one-to-one-lessons',
        'buy-weekly-lessons',
      );
    
      // allow public access to specified pages
      if ( is_page( $allowed ) ) {
        $bypass = true;
      }
      return $bypass;
    }
    add_filter( 'v_forcelogin_bypass', 'my_forcelogin_bypass' );
    Thread Starter marlonsabala

    (@marlonsabala)

    That makes total sense now!

    The URLs I was struggling with were the ones I was typing manually and so didn’t have the last slash.

    Thanks so much for taking the time to answer this.

    Great plugin once more. Crucial for me! Do you accept donations?

    Plugin Author Kevin Vess

    (@kevinvess)

    Excellent– I’m glad I was able to help.

    I do accept donations and they’re greatly appreciated!
    Donate Here ›

    Also, be sure to rate and review my plugin to let others know how you like it.

    Thanks for using Force Login!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Prejudice to what? (whitelist issue)’ is closed to new replies.