WordPress.org

Make WordPress Core

Ticket #44432: 44432.diff

File 44432.diff, 3.8 KB (added by TimothyBlynJacobs, 19 months ago)
  • src/wp-includes/rest-api.php

    diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php
    index 5ec557547c..97af03bf0c 100644
    a b function register_rest_route( $namespace, $route, $args = array(), $override = f 
    102102 * @param array  $args {
    103103 *     Optional. An array of arguments used to handle the registered field.
    104104 *
    105  *     @type string|array|null $get_callback    Optional. The callback function used to retrieve the field
    106  *                                              value. Default is 'null', the field will not be returned in
    107  *                                              the response.
    108  *     @type string|array|null $update_callback Optional. The callback function used to set and update the
    109  *                                              field value. Default is 'null', the value cannot be set or
    110  *                                              updated.
    111  *     @type string|array|null $schema          Optional. The callback function used to create the schema for
    112  *                                              this field. Default is 'null', no schema entry will be returned.
     105 *     @type callable|null $get_callback    Optional. The callback function used to retrieve the field value. Default is
     106 *                                          'null', the field will not be returned in the response. The function will
     107 *                                          be passed the prepared object data.
     108 *     @type callable|null $update_callback Optional. The callback function used to set and update the field value. Default
     109 *                                          is 'null', the value cannot be set or updated. The function will be passed
     110 *                                          the model object, like WP_Post.
     111 *     @type array|null $schema             Optional. The callback function used to create the schema for this field.
     112 *                                          Default is 'null', no schema entry will be returned.
    113113 * }
    114114 */
    115115function register_rest_field( $object_type, $attribute, $args = array() ) {
  • src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php

    diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php
    index cd976f3357..631eb482bd 100644
    a b abstract class WP_REST_Controller { 
    372372         *
    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.
     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();
    382382
    abstract class WP_REST_Controller { 
    392392                                continue;
    393393                        }
    394394
    395                         $object[ $field_name ] = call_user_func( $field_options['get_callback'], $object, $field_name, $request, $this->get_object_type() );
     395                        $prepared[ $field_name ] = call_user_func( $field_options['get_callback'], $prepared, $field_name, $request, $this->get_object_type() );
    396396                }
    397397
    398                 return $object;
     398                return $prepared;
    399399        }
    400400
    401401        /**
    abstract class WP_REST_Controller { 
    403403         *
    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.
    409409         */