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;
}