The problem you are having is the user condition $userinfo['showbirthday'], which alters when $age is valid in the vbulletin code. In reality all you need to check is if $userinfo['birthday'] is valid.
Using @Scanu suggestion, this is all you need -- although, that code needs to be fully vetted. I believe $userinfo['birthday'] should be properly validated from vBulletin. I would re-validate it if you run many modifications, that might tamper with it.
Code:
// For testing purposes use an expanded format,
// you can always combine terms after you have it working.
// Exempt: smods, mods, admins
if (!is_member_of($vbulletin->userinfo, 5, 6, 7))
{
// Should already be validated if comming from vbulletin.
// or add additional validation to be on the safe side.
if (!empty($userinfo['birthday']) && ($userinfo['birthday'] != ' '))
{
$birthdate = $userinfo['birthday'];
$birthdate = explode("-", $birthdate);
//Calculate Age (@Scanu's suggestion)
$age = (date("md", date("U", mktime(0, 0, 0, $birthdate[0], $birthdate[1], $birthdate[2]))) > date("md")
? ((date("Y") - $birthdate[2]) - 1) : (date("Y") - $birthdate[2]));
// $Age Check
if (isset($age) && ($age < 18))
{
print_no_permission();
}
}
}