get_raw_theme_root

函式
get_raw_theme_root ( $stylesheet_or_template, $skip_cache = false )
引數
  • (string) $stylesheet_or_template The stylesheet or template name of the theme.
    Required:
  • (bool) $skip_cache Optional. Whether to skip the cache. Defaults to false, meaning the cache is used.
    Required:
    Default: false
返回值
  • (string) Theme root.
定義位置
相關方法
get_theme_rootget_theme_rootsget_theme_root_uriget_theme_modget_theme_data
引入
3.1.0
棄用
-

get_raw_theme_root函式是WordPress的一個函式,用於檢索原始主題根目錄的路徑: 這個函式需要一個可選的引數,即主題的樣式表或模板,它返回到原始主題根目錄的路徑,但沒有尾部斜線。

獲得相對於內容目錄的原始主題根,沒有應用過濾器。

function get_raw_theme_root( $stylesheet_or_template, $skip_cache = false ) {
	global $wp_theme_directories;

	if ( ! is_array( $wp_theme_directories ) || count( $wp_theme_directories ) <= 1 ) {
		return '/themes';
	}

	$theme_root = false;

	// If requesting the root for the active theme, consult options to avoid calling get_theme_roots().
	if ( ! $skip_cache ) {
		if ( get_option( 'stylesheet' ) == $stylesheet_or_template ) {
			$theme_root = get_option( 'stylesheet_root' );
		} elseif ( get_option( 'template' ) == $stylesheet_or_template ) {
			$theme_root = get_option( 'template_root' );
		}
	}

	if ( empty( $theme_root ) ) {
		$theme_roots = get_theme_roots();
		if ( ! empty( $theme_roots[ $stylesheet_or_template ] ) ) {
			$theme_root = $theme_roots[ $stylesheet_or_template ];
		}
	}

	return $theme_root;
}

常見問題

FAQs
檢視更多 >