Opened 10 years ago
Closed 9 years ago
#35312 closed enhancement (wontfix)
Support for transforming REST API request arguments
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | |
| Component: | REST API | Keywords: | needs-patch |
| Focuses: | Cc: |
Description
The REST API controllers have a fair amount of procedural transformation code like this:
/**
* Prepend internal property prefix to query parameters to match our response fields.
*
* @param string $query_param
* @return string $normalized
*/
protected function normalize_query_param( $query_param ) {
$prefix = 'comment_';
switch ( $query_param ) {
case 'id':
$normalized = $prefix . 'ID';
break;
case 'post':
$normalized = $prefix . 'post_ID';
break;
case 'parent':
$normalized = $prefix . 'parent';
break;
default:
$normalized = $prefix . $query_param;
break;
}
return $normalized;
}
What if I could just define some transform_to argument when registering my request arguments, and have the request data transformed before it gets to my callback?
Change History (2)
Note: See
TracTickets for help on using
tickets.
I'm going to close this out as a wontfix. While there are a bunch of spots which have code repetition, they usually turn out to be full of special cases that make a generic
transform_touseless. Where this isn't the case, the code is usually pretty clean anyway, or could simply use aforeachloop.I don't see the need for this as a general-purpose argument in parameter registration. This could always be implemented as a plugin if you really want it.