WPLib::maybe_make_absolute_path PHP Method

maybe_make_absolute_path() static public method

Recognize a path with a leading slash as an absolute, a no leading slash or starting with '~/' as relative.
static public maybe_make_absolute_path ( string $filepath, boolean | string $dir = false ) : string
$filepath string
$dir boolean | string
return string
    static function maybe_make_absolute_path($filepath, $dir = false)
    {
        self::stability()->check_method(__METHOD__, WPLib_Stability::EXPERIMENTAL);
        if ('/' !== $filepath[0]) {
            if (preg_match("#^~/(.*)\$#", $filepath, $match)) {
                $path = $match[1];
            } else {
                $path = '/' . ltrim($filepath, '/');
            }
            $filepath = $dir ? "{$dir}{$path}" : static::get_root_dir($path);
        }
        return $filepath;
    }