函数文档

get_registered_settings()

💡 云策文档标注

概述

get_registered_settings() 函数用于检索已注册设置的数组,返回以选项名作为键的列表。该函数是 WordPress 设置 API 的一部分,帮助开发者获取和管理设置数据。

关键要点

  • 函数返回一个数组,包含所有已注册的设置,键为选项名。
  • 设置数据包括类型(如 'string'、'boolean')、标签、描述、sanitize_callback、show_in_rest 和默认值等属性。
  • 函数内部检查全局变量 $wp_registered_settings,如果不是数组则返回空数组。
  • 该函数自 WordPress 4.7.0 版本引入,常用于 REST API 和设置管理。

代码示例

function get_registered_settings() {
	global $wp_registered_settings;

	if ( ! is_array( $wp_registered_settings ) ) {
		return array();
	}

	return $wp_registered_settings;
}

📄 原文内容

Retrieves an array of registered settings.

Return

array List of registered settings, keyed by option name.
  • ...$0 array
    Data used to describe the setting when registered.
    • type string
      The type of data associated with this setting.
      Valid values are 'string', 'boolean', 'integer', 'number', 'array', and 'object'.
    • label string
      A label of the data attached to this setting.
    • description string
      A description of the data attached to this setting.
    • sanitize_callback callable
      A callback function that sanitizes the option’s value.
    • show_in_rest bool|array
      Whether data associated with this setting should be included in the REST API.
      When registering complex settings, this argument may optionally be an array with a 'schema' key.
    • default mixed
      Default value when calling get_option().

Source

function get_registered_settings() {
	global $wp_registered_settings;

	if ( ! is_array( $wp_registered_settings ) ) {
		return array();
	}

	return $wp_registered_settings;
}

Changelog

VersionDescription
4.7.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.