dougu5886 2014-08-24 19:43
浏览 34
已采纳

wp_redirect和header re-directs阻止我使用Wordpress功能

None of the functions in my functions.php file work after I perform a redirect.

To be more specific, what I have done is use a first php file to do an inital API call, write an array into a txt file, then redirects to another php file that starts off by reading the txt file and then making another API call based on the array of the first. Then parsing that data, and putting it into a wp database in a certain format.

I know that the problem lies with the re-direct because I have tested multiple scenarios as can be seen below and they all point to the re-direct being the culprit.

For example, on my first php file I have the below.

if (function_exists('is_wp_version')){
    echo "is_wp_version exists!! <br>";
} else {
    echo "is_wp_version, it does not exist <br>";
}


if (function_exists('fopen')){
    echo "fopen exists!! <br>";
} else {
    echo "fopen, it does not exist <br>";
}

... More code...
... More code...

wp_redirect( 'PHPfile2.php', 301 ); exit; // I have also tried the header 
//function with same results
?>

And I will always see printed the below output if I comment out the redirect line .

is_wp_version exists!!
fopen exists!!

However, in PHPfile2.php, I always see the below and get some error and the below output.

is_wp_version, it does not exist
fopen exists!!

Fatal error: Call to undefined function get_header() in PHPfile2.php on line 22

And it gives me some sort of Fatal error. If I remove or comment out the code with the get_header function, then I get a Fatal error on the next wordpress function.

Can someone point me in the right direction? Am I going about this the wrong way? I just need to be able to do 2 API calls with the second dependent on what I get back from the first one.

Thank you!

  • 写回答

1条回答 默认 最新

  • douhuang9886 2014-08-24 20:08
    关注

    This is due to the fact that you're leaving the wordpress framework and using your own custom files (which is highly inadvisable).

    You need to require_once('wp-blog-header.php');. in PHPfile2.php.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog