• Resolved melindacooper

    (@melindacooper)


    I am trying to add a bypass so that my users can open the registration form, but when I add it to functions.php, it breaks my website. Any help please! Also, this is a multi-site installation:

    function my_forcelogin_bypass( $bypass ) {
        // Get visited URL without query string
        $url_path = preg_replace('/\?.*/', '', $_SERVER['REQUEST_URI']);
    
        // Allow URL
        if ( '/registration/' === $url_path ) {
            $bypass = true;
        }
    
        return $bypass;
    }
    add_filter( 'v_forcelogin_bypass', 'my_forcelogin_bypass' );
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Kevin Vess

    (@kevinvess)

    Hi, thanks for using Force Login!

    Your bypass code looks fine, but can you elaborate on how exactly it “breaks [your] website?”

    Is there an error being thrown? Try enabling WP_DEBUG to see if any errors are being thrown.

    Also, instead of using the URL path to determine whether or not to bypass the page, try using some Conditional Tags to identify what page is being loaded.

    Thread Starter melindacooper

    (@melindacooper)

    Thank you, i did get it work using this:

    //Bypass Force Login to allow for exceptions.
    
    function my_forcelogin_bypass( $bypass, $visited_url ) {
    
    // Allow these absolute URLs
        $allowed = array('https://**********/registration/');
        if ( ! $bypass ) {
            $bypass = in_array( $visited_url, $allowed );
        }
    
        return $bypass;
    }
    add_filter( 'v_forcelogin_bypass', 'my_forcelogin_bypass', 10, 2 );

    The reason it was breaking my website was because i forgot to remove below when adding to the functions.php file, was a stupid mistake:

    /**
    * 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
    */
    • This reply was modified 2 years, 3 months ago by melindacooper.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Cannot get bypass to work’ is closed to new replies.