• Resolved Omar

    (@onabhani)


    Hello,
    I am using the following code to control the bypass for pages

    
    /**
     * 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(
        'https://my.site.com/gps/',
    
      );
      if ( ! $bypass ) {
        $bypass = in_array( $visited_url, $allowed );
      }
    
      return $bypass;
    }
    add_filter( 'v_forcelogin_bypass', 'my_forcelogin_bypass', 10, 2 );

    `

    Everything working fine but now I am adding one new feature which will generate dynamic URLs with a different token each time. All URL will be through the same path https://my.site.com/gps/ but after “gps/” the token will be added.

    Is there a way to do that?

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

    (@kevinvess)

    Hi– thanks for using Force Login!

    I recommend you use the is_page() Conditional Tag to bypass visits to that page instead of using the absolute URL method.

    Also, in case you’re unaware, the if ( is_single() ) { line in your bypass function is allowing all Posts to be publicly available. That was intended as an example in the FAQ and not required to use the bypass filter.

    /**
     * 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 ) {
    
      if ( is_page('gps') ) {
        $bypass = true;
      }
    
      return $bypass;
    }
    add_filter( 'v_forcelogin_bypass', 'my_forcelogin_bypass', 10, 2 );
    Thread Starter Omar

    (@onabhani)

    Hi Kevin,
    I appreciate your time to assist me!

    I tried to use the code that you shared with me, but now, I can’t access any pages.

    not my.site.com/gps nor my.site.com/gps/private_token%456g54

    Plugin Author Kevin Vess

    (@kevinvess)

    Are you using a WordPress Multisite? Make sure your bypass code is running on the correct site.

    Did you try playing with the is_page() function? You can also pass a page ID (instead of the url slug) or an array of pages to check for; for example: is_page(1234).

    Is your https://my.site.com/gps/ page a WP Page or a different post-type? Maybe you need to try using the is_singular() function instead?

    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 ‘Bypass all relative path’ is closed to new replies.