Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
821 views
in Technique[技术] by (71.8m points)

php - 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:

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

<?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');

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...