Make WordPress Core

Opened 21 months ago

Last modified 3 months ago

#54087 new enhancement

A plugin can't change the parameters of a REST API endpoint

Reported by: antonvlasenko's profile antonvlasenko Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.9
Component: REST API Keywords: has-patch
Focuses: rest-api Cc:


Sometimes a plugin needs to change the parameters of an already registered REST API endpoint.
Now we need to override the whole WP_REST_Controller::register_routes method to achieve it. Unfortunately, that leads to code duplication, and that is not the best practice.
See an example of this here:

We should add a new filter (add_filter) at the very beginning of the register_rest_route's function body. That filter must allow to modify all arguments of the register_rest_route function.

Change History (4)

This ticket was mentioned in PR #3730 on WordPress/wordpress-develop by @dd32.

6 months ago

  • Keywords has-patch added

Add a register_route_args filter.

Trac ticket:

#2 @spacedmonkey
6 months ago

@TimothyBlynJacobs Can you provide any context here?

#3 @TimothyBlynJacobs
6 months ago

I don't have any context here, why this function was implemented without a filter was probably a very early decision.

Personally, I worry that such a low-level filter will get abused to add parameters to controllers without using the more intentional exposed APIs like register_rest_field.

I'm of the opinion that if controllers want to make portions of their route registration customizable, they should provide specific filters for that.

Gutenberg has pretty specialized needs as a place for prototyping features for Core, but I don't think we should be encouraging plugin developers to do the same.

#4 @rachelbaker
3 months ago

why this function was implemented without a filter was probably a very early decision.

@TimothyBlynJacobs is correct.

We intentionally avoided making it "easy" for plugins to have full control over the core endpoints. This design decision was made to favor standardization across all WP sites for the built-in endpoints. Plugins can easily extend existing endpoints or add new endpoints.

Note: See TracTickets for help on using tickets.