register_theme_directory()重新注册一个目录来放置主题

目录

描述

Register a directory that contains themes.

register_theme_directory() 描述

用法

<?php register_theme_directory$directory ?>

register_theme_directory() 用法

参数

$directory

(string) (必填) Either the full filesystem path to a theme folder or a folder within WP_CONTENT_DIR. Do not include a trailing slash.

默认值: None

register_theme_directory() 参数

返回值

(boolean) 

register_theme_directory() 返回值

示例

Register a plugin's subdirectory as a theme folder

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
<?php

/*
 * For directory structure like:
 * 
 * /my-plugin/
 * - /my-plugin.php
 * - /themes/
 *
 * You would put this in my-plugin.php.
 */
register_theme_directory( dirname( __FILE__ ) . '/themes' );

register_theme_directory() 示例

注意

  • 使用到 global: (unknown type) $wp_theme_directories

register_theme_directory() 注意

历史

添加于 版本: 2.9.0

register_theme_directory() 历史

源文件

register_theme_directory() 函数的代码位于 wp-includes/theme.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Register a directory that contains themes.
 *
 * @since 2.9.0
 *
 * @global array $wp_theme_directories
 *
 * @param string $directory Either the full filesystem path to a theme folder or a folder within WP_CONTENT_DIR
 * @return bool
 */
function register_theme_directory( $directory ) {
	global $wp_theme_directories;

	if ( ! file_exists( $directory ) ) {
		// Try prepending as the theme directory could be relative to the content directory
		$directory = WP_CONTENT_DIR . '/' . $directory;
		// If this directory does not exist, return and do not register
		if ( ! file_exists( $directory ) ) {
			return false;
		}
	}

	if ( ! is_array( $wp_theme_directories ) ) {
		$wp_theme_directories = array();
	}

	$untrailed = untrailingslashit( $directory );
	if ( ! empty( $untrailed ) && ! in_array( $untrailed, $wp_theme_directories ) ) {
		$wp_theme_directories[] = $untrailed;
	}

	return true;
}

register_theme_directory() 源文件