Make WordPress Core


Ignore:
Timestamp:
05/22/2017 04:15:25 PM (8 years ago)
Author:
jnylen0
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/class-wp-rest-request.php

    r40577 r40815  
    355355    protected function get_parameter_order() {
    356356        $order = array();
    357         $order[] = 'JSON';
     357
     358        $content_type = $this->get_content_type();
     359        if ( $content_type['value'] === 'application/json' ) {
     360            $order[] = 'JSON';
     361        }
    358362
    359363        $this->parse_json_params();
     
    425429     */
    426430    public function set_param( $key, $value ) {
    427         switch ( $this->method ) {
    428             case 'POST':
    429                 $this->params['POST'][ $key ] = $value;
    430                 break;
    431 
    432             default:
    433                 $this->params['GET'][ $key ] = $value;
    434                 break;
    435         }
     431        $order = $this->get_parameter_order();
     432        $this->params[ $order[0] ][ $key ] = $value;
    436433    }
    437434
Note: See TracChangeset for help on using the changeset viewer.