REST API: Fix warning when using set_param() on a JSON request with no body.

In [47559] the `WP_REST_Request::set_param()` method was adjusted to try and overwrite an existing parameter definition before forcing the value in the first parameter slot. If `set_param()` was called on a request with an `application/json` content type and an empty body, a PHP warning would be issued. This was due to the JSON parameter type not being set to an array when the body is empty.

This commit avoids the warning by adding an `is_array()` check before calling `array_key_exists`. Ideally, `WP_REST_Reuest::parse_json_params()` would set the JSON parameter type to an empty array in this case, but that is too large of a change at this point in the cycle.

Props manooweb.
Fixes #50786.

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


git-svn-id: http://core.svn.wordpress.org/trunk@48404 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
TimothyBlynJacobs 2020-07-27 18:46:05 +00:00
parent de5533e56b
commit 86ea4f0838
2 changed files with 3 additions and 3 deletions

View File

@ -408,7 +408,7 @@ class WP_REST_Request implements ArrayAccess {
$order = $this->get_parameter_order();
foreach ( $order as $type ) {
if ( array_key_exists( $key, $this->params[ $type ] ) ) {
if ( is_array( $this->params[ $type ] ) && array_key_exists( $key, $this->params[ $type ] ) ) {
return true;
}
}
@ -433,7 +433,7 @@ class WP_REST_Request implements ArrayAccess {
$found_key = false;
foreach ( $order as $type ) {
if ( 'defaults' !== $type && array_key_exists( $key, $this->params[ $type ] ) ) {
if ( 'defaults' !== $type && is_array( $this->params[ $type ] ) && array_key_exists( $key, $this->params[ $type ] ) ) {
$this->params[ $type ][ $key ] = $value;
$found_key = true;
}

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.5-beta3-48641';
$wp_version = '5.5-beta3-48642';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.