2013-04-09 107 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