开发者

Need to Bulletproof this PHP include. Getting Failed to Open Stream

I've got some functions in my file that require taxonomy.php to execute. I'm attempting to include the file like so...(this is called from functions.php, which is located in wp_content/themes/mytheme/

include($_SERVER['DOCUMENT_ROOT'] .'/wp-admin/includes/taxonomy.php');

However, depending on the particular server setup, its hit or miss (mostly hit) whether the include will be found. In the case its not found, I get this error...

Warning: include(/home/user/domainname.com/wp-admin/includes/taxonomy.php) [function.include]: failed to open stream: No such file or directory in /home/user/domainname.com/testing123/wp-content/themes/mytheme/functions.php on line 10

UPDATE: Assuming I'm already doing about as much as I can 开发者_Go百科by using DOCUMENT_ROOT, is there a means of avoiding the error that occurs when the file is not found? And I will be checking for function_exists in any functions that require taxonomy.php so as to suppress errors...


Well, the only way to bulletproof this is to actually configure it on each server you deploy it on. If you can't assume document_root is a reliable factor, I can't imagine any other variable that could give you a better result.

You could start searching for taxonomy.php but that is expensive, and horribly prone to failure or picking the wrong file (what happens if my neighbor has wordpress installed in /home/user/domainname2.com?


If your application depends on a particular file, you should be using require/require_once to ensure your application does not partially load despite missing the required file.

As for making sure that file always exists and is in a place you need it, you could move that to a configuration file and allow the user running the software to set it, along with auto-attempting to find the find in the event the user is clueless.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜