mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-04 12:44:31 +00:00
REST API: Don't add fields to object when not included in ?_fields=.
In [43087], we improved REST API performance by only rendering the fields specified in the request. Similarly, any fields registered with `register_rest_field()` should only be rendered when included in `?_fields=`. Props dlh, danielbachhuber. Merges [43736] to trunk. Fixes #45099. git-svn-id: https://develop.svn.wordpress.org/trunk@43986 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -385,12 +385,18 @@ abstract class WP_REST_Controller {
|
||||
|
||||
$additional_fields = $this->get_additional_fields();
|
||||
|
||||
$requested_fields = $this->get_fields_for_response( $request );
|
||||
|
||||
foreach ( $additional_fields as $field_name => $field_options ) {
|
||||
|
||||
if ( ! $field_options['get_callback'] ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ! in_array( $field_name, $requested_fields, true ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$object[ $field_name ] = call_user_func( $field_options['get_callback'], $object, $field_name, $request, $this->get_object_type() );
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user