It is checkedI came up with this solution.
This function checks in each directory level starting from the directory of the current file for the file wp-config.php
. ThisIf it is found the directory is to be assumed the wordpress base path.
The check can of course be changed to other wordpress core files.
function find_wordpress_base_path() {
$dir = dirname(__FILE__);
while( $dir = realpath("$dir/..") )do {
//it is possible to check for other files here
if( file_exists($dir."/wp-config.php") ) {
return $dir;
}
} while( $dir = realpath("$dir/..") );
return null;
}