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:
include("../../../wp-blog-header.php");
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
include("../../../wp-blog-header.php");
Is there any reason for this call to work on one .php file and not another, when they reside in the same directory?
This is your solution to get the real path in plugin file
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.
You should try using the WP_PLUGIN_URL constant provided by wordpress. For example, you can define you actual plugin url like this:
and then use it in your calls like:
Thats how i solve the problem, sorry for late answer but it might help the next ones checking in.
it works, do as suggested and use an absolute url, i used
include(“wp-content/themes/YOUR_THEME/DESIRED_FILE.php”);