Changeset 46249 for trunk/src/wp-includes/rest-api.php
- Timestamp:
- 09/23/2019 05:24:58 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api.php
r46233 r46249 1210 1210 */ 1211 1211 function rest_validate_value_from_schema( $value, $args, $param = '' ) { 1212 if ( is_array( $args['type'] ) ) { 1213 foreach ( $args['type'] as $type ) { 1214 $type_args = $args; 1215 $type_args['type'] = $type; 1216 1217 if ( true === rest_validate_value_from_schema( $value, $type_args, $param ) ) { 1218 return true; 1219 } 1220 } 1221 1222 /* translators: 1: Parameter, 2: List of types. */ 1223 return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s is not of type %2$s' ), $param, implode( ',', $args['type'] ) ) ); 1224 } 1225 1212 1226 if ( 'array' === $args['type'] ) { 1213 1227 if ( ! is_null( $value ) ) { … … 1260 1274 } 1261 1275 } 1276 } 1277 1278 if ( 'null' === $args['type'] ) { 1279 if ( null !== $value ) { 1280 /* translators: 1: Parameter, 2: Type name. */ 1281 return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s is not of type %2$s.' ), $param, 'null' ) ); 1282 } 1283 1284 return true; 1262 1285 } 1263 1286 … … 1366 1389 */ 1367 1390 function rest_sanitize_value_from_schema( $value, $args ) { 1391 if ( is_array( $args['type'] ) ) { 1392 // Determine which type the value was validated against, and use that type when performing sanitization 1393 $validated_type = ''; 1394 1395 foreach ( $args['type'] as $type ) { 1396 $type_args = $args; 1397 $type_args['type'] = $type; 1398 1399 if ( ! is_wp_error( rest_validate_value_from_schema( $value, $type_args ) ) ) { 1400 $validated_type = $type; 1401 break; 1402 } 1403 } 1404 1405 if ( ! $validated_type ) { 1406 return null; 1407 } 1408 1409 $args['type'] = $validated_type; 1410 } 1411 1368 1412 if ( 'array' === $args['type'] ) { 1369 1413 if ( empty( $args['items'] ) ) { … … 1408 1452 } 1409 1453 1454 if ( 'null' === $args['type'] ) { 1455 return null; 1456 } 1457 1410 1458 if ( 'integer' === $args['type'] ) { 1411 1459 return (int) $value;
Note: See TracChangeset
for help on using the changeset viewer.