现在我让它工作了!与此同时,杰夫·科恩(JeffCohan)也给出了正确的建议(见他对这个问题的评论)。这是我的全部代码,按照他建议的方式工作:
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();
}
?>
这些代码都在
page-intra.php
现在,不要利用
functions.php
或者别的什么。现在,您只需在添加新页面时选择模板,即可完成添加。