Make WordPress Core


Ignore:
Timestamp:
08/15/2019 08:03:18 PM (7 years ago)
Author:
kadamwhite
Message:

REST API: Clarify arguments passed to rest route get & update callbacks.

Update doc block argument definitions to clarify that the REST API always passes an array to the get_callback and always passes an entity object to the update_callback.

Props TimothyBlynJacobs, salzano.
Fixes #44432.

File:
1 edited

Legend:

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

    r45706 r45810  
    373373         * @since 4.7.0
    374374         *
    375          * @param array           $object  Data object.
    376          * @param WP_REST_Request $request Full details about the request.
     375         * @param array           $prepared Prepared response array.
     376         * @param WP_REST_Request $request  Full details about the request.
    377377         * @return array Modified data object with additional fields.
    378378         */
    379         protected function add_additional_fields_to_object( $object, $request ) {
     379        protected function add_additional_fields_to_object( $prepared, $request ) {
    380380
    381381                $additional_fields = $this->get_additional_fields();
     
    393393                        }
    394394
    395                         $object[ $field_name ] = call_user_func( $field_options['get_callback'], $object, $field_name, $request, $this->get_object_type() );
    396                 }
    397 
    398                 return $object;
     395                        $prepared[ $field_name ] = call_user_func( $field_options['get_callback'], $prepared, $field_name, $request, $this->get_object_type() );
     396                }
     397
     398                return $prepared;
    399399        }
    400400
     
    404404         * @since 4.7.0
    405405         *
    406          * @param array           $object  Data Object.
     406         * @param object          $object  Data model like WP_Term or WP_Post.
    407407         * @param WP_REST_Request $request Full details about the request.
    408408         * @return bool|WP_Error True on success, WP_Error object if a field cannot be updated.
Note: See TracChangeset for help on using the changeset viewer.