Changeset 42343 for trunk/src/wp-includes/rest-api/class-wp-rest-server.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/class-wp-rest-server.php
r42142 r42343 89 89 '/' => array( 90 90 'callback' => array( $this, 'get_index' ), 91 'methods' => 'GET',92 'args' => array(91 'methods' => 'GET', 92 'args' => array( 93 93 'context' => array( 94 94 'default' => 'view', … … 161 161 foreach ( (array) $error->errors as $code => $messages ) { 162 162 foreach ( (array) $messages as $message ) { 163 $errors[] = array( 'code' => $code, 'message' => $message, 'data' => $error->get_error_data( $code ) ); 163 $errors[] = array( 164 'code' => $code, 165 'message' => $message, 166 'data' => $error->get_error_data( $code ), 167 ); 164 168 } 165 169 } … … 261 265 * @param bool $rest_enabled Whether the REST API is enabled. Default true. 262 266 */ 263 apply_filters_deprecated( 'rest_enabled', array( true ), '4.7.0', 'rest_authentication_errors', 267 apply_filters_deprecated( 268 'rest_enabled', array( true ), '4.7.0', 'rest_authentication_errors', 264 269 __( 'The REST API can no longer be completely disabled, the rest_authentication_errors filter can be used to restrict access to the API, instead.' ) 265 270 ); … … 399 404 if ( $json_error_message ) { 400 405 $json_error_obj = new WP_Error( 'rest_encode_error', $json_error_message, array( 'status' => 500 ) ); 401 $result = $this->error_to_response( $json_error_obj );402 $result = wp_json_encode( $result->data[0] );406 $result = $this->error_to_response( $json_error_obj ); 407 $result = wp_json_encode( $result->data[0] ); 403 408 } 404 409 … … 472 477 473 478 foreach ( $items as $item ) { 474 $attributes = $item['attributes'];479 $attributes = $item['attributes']; 475 480 $attributes['href'] = $item['href']; 476 $data[ $rel ][] = $attributes;481 $data[ $rel ][] = $attributes; 477 482 } 478 483 } … … 500 505 } 501 506 502 $curies = $response->get_curies();507 $curies = $response->get_curies(); 503 508 $used_curies = array(); 504 509 … … 516 521 preg_match( '!' . $rel_regex . '!', $rel, $matches ); 517 522 if ( $matches ) { 518 $new_rel = $curie['name'] . ':' . $matches[1];523 $new_rel = $curie['name'] . ':' . $matches[1]; 519 524 $used_curies[ $curie['name'] ] = $curie; 520 $links[ $new_rel ] = $items;525 $links[ $new_rel ] = $items; 521 526 unset( $links[ $rel ] ); 522 527 break; … … 653 658 $this->namespaces[ $namespace ] = array(); 654 659 655 $this->register_route( $namespace, '/' . $namespace, array( 656 array( 657 'methods' => self::READABLE, 658 'callback' => array( $this, 'get_namespace_index' ), 659 'args' => array( 660 'namespace' => array( 661 'default' => $namespace, 662 ), 663 'context' => array( 664 'default' => 'view', 660 $this->register_route( 661 $namespace, '/' . $namespace, array( 662 array( 663 'methods' => self::READABLE, 664 'callback' => array( $this, 'get_namespace_index' ), 665 'args' => array( 666 'namespace' => array( 667 'default' => $namespace, 668 ), 669 'context' => array( 670 'default' => 'view', 671 ), 665 672 ), 666 673 ), 667 ) ,668 ) );674 ) 675 ); 669 676 } 670 677 671 678 // Associative to avoid double-registration. 672 679 $this->namespaces[ $namespace ][ $route ] = true; 673 $route_args['namespace'] = $namespace;680 $route_args['namespace'] = $namespace; 674 681 675 682 if ( $override || empty( $this->endpoints[ $route ] ) ) { … … 757 764 758 765 foreach ( $methods as $method ) { 759 $method = strtoupper( trim( $method ) );766 $method = strtoupper( trim( $method ) ); 760 767 $handler['methods'][ $method ] = true; 761 768 } … … 839 846 840 847 foreach ( $handlers as $handler ) { 841 $callback 848 $callback = $handler['callback']; 842 849 $response = null; 843 850 … … 1064 1071 } 1065 1072 1066 $routes = $this->namespaces[ $namespace ];1073 $routes = $this->namespaces[ $namespace ]; 1067 1074 $endpoints = array_intersect_key( $this->get_routes(), $routes ); 1068 1075 1069 $data = array(1076 $data = array( 1070 1077 'namespace' => $namespace, 1071 'routes' => $this->get_data_for_routes( $endpoints, $request['context'] ),1078 'routes' => $this->get_data_for_routes( $endpoints, $request['context'] ), 1072 1079 ); 1073 1080 $response = rest_ensure_response( $data ); … … 1147 1154 $data = array( 1148 1155 'namespace' => '', 1149 'methods' => array(),1156 'methods' => array(), 1150 1157 'endpoints' => array(), 1151 1158 ); … … 1172 1179 1173 1180 $data['methods'] = array_merge( $data['methods'], array_keys( $callback['methods'] ) ); 1174 $endpoint_data = array(1181 $endpoint_data = array( 1175 1182 'methods' => array_keys( $callback['methods'] ), 1176 1183 ); … … 1321 1328 1322 1329 // CONTENT_* headers are not prefixed with HTTP_. 1323 $additional = array( 'CONTENT_LENGTH' => true, 'CONTENT_MD5' => true, 'CONTENT_TYPE' => true ); 1330 $additional = array( 1331 'CONTENT_LENGTH' => true, 1332 'CONTENT_MD5' => true, 1333 'CONTENT_TYPE' => true, 1334 ); 1324 1335 1325 1336 foreach ( $server as $key => $value ) {
Note: See TracChangeset
for help on using the changeset viewer.