• Hi, there’s a way to force a bypass if the visitor comes from a specific site, or using a variable?

    My client have two sites, both having age restriction content. He wants a setup like this:

    – if he access directly site A: Age Gate appears;
    – if he access site B THEN click on a link to site A: Age Gate don’t appear.

    It’s possible?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Phil

    (@philsbury)

    Hi @phalkmin,

    This depends on if you’re using standard or the JS version of the age gate. I’e got a solution for standard, but it doesn’t work in JS so I’d need to have a look into why that is. Let me know which you’re using.

    If it’s standard, you can add this to your functions.php:

    
    function bypass_from_referrer($restricted, $meta)
    {
      // Bail early if it's direct traffic
      if(!isset($_SERVER['HTTP_REFERER'])) return $restricted;
    
      // Create an array of domains that would bypass checks
      // could be a string for only one but this gives the option 
      // for more sites in future. Note no http(s) etc
      $domains = array('site-a.com', 'site-b.org');
    
      // check the info from the referer so we don't have to worry about
      // http and https being different things
      $refData = parse_url($_SERVER['HTTP_REFERER']);
      
      // is the referer in out array
      if(in_array($refData['host'], $domains)){
        
        // set age gate cookie for future pages
        // we'll use the age of the current page provided in the $meta
        
        setcookie( 'age_gate', $meta->age, 0, COOKIEPATH, COOKIE_DOMAIN);
    
        // we can now say we want this content to be unrestricted
        $restricted = false;
      }
    
      // finally, we return the restricted value so Age Gate can process it.
      return $restricted;
    }
    
    add_filter('age_gate_restricted', 'bypass_from_referrer', 10, 2);
    

    If you’re on JS, I’ll look for why this doesn’t work. It should really! :/

    Thanks
    Phil

    Thread Starter phalkmin

    (@phalkmin)

    Hi, I’m using the js version, Admin Ajax

    We have w3 total cache too, so we can’t use the standard version 🙁

    Plugin Author Phil

    (@philsbury)

    @phalkmin, damn… ok, I’ll look into why it’s not working here and update you

    Cheers
    Phil

    Thread Starter phalkmin

    (@phalkmin)

    Ty!

    Plugin Author Phil

    (@philsbury)

    Hi @phalkmin,

    So this was a little more complicated than I thought it would be. But it is possible. Here’s what to do:

    Update to the latest version of the plugin (I had to make some changes!)
    In the Advanced settings check the Hook query string option

    We’ll now get some extra info sent to the hook in JS mode that would normally just be available in standard.

    We’ll be passing a query parameter across your sites, it can be anything you want, but something like site-a.com?referer=http://site-b.com will work with the below out of the box. If you don’t want referee just change the value of $key.

    Finally, add this to your functions.php:

    
    function bypass_from_get($restricted, $meta)
    {
    
      // we will now have some things to get via $_REQUEST
      // $key can be whatever you send as a query parameter
      $key = 'referer';
      $referer = (isset($_REQUEST['query'][$key]) ? esc_url(urldecode($_REQUEST['query'][$key])) : false);
    
      // bit of basic sanitation
      $referer = strval( urldecode($referer) );
    
      // Bail early if it's direct traffic
      if(!$referer) return $restricted;
    
      // Create an array of domains that would bypass checks
      // could be a string for only one but this gives the option 
      // for more sites in future. Note no http(s) etc
      $domains = array('site-a.com', 'site-b.org');
    
      // check the info from the referer so we don't have to worry about
      // http and https being different things
      $refData = parse_url($referer);
    
      // if the host isn't present, then we return
      if(!isset($refData['host'])) return $restricted;
    
      // is the referer in out array
      if(in_array($refData['host'], $domains)){
        
        // set age gate cookie for future pages
        // we'll use the age of the current page provided in the $meta
        
        setcookie( 'age_gate', $meta->age, 0, COOKIEPATH, COOKIE_DOMAIN);
    
        // we can now say we want this content to be unrestricted
        $restricted = false;
      }
    
      // finally, we return the restricted value so Age Gate can process it.
      return $restricted;
    }
    
    add_filter('age_gate_restricted', 'bypass_from_get', 10, 2);
    

    You might see a very minor delay in showing the age gate, but adding filters in JS mode performs and ajax request.

    Hope this works for you

    Thanks
    Phil

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Bypass via referer or GET variable’ is closed to new replies.