Wordpress include("../../../wp-blog-header"); failing


I am currently working on a plugin for Wordpress involving lots of .php files. I see that for my AddShift.php file, we are successfully importing the blog header using the following line of code:


However, when I try to do the same thing in my ajax_cal_split.php file, I get the following error:

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

Line 11 of course says


Is there any reason for this call to work on one .php file and not another, when they reside in the same directory?

1/28/2010 8:13:20 PM

Accepted Answer

Yes - I believe wordpress operates a security mechanism on content in the wp-content directory, I had the same problem with themes. The workaround I used was to include with absolute path names.

1/28/2010 8:12:59 PM

This is your solution to get the real path in plugin file

$scriptPath = dirname(__FILE__);
 $path = realpath($scriptPath . '/./');
 $filepath = explode("wp-content",$path);
// print_r($filepath);
define('WP_USE_THEMES', false);

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow