• Resolved giuseppecuttone

    (@giuseppecuttone)


    Hi, I like your plugin, it works well in my web. But I need an special feature.
    Actually, with your pluguin, visitors are immediately redirected to the login page .
    I`d like let visitor look my page during 2 or 3 minuts (for example), and after this time redirect them to login page.
    I think it will be a good feature for administrator in order to have more suscriptors.
    How can I have this feature?
    Maybe will you introduce it in your pluguin?
    Or, maybe you can help me in order to add it in my web? (what codec line I must add to your pluguin)?
    Thanks for you support.

    https://www.ads-software.com/plugins/wp-force-login/

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

    (@kevinvess)

    Just to clarify, you want to allow visitors to view your site only for a specified duration of their first visit? Then every time afterwards they’re redirected immediately to login?

    Meaning, you don’t want to allow visitors to reload the page for another 2-3 minute session before a redirect, but redirect them after those initial 2-3 minutes have been used?

    To accomplish that, I think what you need to do is set a cookie that sets or tracks their visit duration. Then apply a filter based on that cookie’s status.

    You’ll want to do something like this:

    // Set a cookie for redirect duration.
    function my_forcelogin_cookie() {
      $duration = time() + (60 * 5);  // 5 minutes
      return setcookie('unlocked', true, $duration);
    }
    add_action('init', 'my_forcelogin_cookie');
    
    // Redirect logged-out users to login after set duration
    if ( !is_user_logged_in() ) {
      if ( !isset($_COOKIE['unlocked']) && $_COOKIE['unlocked'] != true ) {
        wp_redirect( wp_login_url() );
        exit;
      }
    }
    Thread Starter giuseppecuttone

    (@giuseppecuttone)

    Hi, thanks very much for your support. You are right. If it is possible I don’t want to allow visitors to reload the page. It is correct.
    I am not informatico, so I will ask to my “informatic friend” in order to introduce your code and look if work fine.
    If it is so simple, I suggest you introduce that in your pluguin. It will be a very good feature in order to have more suscriptors.
    Thanks for the code. Thanks very much.
    Bye

    Hi Kevin,

    I have a question on your above code. Would this go to the header, your plugin or functions.php?

    Thanks a lot in advance

    Martin

    Plugin Author Kevin Vess

    (@kevinvess)

    That code was just an untested rough example to give giuseppecuttone an idea for how to achieve their goal.

    I’d add it to the theme’s functions.php file –?however, the second part for the redirect probably needs to be reworked some:

    // Set a cookie for redirect duration.
    function my_forcelogin_cookie() {
      $duration = time() + (60 * 5);  // 5 minutes
      return setcookie('unlocked', true, $duration);
    }
    add_action('init', 'my_forcelogin_cookie');
    
    // Redirect logged-out users to login after set duration
    function my_forcelogin_redirect() {
      if ( !is_user_logged_in() ) {
        if ( !isset($_COOKIE['unlocked']) && $_COOKIE['unlocked'] != true ) {
          wp_redirect( wp_login_url() );
          exit;
        }
      }
    }
    add_action('init', 'my_forcelogin_redirect');

    Thanks a lot for getting back to me. Also the first part

    function my_forcelogin_cookie() {
      $duration = time() + (60 * 5);  // 5 minutes
      return setcookie('unlocked', true, $duration);
    }
    add_action('init', 'my_forcelogin_cookie');

    did not show any results. Any ideas?

    Plugin Author Kevin Vess

    (@kevinvess)

    Unfortunately, this request is not about existing functionality within the plugin and the above code examples were just suggestions for a possible solution that wouldn’t require the Force Login plugin.

    I think you’ll have to look elsewhere for a solution to allow visitors to view your site only for a specified duration of their first visit, then every time afterward redirect to login.

    Thread Starter giuseppecuttone

    (@giuseppecuttone)

    Hi kevin, during this 2 last month I have been thinking about the question done in this post.

    Two months ago you told me:

    “Just to clarify, you want to allow visitors to view your site only for a specified duration of their first visit? Then every time afterwards they’re redirected immediately to login?
    Meaning, you don’t want to allow visitors to reload the page for another 2-3 minute session before a redirect.”

    Now I think that this solution is not good for to have more suscriptions.
    And Now I think that the better solution is just this:

    Allow visitors to reload the page for another 2-3 minute session before a redirect.

    Is it possible with your pluguin?
    In order to do that, have you a solution? Do yuo know the codec I need?
    I hope you can help me.
    Thanks very much for your profesional support.

    Plugin Author Kevin Vess

    (@kevinvess)

    Hi, unfortunately, my plugin is not configured to do any time-based locking of the site –?it’s either locked down or not.

    This is probably not functionality I will add to the plugin either –?Force Login is not intended to be a marketing tool for enticing users to subscribe; but was built to do one simple task of making an entire site private.

    I think your best option would be to look elsewhere for that type of functionality. I suggest you look for a JavaScript solution that adds a fullscreen overlay with a subscribe form on top of the page after your desired timeframe –?that might be a more elegant solution than just redirecting them to the WordPress login screen.

    Thanks for trying my plugin and good luck!

    Thread Starter giuseppecuttone

    (@giuseppecuttone)

    I kevein,
    you are right…
    thanks a lot for your suggesstion.
    Bye

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘how redirect to login page after specific time’ is closed to new replies.