• Resolved aglovervaltim

    (@aglovervaltim)


    I need to allow a bypass page to by bypassed even when a variable URL parameter exists in the URL string.

    For instance I have this code:

     // Allow all single posts
      if ( is_single() ) {
        $bypass = true;
      }
    
      // Allow these absolute URLs
      $allowed = array(
        home_url( '/my-account/' ),
        home_url( '/commissary-login/' ),
        home_url( '/storehouse-registration-page/' ),      );
      if ( ! $bypass ) {
        $bypass = in_array( $visited_url, $allowed );
      }
    
      return $bypass;
    }
    add_filter( 'v_forcelogin_bypass', 'my_forcelogin_bypass', 10, 2 );
    
    
    /** 
    * Sets Custom Registration and Login Page  
    */ 
    add_filter( 'register_url', 'custom_register_url' );
    function custom_register_url( $register_url )
    {
        $register_url = home_url( '/storehouse-registration-page/' );
        return $register_url;
    }
    
    

    It allows access to my custom registration page when accessed directly. Such as: https://domain.com/storehouse-registration-page/

    However, I need it also to allow access if a URL parameter is being used such as a UTM code or other parameters that are needed for the registration form to capture in a hidden field. Such as:

    https://domain.com/storehouse-registration-page/?registration-source=Google
    or
    https://domain.com/storehouse-registration-page/?registration-source=Facebook

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

    (@kevinvess)

    Hi, thanks for using Force Login!

    I recommend you use the is_page() function to determine access to pages instead of using the absolute URL method. For example:

    /**
     * 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 page(s) to be publicly accessible
      if ( is_page('storehouse-registration-page') ) {
        $bypass = true;
      }
    
      return $bypass;
    }
    add_filter( 'v_forcelogin_bypass', 'my_forcelogin_bypass', 10, 2 );
Viewing 1 replies (of 1 total)
  • The topic ‘Bypass when using URL parameters’ is closed to new replies.