Make WordPress Core


Ignore:
Timestamp:
10/26/2016 09:36:29 PM (8 years ago)
Author:
rachelbaker
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

    r38911 r38968  
    112112
    113113        // Make sure a search string is set in case the orderby is set to 'relevance'.
    114         if ( ! empty( $request['orderby'] ) && 'relevance' === $request['orderby'] && empty( $request['search'] ) && empty( $request['filter']['s'] ) ) {
     114        if ( ! empty( $request['orderby'] ) && 'relevance' === $request['orderby'] && empty( $request['search'] ) ) {
    115115            return new WP_Error( 'rest_no_search_term_defined', __( 'You need to define a search term to order by relevance.' ), array( 'status' => 400 ) );
    116116        }
     
    162162        }
    163163
    164         if ( isset( $registered['filter'] ) && is_array( $request['filter'] ) ) {
    165             $args = array_merge( $args, $request['filter'] );
    166             unset( $args['filter'] );
    167         }
    168 
    169164        // Ensure our per_page parameter overrides any provided posts_per_page filter.
    170165        if ( isset( $registered['per_page'] ) ) {
     
    270265        }
    271266
    272         $max_pages = ceil( $total_posts / (int) $query_args['posts_per_page'] );
     267        $max_pages = ceil( $total_posts / (int) $posts_query->query_vars['posts_per_page'] );
    273268
    274269        $response = rest_ensure_response( $posts );
     
    277272
    278273        $request_params = $request->get_query_params();
    279         if ( ! empty( $request_params['filter'] ) ) {
    280             // Normalize the pagination params.
    281             unset( $request_params['filter']['posts_per_page'], $request_params['filter']['paged'] );
    282         }
    283274        $base = add_query_arg( $request_params, rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ) );
    284275
     
    19111902            'validate_callback' => array( $this, 'validate_user_can_query_private_statuses' ),
    19121903        );
    1913         $params['filter'] = array(
    1914             'description'       => __( 'Use WP Query arguments to modify the response; private query vars require appropriate authorization.' ),
    1915         );
    19161904
    19171905        $taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_rest' => true ) );
Note: See TracChangeset for help on using the changeset viewer.