0

How to have access to wp-load.php ?

I can access it using the following

 require_once("../../../../wp-load.php");

But I need to find it dynamically so I am using the following but none of them works.

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");

How to have access to localhost:8888/wordpress/wp-load.php?

J888
  • 1,944
  • 8
  • 42
  • 76

2 Answers2

1

Add below code snippets at beginning of file where you require to load 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";

}
Denish
  • 2,800
  • 2
  • 23
  • 33
0

The same question is here.

Denzel Chia answer was :

Put the following in the beginning of your file that requires 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');

}

Hope it helps

demongolem
  • 9,474
  • 36
  • 90
  • 105
zeropol
  • 146
  • 1
  • 6
  • still does not work the only one that works is the one that I mentioned in the question, is there any alternative ? – J888 Jun 03 '13 at 11:12
  • @Jack I'm not sure, you may try `$_SERVER['HTTP_HOST']` as described [here](http://stackoverflow.com/questions/2820723/how-to-get-base-url-with-php) – zeropol Jun 05 '13 at 14:27