Working with other plugins

You are reading the documentation for Age Gate 2.x. Switch to the documentation for 3.x.

Stored user Date of Birth

Other plugins may hold data about your users, for instance a date of birth. It is possible, if they are logged in, to use this information to check if Age Gate should challenge them.

Let’s assume we have a BuddyPress installation and have captured a users date of birth when they registered, we can then use the age_gate_restricted filter to test their age:

add_filter('age_gate_restricted', 'buddy_press_test', 10, 2);
function buddy_press_test($restrict, $meta){
  
  if(function_exists('xprofile_get_field_data')){
    // assuming a date format of YYYY-MM-DD
    $dob = xprofile_get_field_data('Date of Birth', get_current_user_id());

    if($dob){
      $from = new DateTime($dob);
      $to   = new DateTime('today');
      $age = $from->diff($to)->y;
      return ($meta->age >= $age);
    }
  }

  return $restrict;
}

This could be applied to custom date from any number of sources.

Note: in JavaScript mode, heavy calls to this filter could result in a delay to showing the challenge.