diff --git a/src/wp-includes/rest-api/class-wp-rest-request.php b/src/wp-includes/rest-api/class-wp-rest-request.php
index 74a81c9..9360cca 100644
a
|
b
|
class WP_REST_Request implements ArrayAccess { |
353 | 353 | */ |
354 | 354 | protected function get_parameter_order() { |
355 | 355 | $order = array(); |
356 | | $order[] = 'JSON'; |
| 356 | |
| 357 | $content_type = $this->get_content_type(); |
| 358 | |
| 359 | if ( $content_type['value'] === 'application/json' ) { |
| 360 | $order[] = 'JSON'; |
| 361 | } |
357 | 362 | |
358 | 363 | $this->parse_json_params(); |
359 | 364 | |
… |
… |
class WP_REST_Request implements ArrayAccess { |
423 | 428 | * @param mixed $value Parameter value. |
424 | 429 | */ |
425 | 430 | public function set_param( $key, $value ) { |
426 | | switch ( $this->method ) { |
427 | | case 'POST': |
428 | | $this->params['POST'][ $key ] = $value; |
429 | | break; |
430 | | |
431 | | default: |
432 | | $this->params['GET'][ $key ] = $value; |
433 | | break; |
434 | | } |
| 431 | |
| 432 | $order = $this->get_parameter_order(); |
| 433 | $first = reset( $order ); |
| 434 | |
| 435 | $this->params[ $first ][ $key ] = $value; |
435 | 436 | } |
436 | 437 | |
437 | 438 | /** |
diff --git a/tests/phpunit/tests/rest-api/rest-request.php b/tests/phpunit/tests/rest-api/rest-request.php
index ffd4ea2..a96bbb0 100644
a
|
b
|
class Tests_REST_Request extends WP_UnitTestCase { |
572 | 572 | $request = WP_REST_Request::from_url( $using_home ); |
573 | 573 | $this->assertFalse( $request ); |
574 | 574 | } |
| 575 | |
| 576 | public function test_set_param() { |
| 577 | |
| 578 | $request = new WP_REST_Request(); |
| 579 | $request->set_param( 'param', 'value' ); |
| 580 | |
| 581 | $this->assertEquals( 'value', $request->get_param( 'param' ) ); |
| 582 | } |
| 583 | |
| 584 | public function test_set_param_follows_parameter_order() { |
| 585 | |
| 586 | $request = new WP_REST_Request(); |
| 587 | $request->add_header( 'content-type', 'application/json' ); |
| 588 | $request->set_method( 'POST' ); |
| 589 | $request->set_body( wp_json_encode( [ |
| 590 | 'param' => 'value' |
| 591 | ] ) ); |
| 592 | |
| 593 | $this->assertEquals( 'value', $request->get_param( 'param' ) ); |
| 594 | $request->set_param( 'param', 'new_value' ); |
| 595 | $this->assertEquals( 'new_value', $request->get_param( 'param' ) ); |
| 596 | } |
575 | 597 | } |