Phpstorm doesn't know how to run Wordpress

不问归期 提交于 2019-12-13 10:13:20

问题


I've tried all I could found here and googling. Include paths, external libraries, interpreter settings...

Whenever I try to run my theme's index.php file:

C:\XAMPP\php\php.exe "C:\path\to\project\wp-content\themes\MYTHEME\index.php"

Fatal error: Call to undefined function get_header() in C:\path\to\project\wp-content\themes\MYTHEME\index.php on line 1

Process finished with exit code 255

So yes on line 1 I'm just calling my header.

Turns out it's trying to run index.php like a standalone file, but ignoring the whole Wordpress instalation (that I have included from different angles). Certainly it nows where get_header() is because I can control click it and it'll bring me to the file it's declared in, no problems.

It correctly detects XAMP's PHP interpreter too.

It also works well if I just visit the site typing my localhost URL in the browser. It just won't work through Phpstorm.


回答1:


You are directly calling theme's index file which is not correct way, as your theme must be using some default functions of WordPress, like get_header() in this case.

So you need to make sure wp-load.php is loaded to make all WP functions available to use. You have two way for that:

1) Call root index.php so everything will be loaded by default.

2) Call theme's index.php but add Below code in that:

if(!function_exists('get_header')) {
    require_once( '/wp-load.php' );
}

However this is not good way :)



来源:https://stackoverflow.com/questions/26289283/phpstorm-doesnt-know-how-to-run-wordpress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!