Changeset 48300 for trunk/src/wp-includes/rest-api.php
- Timestamp:
- 07/04/2020 07:51:10 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api.php
r48273 r48300 1282 1282 */ 1283 1283 function rest_validate_value_from_schema( $value, $args, $param = '' ) { 1284 $allowed_types = array( 'array', 'object', 'string', 'number', 'integer', 'boolean', 'null' ); 1285 1286 if ( ! isset( $args['type'] ) ) { 1287 _doing_it_wrong( __FUNCTION__, __( 'The "type" schema keyword is required.' ), '5.5.0' ); 1288 } 1289 1284 1290 if ( is_array( $args['type'] ) ) { 1285 1291 foreach ( $args['type'] as $type ) { … … 1294 1300 /* translators: 1: Parameter, 2: List of types. */ 1295 1301 return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s is not of type %2$s.' ), $param, implode( ',', $args['type'] ) ) ); 1302 } 1303 1304 if ( ! in_array( $args['type'], $allowed_types, true ) ) { 1305 _doing_it_wrong( 1306 __FUNCTION__, 1307 /* translators: 1. The list of allowed types. */ 1308 wp_sprintf( __( 'The "type" schema keyword can only be on of the built-in types: %l.' ), $allowed_types ), 1309 '5.5.0' 1310 ); 1296 1311 } 1297 1312 … … 1450 1465 } 1451 1466 1452 if ( isset( $args['format'] ) ) { 1467 // The "format" keyword should only be applied to strings. However, for backwards compatibility, 1468 // we allow the "format" keyword if the type keyword was not specified, or was set to an invalid value. 1469 if ( isset( $args['format'] ) && ( ! isset( $args['type'] ) || 'string' === $args['type'] || ! in_array( $args['type'], $allowed_types, true ) ) ) { 1453 1470 switch ( $args['format'] ) { 1454 1471 case 'hex-color': … … 1539 1556 */ 1540 1557 function rest_sanitize_value_from_schema( $value, $args ) { 1558 $allowed_types = array( 'array', 'object', 'string', 'number', 'integer', 'boolean', 'null' ); 1559 1560 if ( ! isset( $args['type'] ) ) { 1561 _doing_it_wrong( __FUNCTION__, __( 'The "type" schema keyword is required.' ), '5.5.0' ); 1562 } 1563 1541 1564 if ( is_array( $args['type'] ) ) { 1542 1565 // Determine which type the value was validated against, … … 1559 1582 1560 1583 $args['type'] = $validated_type; 1584 } 1585 1586 if ( ! in_array( $args['type'], $allowed_types, true ) ) { 1587 _doing_it_wrong( 1588 __FUNCTION__, 1589 /* translators: 1. The list of allowed types. */ 1590 wp_sprintf( __( 'The "type" schema keyword can only be on of the built-in types: %l.' ), $allowed_types ), 1591 '5.5.0' 1592 ); 1561 1593 } 1562 1594 … … 1620 1652 } 1621 1653 1622 if ( isset( $args['format'] ) ) { 1654 // This behavior matches rest_validate_value_from_schema(). 1655 if ( isset( $args['format'] ) && ( ! isset( $args['type'] ) || 'string' === $args['type'] || ! in_array( $args['type'], $allowed_types, true ) ) ) { 1623 1656 switch ( $args['format'] ) { 1624 1657 case 'hex-color':
Note: See TracChangeset
for help on using the changeset viewer.