获取WordPress安装根目录的绝对文件系统路径
原型
get_home_path()
返回值
(string)
WordPress安装根目录的完整文件系统路径
源文件
路径:wp-admin/includes/file.php
<?php
...
function get_home_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( str_replace( '\', '/', $_SERVER['SCRIPT_FILENAME'] ), trailingslashit( $wp_path_rel_to_home ) );
$home_path = substr( $_SERVER['SCRIPT_FILENAME'], 0, $pos );
$home_path = trailingslashit( $home_path );
} else {
$home_path = ABSPATH;
}
return str_replace( '\', '/', $home_path );
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/get_home_path/