函数文档

get_registered_theme_feature()

💡 云策文档标注

概述

get_registered_theme_feature() 函数用于获取已注册主题功能的配置信息。它通过全局变量 $_wp_registered_theme_features 查询指定功能的注册参数,若未注册则返回 null。

关键要点

  • 参数 $feature 为字符串类型,必需,表示主题功能名称,可参考 add_theme_support() 的列表。
  • 返回值类型为数组或 null,返回注册参数数组,若功能未注册则返回 null。
  • 该函数自 WordPress 5.5.0 版本引入。

代码示例

function get_registered_theme_feature( $feature ) {
	global $_wp_registered_theme_features;

	if ( ! is_array( $_wp_registered_theme_features ) ) {
		return null;
	}

	return isset( $_wp_registered_theme_features[ $feature ] ) ? $_wp_registered_theme_features[ $feature ] : null;
}

📄 原文内容

Gets the registration config for a theme feature.

Parameters

$featurestringrequired
The feature name. See add_theme_support() for the list of possible values.

More Arguments from add_theme_support( … $feature )

The feature being added. Likely core values include:

  • 'admin-bar'
  • 'align-wide'
  • 'appearance-tools'
  • 'automatic-feed-links'
  • 'block-templates'
  • 'block-template-parts'
  • 'border'
  • 'core-block-patterns'
  • 'custom-background'
  • 'custom-header'
  • 'custom-line-height'
  • 'custom-logo'
  • 'customize-selective-refresh-widgets'
  • 'custom-spacing'
  • 'custom-units'
  • 'dark-editor-style'
  • 'disable-custom-colors'
  • 'disable-custom-font-sizes'
  • 'disable-custom-gradients'
  • 'disable-layout-styles'
  • 'editor-color-palette'
  • 'editor-gradient-presets'
  • 'editor-font-sizes'
  • 'editor-spacing-sizes'
  • 'editor-styles'
  • 'featured-content'
  • 'html5'
  • 'link-color'
  • 'menus'
  • 'post-formats'
  • 'post-thumbnails'
  • 'responsive-embeds'
  • 'starter-content'
  • 'title-tag'
  • 'widgets'
  • 'widgets-block-editor'
  • 'wp-block-styles'

Return

array|null The registration args, or null if the feature was not registered.

Source

function get_registered_theme_feature( $feature ) {
	global $_wp_registered_theme_features;

	if ( ! is_array( $_wp_registered_theme_features ) ) {
		return null;
	}

	return isset( $_wp_registered_theme_features[ $feature ] ) ? $_wp_registered_theme_features[ $feature ] : null;
}

Changelog

Version Description
5.5.0 Introduced.