How can retrieve root directory in wordpress...Please help.......
+1
A:
You can get blog url with get_bloginfo('url') However, dunno if you can get wp root. However, why do you need that?
Ionut Staicu
2010-03-01 08:49:41
+1
A:
Looking at the bottom of your wp-config.php file in the wordpress root directory will let you find something like this:
if ( !defined('ABSPATH') ) define('ABSPATH', dirname(__FILE__) . '/');
For an example file have a look here:
http://core.trac.wordpress.org/browser/trunk/wp-config-sample.php
You can make use of this constant called ABSPATH in other places of your wordpress scripts and in most cases it should point to your wordpress root directory.
codescape
2010-03-01 14:34:41
this is only useful if wp-config.php have already been included.in some cases (specifically an out of context ajax call to your plugin code) this does not hold true.
Omry
2010-03-01 14:43:59
+1
A:
I am guessing that you need to detect the wordpress root from your plugin or theme. I use the following code in FireStats to detect the root wordpress directory where firestats is installed a a wordpress plugin.
function fs_get_wp_config_path()
{
$base = dirname(__FILE__);
$path = false;
if (@file_exists(dirname(dirname($base))."/wp-config.php"))
{
$path = dirname(dirname($base))."/wp-config.php";
}
else
if (@file_exists(dirname(dirname(dirname($base)))."/wp-config.php"))
{
$path = dirname(dirname(dirname($base)))."/wp-config.php";
}
else
$path = false;
if ($path != false)
{
$path = str_replace("\\", "/", $path);
}
return $path;
}
Omry
2010-03-01 14:42:59