mirror of
https://github.com/WordPress/WordPress.git
synced 2025-02-08 16:41:44 +01:00
REST API: Add support for "integer" type for meta and options
Previously Settings only supported "number" which meant it was possible to push floats to things like posts_per_page. This means now developers can also specify `type => ineger` in meta nad settings resgration. Props flixos90. Fixes #38393. Built from https://develop.svn.wordpress.org/trunk@39058 git-svn-id: http://core.svn.wordpress.org/trunk@39000 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
1dd88e334b
commit
f1591eccca
@ -1781,7 +1781,7 @@ function register_initial_settings() {
|
|||||||
|
|
||||||
register_setting( 'general', 'start_of_week', array(
|
register_setting( 'general', 'start_of_week', array(
|
||||||
'show_in_rest' => true,
|
'show_in_rest' => true,
|
||||||
'type' => 'number',
|
'type' => 'integer',
|
||||||
'description' => __( 'A day number of the week that the week should start on.' ),
|
'description' => __( 'A day number of the week that the week should start on.' ),
|
||||||
) );
|
) );
|
||||||
|
|
||||||
@ -1803,7 +1803,7 @@ function register_initial_settings() {
|
|||||||
|
|
||||||
register_setting( 'writing', 'default_category', array(
|
register_setting( 'writing', 'default_category', array(
|
||||||
'show_in_rest' => true,
|
'show_in_rest' => true,
|
||||||
'type' => 'number',
|
'type' => 'integer',
|
||||||
'description' => __( 'Default category.' ),
|
'description' => __( 'Default category.' ),
|
||||||
) );
|
) );
|
||||||
|
|
||||||
@ -1815,7 +1815,7 @@ function register_initial_settings() {
|
|||||||
|
|
||||||
register_setting( 'reading', 'posts_per_page', array(
|
register_setting( 'reading', 'posts_per_page', array(
|
||||||
'show_in_rest' => true,
|
'show_in_rest' => true,
|
||||||
'type' => 'number',
|
'type' => 'integer',
|
||||||
'description' => __( 'Blog pages show at most.' ),
|
'description' => __( 'Blog pages show at most.' ),
|
||||||
'default' => 10,
|
'default' => 10,
|
||||||
) );
|
) );
|
||||||
|
@ -132,6 +132,8 @@ class WP_REST_Settings_Controller extends WP_REST_Controller {
|
|||||||
switch ( $schema['type'] ) {
|
switch ( $schema['type'] ) {
|
||||||
case 'string':
|
case 'string':
|
||||||
return (string) $value;
|
return (string) $value;
|
||||||
|
case 'integer':
|
||||||
|
return (int) $value;
|
||||||
case 'number':
|
case 'number':
|
||||||
return (float) $value;
|
return (float) $value;
|
||||||
case 'boolean':
|
case 'boolean':
|
||||||
@ -258,7 +260,7 @@ class WP_REST_Settings_Controller extends WP_REST_Controller {
|
|||||||
* Whitelist the supported types for settings, as we don't want invalid types
|
* Whitelist the supported types for settings, as we don't want invalid types
|
||||||
* to be updated with arbitrary values that we can't do decent sanitizing for.
|
* to be updated with arbitrary values that we can't do decent sanitizing for.
|
||||||
*/
|
*/
|
||||||
if ( ! in_array( $rest_args['schema']['type'], array( 'number', 'string', 'boolean' ), true ) ) {
|
if ( ! in_array( $rest_args['schema']['type'], array( 'number', 'integer', 'string', 'boolean' ), true ) ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -404,6 +404,9 @@ abstract class WP_REST_Meta_Fields {
|
|||||||
case 'string':
|
case 'string':
|
||||||
$value = (string) $value;
|
$value = (string) $value;
|
||||||
break;
|
break;
|
||||||
|
case 'integer':
|
||||||
|
$value = (int) $value;
|
||||||
|
break;
|
||||||
case 'number':
|
case 'number':
|
||||||
$value = (float) $value;
|
$value = (float) $value;
|
||||||
break;
|
break;
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '4.7-beta1-39057';
|
$wp_version = '4.7-beta1-39058';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
Loading…
Reference in New Issue
Block a user