2016-07-05 58 views
-1

我正在WP插件重定向用户启用维护时;WordPress的插件:而不是重定向,使用包括

if(! is_page(intval($maintenance_options['page']))) { 
    wp_redirect(get_permalink($maintenance_options['page'])); exit; 
} 

我宁可不将用户重定向,但include页面。这个例子是完全错误的,但只是为了清除它:

include($maintenance_options['page']); 

...所以用户停留在索引,而不是一个斜杠页。

这是可能的,它是安全的,我该如何执行它?

回答

0

有一个action hook for this purpose称为template_include:WordPress的包括该预定的模板文件之前

该滤波器钩立即执行。这可以用来覆盖WordPress的默认模板行为。

一个例子:

add_filter('template_include', 'maintenance_template', 99); 
function maintenance_template($template) { 
    if(! is_page(intval($maintenance_options['page']))) { 
     $new_template = locate_template(array('path-to-template-relative-to-theme-root.php')); 
     if ('' != $new_template) { 
      return $new_template ; 
     } 
    } 
    return $template; 
} 
+0

好知道了,谢谢。它们与'path-to-template-relative-to-theme-root.php'是什么意思? –

+0

我不确定谁是“他们”。我把它写成占位符。您需要将该路径替换为模板的实际路径。该模板路径与主题根目录相关。 – rnevius

+0

所以这也让我给用户一个空白页面模板?这将是我需要的东西! –