Opened 8 years ago
Closed 8 years ago
#40344 closed defect (bug) (fixed)
WP_REST_Request::set_param() ignores parameter order.
Reported by: | TimothyBlynJacobs | Owned by: | jnylen0 |
---|---|---|---|
Milestone: | 4.8 | Priority: | normal |
Severity: | normal | Version: | 4.4 |
Component: | REST API | Keywords: | has-patch has-unit-tests commit |
Focuses: | rest-api | Cc: |
Description
WP_Rest_Request::get_param()
traverses through the parameter order but WP_Rest_Request::set_param()
does not. For JSON requests, this means that changing a parameter with set_param()
will have no affect on get_param()
.
Example Code:
$request = new WP_REST_Request(); $request->add_header( 'content-type', 'application/json' ); $request->set_method( 'POST' ); $request->set_body( wp_json_encode( [ 'param' => 'hi' ] ) ); echo $request->get_param( 'param' ); // hi $request->set_param( 'param', 'hello' ); echo $request->get_param( 'param' ); // hi
Patch incoming.
Attachments (2)
Change History (10)
This ticket was mentioned in Slack in #core by jeffpaul. View the logs.
8 years ago
#6
@
8 years ago
- Keywords commit added
- Owner set to jnylen0
- Status changed from new to accepted
@TimothyBlynJacobs in general, yes, if a patch has known issues then it is always useful to have a refreshed version on the ticket.
40344.2.diff addresses the following issues:
- Use
[0]
instead ofreset
to get the first element of the array - Core (including unit tests) cannot use
[ 'key' => 'value' ]
array syntax; we still support PHP 5.2 - Trailing whitespace on blank lines
Patch LGTM as well. I'll commit when tests pass locally.
Note: See
TracTickets for help on using
tickets.
Good catch! I didn't get to this previously, but good to go for 4.8, because it's a bugfix.
Patch looks good, but I'd rather avoid using
reset()
, since it modifies the array. We know$order
is an indexed array, so$first = $order[0]
is fine.