无法动态访问wp-load.php

时间:2013-06-03 10:45:10

标签: wordpress-plugin wordpress

如何访问wp-load.php?

我可以使用以下

访问它
 require_once("../../../../wp-load.php");

但是我需要动态地找到它,所以我使用以下内容,但它们都不起作用。

require_once( dirname(__FILE__).'/../../../wp-load.php');
require_once( dirname(__FILE__)."/../../../wp-load.php");
require_once( ABSPATH.'wp-load.php');
require_once( ABSPATH."wp-load.php");

如何访问localhost:8888 / wordpress / wp-load.php?

2 个答案:

答案 0 :(得分:1)

在您需要加载wp-load.php的文件开头添加以下代码段

/* FindWPConfig - searching for a root of wp */

function FindWPConfig($dirrectory){

global $confroot;


foreach(glob($dirrectory."/*") as $f){



    if (basename($f) == 'wp-config.php' ){

        $confroot = str_replace("\\", "/", dirname($f));

        return true;

    }



    if (is_dir($f)){

        $newdir = dirname(dirname($f));

    }

}



if (isset($newdir) && $newdir != $dirrectory){

    if (FindWPConfig($newdir)){

        return false;

    }   

}

return false;

}



if (!isset($table_prefix)){

global $confroot;

FindWPConfig(dirname(dirname(__FILE__)));

include_once $confroot."/wp-config.php";

include_once $confroot."/wp-load.php";

}

答案 1 :(得分:0)

同样的问题是here

Denzel Chia的回答是:

  

将以下内容放在需要的文件的开头   WP-load.php

//include wp-config or wp-load.php

$root = dirname(dirname(dirname(dirname(__FILE__))));

if (file_exists($root.'/wp-load.php')) {

// WP 2.6

require_once($root.'/wp-load.php');

} else {

// Before 2.6

require_once($root.'/wp-config.php');

}

希望有所帮助