mirror of
https://github.com/WordPress/WordPress.git
synced 2025-03-30 08:26:42 +02:00
REST API: Warn if registering array settings without an items schema.
The documentation for register_setting has also been clarified to include all of the supported types and the flexibility of the show_in_rest parameter. Fixes #42875. Props perrywagle, dshanske, kadamwhite. Built from https://develop.svn.wordpress.org/trunk@47325 git-svn-id: http://core.svn.wordpress.org/trunk@47119 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
c15cd5f5c4
commit
808768224d
@ -2104,12 +2104,14 @@ function register_initial_settings() {
|
||||
* @param array $args {
|
||||
* Data used to describe the setting when registered.
|
||||
*
|
||||
* @type string $type The type of data associated with this setting.
|
||||
* Valid values are 'string', 'boolean', 'integer', and 'number'.
|
||||
* @type string $description A description of the data attached to this setting.
|
||||
* @type callable $sanitize_callback A callback function that sanitizes the option's value.
|
||||
* @type bool $show_in_rest Whether data associated with this setting should be included in the REST API.
|
||||
* @type mixed $default Default value when calling `get_option()`.
|
||||
* @type string $type The type of data associated with this setting.
|
||||
* Valid values are 'string', 'boolean', 'integer', 'number', 'array', and 'object'.
|
||||
* @type string $description A description of the data attached to this setting.
|
||||
* @type callable $sanitize_callback A callback function that sanitizes the option's value.
|
||||
* @type bool|array $show_in_rest 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.
|
||||
* @type mixed $default Default value when calling `get_option()`.
|
||||
* }
|
||||
*/
|
||||
function register_setting( $option_group, $option_name, $args = array() ) {
|
||||
@ -2143,6 +2145,11 @@ function register_setting( $option_group, $option_name, $args = array() ) {
|
||||
$args = apply_filters( 'register_setting_args', $args, $defaults, $option_group, $option_name );
|
||||
$args = wp_parse_args( $args, $defaults );
|
||||
|
||||
// Require an item schema when registering settings with an array type.
|
||||
if ( false !== $args['show_in_rest'] && 'array' === $args['type'] && ( ! is_array( $args['show_in_rest'] ) || ! isset( $args['show_in_rest']['schema']['items'] ) ) ) {
|
||||
_doing_it_wrong( __FUNCTION__, __( 'When registering an "array" setting to show in the REST API, you must specify the schema for each array item in "show_in_rest.schema.items".' ), '5.4.0' );
|
||||
}
|
||||
|
||||
if ( ! is_array( $wp_registered_settings ) ) {
|
||||
$wp_registered_settings = array();
|
||||
}
|
||||
|
@ -13,7 +13,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.4-beta2-47324';
|
||||
$wp_version = '5.4-beta2-47325';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
Reference in New Issue
Block a user