diff -r 34716fd837a4 -r be944660c56a wp/wp-includes/rest-api/endpoints/class-wp-rest-controller.php --- a/wp/wp-includes/rest-api/endpoints/class-wp-rest-controller.php Tue Dec 15 15:52:01 2020 +0100 +++ b/wp/wp-includes/rest-api/endpoints/class-wp-rest-controller.php Wed Sep 21 18:19:35 2022 +0200 @@ -50,7 +50,7 @@ 'WP_REST_Controller::register_routes', /* translators: %s: register_routes() */ sprintf( __( "Method '%s' must be overridden." ), __METHOD__ ), - '4.7' + '4.7.0' ); } @@ -443,7 +443,7 @@ * * @param object $object Data model like WP_Term or WP_Post. * @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 true|WP_Error True on success, WP_Error object if a field cannot be updated. */ protected function update_additional_fields_for_object( $object, $request ) { $additional_fields = $this->get_additional_fields(); @@ -552,7 +552,7 @@ * @since 4.9.6 * * @param WP_REST_Request $request Full details about the request. - * @return array Fields to be included in the response. + * @return string[] Fields to be included in the response. */ public function get_fields_for_response( $request ) { $schema = $this->get_item_schema(); @@ -625,78 +625,7 @@ * @return array Endpoint arguments. */ public function get_endpoint_args_for_item_schema( $method = WP_REST_Server::CREATABLE ) { - - $schema = $this->get_item_schema(); - $schema_properties = ! empty( $schema['properties'] ) ? $schema['properties'] : array(); - $endpoint_args = array(); - $valid_schema_properties = array( - 'type', - 'format', - 'enum', - 'items', - 'properties', - 'additionalProperties', - 'minimum', - 'maximum', - 'exclusiveMinimum', - 'exclusiveMaximum', - 'minLength', - 'maxLength', - 'pattern', - 'minItems', - 'maxItems', - 'uniqueItems', - ); - - foreach ( $schema_properties as $field_id => $params ) { - - // Arguments specified as `readonly` are not allowed to be set. - if ( ! empty( $params['readonly'] ) ) { - continue; - } - - $endpoint_args[ $field_id ] = array( - 'validate_callback' => 'rest_validate_request_arg', - 'sanitize_callback' => 'rest_sanitize_request_arg', - ); - - if ( isset( $params['description'] ) ) { - $endpoint_args[ $field_id ]['description'] = $params['description']; - } - - if ( WP_REST_Server::CREATABLE === $method && isset( $params['default'] ) ) { - $endpoint_args[ $field_id ]['default'] = $params['default']; - } - - if ( WP_REST_Server::CREATABLE === $method && ! empty( $params['required'] ) ) { - $endpoint_args[ $field_id ]['required'] = true; - } - - foreach ( $valid_schema_properties as $schema_prop ) { - if ( isset( $params[ $schema_prop ] ) ) { - $endpoint_args[ $field_id ][ $schema_prop ] = $params[ $schema_prop ]; - } - } - - // Merge in any options provided by the schema property. - if ( isset( $params['arg_options'] ) ) { - - // Only use required / default from arg_options on CREATABLE endpoints. - if ( WP_REST_Server::CREATABLE !== $method ) { - $params['arg_options'] = array_diff_key( - $params['arg_options'], - array( - 'required' => '', - 'default' => '', - ) - ); - } - - $endpoint_args[ $field_id ] = array_merge( $endpoint_args[ $field_id ], $params['arg_options'] ); - } - } - - return $endpoint_args; + return rest_get_endpoint_args_for_schema( $this->get_item_schema(), $method ); } /**