WordPress.org

Make WordPress Core

Opened 16 months ago

Closed 15 months ago

Last modified 15 months ago

#50876 closed enhancement (fixed)

REST API: Extract get_endpoint_args_for_item_schema to standalone function

Reported by: TimothyBlynJacobs Owned by: 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:

Description

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.


16 months 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

https://core.trac.wordpress.org/ticket/50876

#2 @pentatonicfunk
16 months ago

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

#3 @TimothyBlynJacobs
15 months 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
15 months ago

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

#5 @prbot
15 months ago

TimothyBJacobs commented on PR #492:

Merged in 84d524e. Thanks again for the patch!

Note: See TracTickets for help on using tickets.