Changeset 47122 for trunk/src/wp-includes/rest-api.php
- Timestamp:
- 01/29/2020 12:43:23 AM (7 years ago)
- File:
-
- 1 edited
-
trunk/src/wp-includes/rest-api.php (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api.php
r47091 r47122 74 74 'args' => array(), 75 75 ); 76 76 77 foreach ( $args as $key => &$arg_group ) { 77 78 if ( ! is_numeric( $key ) ) { … … 361 362 } else { 362 363 $url = trailingslashit( get_home_url( $blog_id, '', $scheme ) ); 363 // nginx only allows HTTP/1.0 methods when redirecting from / to /index.php 364 // nginx only allows HTTP/1.0 methods when redirecting from / to /index.php. 364 365 // To work around this, we manually add index.php to the URL, avoiding the redirect. 365 366 if ( 'index.php' !== substr( $url, 9 ) ) { … … 378 379 379 380 if ( is_admin() && force_ssl_admin() ) { 380 // In this situation the home URL may be http:, and `is_ssl()` may be 381 // false, but the admin is served over https: (one way or another), so 382 // REST API usage will be blocked by browsers unless it is also served 383 // over HTTPS. 381 /* 382 * In this situation the home URL may be http:, and `is_ssl()` may be false, 383 * but the admin is served over https: (one way or another), so REST API usage 384 * will be blocked by browsers unless it is also served over HTTPS. 385 */ 384 386 $url = set_url_scheme( $url, 'https' ); 385 387 } … … 582 584 583 585 if ( $origin ) { 584 // Requests from file:// and data: URLs send "Origin: null" 586 // Requests from file:// and data: URLs send "Origin: null". 585 587 if ( 'null' !== $origin ) { 586 588 $origin = esc_url_raw( $origin ); … … 633 635 634 636 foreach ( $endpoints as $endpoint ) { 635 // Remove the redundant preg_match argument.637 // Remove the redundant preg_match() argument. 636 638 unset( $args[0] ); 637 639 … … 792 794 return true; 793 795 } 796 794 797 foreach ( $fields as $accepted_field ) { 795 798 // Check to see if $field is the parent of any item in $fields. … … 798 801 return true; 799 802 } 800 // Conversely, if "parent" is accepted, all "parent.child" fields should801 // also be accepted.803 // Conversely, if "parent" is accepted, all "parent.child" fields 804 // should also be accepted. 802 805 if ( strpos( $field, "$accepted_field." ) === 0 ) { 803 806 return true; 804 807 } 805 808 } 809 806 810 return false; 807 811 } … … 980 984 */ 981 985 function rest_get_date_with_gmt( $date, $is_utc = false ) { 982 // Whether or not the original date actually has a timezone string 983 // changes the way we need to do timezone conversion. Store this info 984 // before parsing the date, and use it later. 986 /* 987 * Whether or not the original date actually has a timezone string 988 * changes the way we need to do timezone conversion. 989 * Store this info before parsing the date, and use it later. 990 */ 985 991 $has_timezone = preg_match( '#(Z|[+-]\d{2}(:\d{2})?)$#', $date ); 986 992 … … 991 997 } 992 998 993 // At this point $date could either be a local date (if we were passed a 994 // *local* date without a timezone offset) or a UTC date (otherwise). 995 // Timezone conversion needs to be handled differently between these two 996 // cases. 999 /* 1000 * At this point $date could either be a local date (if we were passed 1001 * a *local* date without a timezone offset) or a UTC date (otherwise). 1002 * Timezone conversion needs to be handled differently between these two cases. 1003 */ 997 1004 if ( ! $is_utc && ! $has_timezone ) { 998 1005 $local = gmdate( 'Y-m-d H:i:s', $date ); … … 1229 1236 $value = wp_parse_list( $value ); 1230 1237 } 1238 1231 1239 if ( ! wp_is_numeric_array( $value ) ) { 1232 1240 /* translators: 1: Parameter, 2: Type name. */ 1233 1241 return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s is not of type %2$s.' ), $param, 'array' ) ); 1234 1242 } 1243 1235 1244 foreach ( $value as $index => $v ) { 1236 1245 $is_valid = rest_validate_value_from_schema( $v, $args['items'], $param . '[' . $index . ']' ); … … 1391 1400 function rest_sanitize_value_from_schema( $value, $args ) { 1392 1401 if ( is_array( $args['type'] ) ) { 1393 // Determine which type the value was validated against, and use that type when performing sanitization 1402 // Determine which type the value was validated against, 1403 // and use that type when performing sanitization. 1394 1404 $validated_type = ''; 1395 1405 … … 1415 1425 return (array) $value; 1416 1426 } 1427 1417 1428 $value = wp_parse_list( $value ); 1418 1429 foreach ( $value as $index => $v ) { 1419 1430 $value[ $index ] = rest_sanitize_value_from_schema( $v, $args['items'] ); 1420 1431 } 1421 // Normalize to numeric array so nothing unexpected 1422 // is in the keys.1432 1433 // Normalize to numeric array so nothing unexpected is in the keys. 1423 1434 $value = array_values( $value ); 1424 1435 return $value; … … 1475 1486 1476 1487 case 'email': 1477 /* 1478 * sanitize_email() validates, which would be unexpected. 1479 */ 1488 // sanitize_email() validates, which would be unexpected. 1480 1489 return sanitize_text_field( $value ); 1481 1490 … … 1506 1515 */ 1507 1516 function rest_preload_api_request( $memo, $path ) { 1508 // array_reduce() doesn't support passing an array in PHP 5.2, so we need to make sure we start with one. 1517 // array_reduce() doesn't support passing an array in PHP 5.2, 1518 // so we need to make sure we start with one. 1509 1519 if ( ! is_array( $memo ) ) { 1510 1520 $memo = array();
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)