mirror of
https://github.com/WordPress/WordPress.git
synced 2025-01-30 20:21:37 +01:00
REST API: Cast empty meta values to correct scalar types in REST response.
Introducing complex meta value handling in [45807] unintentionally removed value casting for empty scalar meta values. Props TimothyBlynJacobs, chrisvanpatten, rmccue, kadamwhite. Fixes #48363. Built from https://develop.svn.wordpress.org/trunk@46563 git-svn-id: http://core.svn.wordpress.org/trunk@46360 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
21bf3bf8dd
commit
cfec48cc31
@ -430,7 +430,7 @@ abstract class WP_REST_Meta_Fields {
|
||||
$type = ! empty( $rest_args['schema']['type'] ) ? $rest_args['schema']['type'] : $type;
|
||||
|
||||
if ( null === $rest_args['schema']['default'] ) {
|
||||
$rest_args['schema']['default'] = $this->get_default_for_type( $type );
|
||||
$rest_args['schema']['default'] = static::get_empty_value_for_type( $type );
|
||||
}
|
||||
|
||||
$rest_args['schema'] = $this->default_additional_properties_to_false( $rest_args['schema'] );
|
||||
@ -501,6 +501,10 @@ abstract class WP_REST_Meta_Fields {
|
||||
$schema = $args['schema']['items'];
|
||||
}
|
||||
|
||||
if ( '' === $value && in_array( $schema['type'], array( 'boolean', 'integer', 'number' ), true ) ) {
|
||||
$value = static::get_empty_value_for_type( $schema['type'] );
|
||||
}
|
||||
|
||||
if ( is_wp_error( rest_validate_value_from_schema( $value, $schema ) ) ) {
|
||||
return null;
|
||||
}
|
||||
@ -559,14 +563,14 @@ abstract class WP_REST_Meta_Fields {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the default value for a schema type.
|
||||
* Gets the empty value for a schema type.
|
||||
*
|
||||
* @since 5.3.0
|
||||
*
|
||||
* @param string $type The schema type.
|
||||
* @return mixed
|
||||
*/
|
||||
protected function get_default_for_type( $type ) {
|
||||
protected static function get_empty_value_for_type( $type ) {
|
||||
switch ( $type ) {
|
||||
case 'string':
|
||||
return '';
|
||||
|
@ -13,7 +13,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.3-RC1-46562';
|
||||
$wp_version = '5.3-RC1-46563';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
Reference in New Issue
Block a user