Update WP and plugins
This commit is contained in:
parent
10a4713229
commit
1fb77fc4ff
864 changed files with 101724 additions and 78262 deletions
|
@ -111,13 +111,13 @@ class WP_REST_Request implements ArrayAccess {
|
|||
*/
|
||||
public function __construct( $method = '', $route = '', $attributes = array() ) {
|
||||
$this->params = array(
|
||||
'URL' => array(),
|
||||
'GET' => array(),
|
||||
'POST' => array(),
|
||||
'FILES' => array(),
|
||||
'URL' => array(),
|
||||
'GET' => array(),
|
||||
'POST' => array(),
|
||||
'FILES' => array(),
|
||||
|
||||
// See parse_json_params.
|
||||
'JSON' => null,
|
||||
'JSON' => null,
|
||||
|
||||
'defaults' => array(),
|
||||
);
|
||||
|
@ -174,7 +174,6 @@ class WP_REST_Request implements ArrayAccess {
|
|||
* @link https://nginx.org/en/docs/http/ngx_http_core_module.html#underscores_in_headers
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @static
|
||||
*
|
||||
* @param string $key Header name.
|
||||
* @return string Canonicalized name.
|
||||
|
@ -235,7 +234,7 @@ class WP_REST_Request implements ArrayAccess {
|
|||
* @param string $value Header value, or list of values.
|
||||
*/
|
||||
public function set_header( $key, $value ) {
|
||||
$key = $this->canonicalize_header_name( $key );
|
||||
$key = $this->canonicalize_header_name( $key );
|
||||
$value = (array) $value;
|
||||
|
||||
$this->headers[ $key ] = $value;
|
||||
|
@ -250,7 +249,7 @@ class WP_REST_Request implements ArrayAccess {
|
|||
* @param string $value Header value, or list of values.
|
||||
*/
|
||||
public function add_header( $key, $value ) {
|
||||
$key = $this->canonicalize_header_name( $key );
|
||||
$key = $this->canonicalize_header_name( $key );
|
||||
$value = (array) $value;
|
||||
|
||||
if ( ! isset( $this->headers[ $key ] ) ) {
|
||||
|
@ -368,7 +367,7 @@ class WP_REST_Request implements ArrayAccess {
|
|||
* @param array $order {
|
||||
* An array of types to check, in order of priority.
|
||||
*
|
||||
* @param string $type The type to check.
|
||||
* @param string $type The type to check.
|
||||
* }
|
||||
* @param WP_REST_Request $this The request object.
|
||||
*/
|
||||
|
@ -405,7 +404,7 @@ class WP_REST_Request implements ArrayAccess {
|
|||
* @param mixed $value Parameter value.
|
||||
*/
|
||||
public function set_param( $key, $value ) {
|
||||
$order = $this->get_parameter_order();
|
||||
$order = $this->get_parameter_order();
|
||||
$this->params[ $order[0] ][ $key ] = $value;
|
||||
}
|
||||
|
||||
|
@ -587,8 +586,8 @@ class WP_REST_Request implements ArrayAccess {
|
|||
$this->body = $data;
|
||||
|
||||
// Enable lazy parsing.
|
||||
$this->parsed_json = false;
|
||||
$this->parsed_body = false;
|
||||
$this->parsed_json = false;
|
||||
$this->parsed_body = false;
|
||||
$this->params['JSON'] = null;
|
||||
}
|
||||
|
||||
|
@ -650,7 +649,7 @@ class WP_REST_Request implements ArrayAccess {
|
|||
'status' => WP_Http::BAD_REQUEST,
|
||||
);
|
||||
if ( function_exists( 'json_last_error' ) ) {
|
||||
$error_data['json_error_code'] = json_last_error();
|
||||
$error_data['json_error_code'] = json_last_error();
|
||||
$error_data['json_error_message'] = json_last_error_msg();
|
||||
}
|
||||
|
||||
|
@ -802,7 +801,14 @@ class WP_REST_Request implements ArrayAccess {
|
|||
}
|
||||
|
||||
if ( $invalid_params ) {
|
||||
return new WP_Error( 'rest_invalid_param', sprintf( __( 'Invalid parameter(s): %s' ), implode( ', ', array_keys( $invalid_params ) ) ), array( 'status' => 400, 'params' => $invalid_params ) );
|
||||
return new WP_Error(
|
||||
'rest_invalid_param',
|
||||
sprintf( __( 'Invalid parameter(s): %s' ), implode( ', ', array_keys( $invalid_params ) ) ),
|
||||
array(
|
||||
'status' => 400,
|
||||
'params' => $invalid_params,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -824,7 +830,7 @@ class WP_REST_Request implements ArrayAccess {
|
|||
}
|
||||
|
||||
$attributes = $this->get_attributes();
|
||||
$required = array();
|
||||
$required = array();
|
||||
|
||||
// No arguments set, skip validation.
|
||||
if ( empty( $attributes['args'] ) ) {
|
||||
|
@ -840,7 +846,14 @@ class WP_REST_Request implements ArrayAccess {
|
|||
}
|
||||
|
||||
if ( ! empty( $required ) ) {
|
||||
return new WP_Error( 'rest_missing_callback_param', sprintf( __( 'Missing parameter(s): %s' ), implode( ', ', $required ) ), array( 'status' => 400, 'params' => $required ) );
|
||||
return new WP_Error(
|
||||
'rest_missing_callback_param',
|
||||
sprintf( __( 'Missing parameter(s): %s' ), implode( ', ', $required ) ),
|
||||
array(
|
||||
'status' => 400,
|
||||
'params' => $required,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -868,7 +881,14 @@ class WP_REST_Request implements ArrayAccess {
|
|||
}
|
||||
|
||||
if ( $invalid_params ) {
|
||||
return new WP_Error( 'rest_invalid_param', sprintf( __( 'Invalid parameter(s): %s' ), implode( ', ', array_keys( $invalid_params ) ) ), array( 'status' => 400, 'params' => $invalid_params ) );
|
||||
return new WP_Error(
|
||||
'rest_invalid_param',
|
||||
sprintf( __( 'Invalid parameter(s): %s' ), implode( ', ', array_keys( $invalid_params ) ) ),
|
||||
array(
|
||||
'status' => 400,
|
||||
'params' => $invalid_params,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -938,14 +958,13 @@ class WP_REST_Request implements ArrayAccess {
|
|||
/**
|
||||
* Retrieves a WP_REST_Request object from a full URL.
|
||||
*
|
||||
* @static
|
||||
* @since 4.5.0
|
||||
*
|
||||
* @param string $url URL with protocol, domain, path and query args.
|
||||
* @return WP_REST_Request|false WP_REST_Request object on success, false on failure.
|
||||
*/
|
||||
public static function from_url( $url ) {
|
||||
$bits = parse_url( $url );
|
||||
$bits = parse_url( $url );
|
||||
$query_params = array();
|
||||
|
||||
if ( ! empty( $bits['query'] ) ) {
|
||||
|
@ -956,7 +975,7 @@ class WP_REST_Request implements ArrayAccess {
|
|||
if ( get_option( 'permalink_structure' ) && 0 === strpos( $url, $api_root ) ) {
|
||||
// Pretty permalinks on, and URL is under the API root.
|
||||
$api_url_part = substr( $url, strlen( untrailingslashit( $api_root ) ) );
|
||||
$route = parse_url( $api_url_part, PHP_URL_PATH );
|
||||
$route = parse_url( $api_url_part, PHP_URL_PATH );
|
||||
} elseif ( ! empty( $query_params['rest_route'] ) ) {
|
||||
// ?rest_route=... set directly
|
||||
$route = $query_params['rest_route'];
|
||||
|
|
|
@ -193,7 +193,7 @@ class WP_REST_Response extends WP_HTTP_Response {
|
|||
}
|
||||
|
||||
/**
|
||||
* Retrieves the handler that was responsible for generating the response.
|
||||
* Sets the handler that was responsible for generating the response.
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
|
@ -232,7 +232,7 @@ class WP_REST_Response extends WP_HTTP_Response {
|
|||
$data = $this->get_data();
|
||||
$error->add( $data['code'], $data['message'], $data['data'] );
|
||||
if ( ! empty( $data['additional_errors'] ) ) {
|
||||
foreach( $data['additional_errors'] as $err ) {
|
||||
foreach ( $data['additional_errors'] as $err ) {
|
||||
$error->add( $err['code'], $err['message'], $err['data'] );
|
||||
}
|
||||
}
|
||||
|
@ -253,8 +253,8 @@ class WP_REST_Response extends WP_HTTP_Response {
|
|||
public function get_curies() {
|
||||
$curies = array(
|
||||
array(
|
||||
'name' => 'wp',
|
||||
'href' => 'https://api.w.org/{rel}',
|
||||
'name' => 'wp',
|
||||
'href' => 'https://api.w.org/{rel}',
|
||||
'templated' => true,
|
||||
),
|
||||
);
|
||||
|
|
|
@ -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,11 @@ 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 +406,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 ) {
|
||||
|
@ -454,7 +462,6 @@ class WP_REST_Server {
|
|||
* direct output.
|
||||
*
|
||||
* @since 4.4.0
|
||||
* @static
|
||||
*
|
||||
* @param WP_REST_Response $response Response to extract links from.
|
||||
* @return array Map of link relation to list of link hashes.
|
||||
|
@ -471,9 +478,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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -487,7 +494,6 @@ class WP_REST_Server {
|
|||
* direct output.
|
||||
*
|
||||
* @since 4.5.0
|
||||
* @static
|
||||
*
|
||||
* @param WP_REST_Response $response Response to extract links from.
|
||||
* @return array Map of link relation to list of link hashes.
|
||||
|
@ -499,7 +505,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 +521,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 +658,29 @@ class WP_REST_Server {
|
|||
if ( ! isset( $this->namespaces[ $namespace ] ) ) {
|
||||
$this->namespaces[ $namespace ] = array();
|
||||
|
||||
$this->register_route( $namespace, '/' . $namespace, array(
|
||||
$this->register_route(
|
||||
$namespace,
|
||||
'/' . $namespace,
|
||||
array(
|
||||
'methods' => self::READABLE,
|
||||
'callback' => array( $this, 'get_namespace_index' ),
|
||||
'args' => array(
|
||||
'namespace' => array(
|
||||
'default' => $namespace,
|
||||
),
|
||||
'context' => array(
|
||||
'default' => 'view',
|
||||
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 +766,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 +848,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.
|
||||
|
@ -894,9 +904,9 @@ class WP_REST_Server {
|
|||
*
|
||||
* @since 4.7.0
|
||||
*
|
||||
* @param WP_HTTP_Response $response Result to send to the client. Usually a WP_REST_Response.
|
||||
* @param WP_REST_Server $handler ResponseHandler instance (usually WP_REST_Server).
|
||||
* @param WP_REST_Request $request Request used to generate the response.
|
||||
* @param WP_HTTP_Response|WP_Error $response Result to send to the client. Usually a WP_REST_Response or WP_Error.
|
||||
* @param array $handler Route handler used for the request.
|
||||
* @param WP_REST_Request $request Request used to generate the response.
|
||||
*/
|
||||
$response = apply_filters( 'rest_request_before_callbacks', $response, $handler, $request );
|
||||
|
||||
|
@ -922,7 +932,7 @@ class WP_REST_Server {
|
|||
* @since 4.4.0
|
||||
* @since 4.5.0 Added `$route` and `$handler` parameters.
|
||||
*
|
||||
* @param bool $dispatch_result Dispatch result, will be used if not empty.
|
||||
* @param mixed $dispatch_result Dispatch result, will be used if not empty.
|
||||
* @param WP_REST_Request $request Request used to generate the response.
|
||||
* @param string $route Route matched for the request.
|
||||
* @param array $handler Route handler used for the request.
|
||||
|
@ -953,9 +963,9 @@ class WP_REST_Server {
|
|||
*
|
||||
* @since 4.7.0
|
||||
*
|
||||
* @param WP_HTTP_Response $response Result to send to the client. Usually a WP_REST_Response.
|
||||
* @param WP_REST_Server $handler ResponseHandler instance (usually WP_REST_Server).
|
||||
* @param WP_REST_Request $request Request used to generate the response.
|
||||
* @param WP_HTTP_Response|WP_Error $response Result to send to the client. Usually a WP_REST_Response or WP_Error.
|
||||
* @param array $handler Route handler used for the request.
|
||||
* @param WP_REST_Request $request Request used to generate the response.
|
||||
*/
|
||||
$response = apply_filters( 'rest_request_after_callbacks', $response, $handler, $request );
|
||||
|
||||
|
@ -1062,12 +1072,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 );
|
||||
|
||||
|
@ -1145,7 +1155,7 @@ class WP_REST_Server {
|
|||
public function get_data_for_route( $route, $callbacks, $context = 'view' ) {
|
||||
$data = array(
|
||||
'namespace' => '',
|
||||
'methods' => array(),
|
||||
'methods' => array(),
|
||||
'endpoints' => array(),
|
||||
);
|
||||
|
||||
|
@ -1170,7 +1180,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'] ),
|
||||
);
|
||||
|
||||
|
@ -1319,7 +1329,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 ) {
|
||||
|
|
|
@ -75,7 +75,7 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
|
|||
|
||||
// Attaching media to a post requires ability to edit said post.
|
||||
if ( ! empty( $request['post'] ) ) {
|
||||
$parent = get_post( (int) $request['post'] );
|
||||
$parent = get_post( (int) $request['post'] );
|
||||
$post_parent_type = get_post_type_object( $parent->post_type );
|
||||
|
||||
if ( ! current_user_can( $post_parent_type->cap->edit_post, $request['post'] ) ) {
|
||||
|
@ -101,7 +101,7 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
|
|||
}
|
||||
|
||||
// Get the file via $_FILES or raw data.
|
||||
$files = $request->get_file_params();
|
||||
$files = $request->get_file_params();
|
||||
$headers = $request->get_headers();
|
||||
|
||||
if ( ! empty( $files ) ) {
|
||||
|
@ -116,11 +116,11 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
|
|||
|
||||
$name = basename( $file['file'] );
|
||||
$name_parts = pathinfo( $name );
|
||||
$name = trim( substr( $name, 0, -(1 + strlen( $name_parts['extension'] ) ) ) );
|
||||
$name = trim( substr( $name, 0, -( 1 + strlen( $name_parts['extension'] ) ) ) );
|
||||
|
||||
$url = $file['url'];
|
||||
$type = $file['type'];
|
||||
$file = $file['file'];
|
||||
$url = $file['url'];
|
||||
$type = $file['type'];
|
||||
$file = $file['file'];
|
||||
|
||||
// Include image functions to get access to wp_read_image_metadata().
|
||||
require_once ABSPATH . 'wp-admin/includes/image.php';
|
||||
|
@ -138,9 +138,9 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
|
|||
}
|
||||
}
|
||||
|
||||
$attachment = $this->prepare_item_for_database( $request );
|
||||
$attachment = $this->prepare_item_for_database( $request );
|
||||
$attachment->post_mime_type = $type;
|
||||
$attachment->guid = $url;
|
||||
$attachment->guid = $url;
|
||||
|
||||
if ( empty( $attachment->post_title ) ) {
|
||||
$attachment->post_title = preg_replace( '/\.[^.]+$/', '', basename( $file ) );
|
||||
|
@ -228,7 +228,7 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
|
|||
}
|
||||
|
||||
$response = rest_ensure_response( $response );
|
||||
$data = $response->get_data();
|
||||
$data = $response->get_data();
|
||||
|
||||
if ( isset( $request['alt_text'] ) ) {
|
||||
update_post_meta( $data['id'], '_wp_attachment_image_alt', $request['alt_text'] );
|
||||
|
@ -421,10 +421,10 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
|
|||
$schema = parent::get_item_schema();
|
||||
|
||||
$schema['properties']['alt_text'] = array(
|
||||
'description' => __( 'Alternative text to display when attachment is not displayed.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'arg_options' => array(
|
||||
'description' => __( 'Alternative text to display when attachment is not displayed.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'arg_options' => array(
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
),
|
||||
);
|
||||
|
@ -438,7 +438,7 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
|
|||
'validate_callback' => null, // Note: validation implemented in self::prepare_item_for_database()
|
||||
),
|
||||
'properties' => array(
|
||||
'raw' => array(
|
||||
'raw' => array(
|
||||
'description' => __( 'Caption for the attachment, as it exists in the database.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'edit' ),
|
||||
|
@ -461,7 +461,7 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
|
|||
'validate_callback' => null, // Note: validation implemented in self::prepare_item_for_database()
|
||||
),
|
||||
'properties' => array(
|
||||
'raw' => array(
|
||||
'raw' => array(
|
||||
'description' => __( 'Description for the object, as it exists in the database.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'edit' ),
|
||||
|
@ -476,39 +476,39 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
|
|||
);
|
||||
|
||||
$schema['properties']['media_type'] = array(
|
||||
'description' => __( 'Attachment type.' ),
|
||||
'type' => 'string',
|
||||
'enum' => array( 'image', 'file' ),
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'readonly' => true,
|
||||
'description' => __( 'Attachment type.' ),
|
||||
'type' => 'string',
|
||||
'enum' => array( 'image', 'file' ),
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'readonly' => true,
|
||||
);
|
||||
|
||||
$schema['properties']['mime_type'] = array(
|
||||
'description' => __( 'The attachment MIME type.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'readonly' => true,
|
||||
'description' => __( 'The attachment MIME type.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'readonly' => true,
|
||||
);
|
||||
|
||||
$schema['properties']['media_details'] = array(
|
||||
'description' => __( 'Details about the media file, specific to its type.' ),
|
||||
'type' => 'object',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'readonly' => true,
|
||||
'description' => __( 'Details about the media file, specific to its type.' ),
|
||||
'type' => 'object',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'readonly' => true,
|
||||
);
|
||||
|
||||
$schema['properties']['post'] = array(
|
||||
'description' => __( 'The ID for the associated post of the attachment.' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'description' => __( 'The ID for the associated post of the attachment.' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
);
|
||||
|
||||
$schema['properties']['source_url'] = array(
|
||||
'description' => __( 'URL to the original attachment file.' ),
|
||||
'type' => 'string',
|
||||
'format' => 'uri',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'readonly' => true,
|
||||
'description' => __( 'URL to the original attachment file.' ),
|
||||
'type' => 'string',
|
||||
'format' => 'uri',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'readonly' => true,
|
||||
);
|
||||
|
||||
unset( $schema['properties']['password'] );
|
||||
|
@ -678,16 +678,16 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
|
|||
* @return array Query parameters for the attachment collection as an array.
|
||||
*/
|
||||
public function get_collection_params() {
|
||||
$params = parent::get_collection_params();
|
||||
$params['status']['default'] = 'inherit';
|
||||
$params = parent::get_collection_params();
|
||||
$params['status']['default'] = 'inherit';
|
||||
$params['status']['items']['enum'] = array( 'inherit', 'private', 'trash' );
|
||||
$media_types = $this->get_media_types();
|
||||
$media_types = $this->get_media_types();
|
||||
|
||||
$params['media_type'] = array(
|
||||
'default' => null,
|
||||
'description' => __( 'Limit result set to attachments of a particular media type.' ),
|
||||
'type' => 'string',
|
||||
'enum' => array_keys( $media_types ),
|
||||
'default' => null,
|
||||
'description' => __( 'Limit result set to attachments of a particular media type.' ),
|
||||
'type' => 'string',
|
||||
'enum' => array_keys( $media_types ),
|
||||
);
|
||||
|
||||
$params['mime_type'] = array(
|
||||
|
@ -744,7 +744,7 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
|
|||
|
||||
// Pass off to WP to handle the actual upload.
|
||||
$overrides = array(
|
||||
'test_form' => false,
|
||||
'test_form' => false,
|
||||
);
|
||||
|
||||
// Bypasses is_uploaded_file() when running unit tests.
|
||||
|
|
|
@ -43,65 +43,73 @@ class WP_REST_Comments_Controller extends WP_REST_Controller {
|
|||
*/
|
||||
public function register_routes() {
|
||||
|
||||
register_rest_route( $this->namespace, '/' . $this->rest_base, array(
|
||||
register_rest_route(
|
||||
$this->namespace,
|
||||
'/' . $this->rest_base,
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_items' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
'args' => $this->get_collection_params(),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'callback' => array( $this, 'create_item' ),
|
||||
'permission_callback' => array( $this, 'create_item_permissions_check' ),
|
||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
) );
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_items' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
'args' => $this->get_collection_params(),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'callback' => array( $this, 'create_item' ),
|
||||
'permission_callback' => array( $this, 'create_item_permissions_check' ),
|
||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
|
||||
'args' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'Unique identifier for the object.' ),
|
||||
'type' => 'integer',
|
||||
),
|
||||
),
|
||||
register_rest_route(
|
||||
$this->namespace,
|
||||
'/' . $this->rest_base . '/(?P<id>[\d]+)',
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_item' ),
|
||||
'permission_callback' => array( $this, 'get_item_permissions_check' ),
|
||||
'args' => array(
|
||||
'context' => $this->get_context_param( array( 'default' => 'view' ) ),
|
||||
'password' => array(
|
||||
'description' => __( 'The password for the parent post of the comment (if the post is password protected).' ),
|
||||
'type' => 'string',
|
||||
'args' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'Unique identifier for the object.' ),
|
||||
'type' => 'integer',
|
||||
),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'update_item' ),
|
||||
'permission_callback' => array( $this, 'update_item_permissions_check' ),
|
||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::DELETABLE,
|
||||
'callback' => array( $this, 'delete_item' ),
|
||||
'permission_callback' => array( $this, 'delete_item_permissions_check' ),
|
||||
'args' => array(
|
||||
'force' => array(
|
||||
'type' => 'boolean',
|
||||
'default' => false,
|
||||
'description' => __( 'Whether to bypass trash and force deletion.' ),
|
||||
),
|
||||
'password' => array(
|
||||
'description' => __( 'The password for the parent post of the comment (if the post is password protected).' ),
|
||||
'type' => 'string',
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_item' ),
|
||||
'permission_callback' => array( $this, 'get_item_permissions_check' ),
|
||||
'args' => array(
|
||||
'context' => $this->get_context_param( array( 'default' => 'view' ) ),
|
||||
'password' => array(
|
||||
'description' => __( 'The password for the parent post of the comment (if the post is password protected).' ),
|
||||
'type' => 'string',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
) );
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'update_item' ),
|
||||
'permission_callback' => array( $this, 'update_item_permissions_check' ),
|
||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::DELETABLE,
|
||||
'callback' => array( $this, 'delete_item' ),
|
||||
'permission_callback' => array( $this, 'delete_item_permissions_check' ),
|
||||
'args' => array(
|
||||
'force' => array(
|
||||
'type' => 'boolean',
|
||||
'default' => false,
|
||||
'description' => __( 'Whether to bypass trash and force deletion.' ),
|
||||
),
|
||||
'password' => array(
|
||||
'description' => __( 'The password for the parent post of the comment (if the post is password protected).' ),
|
||||
'type' => 'string',
|
||||
),
|
||||
),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -245,7 +253,7 @@ class WP_REST_Comments_Controller extends WP_REST_Controller {
|
|||
*/
|
||||
$prepared_args = apply_filters( 'rest_comment_query', $prepared_args, $request );
|
||||
|
||||
$query = new WP_Comment_Query;
|
||||
$query = new WP_Comment_Query;
|
||||
$query_result = $query->query( $prepared_args );
|
||||
|
||||
$comments = array();
|
||||
|
@ -255,7 +263,7 @@ class WP_REST_Comments_Controller extends WP_REST_Controller {
|
|||
continue;
|
||||
}
|
||||
|
||||
$data = $this->prepare_item_for_response( $comment, $request );
|
||||
$data = $this->prepare_item_for_response( $comment, $request );
|
||||
$comments[] = $this->prepare_response_for_collection( $data );
|
||||
}
|
||||
|
||||
|
@ -266,11 +274,11 @@ class WP_REST_Comments_Controller extends WP_REST_Controller {
|
|||
// Out-of-bounds, run the query again without LIMIT for total count.
|
||||
unset( $prepared_args['number'], $prepared_args['offset'] );
|
||||
|
||||
$query = new WP_Comment_Query;
|
||||
$query = new WP_Comment_Query;
|
||||
$prepared_args['count'] = true;
|
||||
|
||||
$total_comments = $query->query( $prepared_args );
|
||||
$max_pages = ceil( $total_comments / $request['per_page'] );
|
||||
$max_pages = ceil( $total_comments / $request['per_page'] );
|
||||
}
|
||||
|
||||
$response = rest_ensure_response( $comments );
|
||||
|
@ -314,7 +322,7 @@ class WP_REST_Comments_Controller extends WP_REST_Controller {
|
|||
return $error;
|
||||
}
|
||||
|
||||
$id = (int) $id;
|
||||
$id = (int) $id;
|
||||
$comment = get_comment( $id );
|
||||
if ( empty( $comment ) ) {
|
||||
return $error;
|
||||
|
@ -375,7 +383,7 @@ class WP_REST_Comments_Controller extends WP_REST_Controller {
|
|||
return $comment;
|
||||
}
|
||||
|
||||
$data = $this->prepare_item_for_response( $comment, $request );
|
||||
$data = $this->prepare_item_for_response( $comment, $request );
|
||||
$response = rest_ensure_response( $data );
|
||||
|
||||
return $response;
|
||||
|
@ -415,7 +423,8 @@ class WP_REST_Comments_Controller extends WP_REST_Controller {
|
|||
|
||||
// Limit who can set comment `author`, `author_ip` or `status` to anything other than the default.
|
||||
if ( isset( $request['author'] ) && get_current_user_id() !== $request['author'] && ! current_user_can( 'moderate_comments' ) ) {
|
||||
return new WP_Error( 'rest_comment_invalid_author',
|
||||
return new WP_Error(
|
||||
'rest_comment_invalid_author',
|
||||
/* translators: %s: request parameter */
|
||||
sprintf( __( "Sorry, you are not allowed to edit '%s' for comments." ), 'author' ),
|
||||
array( 'status' => rest_authorization_required_code() )
|
||||
|
@ -424,7 +433,8 @@ class WP_REST_Comments_Controller extends WP_REST_Controller {
|
|||
|
||||
if ( isset( $request['author_ip'] ) && ! current_user_can( 'moderate_comments' ) ) {
|
||||
if ( empty( $_SERVER['REMOTE_ADDR'] ) || $request['author_ip'] !== $_SERVER['REMOTE_ADDR'] ) {
|
||||
return new WP_Error( 'rest_comment_invalid_author_ip',
|
||||
return new WP_Error(
|
||||
'rest_comment_invalid_author_ip',
|
||||
/* translators: %s: request parameter */
|
||||
sprintf( __( "Sorry, you are not allowed to edit '%s' for comments." ), 'author_ip' ),
|
||||
array( 'status' => rest_authorization_required_code() )
|
||||
|
@ -433,7 +443,8 @@ class WP_REST_Comments_Controller extends WP_REST_Controller {
|
|||
}
|
||||
|
||||
if ( isset( $request['status'] ) && ! current_user_can( 'moderate_comments' ) ) {
|
||||
return new WP_Error( 'rest_comment_invalid_status',
|
||||
return new WP_Error(
|
||||
'rest_comment_invalid_status',
|
||||
/* translators: %s: request parameter */
|
||||
sprintf( __( "Sorry, you are not allowed to edit '%s' for comments." ), 'status' ),
|
||||
array( 'status' => rest_authorization_required_code() )
|
||||
|
@ -515,10 +526,10 @@ class WP_REST_Comments_Controller extends WP_REST_Controller {
|
|||
if ( is_user_logged_in() && $missing_author ) {
|
||||
$user = wp_get_current_user();
|
||||
|
||||
$prepared_comment['user_id'] = $user->ID;
|
||||
$prepared_comment['comment_author'] = $user->display_name;
|
||||
$prepared_comment['user_id'] = $user->ID;
|
||||
$prepared_comment['comment_author'] = $user->display_name;
|
||||
$prepared_comment['comment_author_email'] = $user->user_email;
|
||||
$prepared_comment['comment_author_url'] = $user->user_url;
|
||||
$prepared_comment['comment_author_url'] = $user->user_url;
|
||||
}
|
||||
|
||||
// Honor the discussion setting that requires a name and email address of the comment author.
|
||||
|
@ -571,7 +582,7 @@ class WP_REST_Comments_Controller extends WP_REST_Controller {
|
|||
* skipping further processing.
|
||||
*
|
||||
* @since 4.7.0
|
||||
* @since 4.8.0 $prepared_comment can now be a WP_Error to shortcircuit insertion.
|
||||
* @since 4.8.0 `$prepared_comment` can now be a WP_Error to shortcircuit insertion.
|
||||
*
|
||||
* @param array|WP_Error $prepared_comment The prepared comment data for wp_insert_comment().
|
||||
* @param WP_REST_Request $request Request used to insert the comment.
|
||||
|
@ -642,7 +653,6 @@ class WP_REST_Comments_Controller extends WP_REST_Controller {
|
|||
$response->set_status( 201 );
|
||||
$response->header( 'Location', rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $comment_id ) ) );
|
||||
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
@ -818,9 +828,14 @@ class WP_REST_Comments_Controller extends WP_REST_Controller {
|
|||
|
||||
if ( $force ) {
|
||||
$previous = $this->prepare_item_for_response( $comment, $request );
|
||||
$result = wp_delete_comment( $comment->comment_ID, true );
|
||||
$result = wp_delete_comment( $comment->comment_ID, true );
|
||||
$response = new WP_REST_Response();
|
||||
$response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data() ) );
|
||||
$response->set_data(
|
||||
array(
|
||||
'deleted' => true,
|
||||
'previous' => $previous->get_data(),
|
||||
)
|
||||
);
|
||||
} else {
|
||||
// If this type doesn't support trashing, error out.
|
||||
if ( ! $supports_trash ) {
|
||||
|
@ -832,8 +847,8 @@ class WP_REST_Comments_Controller extends WP_REST_Controller {
|
|||
return new WP_Error( 'rest_already_trashed', __( 'The comment has already been trashed.' ), array( 'status' => 410 ) );
|
||||
}
|
||||
|
||||
$result = wp_trash_comment( $comment->comment_ID );
|
||||
$comment = get_comment( $comment->comment_ID );
|
||||
$result = wp_trash_comment( $comment->comment_ID );
|
||||
$comment = get_comment( $comment->comment_ID );
|
||||
$response = $this->prepare_item_for_response( $comment, $request );
|
||||
}
|
||||
|
||||
|
@ -974,7 +989,7 @@ class WP_REST_Comments_Controller extends WP_REST_Controller {
|
|||
*/
|
||||
protected function prepare_links( $comment ) {
|
||||
$links = array(
|
||||
'self' => array(
|
||||
'self' => array(
|
||||
'href' => rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $comment->comment_ID ) ),
|
||||
),
|
||||
'collection' => array(
|
||||
|
@ -993,7 +1008,7 @@ class WP_REST_Comments_Controller extends WP_REST_Controller {
|
|||
$post = get_post( $comment->comment_post_ID );
|
||||
|
||||
if ( ! empty( $post->ID ) ) {
|
||||
$obj = get_post_type_object( $post->post_type );
|
||||
$obj = get_post_type_object( $post->post_type );
|
||||
$base = ! empty( $obj->rest_base ) ? $obj->rest_base : $obj->name;
|
||||
|
||||
$links['up'] = array(
|
||||
|
@ -1012,14 +1027,16 @@ class WP_REST_Comments_Controller extends WP_REST_Controller {
|
|||
}
|
||||
|
||||
// Only grab one comment to verify the comment has children.
|
||||
$comment_children = $comment->get_children( array(
|
||||
'number' => 1,
|
||||
'count' => true
|
||||
) );
|
||||
$comment_children = $comment->get_children(
|
||||
array(
|
||||
'number' => 1,
|
||||
'count' => true,
|
||||
)
|
||||
);
|
||||
|
||||
if ( ! empty( $comment_children ) ) {
|
||||
$args = array(
|
||||
'parent' => $comment->comment_ID
|
||||
'parent' => $comment->comment_ID,
|
||||
);
|
||||
|
||||
$rest_url = add_query_arg( $args, rest_url( $this->namespace . '/' . $this->rest_base ) );
|
||||
|
@ -1128,10 +1145,10 @@ class WP_REST_Comments_Controller extends WP_REST_Controller {
|
|||
$user = new WP_User( $request['author'] );
|
||||
|
||||
if ( $user->exists() ) {
|
||||
$prepared_comment['user_id'] = $user->ID;
|
||||
$prepared_comment['comment_author'] = $user->display_name;
|
||||
$prepared_comment['user_id'] = $user->ID;
|
||||
$prepared_comment['comment_author'] = $user->display_name;
|
||||
$prepared_comment['comment_author_email'] = $user->user_email;
|
||||
$prepared_comment['comment_author_url'] = $user->user_url;
|
||||
$prepared_comment['comment_author_url'] = $user->user_url;
|
||||
} else {
|
||||
return new WP_Error( 'rest_comment_author_invalid', __( 'Invalid comment author ID.' ), array( 'status' => 400 ) );
|
||||
}
|
||||
|
@ -1199,125 +1216,125 @@ class WP_REST_Comments_Controller extends WP_REST_Controller {
|
|||
*/
|
||||
public function get_item_schema() {
|
||||
$schema = array(
|
||||
'$schema' => 'http://json-schema.org/draft-04/schema#',
|
||||
'title' => 'comment',
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'Unique identifier for the object.' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'readonly' => true,
|
||||
'$schema' => 'http://json-schema.org/draft-04/schema#',
|
||||
'title' => 'comment',
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'Unique identifier for the object.' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'author' => array(
|
||||
'description' => __( 'The ID of the user object, if author was a user.' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'author' => array(
|
||||
'description' => __( 'The ID of the user object, if author was a user.' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
),
|
||||
'author_email' => array(
|
||||
'description' => __( 'Email address for the object author.' ),
|
||||
'type' => 'string',
|
||||
'format' => 'email',
|
||||
'context' => array( 'edit' ),
|
||||
'arg_options' => array(
|
||||
'author_email' => array(
|
||||
'description' => __( 'Email address for the object author.' ),
|
||||
'type' => 'string',
|
||||
'format' => 'email',
|
||||
'context' => array( 'edit' ),
|
||||
'arg_options' => array(
|
||||
'sanitize_callback' => array( $this, 'check_comment_author_email' ),
|
||||
'validate_callback' => null, // skip built-in validation of 'email'.
|
||||
),
|
||||
),
|
||||
'author_ip' => array(
|
||||
'description' => __( 'IP address for the object author.' ),
|
||||
'type' => 'string',
|
||||
'format' => 'ip',
|
||||
'context' => array( 'edit' ),
|
||||
'author_ip' => array(
|
||||
'description' => __( 'IP address for the object author.' ),
|
||||
'type' => 'string',
|
||||
'format' => 'ip',
|
||||
'context' => array( 'edit' ),
|
||||
),
|
||||
'author_name' => array(
|
||||
'description' => __( 'Display name for the object author.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'arg_options' => array(
|
||||
'author_name' => array(
|
||||
'description' => __( 'Display name for the object author.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'arg_options' => array(
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
),
|
||||
),
|
||||
'author_url' => array(
|
||||
'description' => __( 'URL for the object author.' ),
|
||||
'type' => 'string',
|
||||
'format' => 'uri',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'author_url' => array(
|
||||
'description' => __( 'URL for the object author.' ),
|
||||
'type' => 'string',
|
||||
'format' => 'uri',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
),
|
||||
'author_user_agent' => array(
|
||||
'description' => __( 'User agent for the object author.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'edit' ),
|
||||
'arg_options' => array(
|
||||
'author_user_agent' => array(
|
||||
'description' => __( 'User agent for the object author.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'edit' ),
|
||||
'arg_options' => array(
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
),
|
||||
),
|
||||
'content' => array(
|
||||
'description' => __( 'The content for the object.' ),
|
||||
'type' => 'object',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'arg_options' => array(
|
||||
'content' => array(
|
||||
'description' => __( 'The content for the object.' ),
|
||||
'type' => 'object',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'arg_options' => array(
|
||||
'sanitize_callback' => null, // Note: sanitization implemented in self::prepare_item_for_database()
|
||||
'validate_callback' => null, // Note: validation implemented in self::prepare_item_for_database()
|
||||
),
|
||||
'properties' => array(
|
||||
'raw' => array(
|
||||
'description' => __( 'Content for the object, as it exists in the database.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'edit' ),
|
||||
'properties' => array(
|
||||
'raw' => array(
|
||||
'description' => __( 'Content for the object, as it exists in the database.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'edit' ),
|
||||
),
|
||||
'rendered' => array(
|
||||
'description' => __( 'HTML content for the object, transformed for display.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'readonly' => true,
|
||||
'rendered' => array(
|
||||
'description' => __( 'HTML content for the object, transformed for display.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
),
|
||||
),
|
||||
'date' => array(
|
||||
'description' => __( "The date the object was published, in the site's timezone." ),
|
||||
'type' => 'string',
|
||||
'format' => 'date-time',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'date' => array(
|
||||
'description' => __( "The date the object was published, in the site's timezone." ),
|
||||
'type' => 'string',
|
||||
'format' => 'date-time',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
),
|
||||
'date_gmt' => array(
|
||||
'description' => __( 'The date the object was published, as GMT.' ),
|
||||
'type' => 'string',
|
||||
'format' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'date_gmt' => array(
|
||||
'description' => __( 'The date the object was published, as GMT.' ),
|
||||
'type' => 'string',
|
||||
'format' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'link' => array(
|
||||
'description' => __( 'URL to the object.' ),
|
||||
'type' => 'string',
|
||||
'format' => 'uri',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'readonly' => true,
|
||||
'link' => array(
|
||||
'description' => __( 'URL to the object.' ),
|
||||
'type' => 'string',
|
||||
'format' => 'uri',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'parent' => array(
|
||||
'description' => __( 'The ID for the parent of the object.' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'default' => 0,
|
||||
'parent' => array(
|
||||
'description' => __( 'The ID for the parent of the object.' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'default' => 0,
|
||||
),
|
||||
'post' => array(
|
||||
'description' => __( 'The ID of the associated post object.' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'default' => 0,
|
||||
'post' => array(
|
||||
'description' => __( 'The ID of the associated post object.' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'default' => 0,
|
||||
),
|
||||
'status' => array(
|
||||
'description' => __( 'State of the object.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'arg_options' => array(
|
||||
'status' => array(
|
||||
'description' => __( 'State of the object.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'arg_options' => array(
|
||||
'sanitize_callback' => 'sanitize_key',
|
||||
),
|
||||
),
|
||||
'type' => array(
|
||||
'description' => __( 'Type of Comment for the object.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'readonly' => true,
|
||||
'type' => array(
|
||||
'description' => __( 'Type of Comment for the object.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
@ -1337,11 +1354,11 @@ class WP_REST_Comments_Controller extends WP_REST_Controller {
|
|||
}
|
||||
|
||||
$schema['properties']['author_avatar_urls'] = array(
|
||||
'description' => __( 'Avatar URLs for the object author.' ),
|
||||
'type' => 'object',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'readonly' => true,
|
||||
'properties' => $avatar_properties,
|
||||
'description' => __( 'Avatar URLs for the object author.' ),
|
||||
'type' => 'object',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'readonly' => true,
|
||||
'properties' => $avatar_properties,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1363,78 +1380,78 @@ class WP_REST_Comments_Controller extends WP_REST_Controller {
|
|||
$query_params['context']['default'] = 'view';
|
||||
|
||||
$query_params['after'] = array(
|
||||
'description' => __( 'Limit response to comments published after a given ISO8601 compliant date.' ),
|
||||
'type' => 'string',
|
||||
'format' => 'date-time',
|
||||
'description' => __( 'Limit response to comments published after a given ISO8601 compliant date.' ),
|
||||
'type' => 'string',
|
||||
'format' => 'date-time',
|
||||
);
|
||||
|
||||
$query_params['author'] = array(
|
||||
'description' => __( 'Limit result set to comments assigned to specific user IDs. Requires authorization.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
'description' => __( 'Limit result set to comments assigned to specific user IDs. Requires authorization.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
),
|
||||
);
|
||||
|
||||
$query_params['author_exclude'] = array(
|
||||
'description' => __( 'Ensure result set excludes comments assigned to specific user IDs. Requires authorization.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
'description' => __( 'Ensure result set excludes comments assigned to specific user IDs. Requires authorization.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
),
|
||||
);
|
||||
|
||||
$query_params['author_email'] = array(
|
||||
'default' => null,
|
||||
'description' => __( 'Limit result set to that from a specific author email. Requires authorization.' ),
|
||||
'format' => 'email',
|
||||
'type' => 'string',
|
||||
'default' => null,
|
||||
'description' => __( 'Limit result set to that from a specific author email. Requires authorization.' ),
|
||||
'format' => 'email',
|
||||
'type' => 'string',
|
||||
);
|
||||
|
||||
$query_params['before'] = array(
|
||||
'description' => __( 'Limit response to comments published before a given ISO8601 compliant date.' ),
|
||||
'type' => 'string',
|
||||
'format' => 'date-time',
|
||||
'description' => __( 'Limit response to comments published before a given ISO8601 compliant date.' ),
|
||||
'type' => 'string',
|
||||
'format' => 'date-time',
|
||||
);
|
||||
|
||||
$query_params['exclude'] = array(
|
||||
'description' => __( 'Ensure result set excludes specific IDs.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
'description' => __( 'Ensure result set excludes specific IDs.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
),
|
||||
'default' => array(),
|
||||
'default' => array(),
|
||||
);
|
||||
|
||||
$query_params['include'] = array(
|
||||
'description' => __( 'Limit result set to specific IDs.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
'description' => __( 'Limit result set to specific IDs.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
),
|
||||
'default' => array(),
|
||||
'default' => array(),
|
||||
);
|
||||
|
||||
$query_params['offset'] = array(
|
||||
'description' => __( 'Offset the result set by a specific number of items.' ),
|
||||
'type' => 'integer',
|
||||
'description' => __( 'Offset the result set by a specific number of items.' ),
|
||||
'type' => 'integer',
|
||||
);
|
||||
|
||||
$query_params['order'] = array(
|
||||
'description' => __( 'Order sort attribute ascending or descending.' ),
|
||||
'type' => 'string',
|
||||
'default' => 'desc',
|
||||
'enum' => array(
|
||||
$query_params['order'] = array(
|
||||
'description' => __( 'Order sort attribute ascending or descending.' ),
|
||||
'type' => 'string',
|
||||
'default' => 'desc',
|
||||
'enum' => array(
|
||||
'asc',
|
||||
'desc',
|
||||
),
|
||||
);
|
||||
|
||||
$query_params['orderby'] = array(
|
||||
'description' => __( 'Sort collection by object attribute.' ),
|
||||
'type' => 'string',
|
||||
'default' => 'date_gmt',
|
||||
'enum' => array(
|
||||
$query_params['orderby'] = array(
|
||||
'description' => __( 'Sort collection by object attribute.' ),
|
||||
'type' => 'string',
|
||||
'default' => 'date_gmt',
|
||||
'enum' => array(
|
||||
'date',
|
||||
'date_gmt',
|
||||
'id',
|
||||
|
@ -1446,29 +1463,29 @@ class WP_REST_Comments_Controller extends WP_REST_Controller {
|
|||
);
|
||||
|
||||
$query_params['parent'] = array(
|
||||
'default' => array(),
|
||||
'description' => __( 'Limit result set to comments of specific parent IDs.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
'default' => array(),
|
||||
'description' => __( 'Limit result set to comments of specific parent IDs.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
),
|
||||
);
|
||||
|
||||
$query_params['parent_exclude'] = array(
|
||||
'default' => array(),
|
||||
'description' => __( 'Ensure result set excludes specific parent IDs.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
'default' => array(),
|
||||
'description' => __( 'Ensure result set excludes specific parent IDs.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
),
|
||||
);
|
||||
|
||||
$query_params['post'] = array(
|
||||
'default' => array(),
|
||||
'description' => __( 'Limit result set to comments assigned to specific post IDs.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
$query_params['post'] = array(
|
||||
'default' => array(),
|
||||
'description' => __( 'Limit result set to comments assigned to specific post IDs.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
),
|
||||
);
|
||||
|
||||
|
@ -1524,7 +1541,7 @@ class WP_REST_Comments_Controller extends WP_REST_Controller {
|
|||
}
|
||||
|
||||
switch ( $new_status ) {
|
||||
case 'approved' :
|
||||
case 'approved':
|
||||
case 'approve':
|
||||
case '1':
|
||||
$changed = wp_set_comment_status( $comment_id, 'approve' );
|
||||
|
@ -1533,19 +1550,19 @@ class WP_REST_Comments_Controller extends WP_REST_Controller {
|
|||
case '0':
|
||||
$changed = wp_set_comment_status( $comment_id, 'hold' );
|
||||
break;
|
||||
case 'spam' :
|
||||
case 'spam':
|
||||
$changed = wp_spam_comment( $comment_id );
|
||||
break;
|
||||
case 'unspam' :
|
||||
case 'unspam':
|
||||
$changed = wp_unspam_comment( $comment_id );
|
||||
break;
|
||||
case 'trash' :
|
||||
case 'trash':
|
||||
$changed = wp_trash_comment( $comment_id );
|
||||
break;
|
||||
case 'untrash' :
|
||||
case 'untrash':
|
||||
$changed = wp_untrash_comment( $comment_id );
|
||||
break;
|
||||
default :
|
||||
default:
|
||||
$changed = false;
|
||||
break;
|
||||
}
|
||||
|
@ -1566,12 +1583,12 @@ class WP_REST_Comments_Controller extends WP_REST_Controller {
|
|||
*/
|
||||
protected function check_read_post_permission( $post, $request ) {
|
||||
$posts_controller = new WP_REST_Posts_Controller( $post->post_type );
|
||||
$post_type = get_post_type_object( $post->post_type );
|
||||
$post_type = get_post_type_object( $post->post_type );
|
||||
|
||||
$has_password_filter = false;
|
||||
|
||||
// Only check password if a specific post was queried for or a single comment
|
||||
$requested_post = ! empty( $request['post'] ) && ( !is_array( $request['post'] ) || 1 === count( $request['post'] ) );
|
||||
$requested_post = ! empty( $request['post'] ) && ( ! is_array( $request['post'] ) || 1 === count( $request['post'] ) );
|
||||
$requested_comment = ! empty( $request['id'] );
|
||||
if ( ( $requested_post || $requested_comment ) && $posts_controller->can_access_password_content( $post, $request ) ) {
|
||||
add_filter( 'post_password_required', '__return_false' );
|
||||
|
|
|
@ -300,29 +300,29 @@ abstract class WP_REST_Controller {
|
|||
*/
|
||||
public function get_collection_params() {
|
||||
return array(
|
||||
'context' => $this->get_context_param(),
|
||||
'page' => array(
|
||||
'description' => __( 'Current page of the collection.' ),
|
||||
'type' => 'integer',
|
||||
'default' => 1,
|
||||
'sanitize_callback' => 'absint',
|
||||
'validate_callback' => 'rest_validate_request_arg',
|
||||
'minimum' => 1,
|
||||
'context' => $this->get_context_param(),
|
||||
'page' => array(
|
||||
'description' => __( 'Current page of the collection.' ),
|
||||
'type' => 'integer',
|
||||
'default' => 1,
|
||||
'sanitize_callback' => 'absint',
|
||||
'validate_callback' => 'rest_validate_request_arg',
|
||||
'minimum' => 1,
|
||||
),
|
||||
'per_page' => array(
|
||||
'description' => __( 'Maximum number of items to be returned in result set.' ),
|
||||
'type' => 'integer',
|
||||
'default' => 10,
|
||||
'minimum' => 1,
|
||||
'maximum' => 100,
|
||||
'sanitize_callback' => 'absint',
|
||||
'validate_callback' => 'rest_validate_request_arg',
|
||||
'per_page' => array(
|
||||
'description' => __( 'Maximum number of items to be returned in result set.' ),
|
||||
'type' => 'integer',
|
||||
'default' => 10,
|
||||
'minimum' => 1,
|
||||
'maximum' => 100,
|
||||
'sanitize_callback' => 'absint',
|
||||
'validate_callback' => 'rest_validate_request_arg',
|
||||
),
|
||||
'search' => array(
|
||||
'description' => __( 'Limit results to those matching a string.' ),
|
||||
'type' => 'string',
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
'validate_callback' => 'rest_validate_request_arg',
|
||||
'search' => array(
|
||||
'description' => __( 'Limit results to those matching a string.' ),
|
||||
'type' => 'string',
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
'validate_callback' => 'rest_validate_request_arg',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -339,10 +339,10 @@ abstract class WP_REST_Controller {
|
|||
*/
|
||||
public function get_context_param( $args = array() ) {
|
||||
$param_details = array(
|
||||
'description' => __( 'Scope under which the request is made; determines fields present in response.' ),
|
||||
'type' => 'string',
|
||||
'sanitize_callback' => 'sanitize_key',
|
||||
'validate_callback' => 'rest_validate_request_arg',
|
||||
'description' => __( 'Scope under which the request is made; determines fields present in response.' ),
|
||||
'type' => 'string',
|
||||
'sanitize_callback' => 'sanitize_key',
|
||||
'validate_callback' => 'rest_validate_request_arg',
|
||||
);
|
||||
|
||||
$schema = $this->get_item_schema();
|
||||
|
@ -532,7 +532,7 @@ abstract class WP_REST_Controller {
|
|||
if ( ! isset( $request['_fields'] ) ) {
|
||||
return $fields;
|
||||
}
|
||||
$requested_fields = is_array( $request['_fields'] ) ? $request['_fields'] : preg_split( '/[\s,]+/', $request['_fields'] );
|
||||
$requested_fields = wp_parse_list( $request['_fields'] );
|
||||
if ( 0 === count( $requested_fields ) ) {
|
||||
return $fields;
|
||||
}
|
||||
|
@ -596,7 +596,13 @@ abstract class WP_REST_Controller {
|
|||
|
||||
// Only use required / default from arg_options on CREATABLE endpoints.
|
||||
if ( WP_REST_Server::CREATABLE !== $method ) {
|
||||
$params['arg_options'] = array_diff_key( $params['arg_options'], array( 'required' => '', 'default' => '' ) );
|
||||
$params['arg_options'] = array_diff_key(
|
||||
$params['arg_options'],
|
||||
array(
|
||||
'required' => '',
|
||||
'default' => '',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$endpoint_args[ $field_id ] = array_merge( $endpoint_args[ $field_id ], $params['arg_options'] );
|
||||
|
|
|
@ -35,33 +35,41 @@ class WP_REST_Post_Statuses_Controller extends WP_REST_Controller {
|
|||
*/
|
||||
public function register_routes() {
|
||||
|
||||
register_rest_route( $this->namespace, '/' . $this->rest_base, array(
|
||||
register_rest_route(
|
||||
$this->namespace,
|
||||
'/' . $this->rest_base,
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_items' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
'args' => $this->get_collection_params(),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
) );
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_items' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
'args' => $this->get_collection_params(),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<status>[\w-]+)', array(
|
||||
'args' => array(
|
||||
'status' => array(
|
||||
'description' => __( 'An alphanumeric identifier for the status.' ),
|
||||
'type' => 'string',
|
||||
),
|
||||
),
|
||||
register_rest_route(
|
||||
$this->namespace,
|
||||
'/' . $this->rest_base . '/(?P<status>[\w-]+)',
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_item' ),
|
||||
'permission_callback' => array( $this, 'get_item_permissions_check' ),
|
||||
'args' => array(
|
||||
'context' => $this->get_context_param( array( 'default' => 'view' ) ),
|
||||
'args' => array(
|
||||
'status' => array(
|
||||
'description' => __( 'An alphanumeric identifier for the status.' ),
|
||||
'type' => 'string',
|
||||
),
|
||||
),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
) );
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_item' ),
|
||||
'permission_callback' => array( $this, 'get_item_permissions_check' ),
|
||||
'args' => array(
|
||||
'context' => $this->get_context_param( array( 'default' => 'view' ) ),
|
||||
),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -96,8 +104,8 @@ class WP_REST_Post_Statuses_Controller extends WP_REST_Controller {
|
|||
* @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure.
|
||||
*/
|
||||
public function get_items( $request ) {
|
||||
$data = array();
|
||||
$statuses = get_post_stati( array( 'internal' => false ), 'object' );
|
||||
$data = array();
|
||||
$statuses = get_post_stati( array( 'internal' => false ), 'object' );
|
||||
$statuses['trash'] = get_post_status_object( 'trash' );
|
||||
|
||||
foreach ( $statuses as $slug => $obj ) {
|
||||
|
@ -107,7 +115,7 @@ class WP_REST_Post_Statuses_Controller extends WP_REST_Controller {
|
|||
continue;
|
||||
}
|
||||
|
||||
$status = $this->prepare_item_for_response( $obj, $request );
|
||||
$status = $this->prepare_item_for_response( $obj, $request );
|
||||
$data[ $obj->name ] = $this->prepare_response_for_collection( $status );
|
||||
}
|
||||
|
||||
|
@ -227,8 +235,8 @@ class WP_REST_Post_Statuses_Controller extends WP_REST_Controller {
|
|||
}
|
||||
|
||||
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
|
||||
$data = $this->add_additional_fields_to_object( $data, $request );
|
||||
$data = $this->filter_response_by_context( $data, $context );
|
||||
$data = $this->add_additional_fields_to_object( $data, $request );
|
||||
$data = $this->filter_response_by_context( $data, $context );
|
||||
|
||||
$response = rest_ensure_response( $data );
|
||||
|
||||
|
@ -261,51 +269,51 @@ class WP_REST_Post_Statuses_Controller extends WP_REST_Controller {
|
|||
*/
|
||||
public function get_item_schema() {
|
||||
$schema = array(
|
||||
'$schema' => 'http://json-schema.org/draft-04/schema#',
|
||||
'title' => 'status',
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'name' => array(
|
||||
'description' => __( 'The title for the status.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'embed', 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
'$schema' => 'http://json-schema.org/draft-04/schema#',
|
||||
'title' => 'status',
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'name' => array(
|
||||
'description' => __( 'The title for the status.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'embed', 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'private' => array(
|
||||
'description' => __( 'Whether posts with this status should be private.' ),
|
||||
'type' => 'boolean',
|
||||
'context' => array( 'edit' ),
|
||||
'readonly' => true,
|
||||
'private' => array(
|
||||
'description' => __( 'Whether posts with this status should be private.' ),
|
||||
'type' => 'boolean',
|
||||
'context' => array( 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'protected' => array(
|
||||
'description' => __( 'Whether posts with this status should be protected.' ),
|
||||
'type' => 'boolean',
|
||||
'context' => array( 'edit' ),
|
||||
'readonly' => true,
|
||||
'protected' => array(
|
||||
'description' => __( 'Whether posts with this status should be protected.' ),
|
||||
'type' => 'boolean',
|
||||
'context' => array( 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'public' => array(
|
||||
'description' => __( 'Whether posts of this status should be shown in the front end of the site.' ),
|
||||
'type' => 'boolean',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
'public' => array(
|
||||
'description' => __( 'Whether posts of this status should be shown in the front end of the site.' ),
|
||||
'type' => 'boolean',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'queryable' => array(
|
||||
'description' => __( 'Whether posts with this status should be publicly-queryable.' ),
|
||||
'type' => 'boolean',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
'queryable' => array(
|
||||
'description' => __( 'Whether posts with this status should be publicly-queryable.' ),
|
||||
'type' => 'boolean',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'show_in_list' => array(
|
||||
'description' => __( 'Whether to include posts in the edit listing for their post type.' ),
|
||||
'type' => 'boolean',
|
||||
'context' => array( 'edit' ),
|
||||
'readonly' => true,
|
||||
'show_in_list' => array(
|
||||
'description' => __( 'Whether to include posts in the edit listing for their post type.' ),
|
||||
'type' => 'boolean',
|
||||
'context' => array( 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'slug' => array(
|
||||
'description' => __( 'An alphanumeric identifier for the status.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'embed', 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
'slug' => array(
|
||||
'description' => __( 'An alphanumeric identifier for the status.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'embed', 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
|
@ -35,32 +35,40 @@ class WP_REST_Post_Types_Controller extends WP_REST_Controller {
|
|||
*/
|
||||
public function register_routes() {
|
||||
|
||||
register_rest_route( $this->namespace, '/' . $this->rest_base, array(
|
||||
register_rest_route(
|
||||
$this->namespace,
|
||||
'/' . $this->rest_base,
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_items' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
'args' => $this->get_collection_params(),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
) );
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_items' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
'args' => $this->get_collection_params(),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<type>[\w-]+)', array(
|
||||
'args' => array(
|
||||
'type' => array(
|
||||
'description' => __( 'An alphanumeric identifier for the post type.' ),
|
||||
'type' => 'string',
|
||||
),
|
||||
),
|
||||
register_rest_route(
|
||||
$this->namespace,
|
||||
'/' . $this->rest_base . '/(?P<type>[\w-]+)',
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_item' ),
|
||||
'args' => array(
|
||||
'context' => $this->get_context_param( array( 'default' => 'view' ) ),
|
||||
'args' => array(
|
||||
'type' => array(
|
||||
'description' => __( 'An alphanumeric identifier for the post type.' ),
|
||||
'type' => 'string',
|
||||
),
|
||||
),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
) );
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_item' ),
|
||||
'args' => array(
|
||||
'context' => $this->get_context_param( array( 'default' => 'view' ) ),
|
||||
),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -101,7 +109,7 @@ class WP_REST_Post_Types_Controller extends WP_REST_Controller {
|
|||
continue;
|
||||
}
|
||||
|
||||
$post_type = $this->prepare_item_for_response( $obj, $request );
|
||||
$post_type = $this->prepare_item_for_response( $obj, $request );
|
||||
$data[ $obj->name ] = $this->prepare_response_for_collection( $post_type );
|
||||
}
|
||||
|
||||
|
@ -141,15 +149,15 @@ class WP_REST_Post_Types_Controller extends WP_REST_Controller {
|
|||
*
|
||||
* @since 4.7.0
|
||||
*
|
||||
* @param stdClass $post_type Post type data.
|
||||
* @param WP_Post_Type $post_type Post type object.
|
||||
* @param WP_REST_Request $request Full details about the request.
|
||||
* @return WP_REST_Response Response object.
|
||||
*/
|
||||
public function prepare_item_for_response( $post_type, $request ) {
|
||||
$taxonomies = wp_list_filter( get_object_taxonomies( $post_type->name, 'objects' ), array( 'show_in_rest' => true ) );
|
||||
$taxonomies = wp_list_pluck( $taxonomies, 'name' );
|
||||
$base = ! empty( $post_type->rest_base ) ? $post_type->rest_base : $post_type->name;
|
||||
$supports = get_all_post_type_supports( $post_type->name );
|
||||
$base = ! empty( $post_type->rest_base ) ? $post_type->rest_base : $post_type->name;
|
||||
$supports = get_all_post_type_supports( $post_type->name );
|
||||
|
||||
$fields = $this->get_fields_for_response( $request );
|
||||
$data = array();
|
||||
|
@ -201,14 +209,16 @@ class WP_REST_Post_Types_Controller extends WP_REST_Controller {
|
|||
// Wrap the data in a response object.
|
||||
$response = rest_ensure_response( $data );
|
||||
|
||||
$response->add_links( array(
|
||||
'collection' => array(
|
||||
'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
|
||||
),
|
||||
'https://api.w.org/items' => array(
|
||||
'href' => rest_url( sprintf( 'wp/v2/%s', $base ) ),
|
||||
),
|
||||
) );
|
||||
$response->add_links(
|
||||
array(
|
||||
'collection' => array(
|
||||
'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
|
||||
),
|
||||
'https://api.w.org/items' => array(
|
||||
'href' => rest_url( sprintf( 'wp/v2/%s', $base ) ),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Filters a post type returned from the API.
|
||||
|
@ -233,72 +243,72 @@ class WP_REST_Post_Types_Controller extends WP_REST_Controller {
|
|||
*/
|
||||
public function get_item_schema() {
|
||||
$schema = array(
|
||||
'$schema' => 'http://json-schema.org/draft-04/schema#',
|
||||
'title' => 'type',
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'capabilities' => array(
|
||||
'description' => __( 'All capabilities used by the post type.' ),
|
||||
'type' => 'object',
|
||||
'context' => array( 'edit' ),
|
||||
'readonly' => true,
|
||||
'$schema' => 'http://json-schema.org/draft-04/schema#',
|
||||
'title' => 'type',
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'capabilities' => array(
|
||||
'description' => __( 'All capabilities used by the post type.' ),
|
||||
'type' => 'object',
|
||||
'context' => array( 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'description' => array(
|
||||
'description' => __( 'A human-readable description of the post type.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
'description' => array(
|
||||
'description' => __( 'A human-readable description of the post type.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'hierarchical' => array(
|
||||
'description' => __( 'Whether or not the post type should have children.' ),
|
||||
'type' => 'boolean',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
'hierarchical' => array(
|
||||
'description' => __( 'Whether or not the post type should have children.' ),
|
||||
'type' => 'boolean',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'viewable' => array(
|
||||
'description' => __( 'Whether or not the post type can be viewed.' ),
|
||||
'type' => 'boolean',
|
||||
'context' => array( 'edit' ),
|
||||
'readonly' => true,
|
||||
'viewable' => array(
|
||||
'description' => __( 'Whether or not the post type can be viewed.' ),
|
||||
'type' => 'boolean',
|
||||
'context' => array( 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'labels' => array(
|
||||
'description' => __( 'Human-readable labels for the post type for various contexts.' ),
|
||||
'type' => 'object',
|
||||
'context' => array( 'edit' ),
|
||||
'readonly' => true,
|
||||
'labels' => array(
|
||||
'description' => __( 'Human-readable labels for the post type for various contexts.' ),
|
||||
'type' => 'object',
|
||||
'context' => array( 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'name' => array(
|
||||
'description' => __( 'The title for the post type.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'readonly' => true,
|
||||
'name' => array(
|
||||
'description' => __( 'The title for the post type.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'slug' => array(
|
||||
'description' => __( 'An alphanumeric identifier for the post type.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'readonly' => true,
|
||||
'slug' => array(
|
||||
'description' => __( 'An alphanumeric identifier for the post type.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'supports' => array(
|
||||
'description' => __( 'All features, supported by the post type.' ),
|
||||
'type' => 'object',
|
||||
'context' => array( 'edit' ),
|
||||
'readonly' => true,
|
||||
'supports' => array(
|
||||
'description' => __( 'All features, supported by the post type.' ),
|
||||
'type' => 'object',
|
||||
'context' => array( 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'taxonomies' => array(
|
||||
'description' => __( 'Taxonomies associated with post type.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'taxonomies' => array(
|
||||
'description' => __( 'Taxonomies associated with post type.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'string',
|
||||
),
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'rest_base' => array(
|
||||
'description' => __( 'REST base route for the post type.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'readonly' => true,
|
||||
'rest_base' => array(
|
||||
'description' => __( 'REST base route for the post type.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
|
@ -42,7 +42,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||
public function __construct( $post_type ) {
|
||||
$this->post_type = $post_type;
|
||||
$this->namespace = 'wp/v2';
|
||||
$obj = get_post_type_object( $post_type );
|
||||
$obj = get_post_type_object( $post_type );
|
||||
$this->rest_base = ! empty( $obj->rest_base ) ? $obj->rest_base : $obj->name;
|
||||
|
||||
$this->meta = new WP_REST_Post_Meta_Fields( $this->post_type );
|
||||
|
@ -57,25 +57,29 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||
*/
|
||||
public function register_routes() {
|
||||
|
||||
register_rest_route( $this->namespace, '/' . $this->rest_base, array(
|
||||
register_rest_route(
|
||||
$this->namespace,
|
||||
'/' . $this->rest_base,
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_items' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
'args' => $this->get_collection_params(),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'callback' => array( $this, 'create_item' ),
|
||||
'permission_callback' => array( $this, 'create_item_permissions_check' ),
|
||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
) );
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_items' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
'args' => $this->get_collection_params(),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'callback' => array( $this, 'create_item' ),
|
||||
'permission_callback' => array( $this, 'create_item_permissions_check' ),
|
||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
)
|
||||
);
|
||||
|
||||
$schema = $this->get_item_schema();
|
||||
$schema = $this->get_item_schema();
|
||||
$get_item_args = array(
|
||||
'context' => $this->get_context_param( array( 'default' => 'view' ) ),
|
||||
'context' => $this->get_context_param( array( 'default' => 'view' ) ),
|
||||
);
|
||||
if ( isset( $schema['properties']['password'] ) ) {
|
||||
$get_item_args['password'] = array(
|
||||
|
@ -83,39 +87,43 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||
'type' => 'string',
|
||||
);
|
||||
}
|
||||
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
|
||||
'args' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'Unique identifier for the object.' ),
|
||||
'type' => 'integer',
|
||||
),
|
||||
),
|
||||
register_rest_route(
|
||||
$this->namespace,
|
||||
'/' . $this->rest_base . '/(?P<id>[\d]+)',
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_item' ),
|
||||
'permission_callback' => array( $this, 'get_item_permissions_check' ),
|
||||
'args' => $get_item_args,
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'update_item' ),
|
||||
'permission_callback' => array( $this, 'update_item_permissions_check' ),
|
||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::DELETABLE,
|
||||
'callback' => array( $this, 'delete_item' ),
|
||||
'permission_callback' => array( $this, 'delete_item_permissions_check' ),
|
||||
'args' => array(
|
||||
'force' => array(
|
||||
'type' => 'boolean',
|
||||
'default' => false,
|
||||
'description' => __( 'Whether to bypass trash and force deletion.' ),
|
||||
'args' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'Unique identifier for the object.' ),
|
||||
'type' => 'integer',
|
||||
),
|
||||
),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
) );
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_item' ),
|
||||
'permission_callback' => array( $this, 'get_item_permissions_check' ),
|
||||
'args' => $get_item_args,
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'update_item' ),
|
||||
'permission_callback' => array( $this, 'update_item_permissions_check' ),
|
||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::DELETABLE,
|
||||
'callback' => array( $this, 'delete_item' ),
|
||||
'permission_callback' => array( $this, 'delete_item_permissions_check' ),
|
||||
'args' => array(
|
||||
'force' => array(
|
||||
'type' => 'boolean',
|
||||
'default' => false,
|
||||
'description' => __( 'Whether to bypass trash and force deletion.' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -159,7 +167,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||
|
||||
// Retrieve the list of registered collection query parameters.
|
||||
$registered = $this->get_collection_params();
|
||||
$args = array();
|
||||
$args = array();
|
||||
|
||||
/*
|
||||
* This array defines mappings between public API query parameters whose
|
||||
|
@ -258,13 +266,13 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||
* @param array $args Key value array of query var to query value.
|
||||
* @param WP_REST_Request $request The request used.
|
||||
*/
|
||||
$args = apply_filters( "rest_{$this->post_type}_query", $args, $request );
|
||||
$args = apply_filters( "rest_{$this->post_type}_query", $args, $request );
|
||||
$query_args = $this->prepare_items_query( $args, $request );
|
||||
|
||||
$taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_rest' => true ) );
|
||||
|
||||
foreach ( $taxonomies as $taxonomy ) {
|
||||
$base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;
|
||||
$base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;
|
||||
$tax_exclude = $base . '_exclude';
|
||||
|
||||
if ( ! empty( $request[ $base ] ) ) {
|
||||
|
@ -311,7 +319,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||
remove_filter( 'post_password_required', '__return_false' );
|
||||
}
|
||||
|
||||
$page = (int) $query_args['paged'];
|
||||
$page = (int) $query_args['paged'];
|
||||
$total_posts = $posts_query->found_posts;
|
||||
|
||||
if ( $total_posts < 1 ) {
|
||||
|
@ -329,13 +337,13 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||
return new WP_Error( 'rest_post_invalid_page_number', __( 'The page number requested is larger than the number of pages available.' ), array( 'status' => 400 ) );
|
||||
}
|
||||
|
||||
$response = rest_ensure_response( $posts );
|
||||
$response = rest_ensure_response( $posts );
|
||||
|
||||
$response->header( 'X-WP-Total', (int) $total_posts );
|
||||
$response->header( 'X-WP-TotalPages', (int) $max_pages );
|
||||
|
||||
$request_params = $request->get_query_params();
|
||||
$base = add_query_arg( $request_params, rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ) );
|
||||
$base = add_query_arg( $request_params, rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ) );
|
||||
|
||||
if ( $page > 1 ) {
|
||||
$prev_page = $page - 1;
|
||||
|
@ -466,7 +474,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||
$response = rest_ensure_response( $data );
|
||||
|
||||
if ( is_post_type_viewable( get_post_type_object( $post->post_type ) ) ) {
|
||||
$response->link_header( 'alternate', get_permalink( $post->ID ), array( 'type' => 'text/html' ) );
|
||||
$response->link_header( 'alternate', get_permalink( $post->ID ), array( 'type' => 'text/html' ) );
|
||||
}
|
||||
|
||||
return $response;
|
||||
|
@ -591,7 +599,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||
}
|
||||
}
|
||||
|
||||
$post = get_post( $post_id );
|
||||
$post = get_post( $post_id );
|
||||
$fields_update = $this->update_additional_fields_for_object( $post, $request );
|
||||
|
||||
if ( is_wp_error( $fields_update ) ) {
|
||||
|
@ -730,7 +738,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||
}
|
||||
}
|
||||
|
||||
$post = get_post( $post_id );
|
||||
$post = get_post( $post_id );
|
||||
$fields_update = $this->update_additional_fields_for_object( $post, $request );
|
||||
|
||||
if ( is_wp_error( $fields_update ) ) {
|
||||
|
@ -817,13 +825,17 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||
|
||||
$request->set_param( 'context', 'edit' );
|
||||
|
||||
|
||||
// If we're forcing, then delete permanently.
|
||||
if ( $force ) {
|
||||
$previous = $this->prepare_item_for_response( $post, $request );
|
||||
$result = wp_delete_post( $id, true );
|
||||
$result = wp_delete_post( $id, true );
|
||||
$response = new WP_REST_Response();
|
||||
$response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data() ) );
|
||||
$response->set_data(
|
||||
array(
|
||||
'deleted' => true,
|
||||
'previous' => $previous->get_data(),
|
||||
)
|
||||
);
|
||||
} else {
|
||||
// If we don't support trashing for this type, error out.
|
||||
if ( ! $supports_trash ) {
|
||||
|
@ -838,8 +850,8 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||
|
||||
// (Note that internally this falls through to `wp_delete_post` if
|
||||
// the trash is disabled.)
|
||||
$result = wp_trash_post( $id );
|
||||
$post = get_post( $id );
|
||||
$result = wp_trash_post( $id );
|
||||
$post = get_post( $id );
|
||||
$response = $this->prepare_item_for_response( $post, $request );
|
||||
}
|
||||
|
||||
|
@ -1013,14 +1025,14 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||
|
||||
if ( ! empty( $date_data ) ) {
|
||||
list( $prepared_post->post_date, $prepared_post->post_date_gmt ) = $date_data;
|
||||
$prepared_post->edit_date = true;
|
||||
$prepared_post->edit_date = true;
|
||||
}
|
||||
} elseif ( ! empty( $schema['properties']['date_gmt'] ) && ! empty( $request['date_gmt'] ) ) {
|
||||
$date_data = rest_get_date_with_gmt( $request['date_gmt'], true );
|
||||
|
||||
if ( ! empty( $date_data ) ) {
|
||||
list( $prepared_post->post_date, $prepared_post->post_date_gmt ) = $date_data;
|
||||
$prepared_post->edit_date = true;
|
||||
$prepared_post->edit_date = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1215,7 +1227,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||
* Sets the template for a post.
|
||||
*
|
||||
* @since 4.7.0
|
||||
* @since 4.9.0 Introduced the $validate parameter.
|
||||
* @since 4.9.0 Added the `$validate` parameter.
|
||||
*
|
||||
* @param string $template Page template filename.
|
||||
* @param integer $post_id Post ID.
|
||||
|
@ -1525,7 +1537,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||
|
||||
if ( in_array( 'excerpt', $fields, true ) ) {
|
||||
/** This filter is documented in wp-includes/post-template.php */
|
||||
$excerpt = apply_filters( 'the_excerpt', apply_filters( 'get_the_excerpt', $post->post_excerpt, $post ) );
|
||||
$excerpt = apply_filters( 'the_excerpt', apply_filters( 'get_the_excerpt', $post->post_excerpt, $post ) );
|
||||
$data['excerpt'] = array(
|
||||
'raw' => $post->post_excerpt,
|
||||
'rendered' => post_password_required( $post ) ? '' : $excerpt,
|
||||
|
@ -1593,13 +1605,13 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||
$base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;
|
||||
|
||||
if ( in_array( $base, $fields, true ) ) {
|
||||
$terms = get_the_terms( $post, $taxonomy->name );
|
||||
$terms = get_the_terms( $post, $taxonomy->name );
|
||||
$data[ $base ] = $terms ? array_values( wp_list_pluck( $terms, 'term_id' ) ) : array();
|
||||
}
|
||||
}
|
||||
|
||||
$post_type_obj = get_post_type_object( $post->post_type );
|
||||
if ( is_post_type_viewable( $post_type_obj ) && $post_type_obj->public ) {
|
||||
if ( is_post_type_viewable( $post_type_obj ) && $post_type_obj->public ) {
|
||||
|
||||
if ( ! function_exists( 'get_sample_permalink' ) ) {
|
||||
require_once ABSPATH . '/wp-admin/includes/post.php';
|
||||
|
@ -1677,14 +1689,14 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||
|
||||
// Entity meta.
|
||||
$links = array(
|
||||
'self' => array(
|
||||
'href' => rest_url( trailingslashit( $base ) . $post->ID ),
|
||||
'self' => array(
|
||||
'href' => rest_url( trailingslashit( $base ) . $post->ID ),
|
||||
),
|
||||
'collection' => array(
|
||||
'href' => rest_url( $base ),
|
||||
'href' => rest_url( $base ),
|
||||
),
|
||||
'about' => array(
|
||||
'href' => rest_url( 'wp/v2/types/' . $this->post_type ),
|
||||
'href' => rest_url( 'wp/v2/types/' . $this->post_type ),
|
||||
),
|
||||
);
|
||||
|
||||
|
@ -1723,7 +1735,6 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||
'id' => $last_revision,
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$post_type_obj = get_post_type_object( $post->post_type );
|
||||
|
@ -1859,19 +1870,19 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||
'type' => 'object',
|
||||
// Base properties for every Post.
|
||||
'properties' => array(
|
||||
'date' => array(
|
||||
'date' => array(
|
||||
'description' => __( "The date the object was published, in the site's timezone." ),
|
||||
'type' => 'string',
|
||||
'format' => 'date-time',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
),
|
||||
'date_gmt' => array(
|
||||
'date_gmt' => array(
|
||||
'description' => __( 'The date the object was published, as GMT.' ),
|
||||
'type' => 'string',
|
||||
'format' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'guid' => array(
|
||||
'guid' => array(
|
||||
'description' => __( 'The globally unique identifier for the object.' ),
|
||||
'type' => 'object',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
|
@ -1891,34 +1902,34 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||
),
|
||||
),
|
||||
),
|
||||
'id' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'Unique identifier for the object.' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'link' => array(
|
||||
'link' => array(
|
||||
'description' => __( 'URL to the object.' ),
|
||||
'type' => 'string',
|
||||
'format' => 'uri',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'modified' => array(
|
||||
'modified' => array(
|
||||
'description' => __( "The date the object was last modified, in the site's timezone." ),
|
||||
'type' => 'string',
|
||||
'format' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'modified_gmt' => array(
|
||||
'modified_gmt' => array(
|
||||
'description' => __( 'The date the object was last modified, as GMT.' ),
|
||||
'type' => 'string',
|
||||
'format' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'slug' => array(
|
||||
'slug' => array(
|
||||
'description' => __( 'An alphanumeric identifier for the object unique to its type.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
|
@ -1926,19 +1937,19 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||
'sanitize_callback' => array( $this, 'sanitize_slug' ),
|
||||
),
|
||||
),
|
||||
'status' => array(
|
||||
'status' => array(
|
||||
'description' => __( 'A named status for the object.' ),
|
||||
'type' => 'string',
|
||||
'enum' => array_keys( get_post_stati( array( 'internal' => false ) ) ),
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'type' => array(
|
||||
'type' => array(
|
||||
'description' => __( 'Type of Post for the object.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'password' => array(
|
||||
'password' => array(
|
||||
'description' => __( 'A password to protect access to the content and excerpt.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'edit' ),
|
||||
|
@ -1983,8 +1994,8 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||
'post-formats',
|
||||
'custom-fields',
|
||||
);
|
||||
$fixed_schemas = array(
|
||||
'post' => array(
|
||||
$fixed_schemas = array(
|
||||
'post' => array(
|
||||
'title',
|
||||
'editor',
|
||||
'author',
|
||||
|
@ -1995,7 +2006,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||
'post-formats',
|
||||
'custom-fields',
|
||||
),
|
||||
'page' => array(
|
||||
'page' => array(
|
||||
'title',
|
||||
'editor',
|
||||
'author',
|
||||
|
@ -2033,7 +2044,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||
'validate_callback' => null, // Note: validation implemented in self::prepare_item_for_database()
|
||||
),
|
||||
'properties' => array(
|
||||
'raw' => array(
|
||||
'raw' => array(
|
||||
'description' => __( 'Title for the object, as it exists in the database.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'edit' ),
|
||||
|
@ -2058,12 +2069,12 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||
'validate_callback' => null, // Note: validation implemented in self::prepare_item_for_database()
|
||||
),
|
||||
'properties' => array(
|
||||
'raw' => array(
|
||||
'raw' => array(
|
||||
'description' => __( 'Content for the object, as it exists in the database.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'edit' ),
|
||||
),
|
||||
'rendered' => array(
|
||||
'rendered' => array(
|
||||
'description' => __( 'HTML content for the object, transformed for display.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
|
@ -2075,7 +2086,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||
'context' => array( 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'protected' => array(
|
||||
'protected' => array(
|
||||
'description' => __( 'Whether the content is protected with a password.' ),
|
||||
'type' => 'boolean',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
|
@ -2103,18 +2114,18 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||
'validate_callback' => null, // Note: validation implemented in self::prepare_item_for_database()
|
||||
),
|
||||
'properties' => array(
|
||||
'raw' => array(
|
||||
'raw' => array(
|
||||
'description' => __( 'Excerpt for the object, as it exists in the database.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'edit' ),
|
||||
),
|
||||
'rendered' => array(
|
||||
'rendered' => array(
|
||||
'description' => __( 'HTML excerpt for the object, transformed for display.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'protected' => array(
|
||||
'protected' => array(
|
||||
'description' => __( 'Whether the excerpt is protected with a password.' ),
|
||||
'type' => 'boolean',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
|
@ -2139,7 +2150,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||
'enum' => array( 'open', 'closed' ),
|
||||
'context' => array( 'view', 'edit' ),
|
||||
);
|
||||
$schema['properties']['ping_status'] = array(
|
||||
$schema['properties']['ping_status'] = array(
|
||||
'description' => __( 'Whether or not the object can be pinged.' ),
|
||||
'type' => 'string',
|
||||
'enum' => array( 'open', 'closed' ),
|
||||
|
@ -2193,13 +2204,13 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||
|
||||
$taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_rest' => true ) );
|
||||
foreach ( $taxonomies as $taxonomy ) {
|
||||
$base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;
|
||||
$base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;
|
||||
$schema['properties'][ $base ] = array(
|
||||
/* translators: %s: taxonomy name */
|
||||
'description' => sprintf( __( 'The terms assigned to the object in the %s taxonomy.' ), $taxonomy->name ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
'type' => 'integer',
|
||||
),
|
||||
'context' => array( 'view', 'edit' ),
|
||||
);
|
||||
|
@ -2249,8 +2260,8 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||
'title' => __( 'The current user can post unfiltered HTML markup and JavaScript.' ),
|
||||
'href' => $href,
|
||||
'targetSchema' => array(
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'content' => array(
|
||||
'raw' => array(
|
||||
'type' => 'string',
|
||||
|
@ -2353,78 +2364,78 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||
$query_params['context']['default'] = 'view';
|
||||
|
||||
$query_params['after'] = array(
|
||||
'description' => __( 'Limit response to posts published after a given ISO8601 compliant date.' ),
|
||||
'type' => 'string',
|
||||
'format' => 'date-time',
|
||||
'description' => __( 'Limit response to posts published after a given ISO8601 compliant date.' ),
|
||||
'type' => 'string',
|
||||
'format' => 'date-time',
|
||||
);
|
||||
|
||||
if ( post_type_supports( $this->post_type, 'author' ) ) {
|
||||
$query_params['author'] = array(
|
||||
'description' => __( 'Limit result set to posts assigned to specific authors.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
$query_params['author'] = array(
|
||||
'description' => __( 'Limit result set to posts assigned to specific authors.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
),
|
||||
'default' => array(),
|
||||
'default' => array(),
|
||||
);
|
||||
$query_params['author_exclude'] = array(
|
||||
'description' => __( 'Ensure result set excludes posts assigned to specific authors.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
'description' => __( 'Ensure result set excludes posts assigned to specific authors.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
),
|
||||
'default' => array(),
|
||||
'default' => array(),
|
||||
);
|
||||
}
|
||||
|
||||
$query_params['before'] = array(
|
||||
'description' => __( 'Limit response to posts published before a given ISO8601 compliant date.' ),
|
||||
'type' => 'string',
|
||||
'format' => 'date-time',
|
||||
'description' => __( 'Limit response to posts published before a given ISO8601 compliant date.' ),
|
||||
'type' => 'string',
|
||||
'format' => 'date-time',
|
||||
);
|
||||
|
||||
$query_params['exclude'] = array(
|
||||
'description' => __( 'Ensure result set excludes specific IDs.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
'description' => __( 'Ensure result set excludes specific IDs.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
),
|
||||
'default' => array(),
|
||||
'default' => array(),
|
||||
);
|
||||
|
||||
$query_params['include'] = array(
|
||||
'description' => __( 'Limit result set to specific IDs.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
'description' => __( 'Limit result set to specific IDs.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
),
|
||||
'default' => array(),
|
||||
'default' => array(),
|
||||
);
|
||||
|
||||
if ( 'page' === $this->post_type || post_type_supports( $this->post_type, 'page-attributes' ) ) {
|
||||
$query_params['menu_order'] = array(
|
||||
'description' => __( 'Limit result set to posts with a specific menu_order value.' ),
|
||||
'type' => 'integer',
|
||||
'description' => __( 'Limit result set to posts with a specific menu_order value.' ),
|
||||
'type' => 'integer',
|
||||
);
|
||||
}
|
||||
|
||||
$query_params['offset'] = array(
|
||||
'description' => __( 'Offset the result set by a specific number of items.' ),
|
||||
'type' => 'integer',
|
||||
'description' => __( 'Offset the result set by a specific number of items.' ),
|
||||
'type' => 'integer',
|
||||
);
|
||||
|
||||
$query_params['order'] = array(
|
||||
'description' => __( 'Order sort attribute ascending or descending.' ),
|
||||
'type' => 'string',
|
||||
'default' => 'desc',
|
||||
'enum' => array( 'asc', 'desc' ),
|
||||
'description' => __( 'Order sort attribute ascending or descending.' ),
|
||||
'type' => 'string',
|
||||
'default' => 'desc',
|
||||
'enum' => array( 'asc', 'desc' ),
|
||||
);
|
||||
|
||||
$query_params['orderby'] = array(
|
||||
'description' => __( 'Sort collection by object attribute.' ),
|
||||
'type' => 'string',
|
||||
'default' => 'date',
|
||||
'enum' => array(
|
||||
'description' => __( 'Sort collection by object attribute.' ),
|
||||
'type' => 'string',
|
||||
'default' => 'date',
|
||||
'enum' => array(
|
||||
'author',
|
||||
'date',
|
||||
'id',
|
||||
|
@ -2445,21 +2456,21 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||
$post_type = get_post_type_object( $this->post_type );
|
||||
|
||||
if ( $post_type->hierarchical || 'attachment' === $this->post_type ) {
|
||||
$query_params['parent'] = array(
|
||||
'description' => __( 'Limit result set to items with particular parent IDs.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
$query_params['parent'] = array(
|
||||
'description' => __( 'Limit result set to items with particular parent IDs.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
),
|
||||
'default' => array(),
|
||||
'default' => array(),
|
||||
);
|
||||
$query_params['parent_exclude'] = array(
|
||||
'description' => __( 'Limit result set to all items except those of a particular parent ID.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
'description' => __( 'Limit result set to all items except those of a particular parent ID.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
),
|
||||
'default' => array(),
|
||||
'default' => array(),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -2467,7 +2478,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||
'description' => __( 'Limit result set to posts with one or more specific slugs.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'string',
|
||||
'type' => 'string',
|
||||
),
|
||||
'sanitize_callback' => 'wp_parse_slug_list',
|
||||
);
|
||||
|
@ -2477,8 +2488,8 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||
'description' => __( 'Limit result set to posts assigned one or more statuses.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'enum' => array_merge( array_keys( get_post_stati() ), array( 'any' ) ),
|
||||
'type' => 'string',
|
||||
'enum' => array_merge( array_keys( get_post_stati() ), array( 'any' ) ),
|
||||
'type' => 'string',
|
||||
),
|
||||
'sanitize_callback' => array( $this, 'sanitize_post_statuses' ),
|
||||
);
|
||||
|
@ -2490,12 +2501,12 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||
|
||||
$query_params[ $base ] = array(
|
||||
/* translators: %s: taxonomy name */
|
||||
'description' => sprintf( __( 'Limit result set to all items that have the specified term assigned in the %s taxonomy.' ), $base ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
'description' => sprintf( __( 'Limit result set to all items that have the specified term assigned in the %s taxonomy.' ), $base ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
),
|
||||
'default' => array(),
|
||||
'default' => array(),
|
||||
);
|
||||
|
||||
$query_params[ $base . '_exclude' ] = array(
|
||||
|
@ -2503,16 +2514,16 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||
'description' => sprintf( __( 'Limit result set to all items except those that have the specified term assigned in the %s taxonomy.' ), $base ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
'type' => 'integer',
|
||||
),
|
||||
'default' => array(),
|
||||
'default' => array(),
|
||||
);
|
||||
}
|
||||
|
||||
if ( 'post' === $this->post_type ) {
|
||||
$query_params['sticky'] = array(
|
||||
'description' => __( 'Limit result set to items that are sticky.' ),
|
||||
'type' => 'boolean',
|
||||
'description' => __( 'Limit result set to items that are sticky.' ),
|
||||
'type' => 'boolean',
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -2549,7 +2560,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||
$statuses = wp_parse_slug_list( $statuses );
|
||||
|
||||
// The default status is different in WP_REST_Attachments_Controller
|
||||
$attributes = $request->get_attributes();
|
||||
$attributes = $request->get_attributes();
|
||||
$default_status = $attributes['args']['status']['default'];
|
||||
|
||||
foreach ( $statuses as $status ) {
|
||||
|
|
|
@ -48,12 +48,12 @@ class WP_REST_Revisions_Controller extends WP_REST_Controller {
|
|||
* @param string $parent_post_type Post type of the parent.
|
||||
*/
|
||||
public function __construct( $parent_post_type ) {
|
||||
$this->parent_post_type = $parent_post_type;
|
||||
$this->parent_post_type = $parent_post_type;
|
||||
$this->parent_controller = new WP_REST_Posts_Controller( $parent_post_type );
|
||||
$this->namespace = 'wp/v2';
|
||||
$this->rest_base = 'revisions';
|
||||
$post_type_object = get_post_type_object( $parent_post_type );
|
||||
$this->parent_base = ! empty( $post_type_object->rest_base ) ? $post_type_object->rest_base : $post_type_object->name;
|
||||
$this->namespace = 'wp/v2';
|
||||
$this->rest_base = 'revisions';
|
||||
$post_type_object = get_post_type_object( $parent_post_type );
|
||||
$this->parent_base = ! empty( $post_type_object->rest_base ) ? $post_type_object->rest_base : $post_type_object->name;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -65,55 +65,63 @@ class WP_REST_Revisions_Controller extends WP_REST_Controller {
|
|||
*/
|
||||
public function register_routes() {
|
||||
|
||||
register_rest_route( $this->namespace, '/' . $this->parent_base . '/(?P<parent>[\d]+)/' . $this->rest_base, array(
|
||||
'args' => array(
|
||||
'parent' => array(
|
||||
'description' => __( 'The ID for the parent of the object.' ),
|
||||
'type' => 'integer',
|
||||
),
|
||||
),
|
||||
register_rest_route(
|
||||
$this->namespace,
|
||||
'/' . $this->parent_base . '/(?P<parent>[\d]+)/' . $this->rest_base,
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_items' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
'args' => $this->get_collection_params(),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
) );
|
||||
|
||||
register_rest_route( $this->namespace, '/' . $this->parent_base . '/(?P<parent>[\d]+)/' . $this->rest_base . '/(?P<id>[\d]+)', array(
|
||||
'args' => array(
|
||||
'parent' => array(
|
||||
'description' => __( 'The ID for the parent of the object.' ),
|
||||
'type' => 'integer',
|
||||
),
|
||||
'id' => array(
|
||||
'description' => __( 'Unique identifier for the object.' ),
|
||||
'type' => 'integer',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_item' ),
|
||||
'permission_callback' => array( $this, 'get_item_permissions_check' ),
|
||||
'args' => array(
|
||||
'context' => $this->get_context_param( array( 'default' => 'view' ) ),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::DELETABLE,
|
||||
'callback' => array( $this, 'delete_item' ),
|
||||
'permission_callback' => array( $this, 'delete_item_permissions_check' ),
|
||||
'args' => array(
|
||||
'force' => array(
|
||||
'type' => 'boolean',
|
||||
'default' => false,
|
||||
'description' => __( 'Required to be true, as revisions do not support trashing.' ),
|
||||
'args' => array(
|
||||
'parent' => array(
|
||||
'description' => __( 'The ID for the parent of the object.' ),
|
||||
'type' => 'integer',
|
||||
),
|
||||
),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
));
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_items' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
'args' => $this->get_collection_params(),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route(
|
||||
$this->namespace,
|
||||
'/' . $this->parent_base . '/(?P<parent>[\d]+)/' . $this->rest_base . '/(?P<id>[\d]+)',
|
||||
array(
|
||||
'args' => array(
|
||||
'parent' => array(
|
||||
'description' => __( 'The ID for the parent of the object.' ),
|
||||
'type' => 'integer',
|
||||
),
|
||||
'id' => array(
|
||||
'description' => __( 'Unique identifier for the object.' ),
|
||||
'type' => 'integer',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_item' ),
|
||||
'permission_callback' => array( $this, 'get_item_permissions_check' ),
|
||||
'args' => array(
|
||||
'context' => $this->get_context_param( array( 'default' => 'view' ) ),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::DELETABLE,
|
||||
'callback' => array( $this, 'delete_item' ),
|
||||
'permission_callback' => array( $this, 'delete_item_permissions_check' ),
|
||||
'args' => array(
|
||||
'force' => array(
|
||||
'type' => 'boolean',
|
||||
'default' => false,
|
||||
'description' => __( 'Required to be true, as revisions do not support trashing.' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
@ -283,7 +291,7 @@ class WP_REST_Revisions_Controller extends WP_REST_Controller {
|
|||
|
||||
$response = array();
|
||||
foreach ( $revisions as $revision ) {
|
||||
$data = $this->prepare_item_for_response( $revision, $request );
|
||||
$data = $this->prepare_item_for_response( $revision, $request );
|
||||
$response[] = $this->prepare_response_for_collection( $data );
|
||||
}
|
||||
|
||||
|
@ -421,7 +429,12 @@ class WP_REST_Revisions_Controller extends WP_REST_Controller {
|
|||
}
|
||||
|
||||
$response = new WP_REST_Response();
|
||||
$response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data() ) );
|
||||
$response->set_data(
|
||||
array(
|
||||
'deleted' => true,
|
||||
'previous' => $previous->get_data(),
|
||||
)
|
||||
);
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
@ -540,9 +553,9 @@ class WP_REST_Revisions_Controller extends WP_REST_Controller {
|
|||
);
|
||||
}
|
||||
|
||||
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
|
||||
$data = $this->add_additional_fields_to_object( $data, $request );
|
||||
$data = $this->filter_response_by_context( $data, $context );
|
||||
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
|
||||
$data = $this->add_additional_fields_to_object( $data, $request );
|
||||
$data = $this->filter_response_by_context( $data, $context );
|
||||
$response = rest_ensure_response( $data );
|
||||
|
||||
if ( ! empty( $data['parent'] ) ) {
|
||||
|
@ -599,51 +612,51 @@ class WP_REST_Revisions_Controller extends WP_REST_Controller {
|
|||
'type' => 'object',
|
||||
// Base properties for every Revision.
|
||||
'properties' => array(
|
||||
'author' => array(
|
||||
'author' => array(
|
||||
'description' => __( 'The ID for the author of the object.' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
),
|
||||
'date' => array(
|
||||
'date' => array(
|
||||
'description' => __( "The date the object was published, in the site's timezone." ),
|
||||
'type' => 'string',
|
||||
'format' => 'date-time',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
),
|
||||
'date_gmt' => array(
|
||||
'date_gmt' => array(
|
||||
'description' => __( 'The date the object was published, as GMT.' ),
|
||||
'type' => 'string',
|
||||
'format' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'guid' => array(
|
||||
'guid' => array(
|
||||
'description' => __( 'GUID for the object, as it exists in the database.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'id' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'Unique identifier for the object.' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
),
|
||||
'modified' => array(
|
||||
'modified' => array(
|
||||
'description' => __( "The date the object was last modified, in the site's timezone." ),
|
||||
'type' => 'string',
|
||||
'format' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'modified_gmt' => array(
|
||||
'modified_gmt' => array(
|
||||
'description' => __( 'The date the object was last modified, as GMT.' ),
|
||||
'type' => 'string',
|
||||
'format' => 'date-time',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'parent' => array(
|
||||
'parent' => array(
|
||||
'description' => __( 'The ID for the parent of the object.' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
),
|
||||
'slug' => array(
|
||||
),
|
||||
'slug' => array(
|
||||
'description' => __( 'An alphanumeric identifier for the object unique to its type.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
|
|
|
@ -35,21 +35,25 @@ class WP_REST_Settings_Controller extends WP_REST_Controller {
|
|||
*/
|
||||
public function register_routes() {
|
||||
|
||||
register_rest_route( $this->namespace, '/' . $this->rest_base, array(
|
||||
register_rest_route(
|
||||
$this->namespace,
|
||||
'/' . $this->rest_base,
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_item' ),
|
||||
'args' => array(),
|
||||
'permission_callback' => array( $this, 'get_item_permissions_check' ),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'update_item' ),
|
||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
|
||||
'permission_callback' => array( $this, 'get_item_permissions_check' ),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
) );
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_item' ),
|
||||
'args' => array(),
|
||||
'permission_callback' => array( $this, 'get_item_permissions_check' ),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'update_item' ),
|
||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
|
||||
'permission_callback' => array( $this, 'get_item_permissions_check' ),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
@ -139,7 +143,7 @@ class WP_REST_Settings_Controller extends WP_REST_Controller {
|
|||
public function update_item( $request ) {
|
||||
$options = $this->get_registered_options();
|
||||
|
||||
$params = $request->get_params();
|
||||
$params = $request->get_params();
|
||||
|
||||
foreach ( $options as $name => $args ) {
|
||||
if ( ! array_key_exists( $name, $params ) ) {
|
||||
|
@ -185,7 +189,9 @@ class WP_REST_Settings_Controller extends WP_REST_Controller {
|
|||
*/
|
||||
if ( is_wp_error( rest_validate_value_from_schema( get_option( $args['option_name'], false ), $args['schema'] ) ) ) {
|
||||
return new WP_Error(
|
||||
'rest_invalid_stored_value', sprintf( __( 'The %s property has an invalid stored value, and cannot be updated to null.' ), $name ), array( 'status' => 500 )
|
||||
'rest_invalid_stored_value',
|
||||
sprintf( __( 'The %s property has an invalid stored value, and cannot be updated to null.' ), $name ),
|
||||
array( 'status' => 500 )
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -232,7 +238,7 @@ class WP_REST_Settings_Controller extends WP_REST_Controller {
|
|||
'default' => isset( $args['default'] ) ? $args['default'] : null,
|
||||
);
|
||||
|
||||
$rest_args['schema'] = array_merge( $default_schema, $rest_args['schema'] );
|
||||
$rest_args['schema'] = array_merge( $default_schema, $rest_args['schema'] );
|
||||
$rest_args['option_name'] = $name;
|
||||
|
||||
// Skip over settings that don't have a defined type in the schema.
|
||||
|
@ -274,7 +280,7 @@ class WP_REST_Settings_Controller extends WP_REST_Controller {
|
|||
);
|
||||
|
||||
foreach ( $options as $option_name => $option ) {
|
||||
$schema['properties'][ $option_name ] = $option['schema'];
|
||||
$schema['properties'][ $option_name ] = $option['schema'];
|
||||
$schema['properties'][ $option_name ]['arg_options'] = array(
|
||||
'sanitize_callback' => array( $this, 'sanitize_callback' ),
|
||||
);
|
||||
|
|
|
@ -35,33 +35,41 @@ class WP_REST_Taxonomies_Controller extends WP_REST_Controller {
|
|||
*/
|
||||
public function register_routes() {
|
||||
|
||||
register_rest_route( $this->namespace, '/' . $this->rest_base, array(
|
||||
register_rest_route(
|
||||
$this->namespace,
|
||||
'/' . $this->rest_base,
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_items' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
'args' => $this->get_collection_params(),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
) );
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_items' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
'args' => $this->get_collection_params(),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<taxonomy>[\w-]+)', array(
|
||||
'args' => array(
|
||||
'taxonomy' => array(
|
||||
'description' => __( 'An alphanumeric identifier for the taxonomy.' ),
|
||||
'type' => 'string',
|
||||
),
|
||||
),
|
||||
register_rest_route(
|
||||
$this->namespace,
|
||||
'/' . $this->rest_base . '/(?P<taxonomy>[\w-]+)',
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_item' ),
|
||||
'permission_callback' => array( $this, 'get_item_permissions_check' ),
|
||||
'args' => array(
|
||||
'context' => $this->get_context_param( array( 'default' => 'view' ) ),
|
||||
'args' => array(
|
||||
'taxonomy' => array(
|
||||
'description' => __( 'An alphanumeric identifier for the taxonomy.' ),
|
||||
'type' => 'string',
|
||||
),
|
||||
),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
) );
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_item' ),
|
||||
'permission_callback' => array( $this, 'get_item_permissions_check' ),
|
||||
'args' => array(
|
||||
'context' => $this->get_context_param( array( 'default' => 'view' ) ),
|
||||
),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -112,8 +120,8 @@ class WP_REST_Taxonomies_Controller extends WP_REST_Controller {
|
|||
if ( empty( $value->show_in_rest ) || ( 'edit' === $request['context'] && ! current_user_can( $value->cap->assign_terms ) ) ) {
|
||||
continue;
|
||||
}
|
||||
$tax = $this->prepare_item_for_response( $value, $request );
|
||||
$tax = $this->prepare_response_for_collection( $tax );
|
||||
$tax = $this->prepare_item_for_response( $value, $request );
|
||||
$tax = $this->prepare_response_for_collection( $tax );
|
||||
$data[ $tax_type ] = $tax;
|
||||
}
|
||||
|
||||
|
@ -229,20 +237,22 @@ class WP_REST_Taxonomies_Controller extends WP_REST_Controller {
|
|||
}
|
||||
|
||||
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
|
||||
$data = $this->add_additional_fields_to_object( $data, $request );
|
||||
$data = $this->filter_response_by_context( $data, $context );
|
||||
$data = $this->add_additional_fields_to_object( $data, $request );
|
||||
$data = $this->filter_response_by_context( $data, $context );
|
||||
|
||||
// Wrap the data in a response object.
|
||||
$response = rest_ensure_response( $data );
|
||||
|
||||
$response->add_links( array(
|
||||
'collection' => array(
|
||||
'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
|
||||
),
|
||||
'https://api.w.org/items' => array(
|
||||
'href' => rest_url( sprintf( 'wp/v2/%s', $base ) ),
|
||||
),
|
||||
) );
|
||||
$response->add_links(
|
||||
array(
|
||||
'collection' => array(
|
||||
'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ),
|
||||
),
|
||||
'https://api.w.org/items' => array(
|
||||
'href' => rest_url( sprintf( 'wp/v2/%s', $base ) ),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Filters a taxonomy returned from the REST API.
|
||||
|
@ -267,72 +277,99 @@ class WP_REST_Taxonomies_Controller extends WP_REST_Controller {
|
|||
*/
|
||||
public function get_item_schema() {
|
||||
$schema = array(
|
||||
'$schema' => 'http://json-schema.org/draft-04/schema#',
|
||||
'title' => 'taxonomy',
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'capabilities' => array(
|
||||
'description' => __( 'All capabilities used by the taxonomy.' ),
|
||||
'type' => 'object',
|
||||
'context' => array( 'edit' ),
|
||||
'readonly' => true,
|
||||
'$schema' => 'http://json-schema.org/draft-04/schema#',
|
||||
'title' => 'taxonomy',
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'capabilities' => array(
|
||||
'description' => __( 'All capabilities used by the taxonomy.' ),
|
||||
'type' => 'object',
|
||||
'context' => array( 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'description' => array(
|
||||
'description' => __( 'A human-readable description of the taxonomy.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
'description' => array(
|
||||
'description' => __( 'A human-readable description of the taxonomy.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'hierarchical' => array(
|
||||
'description' => __( 'Whether or not the taxonomy should have children.' ),
|
||||
'type' => 'boolean',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
'hierarchical' => array(
|
||||
'description' => __( 'Whether or not the taxonomy should have children.' ),
|
||||
'type' => 'boolean',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'labels' => array(
|
||||
'description' => __( 'Human-readable labels for the taxonomy for various contexts.' ),
|
||||
'type' => 'object',
|
||||
'context' => array( 'edit' ),
|
||||
'readonly' => true,
|
||||
'labels' => array(
|
||||
'description' => __( 'Human-readable labels for the taxonomy for various contexts.' ),
|
||||
'type' => 'object',
|
||||
'context' => array( 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'name' => array(
|
||||
'description' => __( 'The title for the taxonomy.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'readonly' => true,
|
||||
'name' => array(
|
||||
'description' => __( 'The title for the taxonomy.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'slug' => array(
|
||||
'description' => __( 'An alphanumeric identifier for the taxonomy.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'readonly' => true,
|
||||
'slug' => array(
|
||||
'description' => __( 'An alphanumeric identifier for the taxonomy.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'show_cloud' => array(
|
||||
'description' => __( 'Whether or not the term cloud should be displayed.' ),
|
||||
'type' => 'boolean',
|
||||
'context' => array( 'edit' ),
|
||||
'readonly' => true,
|
||||
'show_cloud' => array(
|
||||
'description' => __( 'Whether or not the term cloud should be displayed.' ),
|
||||
'type' => 'boolean',
|
||||
'context' => array( 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'types' => array(
|
||||
'description' => __( 'Types associated with the taxonomy.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'types' => array(
|
||||
'description' => __( 'Types associated with the taxonomy.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'string',
|
||||
),
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'visibility' => array(
|
||||
'description' => __( 'The visibility settings for the taxonomy.' ),
|
||||
'type' => 'object',
|
||||
'context' => array( 'edit' ),
|
||||
'readonly' => true,
|
||||
'rest_base' => array(
|
||||
'description' => __( 'REST base route for the taxonomy.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'rest_base' => array(
|
||||
'description' => __( 'REST base route for the taxonomy.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'readonly' => true,
|
||||
'visibility' => array(
|
||||
'description' => __( 'The visibility settings for the taxonomy.' ),
|
||||
'type' => 'object',
|
||||
'context' => array( 'edit' ),
|
||||
'readonly' => true,
|
||||
'properties' => array(
|
||||
'public' => array(
|
||||
'description' => __( 'Whether a taxonomy is intended for use publicly either via the admin interface or by front-end users.' ),
|
||||
'type' => 'boolean',
|
||||
),
|
||||
'publicly_queryable' => array(
|
||||
'description' => __( 'Whether the taxonomy is publicly queryable.' ),
|
||||
'type' => 'boolean',
|
||||
),
|
||||
'show_ui' => array(
|
||||
'description' => __( 'Whether to generate a default UI for managing this taxonomy.' ),
|
||||
'type' => 'boolean',
|
||||
),
|
||||
'show_admin_column' => array(
|
||||
'description' => __( 'Whether to allow automatic creation of taxonomy columns on associated post-types table.' ),
|
||||
'type' => 'boolean',
|
||||
),
|
||||
'show_in_nav_menus' => array(
|
||||
'description' => __( 'Whether to make the taxonomy available for selection in navigation menus.' ),
|
||||
'type' => 'boolean',
|
||||
),
|
||||
'show_in_quick_edit' => array(
|
||||
'description' => __( 'Whether to show the taxonomy in the quick/bulk edit panel.' ),
|
||||
'type' => 'boolean',
|
||||
),
|
||||
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
@ -347,11 +384,11 @@ class WP_REST_Taxonomies_Controller extends WP_REST_Controller {
|
|||
* @return array Collection parameters.
|
||||
*/
|
||||
public function get_collection_params() {
|
||||
$new_params = array();
|
||||
$new_params = array();
|
||||
$new_params['context'] = $this->get_context_param( array( 'default' => 'view' ) );
|
||||
$new_params['type'] = array(
|
||||
'description' => __( 'Limit results to taxonomies associated with a specific post type.' ),
|
||||
'type' => 'string',
|
||||
$new_params['type'] = array(
|
||||
'description' => __( 'Limit results to taxonomies associated with a specific post type.' ),
|
||||
'type' => 'string',
|
||||
);
|
||||
return $new_params;
|
||||
}
|
||||
|
|
|
@ -56,9 +56,9 @@ class WP_REST_Terms_Controller extends WP_REST_Controller {
|
|||
* @param string $taxonomy Taxonomy key.
|
||||
*/
|
||||
public function __construct( $taxonomy ) {
|
||||
$this->taxonomy = $taxonomy;
|
||||
$this->taxonomy = $taxonomy;
|
||||
$this->namespace = 'wp/v2';
|
||||
$tax_obj = get_taxonomy( $taxonomy );
|
||||
$tax_obj = get_taxonomy( $taxonomy );
|
||||
$this->rest_base = ! empty( $tax_obj->rest_base ) ? $tax_obj->rest_base : $tax_obj->name;
|
||||
|
||||
$this->meta = new WP_REST_Term_Meta_Fields( $taxonomy );
|
||||
|
@ -73,57 +73,65 @@ class WP_REST_Terms_Controller extends WP_REST_Controller {
|
|||
*/
|
||||
public function register_routes() {
|
||||
|
||||
register_rest_route( $this->namespace, '/' . $this->rest_base, array(
|
||||
register_rest_route(
|
||||
$this->namespace,
|
||||
'/' . $this->rest_base,
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_items' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
'args' => $this->get_collection_params(),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'callback' => array( $this, 'create_item' ),
|
||||
'permission_callback' => array( $this, 'create_item_permissions_check' ),
|
||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
) );
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_items' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
'args' => $this->get_collection_params(),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'callback' => array( $this, 'create_item' ),
|
||||
'permission_callback' => array( $this, 'create_item_permissions_check' ),
|
||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
|
||||
'args' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'Unique identifier for the term.' ),
|
||||
'type' => 'integer',
|
||||
),
|
||||
),
|
||||
register_rest_route(
|
||||
$this->namespace,
|
||||
'/' . $this->rest_base . '/(?P<id>[\d]+)',
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_item' ),
|
||||
'permission_callback' => array( $this, 'get_item_permissions_check' ),
|
||||
'args' => array(
|
||||
'context' => $this->get_context_param( array( 'default' => 'view' ) ),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'update_item' ),
|
||||
'permission_callback' => array( $this, 'update_item_permissions_check' ),
|
||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::DELETABLE,
|
||||
'callback' => array( $this, 'delete_item' ),
|
||||
'permission_callback' => array( $this, 'delete_item_permissions_check' ),
|
||||
'args' => array(
|
||||
'force' => array(
|
||||
'type' => 'boolean',
|
||||
'default' => false,
|
||||
'description' => __( 'Required to be true, as terms do not support trashing.' ),
|
||||
'args' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'Unique identifier for the term.' ),
|
||||
'type' => 'integer',
|
||||
),
|
||||
),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
) );
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_item' ),
|
||||
'permission_callback' => array( $this, 'get_item_permissions_check' ),
|
||||
'args' => array(
|
||||
'context' => $this->get_context_param( array( 'default' => 'view' ) ),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'update_item' ),
|
||||
'permission_callback' => array( $this, 'update_item_permissions_check' ),
|
||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::DELETABLE,
|
||||
'callback' => array( $this, 'delete_item' ),
|
||||
'permission_callback' => array( $this, 'delete_item_permissions_check' ),
|
||||
'args' => array(
|
||||
'force' => array(
|
||||
'type' => 'boolean',
|
||||
'default' => false,
|
||||
'description' => __( 'Required to be true, as terms do not support trashing.' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -235,7 +243,7 @@ class WP_REST_Terms_Controller extends WP_REST_Controller {
|
|||
*/
|
||||
$prepared_args = apply_filters( "rest_{$this->taxonomy}_query", $prepared_args, $request );
|
||||
|
||||
if ( ! empty( $prepared_args['post'] ) ) {
|
||||
if ( ! empty( $prepared_args['post'] ) ) {
|
||||
$query_result = wp_get_object_terms( $prepared_args['post'], $this->taxonomy, $prepared_args );
|
||||
|
||||
// Used when calling wp_count_terms() below.
|
||||
|
@ -258,7 +266,7 @@ class WP_REST_Terms_Controller extends WP_REST_Controller {
|
|||
$response = array();
|
||||
|
||||
foreach ( $query_result as $term ) {
|
||||
$data = $this->prepare_item_for_response( $term, $request );
|
||||
$data = $this->prepare_item_for_response( $term, $request );
|
||||
$response[] = $this->prepare_response_for_collection( $data );
|
||||
}
|
||||
|
||||
|
@ -418,7 +426,12 @@ class WP_REST_Terms_Controller extends WP_REST_Controller {
|
|||
if ( $term_id = $term->get_error_data( 'term_exists' ) ) {
|
||||
$existing_term = get_term( $term_id, $this->taxonomy );
|
||||
$term->add_data( $existing_term->term_id, 'term_exists' );
|
||||
$term->add_data( array( 'status' => 400, 'term_id' => $term_id ) );
|
||||
$term->add_data(
|
||||
array(
|
||||
'status' => 400,
|
||||
'term_id' => $term_id,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return $term;
|
||||
|
@ -620,7 +633,12 @@ class WP_REST_Terms_Controller extends WP_REST_Controller {
|
|||
}
|
||||
|
||||
$response = new WP_REST_Response();
|
||||
$response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data() ) );
|
||||
$response->set_data(
|
||||
array(
|
||||
'deleted' => true,
|
||||
'previous' => $previous->get_data(),
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Fires after a single term is deleted via the REST API.
|
||||
|
@ -773,7 +791,7 @@ class WP_REST_Terms_Controller extends WP_REST_Controller {
|
|||
* @return array Links for the given term.
|
||||
*/
|
||||
protected function prepare_links( $term ) {
|
||||
$base = $this->namespace . '/' . $this->rest_base;
|
||||
$base = $this->namespace . '/' . $this->rest_base;
|
||||
$links = array(
|
||||
'self' => array(
|
||||
'href' => rest_url( trailingslashit( $base ) . $term->term_id ),
|
||||
|
@ -812,7 +830,7 @@ class WP_REST_Terms_Controller extends WP_REST_Controller {
|
|||
continue;
|
||||
}
|
||||
|
||||
$rest_base = ! empty( $post_type_object->rest_base ) ? $post_type_object->rest_base : $post_type_object->name;
|
||||
$rest_base = ! empty( $post_type_object->rest_base ) ? $post_type_object->rest_base : $post_type_object->name;
|
||||
$post_type_links[] = array(
|
||||
'href' => add_query_arg( $this->rest_base, $term->term_id, rest_url( sprintf( 'wp/v2/%s', $rest_base ) ) ),
|
||||
);
|
||||
|
@ -839,52 +857,52 @@ class WP_REST_Terms_Controller extends WP_REST_Controller {
|
|||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'Unique identifier for the term.' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'embed', 'edit' ),
|
||||
'readonly' => true,
|
||||
'description' => __( 'Unique identifier for the term.' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'embed', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'count' => array(
|
||||
'description' => __( 'Number of published posts for the term.' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
'description' => __( 'Number of published posts for the term.' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'description' => array(
|
||||
'description' => __( 'HTML description of the term.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'description' => __( 'HTML description of the term.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
),
|
||||
'link' => array(
|
||||
'description' => __( 'URL of the term.' ),
|
||||
'type' => 'string',
|
||||
'format' => 'uri',
|
||||
'context' => array( 'view', 'embed', 'edit' ),
|
||||
'readonly' => true,
|
||||
'description' => __( 'URL of the term.' ),
|
||||
'type' => 'string',
|
||||
'format' => 'uri',
|
||||
'context' => array( 'view', 'embed', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'name' => array(
|
||||
'description' => __( 'HTML title for the term.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'embed', 'edit' ),
|
||||
'arg_options' => array(
|
||||
'description' => __( 'HTML title for the term.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'embed', 'edit' ),
|
||||
'arg_options' => array(
|
||||
'sanitize_callback' => 'sanitize_text_field',
|
||||
),
|
||||
'required' => true,
|
||||
'required' => true,
|
||||
),
|
||||
'slug' => array(
|
||||
'description' => __( 'An alphanumeric identifier for the term unique to its type.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'embed', 'edit' ),
|
||||
'arg_options' => array(
|
||||
'description' => __( 'An alphanumeric identifier for the term unique to its type.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'view', 'embed', 'edit' ),
|
||||
'arg_options' => array(
|
||||
'sanitize_callback' => array( $this, 'sanitize_slug' ),
|
||||
),
|
||||
),
|
||||
'taxonomy' => array(
|
||||
'description' => __( 'Type attribution for the term.' ),
|
||||
'type' => 'string',
|
||||
'enum' => array_keys( get_taxonomies() ),
|
||||
'context' => array( 'view', 'embed', 'edit' ),
|
||||
'readonly' => true,
|
||||
'description' => __( 'Type attribution for the term.' ),
|
||||
'type' => 'string',
|
||||
'enum' => array_keys( get_taxonomies() ),
|
||||
'context' => array( 'view', 'embed', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
@ -893,9 +911,9 @@ class WP_REST_Terms_Controller extends WP_REST_Controller {
|
|||
|
||||
if ( $taxonomy->hierarchical ) {
|
||||
$schema['properties']['parent'] = array(
|
||||
'description' => __( 'The parent term ID.' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
'description' => __( 'The parent term ID.' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'view', 'edit' ),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -913,50 +931,50 @@ class WP_REST_Terms_Controller extends WP_REST_Controller {
|
|||
*/
|
||||
public function get_collection_params() {
|
||||
$query_params = parent::get_collection_params();
|
||||
$taxonomy = get_taxonomy( $this->taxonomy );
|
||||
$taxonomy = get_taxonomy( $this->taxonomy );
|
||||
|
||||
$query_params['context']['default'] = 'view';
|
||||
|
||||
$query_params['exclude'] = array(
|
||||
'description' => __( 'Ensure result set excludes specific IDs.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
'description' => __( 'Ensure result set excludes specific IDs.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
),
|
||||
'default' => array(),
|
||||
'default' => array(),
|
||||
);
|
||||
|
||||
$query_params['include'] = array(
|
||||
'description' => __( 'Limit result set to specific IDs.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
'description' => __( 'Limit result set to specific IDs.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
),
|
||||
'default' => array(),
|
||||
'default' => array(),
|
||||
);
|
||||
|
||||
if ( ! $taxonomy->hierarchical ) {
|
||||
$query_params['offset'] = array(
|
||||
'description' => __( 'Offset the result set by a specific number of items.' ),
|
||||
'type' => 'integer',
|
||||
'description' => __( 'Offset the result set by a specific number of items.' ),
|
||||
'type' => 'integer',
|
||||
);
|
||||
}
|
||||
|
||||
$query_params['order'] = array(
|
||||
'description' => __( 'Order sort attribute ascending or descending.' ),
|
||||
'type' => 'string',
|
||||
'default' => 'asc',
|
||||
'enum' => array(
|
||||
'description' => __( 'Order sort attribute ascending or descending.' ),
|
||||
'type' => 'string',
|
||||
'default' => 'asc',
|
||||
'enum' => array(
|
||||
'asc',
|
||||
'desc',
|
||||
),
|
||||
);
|
||||
|
||||
$query_params['orderby'] = array(
|
||||
'description' => __( 'Sort collection by term attribute.' ),
|
||||
'type' => 'string',
|
||||
'default' => 'name',
|
||||
'enum' => array(
|
||||
'description' => __( 'Sort collection by term attribute.' ),
|
||||
'type' => 'string',
|
||||
'default' => 'name',
|
||||
'enum' => array(
|
||||
'id',
|
||||
'include',
|
||||
'name',
|
||||
|
@ -969,29 +987,29 @@ class WP_REST_Terms_Controller extends WP_REST_Controller {
|
|||
);
|
||||
|
||||
$query_params['hide_empty'] = array(
|
||||
'description' => __( 'Whether to hide terms not assigned to any posts.' ),
|
||||
'type' => 'boolean',
|
||||
'default' => false,
|
||||
'description' => __( 'Whether to hide terms not assigned to any posts.' ),
|
||||
'type' => 'boolean',
|
||||
'default' => false,
|
||||
);
|
||||
|
||||
if ( $taxonomy->hierarchical ) {
|
||||
$query_params['parent'] = array(
|
||||
'description' => __( 'Limit result set to terms assigned to a specific parent.' ),
|
||||
'type' => 'integer',
|
||||
'description' => __( 'Limit result set to terms assigned to a specific parent.' ),
|
||||
'type' => 'integer',
|
||||
);
|
||||
}
|
||||
|
||||
$query_params['post'] = array(
|
||||
'description' => __( 'Limit result set to terms assigned to a specific post.' ),
|
||||
'type' => 'integer',
|
||||
'default' => null,
|
||||
'description' => __( 'Limit result set to terms assigned to a specific post.' ),
|
||||
'type' => 'integer',
|
||||
'default' => null,
|
||||
);
|
||||
|
||||
$query_params['slug'] = array(
|
||||
'description' => __( 'Limit result set to terms with one or more specific slugs.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'string'
|
||||
'description' => __( 'Limit result set to terms with one or more specific slugs.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'string',
|
||||
),
|
||||
);
|
||||
|
||||
|
|
|
@ -45,98 +45,110 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
|
|||
*/
|
||||
public function register_routes() {
|
||||
|
||||
register_rest_route( $this->namespace, '/' . $this->rest_base, array(
|
||||
register_rest_route(
|
||||
$this->namespace,
|
||||
'/' . $this->rest_base,
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_items' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
'args' => $this->get_collection_params(),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'callback' => array( $this, 'create_item' ),
|
||||
'permission_callback' => array( $this, 'create_item_permissions_check' ),
|
||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
) );
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_items' ),
|
||||
'permission_callback' => array( $this, 'get_items_permissions_check' ),
|
||||
'args' => $this->get_collection_params(),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::CREATABLE,
|
||||
'callback' => array( $this, 'create_item' ),
|
||||
'permission_callback' => array( $this, 'create_item_permissions_check' ),
|
||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
|
||||
'args' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'Unique identifier for the user.' ),
|
||||
'type' => 'integer',
|
||||
),
|
||||
),
|
||||
register_rest_route(
|
||||
$this->namespace,
|
||||
'/' . $this->rest_base . '/(?P<id>[\d]+)',
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_item' ),
|
||||
'permission_callback' => array( $this, 'get_item_permissions_check' ),
|
||||
'args' => array(
|
||||
'context' => $this->get_context_param( array( 'default' => 'view' ) ),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'update_item' ),
|
||||
'permission_callback' => array( $this, 'update_item_permissions_check' ),
|
||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::DELETABLE,
|
||||
'callback' => array( $this, 'delete_item' ),
|
||||
'permission_callback' => array( $this, 'delete_item_permissions_check' ),
|
||||
'args' => array(
|
||||
'force' => array(
|
||||
'type' => 'boolean',
|
||||
'default' => false,
|
||||
'description' => __( 'Required to be true, as users do not support trashing.' ),
|
||||
),
|
||||
'reassign' => array(
|
||||
'args' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'Unique identifier for the user.' ),
|
||||
'type' => 'integer',
|
||||
'description' => __( 'Reassign the deleted user\'s posts and links to this user ID.' ),
|
||||
'required' => true,
|
||||
'sanitize_callback' => array( $this, 'check_reassign' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
) );
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_item' ),
|
||||
'permission_callback' => array( $this, 'get_item_permissions_check' ),
|
||||
'args' => array(
|
||||
'context' => $this->get_context_param( array( 'default' => 'view' ) ),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'update_item' ),
|
||||
'permission_callback' => array( $this, 'update_item_permissions_check' ),
|
||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::DELETABLE,
|
||||
'callback' => array( $this, 'delete_item' ),
|
||||
'permission_callback' => array( $this, 'delete_item_permissions_check' ),
|
||||
'args' => array(
|
||||
'force' => array(
|
||||
'type' => 'boolean',
|
||||
'default' => false,
|
||||
'description' => __( 'Required to be true, as users do not support trashing.' ),
|
||||
),
|
||||
'reassign' => array(
|
||||
'type' => 'integer',
|
||||
'description' => __( 'Reassign the deleted user\'s posts and links to this user ID.' ),
|
||||
'required' => true,
|
||||
'sanitize_callback' => array( $this, 'check_reassign' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
)
|
||||
);
|
||||
|
||||
register_rest_route( $this->namespace, '/' . $this->rest_base . '/me', array(
|
||||
register_rest_route(
|
||||
$this->namespace,
|
||||
'/' . $this->rest_base . '/me',
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_current_item' ),
|
||||
'args' => array(
|
||||
'context' => $this->get_context_param( array( 'default' => 'view' ) ),
|
||||
),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'update_current_item' ),
|
||||
'permission_callback' => array( $this, 'update_current_item_permissions_check' ),
|
||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::DELETABLE,
|
||||
'callback' => array( $this, 'delete_current_item' ),
|
||||
'permission_callback' => array( $this, 'delete_current_item_permissions_check' ),
|
||||
'args' => array(
|
||||
'force' => array(
|
||||
'type' => 'boolean',
|
||||
'default' => false,
|
||||
'description' => __( 'Required to be true, as users do not support trashing.' ),
|
||||
),
|
||||
'reassign' => array(
|
||||
'type' => 'integer',
|
||||
'description' => __( 'Reassign the deleted user\'s posts and links to this user ID.' ),
|
||||
'required' => true,
|
||||
'sanitize_callback' => array( $this, 'check_reassign' ),
|
||||
array(
|
||||
'methods' => WP_REST_Server::READABLE,
|
||||
'callback' => array( $this, 'get_current_item' ),
|
||||
'args' => array(
|
||||
'context' => $this->get_context_param( array( 'default' => 'view' ) ),
|
||||
),
|
||||
),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
));
|
||||
array(
|
||||
'methods' => WP_REST_Server::EDITABLE,
|
||||
'callback' => array( $this, 'update_current_item' ),
|
||||
'permission_callback' => array( $this, 'update_current_item_permissions_check' ),
|
||||
'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
|
||||
),
|
||||
array(
|
||||
'methods' => WP_REST_Server::DELETABLE,
|
||||
'callback' => array( $this, 'delete_current_item' ),
|
||||
'permission_callback' => array( $this, 'delete_current_item_permissions_check' ),
|
||||
'args' => array(
|
||||
'force' => array(
|
||||
'type' => 'boolean',
|
||||
'default' => false,
|
||||
'description' => __( 'Required to be true, as users do not support trashing.' ),
|
||||
),
|
||||
'reassign' => array(
|
||||
'type' => 'integer',
|
||||
'description' => __( 'Reassign the deleted user\'s posts and links to this user ID.' ),
|
||||
'required' => true,
|
||||
'sanitize_callback' => array( $this, 'check_reassign' ),
|
||||
),
|
||||
),
|
||||
),
|
||||
'schema' => array( $this, 'get_public_item_schema' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -188,7 +200,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
|
|||
|
||||
if ( 'authors' === $request['who'] ) {
|
||||
$can_view = false;
|
||||
$types = get_post_types( array( 'show_in_rest' => true ), 'objects' );
|
||||
$types = get_post_types( array( 'show_in_rest' => true ), 'objects' );
|
||||
foreach ( $types as $type ) {
|
||||
if ( post_type_supports( $type->name, 'author' )
|
||||
&& current_user_can( $type->cap->edit_posts ) ) {
|
||||
|
@ -247,11 +259,11 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
|
|||
if ( isset( $registered['offset'] ) && ! empty( $request['offset'] ) ) {
|
||||
$prepared_args['offset'] = $request['offset'];
|
||||
} else {
|
||||
$prepared_args['offset'] = ( $request['page'] - 1 ) * $prepared_args['number'];
|
||||
$prepared_args['offset'] = ( $request['page'] - 1 ) * $prepared_args['number'];
|
||||
}
|
||||
|
||||
if ( isset( $registered['orderby'] ) ) {
|
||||
$orderby_possibles = array(
|
||||
$orderby_possibles = array(
|
||||
'id' => 'ID',
|
||||
'include' => 'include',
|
||||
'name' => 'display_name',
|
||||
|
@ -290,7 +302,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
|
|||
$users = array();
|
||||
|
||||
foreach ( $query->results as $user ) {
|
||||
$data = $this->prepare_item_for_response( $user, $request );
|
||||
$data = $this->prepare_item_for_response( $user, $request );
|
||||
$users[] = $this->prepare_response_for_collection( $data );
|
||||
}
|
||||
|
||||
|
@ -407,7 +419,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
|
|||
return $user;
|
||||
}
|
||||
|
||||
$user = $this->prepare_item_for_response( $user, $request );
|
||||
$user = $this->prepare_item_for_response( $user, $request );
|
||||
$response = rest_ensure_response( $user );
|
||||
|
||||
return $response;
|
||||
|
@ -432,7 +444,6 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
|
|||
$response = $this->prepare_item_for_response( $user, $request );
|
||||
$response = rest_ensure_response( $response );
|
||||
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
@ -481,7 +492,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
|
|||
if ( is_multisite() ) {
|
||||
$ret = wpmu_validate_user_signup( $user->user_login, $user->user_email );
|
||||
|
||||
if ( is_wp_error( $ret['errors'] ) && ! empty( $ret['errors']->errors ) ) {
|
||||
if ( is_wp_error( $ret['errors'] ) && $ret['errors']->has_errors() ) {
|
||||
$error = new WP_Error( 'rest_invalid_param', __( 'Invalid user parameter(s).' ), array( 'status' => 400 ) );
|
||||
foreach ( $ret['errors']->errors as $code => $messages ) {
|
||||
foreach ( $messages as $message ) {
|
||||
|
@ -509,7 +520,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
|
|||
return $user_id;
|
||||
}
|
||||
|
||||
$result= add_user_to_blog( get_site()->id, $user_id, '' );
|
||||
$result = add_user_to_blog( get_site()->id, $user_id, '' );
|
||||
if ( is_wp_error( $result ) ) {
|
||||
return $result;
|
||||
}
|
||||
|
@ -546,7 +557,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
|
|||
}
|
||||
}
|
||||
|
||||
$user = get_user_by( 'id', $user_id );
|
||||
$user = get_user_by( 'id', $user_id );
|
||||
$fields_update = $this->update_additional_fields_for_object( $user, $request );
|
||||
|
||||
if ( is_wp_error( $fields_update ) ) {
|
||||
|
@ -630,7 +641,9 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
|
|||
return new WP_Error( 'rest_user_invalid_id', __( 'Invalid user ID.' ), array( 'status' => 404 ) );
|
||||
}
|
||||
|
||||
if ( email_exists( $request['email'] ) && $request['email'] !== $user->user_email ) {
|
||||
$owner_id = email_exists( $request['email'] );
|
||||
|
||||
if ( $owner_id && $owner_id !== $id ) {
|
||||
return new WP_Error( 'rest_user_invalid_email', __( 'Invalid email address.' ), array( 'status' => 400 ) );
|
||||
}
|
||||
|
||||
|
@ -680,7 +693,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
|
|||
}
|
||||
}
|
||||
|
||||
$user = get_user_by( 'id', $user_id );
|
||||
$user = get_user_by( 'id', $user_id );
|
||||
$fields_update = $this->update_additional_fields_for_object( $user, $request );
|
||||
|
||||
if ( is_wp_error( $fields_update ) ) {
|
||||
|
@ -795,7 +808,12 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
|
|||
}
|
||||
|
||||
$response = new WP_REST_Response();
|
||||
$response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data() ) );
|
||||
$response->set_data(
|
||||
array(
|
||||
'deleted' => true,
|
||||
'previous' => $previous->get_data(),
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Fires immediately after a user is deleted via the REST API.
|
||||
|
@ -958,7 +976,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
|
|||
*/
|
||||
protected function prepare_links( $user ) {
|
||||
$links = array(
|
||||
'self' => array(
|
||||
'self' => array(
|
||||
'href' => rest_url( sprintf( '%s/%s/%d', $this->namespace, $this->rest_base, $user->ID ) ),
|
||||
),
|
||||
'collection' => array(
|
||||
|
@ -1144,7 +1162,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
|
|||
return new WP_Error( 'rest_user_invalid_password', __( 'Passwords cannot be empty.' ), array( 'status' => 400 ) );
|
||||
}
|
||||
|
||||
if ( false !== strpos( $password, "\\" ) ) {
|
||||
if ( false !== strpos( $password, '\\' ) ) {
|
||||
return new WP_Error( 'rest_user_invalid_password', __( 'Passwords cannot contain the "\\" character.' ), array( 'status' => 400 ) );
|
||||
}
|
||||
|
||||
|
@ -1164,13 +1182,13 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
|
|||
'title' => 'user',
|
||||
'type' => 'object',
|
||||
'properties' => array(
|
||||
'id' => array(
|
||||
'id' => array(
|
||||
'description' => __( 'Unique identifier for the user.' ),
|
||||
'type' => 'integer',
|
||||
'context' => array( 'embed', 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'username' => array(
|
||||
'username' => array(
|
||||
'description' => __( 'Login name for the user.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'edit' ),
|
||||
|
@ -1179,7 +1197,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
|
|||
'sanitize_callback' => array( $this, 'check_username' ),
|
||||
),
|
||||
),
|
||||
'name' => array(
|
||||
'name' => array(
|
||||
'description' => __( 'Display name for the user.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'embed', 'view', 'edit' ),
|
||||
|
@ -1187,7 +1205,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
|
|||
'sanitize_callback' => 'sanitize_text_field',
|
||||
),
|
||||
),
|
||||
'first_name' => array(
|
||||
'first_name' => array(
|
||||
'description' => __( 'First name for the user.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'edit' ),
|
||||
|
@ -1195,7 +1213,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
|
|||
'sanitize_callback' => 'sanitize_text_field',
|
||||
),
|
||||
),
|
||||
'last_name' => array(
|
||||
'last_name' => array(
|
||||
'description' => __( 'Last name for the user.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'edit' ),
|
||||
|
@ -1203,38 +1221,38 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
|
|||
'sanitize_callback' => 'sanitize_text_field',
|
||||
),
|
||||
),
|
||||
'email' => array(
|
||||
'email' => array(
|
||||
'description' => __( 'The email address for the user.' ),
|
||||
'type' => 'string',
|
||||
'format' => 'email',
|
||||
'context' => array( 'edit' ),
|
||||
'required' => true,
|
||||
),
|
||||
'url' => array(
|
||||
'url' => array(
|
||||
'description' => __( 'URL of the user.' ),
|
||||
'type' => 'string',
|
||||
'format' => 'uri',
|
||||
'context' => array( 'embed', 'view', 'edit' ),
|
||||
),
|
||||
'description' => array(
|
||||
'description' => array(
|
||||
'description' => __( 'Description of the user.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'embed', 'view', 'edit' ),
|
||||
),
|
||||
'link' => array(
|
||||
'link' => array(
|
||||
'description' => __( 'Author URL of the user.' ),
|
||||
'type' => 'string',
|
||||
'format' => 'uri',
|
||||
'context' => array( 'embed', 'view', 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'locale' => array(
|
||||
'locale' => array(
|
||||
'description' => __( 'Locale for the user.' ),
|
||||
'type' => 'string',
|
||||
'enum' => array_merge( array( '', 'en_US' ), get_available_languages() ),
|
||||
'context' => array( 'edit' ),
|
||||
),
|
||||
'nickname' => array(
|
||||
'nickname' => array(
|
||||
'description' => __( 'The nickname for the user.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'edit' ),
|
||||
|
@ -1242,7 +1260,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
|
|||
'sanitize_callback' => 'sanitize_text_field',
|
||||
),
|
||||
),
|
||||
'slug' => array(
|
||||
'slug' => array(
|
||||
'description' => __( 'An alphanumeric identifier for the user.' ),
|
||||
'type' => 'string',
|
||||
'context' => array( 'embed', 'view', 'edit' ),
|
||||
|
@ -1250,22 +1268,22 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
|
|||
'sanitize_callback' => array( $this, 'sanitize_slug' ),
|
||||
),
|
||||
),
|
||||
'registered_date' => array(
|
||||
'registered_date' => array(
|
||||
'description' => __( 'Registration date for the user.' ),
|
||||
'type' => 'string',
|
||||
'format' => 'date-time',
|
||||
'context' => array( 'edit' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'roles' => array(
|
||||
'roles' => array(
|
||||
'description' => __( 'Roles assigned to the user.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'string',
|
||||
'type' => 'string',
|
||||
),
|
||||
'context' => array( 'edit' ),
|
||||
),
|
||||
'password' => array(
|
||||
'password' => array(
|
||||
'description' => __( 'Password for the user (never included).' ),
|
||||
'type' => 'string',
|
||||
'context' => array(), // Password is never displayed.
|
||||
|
@ -1274,7 +1292,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
|
|||
'sanitize_callback' => array( $this, 'check_user_password' ),
|
||||
),
|
||||
),
|
||||
'capabilities' => array(
|
||||
'capabilities' => array(
|
||||
'description' => __( 'All capabilities assigned to the user.' ),
|
||||
'type' => 'object',
|
||||
'context' => array( 'edit' ),
|
||||
|
@ -1304,7 +1322,7 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
|
|||
);
|
||||
}
|
||||
|
||||
$schema['properties']['avatar_urls'] = array(
|
||||
$schema['properties']['avatar_urls'] = array(
|
||||
'description' => __( 'Avatar URLs for the user.' ),
|
||||
'type' => 'object',
|
||||
'context' => array( 'embed', 'view', 'edit' ),
|
||||
|
@ -1331,39 +1349,39 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
|
|||
$query_params['context']['default'] = 'view';
|
||||
|
||||
$query_params['exclude'] = array(
|
||||
'description' => __( 'Ensure result set excludes specific IDs.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
'description' => __( 'Ensure result set excludes specific IDs.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
),
|
||||
'default' => array(),
|
||||
'default' => array(),
|
||||
);
|
||||
|
||||
$query_params['include'] = array(
|
||||
'description' => __( 'Limit result set to specific IDs.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
'description' => __( 'Limit result set to specific IDs.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'integer',
|
||||
),
|
||||
'default' => array(),
|
||||
'default' => array(),
|
||||
);
|
||||
|
||||
$query_params['offset'] = array(
|
||||
'description' => __( 'Offset the result set by a specific number of items.' ),
|
||||
'type' => 'integer',
|
||||
'description' => __( 'Offset the result set by a specific number of items.' ),
|
||||
'type' => 'integer',
|
||||
);
|
||||
|
||||
$query_params['order'] = array(
|
||||
'default' => 'asc',
|
||||
'description' => __( 'Order sort attribute ascending or descending.' ),
|
||||
'enum' => array( 'asc', 'desc' ),
|
||||
'type' => 'string',
|
||||
'default' => 'asc',
|
||||
'description' => __( 'Order sort attribute ascending or descending.' ),
|
||||
'enum' => array( 'asc', 'desc' ),
|
||||
'type' => 'string',
|
||||
);
|
||||
|
||||
$query_params['orderby'] = array(
|
||||
'default' => 'name',
|
||||
'description' => __( 'Sort collection by object attribute.' ),
|
||||
'enum' => array(
|
||||
'default' => 'name',
|
||||
'description' => __( 'Sort collection by object attribute.' ),
|
||||
'enum' => array(
|
||||
'id',
|
||||
'include',
|
||||
'name',
|
||||
|
@ -1373,22 +1391,22 @@ class WP_REST_Users_Controller extends WP_REST_Controller {
|
|||
'email',
|
||||
'url',
|
||||
),
|
||||
'type' => 'string',
|
||||
'type' => 'string',
|
||||
);
|
||||
|
||||
$query_params['slug'] = array(
|
||||
'description' => __( 'Limit result set to users with one or more specific slugs.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'string',
|
||||
$query_params['slug'] = array(
|
||||
'description' => __( 'Limit result set to users with one or more specific slugs.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'string',
|
||||
),
|
||||
);
|
||||
|
||||
$query_params['roles'] = array(
|
||||
'description' => __( 'Limit result set to users matching at least one specific role provided. Accepts csv list or single role.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'string',
|
||||
$query_params['roles'] = array(
|
||||
'description' => __( 'Limit result set to users matching at least one specific role provided. Accepts csv list or single role.' ),
|
||||
'type' => 'array',
|
||||
'items' => array(
|
||||
'type' => 'string',
|
||||
),
|
||||
);
|
||||
|
||||
|
|
|
@ -52,11 +52,15 @@ abstract class WP_REST_Meta_Fields {
|
|||
* @see register_rest_field()
|
||||
*/
|
||||
public function register_field() {
|
||||
register_rest_field( $this->get_rest_field_type(), 'meta', array(
|
||||
'get_callback' => array( $this, 'get_value' ),
|
||||
'update_callback' => array( $this, 'update_value' ),
|
||||
'schema' => $this->get_field_schema(),
|
||||
));
|
||||
register_rest_field(
|
||||
$this->get_rest_field_type(),
|
||||
'meta',
|
||||
array(
|
||||
'get_callback' => array( $this, 'get_value' ),
|
||||
'update_callback' => array( $this, 'update_value' ),
|
||||
'schema' => $this->get_field_schema(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -73,7 +77,7 @@ abstract class WP_REST_Meta_Fields {
|
|||
$response = array();
|
||||
|
||||
foreach ( $fields as $meta_key => $args ) {
|
||||
$name = $args['name'];
|
||||
$name = $args['name'];
|
||||
$all_values = get_metadata( $this->get_meta_type(), $object_id, $meta_key, false );
|
||||
if ( $args['single'] ) {
|
||||
if ( empty( $all_values ) ) {
|
||||
|
@ -185,7 +189,10 @@ abstract class WP_REST_Meta_Fields {
|
|||
'rest_cannot_delete',
|
||||
/* translators: %s: custom field key */
|
||||
sprintf( __( 'Sorry, you are not allowed to edit the %s custom field.' ), $name ),
|
||||
array( 'key' => $name, 'status' => rest_authorization_required_code() )
|
||||
array(
|
||||
'key' => $name,
|
||||
'status' => rest_authorization_required_code(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -193,7 +200,10 @@ abstract class WP_REST_Meta_Fields {
|
|||
return new WP_Error(
|
||||
'rest_meta_database_error',
|
||||
__( 'Could not delete meta value from database.' ),
|
||||
array( 'key' => $name, 'status' => WP_Http::INTERNAL_SERVER_ERROR )
|
||||
array(
|
||||
'key' => $name,
|
||||
'status' => WP_Http::INTERNAL_SERVER_ERROR,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -220,7 +230,10 @@ abstract class WP_REST_Meta_Fields {
|
|||
'rest_cannot_update',
|
||||
/* translators: %s: custom field key */
|
||||
sprintf( __( 'Sorry, you are not allowed to edit the %s custom field.' ), $name ),
|
||||
array( 'key' => $name, 'status' => rest_authorization_required_code() )
|
||||
array(
|
||||
'key' => $name,
|
||||
'status' => rest_authorization_required_code(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -255,7 +268,10 @@ abstract class WP_REST_Meta_Fields {
|
|||
return new WP_Error(
|
||||
'rest_meta_database_error',
|
||||
__( 'Could not update meta value in database.' ),
|
||||
array( 'key' => $name, 'status' => WP_Http::INTERNAL_SERVER_ERROR )
|
||||
array(
|
||||
'key' => $name,
|
||||
'status' => WP_Http::INTERNAL_SERVER_ERROR,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -265,7 +281,10 @@ abstract class WP_REST_Meta_Fields {
|
|||
return new WP_Error(
|
||||
'rest_meta_database_error',
|
||||
__( 'Could not update meta value in database.' ),
|
||||
array( 'key' => $name, 'status' => WP_Http::INTERNAL_SERVER_ERROR )
|
||||
array(
|
||||
'key' => $name,
|
||||
'status' => WP_Http::INTERNAL_SERVER_ERROR,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -286,12 +305,15 @@ abstract class WP_REST_Meta_Fields {
|
|||
*/
|
||||
protected function update_meta_value( $object_id, $meta_key, $name, $value ) {
|
||||
$meta_type = $this->get_meta_type();
|
||||
if ( ! current_user_can( "edit_{$meta_type}_meta", $object_id, $meta_key ) ) {
|
||||
if ( ! current_user_can( "edit_{$meta_type}_meta", $object_id, $meta_key ) ) {
|
||||
return new WP_Error(
|
||||
'rest_cannot_update',
|
||||
/* translators: %s: custom field key */
|
||||
sprintf( __( 'Sorry, you are not allowed to edit the %s custom field.' ), $name ),
|
||||
array( 'key' => $name, 'status' => rest_authorization_required_code() )
|
||||
array(
|
||||
'key' => $name,
|
||||
'status' => rest_authorization_required_code(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -309,7 +331,10 @@ abstract class WP_REST_Meta_Fields {
|
|||
return new WP_Error(
|
||||
'rest_meta_database_error',
|
||||
__( 'Could not update meta value in database.' ),
|
||||
array( 'key' => $name, 'status' => WP_Http::INTERNAL_SERVER_ERROR )
|
||||
array(
|
||||
'key' => $name,
|
||||
'status' => WP_Http::INTERNAL_SERVER_ERROR,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -359,7 +384,7 @@ abstract class WP_REST_Meta_Fields {
|
|||
'default' => isset( $args['default'] ) ? $args['default'] : null,
|
||||
);
|
||||
|
||||
$rest_args = array_merge( $default_args, $rest_args );
|
||||
$rest_args = array_merge( $default_args, $rest_args );
|
||||
$rest_args['schema'] = array_merge( $default_schema, $rest_args['schema'] );
|
||||
|
||||
$type = ! empty( $rest_args['type'] ) ? $rest_args['type'] : null;
|
||||
|
@ -373,7 +398,7 @@ abstract class WP_REST_Meta_Fields {
|
|||
$rest_args['schema']['items'] = array(
|
||||
'type' => $rest_args['type'],
|
||||
);
|
||||
$rest_args['schema']['type'] = 'array';
|
||||
$rest_args['schema']['type'] = 'array';
|
||||
}
|
||||
|
||||
$registered[ $name ] = $rest_args;
|
||||
|
|
|
@ -68,6 +68,18 @@ class WP_REST_Post_Search_Handler extends WP_REST_Search_Handler {
|
|||
$query_args['s'] = $request['search'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters the query arguments for a search request.
|
||||
*
|
||||
* Enables adding extra arguments or setting defaults for a post search request.
|
||||
*
|
||||
* @since 5.1.0
|
||||
*
|
||||
* @param array $query_args Key value array of query var to query value.
|
||||
* @param WP_REST_Request $request The request used.
|
||||
*/
|
||||
$query_args = apply_filters( 'rest_post_search_query', $query_args, $request );
|
||||
|
||||
$query = new WP_Query();
|
||||
$found_ids = $query->query( $query_args );
|
||||
$total = $query->found_posts;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue