Ticket #51020: 51020#.2.diff
| File 51020#.2.diff, 3.6 KB (added by , 6 years ago) |
|---|
-
src/wp-includes/rest-api.php
1539 1539 } 1540 1540 1541 1541 /** 1542 * Get all valid JSON schema properties. 1543 * 1544 * @since 5.6.0 1545 * 1546 * @return string[] All valid JSON schema properties. 1547 */ 1548 function rest_get_allowed_schema_keywords() { 1549 return array( 1550 'type', 1551 'format', 1552 'enum', 1553 'items', 1554 'properties', 1555 'additionalProperties', 1556 'minimum', 1557 'maximum', 1558 'exclusiveMinimum', 1559 'exclusiveMaximum', 1560 'minLength', 1561 'maxLength', 1562 'pattern', 1563 'minItems', 1564 'maxItems', 1565 'uniqueItems', 1566 ); 1567 } 1568 1569 /** 1542 1570 * Validate a value based on a schema. 1543 1571 * 1544 1572 * @since 4.7.0 -
src/wp-includes/rest-api/class-wp-rest-server.php
1280 1280 } 1281 1281 } 1282 1282 1283 $allowed_schema_keywords = rest_get_allowed_schema_keywords(); 1283 1284 $route = preg_replace( '#\(\?P<(\w+?)>.*?\)#', '{$1}', $route ); 1284 1285 1285 1286 foreach ( $callbacks as $callback ) { … … 1297 1298 $endpoint_data['args'] = array(); 1298 1299 1299 1300 foreach ( $callback['args'] as $key => $opts ) { 1300 $arg_data = array( 1301 'required' => ! empty( $opts['required'] ), 1302 ); 1303 if ( isset( $opts['default'] ) ) { 1304 $arg_data['default'] = $opts['default']; 1305 } 1306 if ( isset( $opts['enum'] ) ) { 1307 $arg_data['enum'] = $opts['enum']; 1308 } 1309 if ( isset( $opts['description'] ) ) { 1310 $arg_data['description'] = $opts['description']; 1311 } 1312 if ( isset( $opts['type'] ) ) { 1313 $arg_data['type'] = $opts['type']; 1314 } 1315 if ( isset( $opts['items'] ) ) { 1316 $arg_data['items'] = $opts['items']; 1317 } 1318 $endpoint_data['args'][ $key ] = $arg_data; 1301 $arg_data = array( 'required' => ! empty( $opts['required'] ) ); 1302 1303 // take valid schema properties only 1304 foreach ( $allowed_schema_keywords as $allowed_schema_keyword ) 1305 if ( array_key_exists( $allowed_schema_keyword, $opts ) ) 1306 $arg_data[$allowed_schema_keyword] = $opts[$allowed_schema_keyword]; 1307 1308 $endpoint_data['args'][$key] = $arg_data; 1319 1309 } 1320 1310 } 1321 1311 -
src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php
629 629 $schema = $this->get_item_schema(); 630 630 $schema_properties = ! empty( $schema['properties'] ) ? $schema['properties'] : array(); 631 631 $endpoint_args = array(); 632 $valid_schema_properties = array( 633 'type', 634 'format', 635 'enum', 636 'items', 637 'properties', 638 'additionalProperties', 639 'minimum', 640 'maximum', 641 'exclusiveMinimum', 642 'exclusiveMaximum', 643 'minLength', 644 'maxLength', 645 'pattern', 646 'minItems', 647 'maxItems', 648 'uniqueItems', 649 ); 632 $allowed_schema_keywords = rest_get_allowed_schema_keywords(); 650 633 651 634 foreach ( $schema_properties as $field_id => $params ) { 652 635 … … 672 655 $endpoint_args[ $field_id ]['required'] = true; 673 656 } 674 657 675 foreach ( $valid_schema_properties as $schema_prop ) {658 foreach ($allowed_schema_keywords as $schema_prop ) { 676 659 if ( isset( $params[ $schema_prop ] ) ) { 677 660 $endpoint_args[ $field_id ][ $schema_prop ] = $params[ $schema_prop ]; 678 661 }
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)