[wp-trac] [WordPress Trac] #55213: Respect _fields query arg in preloaded requests

WordPress Trac noreply at wordpress.org
Mon Feb 21 11:18:41 UTC 2022


#55213: Respect _fields query arg in preloaded requests
-------------------------+-----------------------------
 Reporter:  jsnajdr      |      Owner:  (none)
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  REST API     |    Version:  5.9
 Severity:  normal       |   Keywords:  has-patch
  Focuses:               |
-------------------------+-----------------------------
 Suppose a preloaded request includes a `_fields` query param that asks
 that only selected response fields are returned. You can add such a
 request with a filter:

 {{{#!php
 function add_filtered_index_request( $preload_paths ) {
   array_push( $preload_paths, '/?_fields=home,title' );
   return $preload_paths;
 }
 add_filter( 'block_editor_rest_api_preload_paths',
 'add_filtered_index_request' );
 }}}

 However, you will discover that the `_fields` param is not respected and
 all fields are returned.

 This is because the `rest_preload_api_request` doesn't call
 `rest_filter_response_fields` on the response object. For other requests
 this call happens inside the `rest_post_dispatch filter`, but this filter
 is not called when preloading responses.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/55213>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list