函数文档

get_all_post_type_supports()

💡 云策文档标注

概述

get_all_post_type_supports() 函数用于获取指定文章类型支持的所有功能特性。它返回一个关联数组,表示功能名称与布尔值的映射。

关键要点

  • 参数 $post_type 为必需字符串,指定要查询的文章类型。
  • 返回值是一个数组,包含文章类型支持的功能列表,以关联数组形式返回,键为功能名称,值为布尔值 true。
  • 函数内部使用全局变量 $_wp_post_type_features 来存储文章类型功能数据。
  • 如果指定文章类型不存在于全局变量中,函数返回空数组。

代码示例

function get_all_post_type_supports( $post_type ) {
    global $_wp_post_type_features;

    if ( isset( $_wp_post_type_features[ $post_type ] ) ) {
        return $_wp_post_type_features[ $post_type ];
    }

    return array();
}

注意事项

  • 返回值是关联数组,而非索引列表,例如 array('title' => true, 'editor' => true)。
  • 函数自 WordPress 3.4.0 版本引入。
  • 相关用途包括在 REST API 和 XML-RPC 中检查文章类型支持的功能。

📄 原文内容

Gets all the post type features

Parameters

$post_typestringrequired
The post type.

Return

array Post type supports list.

Source

function get_all_post_type_supports( $post_type ) {
	global $_wp_post_type_features;

	if ( isset( $_wp_post_type_features[ $post_type ] ) ) {
		return $_wp_post_type_features[ $post_type ];
	}

	return array();
}

Changelog

Version Description
3.4.0 Introduced.

User Contributed Notes

  1. Skip to note 2 content

    The return value of this function is an associative array, not a list.

    For example, if a post type supports the ‘title’ and ‘editor’ features, the return value will be:

    array(24) {
      ["title"]=>
      bool(true)
      ["editor"]=>
      bool(true)
    }

    It will not be the list:

    array(10) {
      [0]=>
      string(5) "title"
      [1]=>
      string(6) "editor"
    }