get_home_path

函式
get_home_path ( No parameters )
返回值
  • (string) Full filesystem path to the root of the WordPress installation.
定義位置
相關方法
get_home_templateget_theme_file_pathget_theme_dataget_theme_updatesget_home_url
引入
1.5.0
棄用
-

get_home_path: 這個函式用來檢索當前WordPress安裝的主目錄的路徑。這對於訪問安裝中的檔案或目錄很有用。

獲取WordPress安裝根目錄的絕對檔案系統路徑。

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

常見問題

FAQs
檢視更多 >