• Resolved courtneyhuber

    (@courtneyhuber)


    Had this code set up and working in my functions.php file, then we recently migrated our site to a new hosting company. During that migration, the wp-config file was not migrated with the site, so the code didn’t come over in the functions. I re-added the code to the functions.php from a backup of the site, but the whitelisted URLs are still forcing login. Confused at why this exact code used to work, but on a new server, it doesn’t? Nothing else changed.

    /**
     * Filter Force Login to allow exceptions for specific URLs.
     *
     * @param array $whitelist An array of URLs. Must be absolute.
     * @return array
     */
    function my_forcelogin_whitelist( $whitelist ) {
      $whitelist[] = 'https://www.advisorsexcel.com/events/';
      $whitelist[] = 'https://www.advisorsexcel.com/events/elite-mastermind-registration/';
      $whitelist[] = 'https://www.advisorsexcel.com/events/leadership-summit-survey/';
      $whitelist[] = 'https://www.advisorsexcel.com/giving-back/';
      $whitelist[] = 'https://www.advisorsexcel.com/giving-back/season-of-sharing/';
      $whitelist[] = 'https://www.advisorsexcel.com/giving-back/season-of-sharing/faqs/';
      $whitelist[] = 'https://www.advisorsexcel.com/giving-back/season-of-sharing/application/';
      $whitelist[] = 'https://www.advisorsexcel.com/giving-back/season-of-sharing/season-of-sharing-application-thank-you/';
      $whitelist[] = 'https://www.advisorsexcel.com/events/transformation-virtual-registration/';
      $whitelist[] = 'https://www.advisorsexcel.com/events/transformation-virtual-registration/?src=Symetra';
      $whitelist[] = 'https://www.advisorsexcel.com/events/transformation-virtual-registration/?src=SymetraAmerican';
      $whitelist[] = 'https://www.advisorsexcel.com/events/virtual-transformation/?src=join';
      $whitelist[] = 'https://www.advisorsexcel.com/events/ae-roadshow/?src=join'; 
      $whitelist[] = 'https://www.advisorsexcel.com/events/wealth-elite-symposium/sponsor/?offer=astor';
      $whitelist[] = 'https://www.advisorsexcel.com/events/wealth-elite-symposium/sponsor/?offer=blackrock';
      $whitelist[] = 'https://www.advisorsexcel.com/events/wealth-elite-symposium/sponsor/?offer=clark';
      $whitelist[] = 'https://www.advisorsexcel.com/events/wealth-elite-symposium/sponsor/?offer=fidelity';
      $whitelist[] = 'https://www.advisorsexcel.com/events/wealth-elite-symposium/sponsor/?offer=firsttrust';
      $whitelist[] = 'https://www.advisorsexcel.com/events/wealth-elite-symposium/sponsor/?offer=milliman';
      $whitelist[] = 'https://www.advisorsexcel.com/events/wealth-elite-symposium/sponsor/?offer=riskalyze';
      $whitelist[] = 'https://www.advisorsexcel.com/events/wealth-elite-symposium/sponsor/?offer=state';
      $whitelist[] = 'https://www.advisorsexcel.com/events/wealth-elite-symposium/sponsor/?offer=jaforlines';
      $whitelist[] = 'https://www.advisorsexcel.com/events/wealth-elite-symposium/sponsor/?offer=wisdom';
      $whitelist[] = 'https://www.advisorsexcel.com/events/wealth-elite-symposium/sponsor/?offer=orion';
      $whitelist[] = 'https://www.advisorsexcel.com/aecreative/';
      
      return $whitelist;
    }
    add_filter( 'v_forcelogin_whitelist', 'my_forcelogin_whitelist' );
    • This topic was modified 4 years, 2 months ago by courtneyhuber.

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

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

    (@kevinvess)

    Hi, thanks for using Force Login!

    I recommend you use the home_url() function to list your allowed pages. It could be your absolute URL doesn’t work in the new server configuration.

    For example, maybe the new server isn’t using HTTPS anymore?

    Or HTTP urls aren’t being forwarded to HTTPS before the WordPress PHP (and Force Login) run and the user is redirected to the login screen?

    Also, the v_forcelogin_whitelist filter has been deprecated in Force Login version 5.5. I recommend you use the v_forcelogin_bypass filter instead. You can find an example in the FAQs section.

    Plugin Author Kevin Vess

    (@kevinvess)

    Another thing to check for–?is if your new hosting is caching the site and hasn’t yet updated to reflect your changes to the functions.php file when you copied over the previous whitelist code.

    Thread Starter courtneyhuber

    (@courtneyhuber)

    So, I’m using the home_URL() function, bypass filter & ensured my site cache was cleared and I’m still having problems. Not sure what the hangup is!?

    /**
     * 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( '/events/' ),
        home_url( '/aecreative/' ),
      );
      if ( ! $bypass ) {
        $bypass = in_array( $visited_url, $allowed );
      }
    
      return $bypass;
    }
    add_filter( 'v_forcelogin_bypass', 'my_forcelogin_bypass', 10, 2 );
    Plugin Author Kevin Vess

    (@kevinvess)

    It sounds like these changes to your new site are not taking affect for some reason. Can you verify if any code change to your functions.php file gets applied?

    Try contacting your hosting support about this and see what they say. Otherwise, you might need to hire a developer who can help troubleshoot this issue with your new hosting.

    Good luck– let me know if you figure out how to resolve this issue.

    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Whitelist suddenly not working’ is closed to new replies.