From 252ab08d8827f6b3b0761b1944618ada2c8a8a13 Mon Sep 17 00:00:00 2001 From: James Nylen Date: Mon, 22 May 2017 16:16:42 +0000 Subject: [PATCH] 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 --- wp-includes/rest-api/class-wp-rest-request.php | 17 +++++++---------- wp-includes/version.php | 2 +- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/wp-includes/rest-api/class-wp-rest-request.php b/wp-includes/rest-api/class-wp-rest-request.php index 0a26d0fe3d..e41c014557 100644 --- a/wp-includes/rest-api/class-wp-rest-request.php +++ b/wp-includes/rest-api/class-wp-rest-request.php @@ -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; } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index 75970d22bd..deae2e3261 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.