mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-04 18:01:42 +01:00
REST API: Remove experimental filter
wrapper parameter from the Posts Controller class.
Hiding WP_Query params under the filter key (instead of allowing them to be top-level params) was one of our biggest complaints from users of v1 of our REST API. This walks back the re-introduction of the `filter` param during Beta 15, which introduced an "inconsistent mess" and "exposing WP_Query through filter has and will continue to be difficult to support." See https://github.com/WP-API/WP-API/issues/2799. Props websupporter, rachelbaker. Fixes #38378. Built from https://develop.svn.wordpress.org/trunk@38968 git-svn-id: http://core.svn.wordpress.org/trunk@38911 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
71afe657b6
commit
d359ffc270
@ -111,7 +111,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||||||
public function get_items( $request ) {
|
public function get_items( $request ) {
|
||||||
|
|
||||||
// Make sure a search string is set in case the orderby is set to 'relevance'.
|
// Make sure a search string is set in case the orderby is set to 'relevance'.
|
||||||
if ( ! empty( $request['orderby'] ) && 'relevance' === $request['orderby'] && empty( $request['search'] ) && empty( $request['filter']['s'] ) ) {
|
if ( ! empty( $request['orderby'] ) && 'relevance' === $request['orderby'] && empty( $request['search'] ) ) {
|
||||||
return new WP_Error( 'rest_no_search_term_defined', __( 'You need to define a search term to order by relevance.' ), array( 'status' => 400 ) );
|
return new WP_Error( 'rest_no_search_term_defined', __( 'You need to define a search term to order by relevance.' ), array( 'status' => 400 ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,11 +161,6 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||||||
$args['date_query'][0]['after'] = $request['after'];
|
$args['date_query'][0]['after'] = $request['after'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( isset( $registered['filter'] ) && is_array( $request['filter'] ) ) {
|
|
||||||
$args = array_merge( $args, $request['filter'] );
|
|
||||||
unset( $args['filter'] );
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure our per_page parameter overrides any provided posts_per_page filter.
|
// Ensure our per_page parameter overrides any provided posts_per_page filter.
|
||||||
if ( isset( $registered['per_page'] ) ) {
|
if ( isset( $registered['per_page'] ) ) {
|
||||||
$args['posts_per_page'] = $request['per_page'];
|
$args['posts_per_page'] = $request['per_page'];
|
||||||
@ -269,17 +264,13 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||||||
$total_posts = $count_query->found_posts;
|
$total_posts = $count_query->found_posts;
|
||||||
}
|
}
|
||||||
|
|
||||||
$max_pages = ceil( $total_posts / (int) $query_args['posts_per_page'] );
|
$max_pages = ceil( $total_posts / (int) $posts_query->query_vars['posts_per_page'] );
|
||||||
|
|
||||||
$response = rest_ensure_response( $posts );
|
$response = rest_ensure_response( $posts );
|
||||||
$response->header( 'X-WP-Total', (int) $total_posts );
|
$response->header( 'X-WP-Total', (int) $total_posts );
|
||||||
$response->header( 'X-WP-TotalPages', (int) $max_pages );
|
$response->header( 'X-WP-TotalPages', (int) $max_pages );
|
||||||
|
|
||||||
$request_params = $request->get_query_params();
|
$request_params = $request->get_query_params();
|
||||||
if ( ! empty( $request_params['filter'] ) ) {
|
|
||||||
// Normalize the pagination params.
|
|
||||||
unset( $request_params['filter']['posts_per_page'], $request_params['filter']['paged'] );
|
|
||||||
}
|
|
||||||
$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 ) {
|
if ( $page > 1 ) {
|
||||||
@ -1910,9 +1901,6 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
|
|||||||
'type' => 'string',
|
'type' => 'string',
|
||||||
'validate_callback' => array( $this, 'validate_user_can_query_private_statuses' ),
|
'validate_callback' => array( $this, 'validate_user_can_query_private_statuses' ),
|
||||||
);
|
);
|
||||||
$params['filter'] = array(
|
|
||||||
'description' => __( 'Use WP Query arguments to modify the response; private query vars require appropriate authorization.' ),
|
|
||||||
);
|
|
||||||
|
|
||||||
$taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_rest' => true ) );
|
$taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_rest' => true ) );
|
||||||
foreach ( $taxonomies as $taxonomy ) {
|
foreach ( $taxonomies as $taxonomy ) {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '4.7-alpha-38967';
|
$wp_version = '4.7-alpha-38968';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
Loading…
Reference in New Issue
Block a user