Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#50876 closed enhancement (fixed)

REST API: Extract get_endpoint_args_for_item_schema to standalone function

Reported by: timothyblynjacobs's profile TimothyBlynJacobs Owned by: timothyblynjacobs's profile TimothyBlynJacobs
Milestone: 5.6 Priority: normal
Severity: normal Version: 4.7
Component: REST API Keywords: good-first-bug has-patch has-unit-tests
Focuses: Cc:


The WP_REST_Controller:get_endpoint_args_for_item_schema() method allows converting a schema to an args format for WP_REST_Request. This is a helpful function for whenever you want to apply this kind of conversion, but since it is a part of the WP_REST_Controller class, and doesn't accept the schema to transform directly, doing this conversion is tricky.

I think it'd be helpful to extract this to a standalone rest_get_endpoint_args_for_schema( $schema, $method ) function that the existing method in WP_REST_Controller can then call.

Change History (5)

This ticket was mentioned in PR #492 on WordPress/wordpress-develop by pentatonicfunk.

4 years ago

  • Keywords has-patch has-unit-tests added; needs-patch needs-unit-tests removed
  • Extract get_endpoint_args_for_item_schema to standalone rest_get_endpoint_args_for_schema function
  • Update unit test rest-controller.php, change focus to rest_get_endpoint_args_for_schema

#2 @pentatonicfunk
4 years ago

Couldn't agree more, exposing this function will give more benefits to developers.
I've create initial PR.

#3 @TimothyBlynJacobs
4 years ago

  • Owner set to TimothyBlynJacobs
  • Resolution set to fixed
  • Status changed from new to closed

In 48951:

REST API: Extract WP_REST_Controller::get_endpoint_args_for_item_schema() to a standalone function.

This method is useful whenever a JSON Schema needs to be converted to a format suitable for argument validation with WP_REST_Request. Moving the logic into a standalone function allows developers to use it outside of the WP_REST_Controller context.

Props pentatonicfunk.
Fixes #50876.

#4 @TimothyBlynJacobs
4 years ago

This is great, thanks for working on the patch @pentatonicfunk!

TimothyBJacobs commented on PR #492:

4 years ago

Merged in 84d524e. Thanks again for the patch!

Note: See TracTickets for help on using tickets.