HM\BackUpWordPress\Path::get_home_path PHP Метод

get_home_path() публичный статический Метод

The home directory is the path equivalent to the home_url. That is, the path to the true root of the website. In situations where WordPress is installed in a subdirectory the home path is different to ABSPATH
public static get_home_path ( string $site_path = ABSPATH )
$site_path string The site_path to use when calculating the home path, defaults to ABSPATH
    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));
    }