REST API: Fix changing parameters with set_param() for some requests.

Prior to this commit, `WP_Rest_Request::get_param()` traversed through the parameter order but `WP_Rest_Request::set_param()` did not. For JSON requests (and likely other situations as well), this meant that changing a parameter with `set_param()` would have no effect on `get_param()`.

Props TimothyBlynJacobs.
Fixes #40344.


Built from https://develop.svn.wordpress.org/trunk@40815


git-svn-id: http://core.svn.wordpress.org/trunk@40673 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
James Nylen 2017-05-22 16:16:42 +00:00
parent 24a7666e69
commit 252ab08d88
2 changed files with 8 additions and 11 deletions

View File

@ -354,7 +354,11 @@ class WP_REST_Request implements ArrayAccess {
*/
protected function get_parameter_order() {
$order = array();
$order[] = 'JSON';
$content_type = $this->get_content_type();
if ( $content_type['value'] === 'application/json' ) {
$order[] = 'JSON';
}
$this->parse_json_params();
@ -424,15 +428,8 @@ class WP_REST_Request implements ArrayAccess {
* @param mixed $value Parameter value.
*/
public function set_param( $key, $value ) {
switch ( $this->method ) {
case 'POST':
$this->params['POST'][ $key ] = $value;
break;
default:
$this->params['GET'][ $key ] = $value;
break;
}
$order = $this->get_parameter_order();
$this->params[ $order[0] ][ $key ] = $value;
}
/**

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.8-beta1-40814';
$wp_version = '4.8-beta1-40815';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.