Find the WordPress root directory from any child directory by using PHP
Today I try to built a TinyMCE plugin with a custom dialog, and I like to dialog to be integrated with the WordPress APIs.
In order to find out the WordPress root directory I have write the following function
function get_wp_root()
{
$depth = 0;
$current_path = __DIR__;
while(!file_exists($current_path . DIRECTORY_SEPARATOR . 'wp-config.php'))
{
++$depth;
$current_path = dirname($current_path);
if($depth > 20)
{
break;
}
}
return $current_path;
}
I hope this helps :)
Written by Merianos Nikos
Related protips
1 Response
WordPress has the ABSPATH constant, which it sets in wp-config.php, which stores the path to the WordPress root directory. Is this what you're trying to access?
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Plugins
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#