2013-04-09 109 views
0

我想通过使用template_redirect的WordPress中的URL加载插件的特定文件。该文件被正确显示,但是发送的报头是404,而不是200Wordpress插件template_redirect抛出404

在插件的代码:

add_filter('query_vars','plugin_add_jb'); 
function plugin_add_jb($vars) { 
    $vars[] = 'jb_ajax'; 
    return $vars; 
} 

add_action('template_redirect', 'plugin_jb_check'); 
function plugin_jb_check() { 
    if(intval(get_query_var('jb_ajax')) == '1') { 
     $jb_action = $_GET['action']; 
     if($jb_action == 'refer') { 
      include('./wp-content/plugins/JobBounties/ajax_refer.php'); 
     } 
     elseif ($jb_action == 'refer_post') { 
      include('./wp-content/plugins/JobBounties/ajax_refer_post.php'); 
     } 
     exit; 
    } 
} 

任何人有任何想法,为什么它抛出404?

+0

您是否尝试过首先检查'404',然后删除该标志并添加'header(“HTTP/1.1 200 OK”);'? – 2013-04-09 15:44:33

回答

4

Wordpress可能无法识别此插件或数据并引发404状态。

要打击404状态,只需测试它,删除标志,然后将头200的状态与include一起发送。

function wp15905643_include($template) { 
    global $wp_query; 
    if ($wp_query->is_404) { 
     $wp_query->is_404 = false; 
    } 
    header("HTTP/1.1 200 OK"); 
    include($template); 

} 

然后用它在你的plugin_jb_check功能像这样,如果没有什么帮助。

wp15905643_include('./wp-content/plugins/JobBounties/ajax_refer.php');

来源here