mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-16 23:00:21 +00:00
Code is Poetry.
WordPress' code just... wasn't. This is now dealt with. Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS. Fixes #41057. git-svn-id: https://develop.svn.wordpress.org/trunk@42343 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -88,8 +88,8 @@ class WP_REST_Server {
|
||||
// Meta endpoints.
|
||||
'/' => array(
|
||||
'callback' => array( $this, 'get_index' ),
|
||||
'methods' => 'GET',
|
||||
'args' => array(
|
||||
'methods' => 'GET',
|
||||
'args' => array(
|
||||
'context' => array(
|
||||
'default' => 'view',
|
||||
),
|
||||
@@ -160,7 +160,11 @@ class WP_REST_Server {
|
||||
|
||||
foreach ( (array) $error->errors as $code => $messages ) {
|
||||
foreach ( (array) $messages as $message ) {
|
||||
$errors[] = array( 'code' => $code, 'message' => $message, 'data' => $error->get_error_data( $code ) );
|
||||
$errors[] = array(
|
||||
'code' => $code,
|
||||
'message' => $message,
|
||||
'data' => $error->get_error_data( $code ),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,7 +264,8 @@ class WP_REST_Server {
|
||||
*
|
||||
* @param bool $rest_enabled Whether the REST API is enabled. Default true.
|
||||
*/
|
||||
apply_filters_deprecated( 'rest_enabled', array( true ), '4.7.0', 'rest_authentication_errors',
|
||||
apply_filters_deprecated(
|
||||
'rest_enabled', array( true ), '4.7.0', 'rest_authentication_errors',
|
||||
__( 'The REST API can no longer be completely disabled, the rest_authentication_errors filter can be used to restrict access to the API, instead.' )
|
||||
);
|
||||
|
||||
@@ -398,8 +403,8 @@ class WP_REST_Server {
|
||||
$json_error_message = $this->get_json_last_error();
|
||||
if ( $json_error_message ) {
|
||||
$json_error_obj = new WP_Error( 'rest_encode_error', $json_error_message, array( 'status' => 500 ) );
|
||||
$result = $this->error_to_response( $json_error_obj );
|
||||
$result = wp_json_encode( $result->data[0] );
|
||||
$result = $this->error_to_response( $json_error_obj );
|
||||
$result = wp_json_encode( $result->data[0] );
|
||||
}
|
||||
|
||||
if ( $jsonp_callback ) {
|
||||
@@ -471,9 +476,9 @@ class WP_REST_Server {
|
||||
$data[ $rel ] = array();
|
||||
|
||||
foreach ( $items as $item ) {
|
||||
$attributes = $item['attributes'];
|
||||
$attributes = $item['attributes'];
|
||||
$attributes['href'] = $item['href'];
|
||||
$data[ $rel ][] = $attributes;
|
||||
$data[ $rel ][] = $attributes;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -499,7 +504,7 @@ class WP_REST_Server {
|
||||
return array();
|
||||
}
|
||||
|
||||
$curies = $response->get_curies();
|
||||
$curies = $response->get_curies();
|
||||
$used_curies = array();
|
||||
|
||||
foreach ( $links as $rel => $items ) {
|
||||
@@ -515,9 +520,9 @@ class WP_REST_Server {
|
||||
$rel_regex = str_replace( '\{rel\}', '(.+)', preg_quote( $curie['href'], '!' ) );
|
||||
preg_match( '!' . $rel_regex . '!', $rel, $matches );
|
||||
if ( $matches ) {
|
||||
$new_rel = $curie['name'] . ':' . $matches[1];
|
||||
$new_rel = $curie['name'] . ':' . $matches[1];
|
||||
$used_curies[ $curie['name'] ] = $curie;
|
||||
$links[ $new_rel ] = $items;
|
||||
$links[ $new_rel ] = $items;
|
||||
unset( $links[ $rel ] );
|
||||
break;
|
||||
}
|
||||
@@ -652,25 +657,27 @@ class WP_REST_Server {
|
||||
if ( ! isset( $this->namespaces[ $namespace ] ) ) {
|
||||
$this->namespaces[ $namespace ] = array();
|
||||
|
||||
$this->register_route( $namespace, '/' . $namespace, array(
|
||||
array(
|
||||
'methods' => self::READABLE,
|
||||
'callback' => array( $this, 'get_namespace_index' ),
|
||||
'args' => array(
|
||||
'namespace' => array(
|
||||
'default' => $namespace,
|
||||
),
|
||||
'context' => array(
|
||||
'default' => 'view',
|
||||
$this->register_route(
|
||||
$namespace, '/' . $namespace, array(
|
||||
array(
|
||||
'methods' => self::READABLE,
|
||||
'callback' => array( $this, 'get_namespace_index' ),
|
||||
'args' => array(
|
||||
'namespace' => array(
|
||||
'default' => $namespace,
|
||||
),
|
||||
'context' => array(
|
||||
'default' => 'view',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
) );
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Associative to avoid double-registration.
|
||||
$this->namespaces[ $namespace ][ $route ] = true;
|
||||
$route_args['namespace'] = $namespace;
|
||||
$route_args['namespace'] = $namespace;
|
||||
|
||||
if ( $override || empty( $this->endpoints[ $route ] ) ) {
|
||||
$this->endpoints[ $route ] = $route_args;
|
||||
@@ -756,7 +763,7 @@ class WP_REST_Server {
|
||||
$handler['methods'] = array();
|
||||
|
||||
foreach ( $methods as $method ) {
|
||||
$method = strtoupper( trim( $method ) );
|
||||
$method = strtoupper( trim( $method ) );
|
||||
$handler['methods'][ $method ] = true;
|
||||
}
|
||||
}
|
||||
@@ -838,7 +845,7 @@ class WP_REST_Server {
|
||||
}
|
||||
|
||||
foreach ( $handlers as $handler ) {
|
||||
$callback = $handler['callback'];
|
||||
$callback = $handler['callback'];
|
||||
$response = null;
|
||||
|
||||
// Fallback to GET method if no HEAD method is registered.
|
||||
@@ -1063,12 +1070,12 @@ class WP_REST_Server {
|
||||
return new WP_Error( 'rest_invalid_namespace', __( 'The specified namespace could not be found.' ), array( 'status' => 404 ) );
|
||||
}
|
||||
|
||||
$routes = $this->namespaces[ $namespace ];
|
||||
$routes = $this->namespaces[ $namespace ];
|
||||
$endpoints = array_intersect_key( $this->get_routes(), $routes );
|
||||
|
||||
$data = array(
|
||||
$data = array(
|
||||
'namespace' => $namespace,
|
||||
'routes' => $this->get_data_for_routes( $endpoints, $request['context'] ),
|
||||
'routes' => $this->get_data_for_routes( $endpoints, $request['context'] ),
|
||||
);
|
||||
$response = rest_ensure_response( $data );
|
||||
|
||||
@@ -1146,7 +1153,7 @@ class WP_REST_Server {
|
||||
public function get_data_for_route( $route, $callbacks, $context = 'view' ) {
|
||||
$data = array(
|
||||
'namespace' => '',
|
||||
'methods' => array(),
|
||||
'methods' => array(),
|
||||
'endpoints' => array(),
|
||||
);
|
||||
|
||||
@@ -1171,7 +1178,7 @@ class WP_REST_Server {
|
||||
}
|
||||
|
||||
$data['methods'] = array_merge( $data['methods'], array_keys( $callback['methods'] ) );
|
||||
$endpoint_data = array(
|
||||
$endpoint_data = array(
|
||||
'methods' => array_keys( $callback['methods'] ),
|
||||
);
|
||||
|
||||
@@ -1320,7 +1327,11 @@ class WP_REST_Server {
|
||||
$headers = array();
|
||||
|
||||
// CONTENT_* headers are not prefixed with HTTP_.
|
||||
$additional = array( 'CONTENT_LENGTH' => true, 'CONTENT_MD5' => true, 'CONTENT_TYPE' => true );
|
||||
$additional = array(
|
||||
'CONTENT_LENGTH' => true,
|
||||
'CONTENT_MD5' => true,
|
||||
'CONTENT_TYPE' => true,
|
||||
);
|
||||
|
||||
foreach ( $server as $key => $value ) {
|
||||
if ( strpos( $key, 'HTTP_' ) === 0 ) {
|
||||
|
||||
Reference in New Issue
Block a user