current_theme_supports()

current_theme_supports( string $feature, mixed $args ) …

current_theme_supports( string $feature, mixed $args )

检查主题对给定功能的支持。
Checks a theme’s support for a given feature.

目录锚点:#说明#参数#返回#源码#笔记


说明(Description)

示例用法:

当前主题支持(“自定义徽标”);

当前主题支持(’html5’,’comment form’);


参数(Parameters)

参数 类型 必填 说明
$feature (string) 必需 正在检查的功能。
$args (mixed) 可选 要对照某些功能检查的额外参数。

返回(Return)

(bool)如果当前主题支持该功能,则为True,否则为false。


源码(Source)

/**
 * Checks a theme's support for a given feature
 *
 * @since 2.9.0
 *
 * @global array $_wp_theme_features
 *
 * @param string $feature the feature being checked
 * @return bool
 */
function current_theme_supports( $feature ) {
	global $_wp_theme_features;

	if ( 'custom-header-uploads' == $feature )
		return current_theme_supports( 'custom-header', 'uploads' );

	if ( !isset( $_wp_theme_features[$feature] ) )
		return false;

	if ( 'title-tag' == $feature ) {
		// Don't confirm support unless called internally.
		$trace = debug_backtrace();
		if ( ! in_array( $trace[1]['function'], array( '_wp_render_title_tag', 'wp_title' ) ) ) {
			return false;
		}
	}

	// If no args passed then no extra checks need be performed
	if ( func_num_args() <= 1="" )="" return="" true;="" $args="array_slice(" func_get_args(),="" 1="" );="" switch="" (="" $feature="" )="" {="" case="" 'post-thumbnails':="" post-thumbnails="" can="" be="" registered="" for="" only="" certain="" content/post="" types="" by="" passing="" an="" array="" of="" types="" to="" add_theme_support().="" if="" no="" array="" was="" passed,="" then="" any="" type="" is="" accepted="" if="" (="" true="==" $_wp_theme_features[$feature]="" )="" registered="" for="" all="" types="" return="" true;="" $content_type="$args[0];" return="" in_array(="" $content_type,="" $_wp_theme_features[$feature][0]="" );="" case="" 'html5':="" case="" 'post-formats':="" specific="" post="" formats="" can="" be="" registered="" by="" passing="" an="" array="" of="" types="" to="" add_theme_support()="" specific="" areas="" of="" html5="" support="" *must*="" be="" passed="" via="" an="" array="" to="" add_theme_support()="" $type="$args[0];" return="" in_array(="" $type,="" $_wp_theme_features[$feature][0]="" );="" case="" 'custom-header':="" case="" 'custom-background'="" :="" specific="" custom="" header="" and="" background="" capabilities="" can="" be="" registered="" by="" passing="" an="" array="" to="" add_theme_support()="" $header_support="$args[0];" return="" (="" isset(="" $_wp_theme_features[$feature][0][$header_support]="" )="" &&="" $_wp_theme_features[$feature][0][$header_support]="" );="" }="" *="" *="" filter="" whether="" the="" current="" theme="" supports="" a="" specific="" feature.="" *="" *="" the="" dynamic="" portion="" of="" the="" hook="" name,="" `$feature`,="" refers="" to="" the="" specific="" theme="" *="" feature.="" possible="" values="" include="" 'post-formats',="" 'post-thumbnails',="" 'custom-background',="" *="" 'custom-header',="" 'menus',="" 'automatic-feed-links',="" and="" 'html5'.="" *="" *="" @since="" 3.4.0="" *="" *="" @param="" bool="" true="" whether="" the="" current="" theme="" supports="" the="" given="" feature.="" default="" true.="" *="" @param="" array="" $args="" array="" of="" arguments="" for="" the="" feature.="" *="" @param="" string="" $feature="" the="" theme="" feature.="" */="" return="" apply_filters(="" "current_theme_supports-{$feature}",="" true,="" $args,="" $_wp_theme_features[$feature]="" );="" }="">
更新版本 源码位置 使用 被使用
5.3.0 wp-includes/theme.php:2826 72 3

笔记(Notes)

基本示例

类别:WordPress 函数手册

本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。

评论 (0)COMMENT

登录 账号发表你的看法,还没有账号?立即免费 注册