返回介绍

current_theme_supports()

发布于 2017-09-10 22:00:03 字数 8341 浏览 888 评论 0 收藏 0

current_theme_supports( string $feature )

Checks a theme’s support for a given feature


description


参数

$feature

(string) (Required) the feature being checked


返回值

(bool)


源代码

File: wp-includes/theme.php

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 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-logo':
		case 'custom-header':
		case 'custom-background':
			// Specific capabilities can be registered by passing an array to add_theme_support().
			return ( isset( $_wp_theme_features[ $feature ][0][ $args[0] ] ) && $_wp_theme_features[ $feature ][0][ $args[0] ] );
	}

	/**
	 * Filters 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', 'html5',
	 * 'starter-content', and 'customize-selective-refresh-widgets'.
	 *
	 * @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] );
}

更新日志

Versiondescription
2.9.0Introduced.

相关函数

Uses

  • wp-includes/theme.php: current_theme_supports()
  • wp-includes/theme.php: current_theme_supports-{$feature}
  • wp-includes/plugin.php: apply_filters()

Used By

  • wp-includes/theme.php: _custom_logo_header_styles()
  • wp-includes/class-wp-customize-widgets.php: WP_Customize_Widgets::customize_dynamic_partial_args()
  • wp-includes/class-wp-customize-widgets.php: WP_Customize_Widgets::selective_refresh_init()
  • wp-includes/class-wp-customize-widgets.php: WP_Customize_Widgets::get_selective_refreshable_widgets()
  • wp-includes/customize/class-wp-customize-nav-menu-control.php: WP_Customize_Nav_Menu_Control::content_template()
  • wp-includes/class-wp-customize-nav-menus.php: WP_Customize_Nav_Menus::customize_register()
  • wp-includes/class-wp-customize-nav-menus.php: WP_Customize_Nav_Menus::available_item_types()
  • wp-admin/includes/class-wp-press-this.php: WP_Press_This::html()
  • wp-admin/includes/class-wp-press-this.php: WP_Press_This::post_formats_html()
  • wp-admin/includes/class-wp-press-this.php: WP_Press_This::save_post()
  • wp-admin/includes/image.php: wp_generate_attachment_metadata()
  • wp-admin/includes/dashboard.php: wp_welcome_panel()
  • wp-admin/includes/template.php: _media_states()
  • wp-admin/includes/media.php: get_media_item()
  • wp-admin/includes/post.php: get_default_post_to_edit()
  • wp-admin/includes/meta-boxes.php: post_format_meta_box()
  • wp-admin/includes/class-wp-posts-list-table.php: WP_Posts_List_Table::inline_edit()
  • wp-admin/custom-header.php: Custom_Image_Header::get_header_dimensions()
  • wp-admin/custom-header.php: Custom_Image_Header::ajax_header_crop()
  • wp-admin/custom-header.php: Custom_Image_Header::step_1()
  • wp-admin/custom-header.php: Custom_Image_Header::step_2()
  • wp-admin/custom-header.php: Custom_Image_Header::step_3()
  • wp-admin/custom-header.php: Custom_Image_Header::js_includes()
  • wp-admin/custom-header.php: Custom_Image_Header::css_includes()
  • wp-admin/custom-header.php: Custom_Image_Header::js()
  • wp-admin/custom-header.php: Custom_Image_Header::js_1()
  • wp-admin/custom-header.php: Custom_Image_Header::js_2()
  • wp-admin/custom-background.php: Custom_Background::admin_page()
  • wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::register_controls()
  • wp-includes/theme.php: remove_editor_styles()
  • wp-includes/theme.php: _custom_header_background_just_in_time()
  • wp-includes/theme.php: current_theme_supports()
  • wp-includes/theme.php: require_if_theme_supports()
  • wp-includes/theme.php: display_header_text()
  • wp-includes/theme.php: _get_random_header_data()
  • wp-includes/theme.php: get_custom_header()
  • wp-includes/general-template.php: feed_links()
  • wp-includes/general-template.php: get_search_form()
  • wp-includes/functions.php: wp_widgets_add_menu()
  • wp-includes/widgets/class-wp-widget-recent-comments.php: WP_Widget_Recent_Comments::recent_comments_style()
  • wp-includes/taxonomy.php: create_initial_taxonomies()
  • wp-includes/class-wp-admin-bar.php: WP_Admin_Bar::initialize()
  • wp-includes/admin-bar.php: wp_admin_bar_appearance_menu()
  • wp-includes/post-template.php: get_post_class()
  • wp-includes/media.php: wp_enqueue_media()
  • wp-includes/media.php: gallery_shortcode()
  • wp-includes/media.php: img_caption_shortcode()
  • wp-includes/post.php: wp_insert_post()
  • wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::wp_getPostFormats()
  • wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::_prepare_post()
  • wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::initialise_blog_option_info()
  • wp-includes/customize/class-wp-customize-header-image-control.php: WP_Customize_Header_Image_Control::render_content()
  • wp-includes/comment-template.php: wp_list_comments()
  • wp-includes/comment-template.php: comment_form()
  • wp-includes/class-wp-customize-widgets.php: WP_Customize_Widgets::get_setting_args()
  • Show 50 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

    Basic Example

    
    <?php 
    if (current_theme_supports('custom-header')) {
      // do something special when custom-header is supported...
    }
    ?>
    

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

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

发布评论

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