get_raw_theme_root()
云策文档标注
概述
get_raw_theme_root() 函数用于获取主题根目录相对于内容目录的原始路径,不应用任何过滤器。它接受主题的样式表或模板名称作为参数,并可选择跳过缓存。
关键要点
- 函数返回主题根目录的字符串路径,相对于内容目录。
- 参数 $stylesheet_or_template 是必需的,指定主题的样式表或模板名称。
- 参数 $skip_cache 是可选的布尔值,默认为 false,表示使用缓存;设置为 true 可跳过缓存。
- 函数内部检查全局变量 $wp_theme_directories 是否为数组且非空。
- 相关函数包括 get_theme_roots()、get_theme_root() 和 get_theme_root_uri() 等。
- 自 WordPress 3.1.0 版本引入。
原文内容
Gets the raw theme root relative to the content directory with no filters applied.
Parameters
$stylesheet_or_templatestringrequired-
The stylesheet or template name of the theme.
$skip_cachebooloptional-
Whether to skip the cache.
Defaults to false, meaning the cache is used.Default:
false
Source
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;
}
Changelog
| Version | Description |
|---|---|
| 3.1.0 | Introduced. |