Now I have it working! In the meanwhile Jeff Cohan also gave the right advice on how to do it (see his comment on the question). Here’s my full code, working the way he suggested:
function getUserIP() {
$client = @$_SERVER['HTTP_CLIENT_IP'];
$forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
$remote = $_SERVER['REMOTE_ADDR'];
if (filter_var($client, FILTER_VALIDATE_IP)) {$ip=$client;}
elseif (filter_var($forward, FILTER_VALIDATE_IP)) {$ip=$forward;}
else {$ip = $remote;}
return $ip;
} $ip=getUserIP();
$whitelist = array('172.18.131.26','172.18.131.254');
if(!in_array($ip, $whitelist)) {
// Here comes the markup for some Error Message on the page if requested from outside
?><!doctype html><html><head><meta charset="utf-8"><meta name="robots" content="noindex, nofollow" /><title>Access denied</title></head><body><div id="wrapper"><h1>401: Access Denied</h1><p>You're not allowed to view the requested page.</p></div></body></html><?php
} else {
// Buisness as usual, the generic wp page loop
get_header(); ?>
<div id="container">
<div id="content" role="main"></div><!-- #content -->
</div><!-- #container -->
<?php
get_sidebar();
get_footer();
}
?>
That code is all inside the page-intra.php
now, not making use of functions.php
or anything. You now may simply choose the Template when adding a new page and you’re done.