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.


Built from https://develop.svn.wordpress.org/trunk@45810


git-svn-id: http://core.svn.wordpress.org/trunk@45621 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
K. Adam White 2019-08-15 20:04:55 +00:00
parent 8dcc10693f
commit dbfa0c7ed4
3 changed files with 15 additions and 15 deletions

View File

@ -102,14 +102,14 @@ function register_rest_route( $namespace, $route, $args = array(), $override = f
* @param array $args { * @param array $args {
* Optional. An array of arguments used to handle the registered field. * Optional. An array of arguments used to handle the registered field.
* *
* @type string|array|null $get_callback Optional. The callback function used to retrieve the field * @type callable|null $get_callback Optional. The callback function used to retrieve the field value. Default is
* value. Default is 'null', the field will not be returned in * 'null', the field will not be returned in the response. The function will
* the response. * be passed the prepared object data.
* @type string|array|null $update_callback Optional. The callback function used to set and update the * @type callable|null $update_callback Optional. The callback function used to set and update the field value. Default
* field value. Default is 'null', the value cannot be set or * is 'null', the value cannot be set or updated. The function will be passed
* updated. * the model object, like WP_Post.
* @type string|array|null $schema Optional. The callback function used to create the schema for * @type array|null $schema Optional. The callback function used to create the schema for this field.
* this field. Default is 'null', no schema entry will be returned. * Default is 'null', no schema entry will be returned.
* } * }
*/ */
function register_rest_field( $object_type, $attribute, $args = array() ) { function register_rest_field( $object_type, $attribute, $args = array() ) {

View File

@ -372,11 +372,11 @@ abstract class WP_REST_Controller {
* *
* @since 4.7.0 * @since 4.7.0
* *
* @param array $object Data object. * @param array $prepared Prepared response array.
* @param WP_REST_Request $request Full details about the request. * @param WP_REST_Request $request Full details about the request.
* @return array Modified data object with additional fields. * @return array Modified data object with additional fields.
*/ */
protected function add_additional_fields_to_object( $object, $request ) { protected function add_additional_fields_to_object( $prepared, $request ) {
$additional_fields = $this->get_additional_fields(); $additional_fields = $this->get_additional_fields();
@ -392,10 +392,10 @@ abstract class WP_REST_Controller {
continue; continue;
} }
$object[ $field_name ] = call_user_func( $field_options['get_callback'], $object, $field_name, $request, $this->get_object_type() ); $prepared[ $field_name ] = call_user_func( $field_options['get_callback'], $prepared, $field_name, $request, $this->get_object_type() );
} }
return $object; return $prepared;
} }
/** /**
@ -403,7 +403,7 @@ abstract class WP_REST_Controller {
* *
* @since 4.7.0 * @since 4.7.0
* *
* @param array $object Data Object. * @param object $object Data model like WP_Term or WP_Post.
* @param WP_REST_Request $request Full details about the request. * @param WP_REST_Request $request Full details about the request.
* @return bool|WP_Error True on success, WP_Error object if a field cannot be updated. * @return bool|WP_Error True on success, WP_Error object if a field cannot be updated.
*/ */

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.3-alpha-45809'; $wp_version = '5.3-alpha-45810';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.