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(
|
||||
'show_in_rest' => true,
|
||||
'type' => 'number',
|
||||
'type' => 'integer',
|
||||
'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(
|
||||
'show_in_rest' => true,
|
||||
'type' => 'number',
|
||||
'type' => 'integer',
|
||||
'description' => __( 'Default category.' ),
|
||||
) );
|
||||
|
||||
|
@ -1815,7 +1815,7 @@ function register_initial_settings() {
|
|||
|
||||
register_setting( 'reading', 'posts_per_page', array(
|
||||
'show_in_rest' => true,
|
||||
'type' => 'number',
|
||||
'type' => 'integer',
|
||||
'description' => __( 'Blog pages show at most.' ),
|
||||
'default' => 10,
|
||||
) );
|
||||
|
|
|
@ -132,6 +132,8 @@ class WP_REST_Settings_Controller extends WP_REST_Controller {
|
|||
switch ( $schema['type'] ) {
|
||||
case 'string':
|
||||
return (string) $value;
|
||||
case 'integer':
|
||||
return (int) $value;
|
||||
case 'number':
|
||||
return (float) $value;
|
||||
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
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -404,6 +404,9 @@ abstract class WP_REST_Meta_Fields {
|
|||
case 'string':
|
||||
$value = (string) $value;
|
||||
break;
|
||||
case 'integer':
|
||||
$value = (int) $value;
|
||||
break;
|
||||
case 'number':
|
||||
$value = (float) $value;
|
||||
break;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* @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.
|
||||
|
|
Loading…
Reference in New Issue