我正试图通过在我的主题功能中添加此功能来使用此功能添加维护模式功能。php和我正在尝试使用我的主题选项来启用/禁用它。
我意识到,当我通过主题选项页面选中/取消选中此选项时,它不起作用。我的猜测是,一旦添加了操作,它就不能被禁用。我试图为同一个钩子添加elseif条件和remove\\u操作,但也没有成功。。
function mytheme_under_construction(){
// if user is logged in, don\'t show the construction page
if ( is_user_logged_in() ) {
return;
}
$protocol = $_SERVER["SERVER_PROTOCOL"];
if ( \'HTTP/1.1\' != $protocol && \'HTTP/1.0\' != $protocol )
$protocol = \'HTTP/1.0\';
// 503 is recommended : http://bit.ly/YdGkXl
header( "$protocol 503 Service Unavailable", true, 503 );
// or header( "$protocol 200 Ok", true, 200 );
header( \'Content-Type: text/html; charset=utf-8\' );
// adjust the Retry-After value (in seconds)
header( \'Retry-After: 3600\' );
?>
<?php get_template_part(\'maintanance\'); ?>
<?php
die();
}
global $mytheme;
if(!empty($mytheme[\'offline_id\'])){
add_action( \'template_redirect\', \'amytheme_under_construction\' );
}
它的唯一工作方式是直接添加/删除!从此行开始:
if(!empty($mytheme[\'offline_id\'])){
有人能帮我解决这个问题吗?
谢谢
SO网友:Towfiq
实际上,我所要做的就是在函数中运行主题选项,如下所示:
function mytheme_under_construction(){
global $mytheme;
if(!empty($mytheme[\'offline_id\'])){
// if user is logged in, don\'t show the construction page
if ( is_user_logged_in() ) {
return;
}
$protocol = $_SERVER["SERVER_PROTOCOL"];
if ( \'HTTP/1.1\' != $protocol && \'HTTP/1.0\' != $protocol )
$protocol = \'HTTP/1.0\';
// 503 is recommended : http://bit.ly/YdGkXl
header( "$protocol 503 Service Unavailable", true, 503 );
// or header( "$protocol 200 Ok", true, 200 );
header( \'Content-Type: text/html; charset=utf-8\' );
// adjust the Retry-After value (in seconds)
header( \'Retry-After: 3600\' );
?>
<?php get_template_part(\'maintanance\'); ?>
<?php
die();
}
}
add_action( \'template_redirect\', \'amytheme_under_construction\' );