public static function get_home_path($site_path = ABSPATH)
{
if (defined('HMBKP_ROOT') && HMBKP_ROOT) {
return wp_normalize_path(HMBKP_ROOT);
}
$home_path = wp_normalize_path($site_path);
if (path_in_php_open_basedir(dirname($site_path))) {
$home = set_url_scheme(get_option('home'), 'http');
$siteurl = set_url_scheme(get_option('siteurl'), 'http');
if (!empty($home) && 0 !== strcasecmp($home, $siteurl)) {
$wp_path_rel_to_home = str_ireplace($home, '', $siteurl);
/* $siteurl - $home */
$pos = strripos(wp_normalize_path($_SERVER['SCRIPT_FILENAME']), trailingslashit($wp_path_rel_to_home));
$home_path = substr(wp_normalize_path($_SERVER['SCRIPT_FILENAME']), 0, $pos);
$home_path = trailingslashit($home_path);
}
if (is_multisite()) {
$slashed_home = trailingslashit(get_option('home'));
$base = parse_url($slashed_home, PHP_URL_PATH);
$document_root_fix = wp_normalize_path(realpath($_SERVER['DOCUMENT_ROOT']));
$abspath_fix = wp_normalize_path(ABSPATH);
$home_path = strpos($abspath_fix, $document_root_fix) === 0 ? $document_root_fix . $base : $home_path;
}
}
return wp_normalize_path(untrailingslashit($home_path));
}