返回介绍

get_theme_root()

发布于 2017-09-11 00:25:19 字数 3736 浏览 1095 评论 0 收藏 0

get_theme_root( string $stylesheet_or_template = false )

Retrieve path to themes directory.


description

Does not have trailing slash.


参数

$stylesheet_or_template

(string) (Optional) The stylesheet or template name of the theme

Default value: false


返回值

(string) Theme path.


源代码

File: wp-includes/theme.php

function get_theme_root( $stylesheet_or_template = false ) {
	global $wp_theme_directories;

	if ( $stylesheet_or_template && $theme_root = get_raw_theme_root( $stylesheet_or_template ) ) {
		// Always prepend WP_CONTENT_DIR unless the root currently registered as a theme directory.
		// This gives relative theme roots the benefit of the doubt when things go haywire.
		if ( ! in_array( $theme_root, (array) $wp_theme_directories ) )
			$theme_root = WP_CONTENT_DIR . $theme_root;
	} else {
		$theme_root = WP_CONTENT_DIR . '/themes';
	}

	/**
	 * Filters the absolute path to the themes directory.
	 *
	 * @since 1.5.0
	 *
	 * @param string $theme_root Absolute path to themes directory.
	 */
	return apply_filters( 'theme_root', $theme_root );
}

更新日志

Versiondescription
1.5.0Introduced.

相关函数

Uses

  • wp-includes/theme.php: get_raw_theme_root()
  • wp-includes/theme.php: theme_root
  • wp-includes/plugin.php: apply_filters()

Used By

  • wp-admin/includes/class-wp-automatic-updater.php: WP_Automatic_Updater::update()
  • wp-admin/includes/class-theme-upgrader.php: Theme_Upgrader::check_parent_theme_filter()
  • wp-admin/includes/class-theme-upgrader.php: Theme_Upgrader::install()
  • wp-admin/includes/class-theme-upgrader.php: Theme_Upgrader::upgrade()
  • wp-admin/includes/class-theme-upgrader.php: Theme_Upgrader::bulk_upgrade()
  • wp-admin/includes/class-wp-upgrader.php: WP_Upgrader::fs_connect()
  • wp-admin/includes/class-wp-filesystem-base.php: WP_Filesystem_Base::wp_themes_dir()
  • wp-includes/theme.php: get_stylesheet_directory()
  • wp-includes/theme.php: get_template_directory()
  • Show 4 more used by Hide more used by

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note Contributed by Codex

    Number of Subdirectories in Themes Directory
    The function below informs about the number of subdirectories in the themes directory. Note that this doesn’t necessarily match the number of themes recognized by WordPress.

    
    <?php
    function display_themes_subdirs_count_info()
      $theme_root = get_theme_root();
      $files_array = glob("$theme_root/*", GLOB_ONLYDIR);
      echo "There are " . count($files_array) . " subdirectories in the " . $theme_root . " directory"; 
    }
    ?>
    

    Example output:

    There are 5 subdirectories in the /home/user/public_html/wp-content/themes directory.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文