我目前正在开发一个涉及大量 .php 文件的 Wordpress 插件。我看到对于我的 AddShift.php 文件,我们使用以下代码行成功导入了博客标题:
include("../../../wp-blog-header.php");
但是,当我尝试在我的 ajax_cal_split.php 文件中执行相同的操作时,出现以下错误:
Warning: include(./wp-blog-header.php) [function.include]: failed to open stream: No such file or directory in /opt/lampp/htdocs/sandboxj/blog/wp-content/plugins/Shifty/ajax_cal_split.php on line 11
Warning: include() [function.include]: Failed opening './wp-blog-header.php' for inclusion (include_path='.:/opt/lampp/lib/php') in /opt/lampp/htdocs/sandboxj/blog/wp-content/plugins/Shifty/ajax_cal_split.php on line 11
第11行当然是说
include("../../../wp-blog-header.php");
当它们驻留在同一目录中时,是否有任何理由让此调用对一个 .php 文件起作用而不对另一个文件起作用?
最佳答案
这是获取插件文件中真实路径的解决方案
<?php
$scriptPath = dirname(__FILE__);
$path = realpath($scriptPath . '/./');
$filepath = explode("wp-content",$path);
// print_r($filepath);
define('WP_USE_THEMES', false);
require(''.$filepath[0].'/wp-blog-header.php');
关于php - WordPress 包含 ("../../../wp-blog-header");失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2157604/