Make WordPress Core


Ignore:
Timestamp:
01/29/2020 12:43:23 AM (7 years ago)
Author:
SergeyBiryukov
Message:

Docs: Improve inline comments per the documentation standards.

Includes minor code layout fixes for better readability.

See #48303.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api.php

    r47091 r47122  
    7474                'args'     => array(),
    7575        );
     76
    7677        foreach ( $args as $key => &$arg_group ) {
    7778                if ( ! is_numeric( $key ) ) {
    … …  
    361362        } else {
    362363                $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.
    364365                // To work around this, we manually add index.php to the URL, avoiding the redirect.
    365366                if ( 'index.php' !== substr( $url, 9 ) ) {
    … …  
    378379
    379380        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                 */
    384386                $url = set_url_scheme( $url, 'https' );
    385387        }
    … …  
    582584
    583585        if ( $origin ) {
    584                 // Requests from file:// and data: URLs send "Origin: null"
     586                // Requests from file:// and data: URLs send "Origin: null".
    585587                if ( 'null' !== $origin ) {
    586588                        $origin = esc_url_raw( $origin );
    … …  
    633635
    634636                foreach ( $endpoints as $endpoint ) {
    635                         // Remove the redundant preg_match argument.
     637                        // Remove the redundant preg_match() argument.
    636638                        unset( $args[0] );
    637639
    … …  
    792794                return true;
    793795        }
     796
    794797        foreach ( $fields as $accepted_field ) {
    795798                // Check to see if $field is the parent of any item in $fields.
    … …  
    798801                        return true;
    799802                }
    800                 // Conversely, if "parent" is accepted, all "parent.child" fields should
    801                 // also be accepted.
     803                // Conversely, if "parent" is accepted, all "parent.child" fields
     804                // should also be accepted.
    802805                if ( strpos( $field, "$accepted_field." ) === 0 ) {
    803806                        return true;
    804807                }
    805808        }
     809
    806810        return false;
    807811}
    … …  
    980984 */
    981985function 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         */
    985991        $has_timezone = preg_match( '#(Z|[+-]\d{2}(:\d{2})?)$#', $date );
    986992
    … …  
    991997        }
    992998
    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         */
    9971004        if ( ! $is_utc && ! $has_timezone ) {
    9981005                $local = gmdate( 'Y-m-d H:i:s', $date );
    … …  
    12291236                        $value = wp_parse_list( $value );
    12301237                }
     1238
    12311239                if ( ! wp_is_numeric_array( $value ) ) {
    12321240                        /* translators: 1: Parameter, 2: Type name. */
    12331241                        return new WP_Error( 'rest_invalid_param', sprintf( __( '%1$s is not of type %2$s.' ), $param, 'array' ) );
    12341242                }
     1243
    12351244                foreach ( $value as $index => $v ) {
    12361245                        $is_valid = rest_validate_value_from_schema( $v, $args['items'], $param . '[' . $index . ']' );
    … …  
    13911400function rest_sanitize_value_from_schema( $value, $args ) {
    13921401        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.
    13941404                $validated_type = '';
    13951405
    … …  
    14151425                        return (array) $value;
    14161426                }
     1427
    14171428                $value = wp_parse_list( $value );
    14181429                foreach ( $value as $index => $v ) {
    14191430                        $value[ $index ] = rest_sanitize_value_from_schema( $v, $args['items'] );
    14201431                }
    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.
    14231434                $value = array_values( $value );
    14241435                return $value;
    … …  
    14751486
    14761487                        case 'email':
    1477                                 /*
    1478                                  * sanitize_email() validates, which would be unexpected.
    1479                                  */
     1488                                // sanitize_email() validates, which would be unexpected.
    14801489                                return sanitize_text_field( $value );
    14811490
    … …  
    15061515 */
    15071516function 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.
    15091519        if ( ! is_array( $memo ) ) {
    15101520                $memo = array();
Note: See TracChangeset for help on using the changeset viewer.