wp_theme_has_theme_json

函式
wp_theme_has_theme_json ( No parameters )
返回值
  • (bool) Returns true if theme or its parent has a theme.json file, false otherwise.
定義位置
相關方法
wp_theme_update_rowwp_clean_theme_json_cachewp_theme_update_rowswp_oembed_add_host_jswp_send_json
引入
6.2.0
棄用
-

wp_theme_has_theme_json: 這是一個WordPress的函式,用來檢查活動主題是否有一個theme.json檔案。這個檔案用於定義主題的各種設定和配置,例如塊樣式和塊支援。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_theme_has_theme_json() {
static $theme_has_support = null;
if (
null !== $theme_has_support &&
/*
* Ignore static cache when `WP_DEBUG` is enabled. Why? To avoid interfering with
* the theme developer's workflow.
*
* @todo Replace `WP_DEBUG` once an "in development mode" check is available in Core.
*/
! WP_DEBUG &&
/*
* Ignore cache when automated test suites are running. Why? To ensure
* the static cache is reset between each test.
*/
! ( defined( 'WP_RUN_CORE_TESTS' ) && WP_RUN_CORE_TESTS )
) {
return $theme_has_support;
}
// Does the theme have its own theme.json?
$theme_has_support = is_readable( get_stylesheet_directory() . '/theme.json' );
// Look up the parent if the child does not have a theme.json.
if ( ! $theme_has_support ) {
$theme_has_support = is_readable( get_template_directory() . '/theme.json' );
}
return $theme_has_support;
}
function wp_theme_has_theme_json() { static $theme_has_support = null; if ( null !== $theme_has_support && /* * Ignore static cache when `WP_DEBUG` is enabled. Why? To avoid interfering with * the theme developer's workflow. * * @todo Replace `WP_DEBUG` once an "in development mode" check is available in Core. */ ! WP_DEBUG && /* * Ignore cache when automated test suites are running. Why? To ensure * the static cache is reset between each test. */ ! ( defined( 'WP_RUN_CORE_TESTS' ) && WP_RUN_CORE_TESTS ) ) { return $theme_has_support; } // Does the theme have its own theme.json? $theme_has_support = is_readable( get_stylesheet_directory() . '/theme.json' ); // Look up the parent if the child does not have a theme.json. if ( ! $theme_has_support ) { $theme_has_support = is_readable( get_template_directory() . '/theme.json' ); } return $theme_has_support; }
function wp_theme_has_theme_json() {
	static $theme_has_support = null;

	if (
		null !== $theme_has_support &&
		/*
		 * Ignore static cache when `WP_DEBUG` is enabled. Why? To avoid interfering with
		 * the theme developer's workflow.
		 *
		 * @todo Replace `WP_DEBUG` once an "in development mode" check is available in Core.
		 */
		! WP_DEBUG &&
		/*
		 * Ignore cache when automated test suites are running. Why? To ensure
		 * the static cache is reset between each test.
		 */
		! ( defined( 'WP_RUN_CORE_TESTS' ) && WP_RUN_CORE_TESTS )
	) {
		return $theme_has_support;
	}

	// Does the theme have its own theme.json?
	$theme_has_support = is_readable( get_stylesheet_directory() . '/theme.json' );

	// Look up the parent if the child does not have a theme.json.
	if ( ! $theme_has_support ) {
		$theme_has_support = is_readable( get_template_directory() . '/theme.json' );
	}

	return $theme_has_support;
}

常見問題

FAQs
檢視更多 >