mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-12 04:40:26 +00:00
REST API: Handle parameter types consistently within set_param().
A request has multiple parameter types, including "query" and "json." Updating a parameter could previously modify a key's value in the wrong parameter type, leading to confusing and self-contradictory response objects. Props mnelson4, TimothyBlynJacobs, vagios, jnylen0. Fixes #40838. git-svn-id: https://develop.svn.wordpress.org/trunk@47559 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -420,14 +420,29 @@ class WP_REST_Request implements ArrayAccess {
|
||||
/**
|
||||
* Sets a parameter on the request.
|
||||
*
|
||||
* If the given parameter key exists in any parameter type an update will take place,
|
||||
* otherwise a new param will be created in the first parameter type (respecting
|
||||
* get_parameter_order()).
|
||||
*
|
||||
* @since 4.4.0
|
||||
*
|
||||
* @param string $key Parameter name.
|
||||
* @param mixed $value Parameter value.
|
||||
*/
|
||||
public function set_param( $key, $value ) {
|
||||
$order = $this->get_parameter_order();
|
||||
$this->params[ $order[0] ][ $key ] = $value;
|
||||
$order = $this->get_parameter_order();
|
||||
$found_key = false;
|
||||
|
||||
foreach ( $order as $type ) {
|
||||
if ( 'defaults' !== $type && array_key_exists( $key, $this->params[ $type ] ) ) {
|
||||
$this->params[ $type ][ $key ] = $value;
|
||||
$found_key = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! $found_key ) {
|
||||
$this->params[ $order[0] ][ $key ] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user