• Resolved circadesign

    (@circadesign)


    I need help getting this page whitelisted. I tried following the code you applied but it’s not working for me, so I don’t think I’m putting it in the right place.

    Is this correct?

    <?php
    /**
     * The7 theme.
     *
     * @since   1.0.0
     *
     * @package The7
     */
    
    defined( 'ABSPATH' ) || exit;
    
    /**
     * Set the content width based on the theme's design and stylesheet.
     *
     * @since 1.0.0
     */
    if ( ! isset( $content_width ) ) {
    	$content_width = 1200; /* pixels */
    }
    
    /**
     * Initialize theme.
     *
     * @since 1.0.0
     */
    require trailingslashit( get_template_directory() ) . 'inc/init.php';
    
    /**
     * 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[] = home_url( 'https://beaconemployee.com/policies/' );
      return $whitelist;
    }
    add_filter( 'v_forcelogin_whitelist', 'my_forcelogin_whitelist' );
    
    

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

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

    (@kevinvess)

    Hi– thanks for using Force Login!

    Your code is flawed. Please use either an absolute URL or the home_url() function – not both.

    For example:

    /**
     * Set the URL to redirect to on login.
     *
     * @param string $url The visited URL.
     * @return string The URL to redirect to on login. Must be absolute.
     */
    function my_forcelogin_redirect( $url ) {
      return 'https://beaconemployee.com/policies/';
    }
    add_filter( 'v_forcelogin_redirect', 'my_forcelogin_redirect' );

    OR

    /**
     * Set the URL to redirect to on login.
     *
     * @param string $url The visited URL.
     * @return string The URL to redirect to on login. Must be absolute.
     */
    function my_forcelogin_redirect( $url ) {
      return home_url('policies/');
    }
    add_filter( 'v_forcelogin_redirect', 'my_forcelogin_redirect' );
    Thread Starter circadesign

    (@circadesign)

    I realized we were using a different plugin. Thank you!

    • This reply was modified 4 years, 3 months ago by circadesign.

    I’m having a similar issue, but may have a flaw that I’m not seeing as well. (I am using the plugin, and it works beautifully!) I am trying to whitelist a directory (plans). I’m placing the below in my child theme’s functions.php file…

    /**
     * Bypass Force Login to allow for exceptions.
     *
     * @param bool $bypass Whether to disable Force Login. Default false.
     * @return bool
     */
    function my_forcelogin_bypass( $bypass ) {
        // Get visited URL without query string
        $url_path = preg_replace('/\?.*/', '', $_SERVER['REQUEST_URI']);
    
        // Allow any page URL within the specified directory
        if ( in_array( 'plans', explode( '/', $url_path ) ) ) {
            $bypass = true;
        }
    
        return $bypass;
    }
    add_filter( 'v_forcelogin_bypass', 'my_forcelogin_bypass' );

    Thank you for any insight or pointing out my mistake.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Whitelist URL’ is closed to new replies.