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

    (@kevinvess)

    I’m working on a new release for the plugin and with it includes an easy way to whitelist any number of URLs you like. Stay tuned, it should be released soon. Thanks!

    Plugin Author Kevin Vess

    (@kevinvess)

    Update the plugin to the newly released version 3.0 and add the following filter to your functions.php file to grant access to your custom lost password page(s).

    /**
     * Filter Force Login to allow exceptions for specific URLs.
     *
     * @return array An array of URLs. Must be absolute.
     **/
    function my_forcelogin_whitelist() {
      return array(
        site_url( '/mypage/' )
      );
    }
    add_filter('v_forcelogin_whitelist', 'my_forcelogin_whitelist', 10, 1);

    You can specify an array of URLs to whitelist and each URL must be absolute (as in, https://example.com/mypage/). I recommend using the site_url( ‘/mypage/’) function.

    Hi Kevin,

    Thank you for this feature. But in my case it’s not enough because I need to authorize ‘wp-json/*’, and your option doesn’t work with a wildcard.

    How can I do ?

    Thanks for your help

    Plugin Author Kevin Vess

    (@kevinvess)

    Hi there,

    That’s a good question; try adding the following code to your functions.php:

    /**
     * Filter Force Login to allow exceptions for specific URLs.
     *
     * @return array An array of URLs. Must be absolute.
     **/
    function my_forcelogin_whitelist() {
      // list of single page URLs
      $my_whitelist = array(
        //site_url( '/mypage/' )
      );
      // add any page URL within a directory to my whitelist
      if( in_array('wp-json', explode('/', $_SERVER['REQUEST_URI'])) ) {
        $my_whitelist[] = site_url($_SERVER['REQUEST_URI']);
      }
      // return whitelist
      return $my_whitelist;
    }
    add_filter('v_forcelogin_whitelist', 'my_forcelogin_whitelist', 10, 1);

    I altered the code example I gave above to attempt to offer you a solution for adding any page within a specified directory to be whitelisted. This code is untested, let me know if it works for you.

    Thanks!

    oh yeah !
    I should have think about it…
    thanks

    I implemented the above code whitelisting the whole directory and worked like a charm. But my earlier single listed pages are not whitelisted anymore.
    Could you please use your above code and add some single page url’s along with the whitelisted directory and provide an example as an reply?

    And how can I add more than 1 directories to be whitelisted ?

    I got my first issue resolved.
    I just need the add more than 1 directory to be whitelisted.

    Plugin Author Kevin Vess

    (@kevinvess)

    Have you tried just repeating the in_arrary() code with the additional directory you want to whitelist?

    // list of single page URLs
    $my_whitelist = array(
      site_url( '/mypage/' )
    );
    // add any page URL within a directory to my whitelist
    if( in_array('wp-json', explode('/', $_SERVER['REQUEST_URI'])) ) {
      $my_whitelist[] = site_url($_SERVER['REQUEST_URI']);
    }
    if( in_array('directory', explode('/', $_SERVER['REQUEST_URI'])) ) {
      $my_whitelist[] = site_url($_SERVER['REQUEST_URI']);
    }
    // return whitelist
    return $my_whitelist;

    Or, you could try implementing something like this:
    https://stackoverflow.com/questions/7542694/in-array-multiple-values?answertab=votes#tab-top

    Awesome! The above code provided by you worked like a charm.

    I have a site where I have headlines for posts on my homepage, I want to add login when someone wants to read any of the posts.

    This is the default wordpress home page. Can use force login with posts?

    Plugin Author Kevin Vess

    (@kevinvess)

    @zamanw100

    sorry, but this plugin is not for displaying teaser posts to get users to sign up on your website; rather it’s for making the entire site/page (header, footer, etc) private by redirecting visitors to the login screen.

    You could use this plugin and whitelist your homepage, but when visitors try to view your posts they will be redirected to the login screen without explanation –?which is probably not what you’re looking for.

    @kevin,

    That is exactly what I was looking for. How can I add WordPress’s default homepage, i.e, “Front Page which displays my Recent Posts”.

    Is that possible using the whitelist feature? If yes, then I need help with that. I am not good with codes.

    Plugin Author Kevin Vess

    (@kevinvess)

    @zamanw100

    In that case, install the plugin and then activate it. Next copy/paste the following code to your theme’s functions.php file:

    /**
     * Filter Force Login to allow exceptions for specific URLs.
     *
     * @return array An array of URLs. Must be absolute.
     **/
    function my_forcelogin_whitelist( $whitelist ) {
      $whitelist[] = site_url('/');
      return $whitelist;
    }
    add_filter('v_forcelogin_whitelist', 'my_forcelogin_whitelist', 10, 1);

    Thanks @kevin

    This shows my homepage. But instead of my posts, the page is showing endless login screens.

    I wanted to show my posts to the viewers (which is default). When a viewer clicks on a post, the site will ask to login to read the whole post and/or comment.

    Thanks man, I appreciate the support.

Viewing 15 replies - 1 through 15 (of 26 total)
  • The topic ‘Allow access to a custom page’ is closed to new replies.