Make WordPress Core

Ticket #37560: 37560.diff

File 37560.diff, 2.1 KB (added by websupporter, 9 years ago)
  • src/wp-includes/rest-api/class-wp-rest-request.php

     
    793793
    794794                $order = $this->get_parameter_order();
    795795
     796                $invalid_params = array();
     797
    796798                foreach ( $order as $type ) {
    797799                        if ( empty( $this->params[ $type ] ) ) {
    798800                                continue;
     
    800802                        foreach ( $this->params[ $type ] as $key => $value ) {
    801803                                // Check if this param has a sanitize_callback added.
    802804                                if ( isset( $attributes['args'][ $key ] ) && ! empty( $attributes['args'][ $key ]['sanitize_callback'] ) ) {
    803                                         $this->params[ $type ][ $key ] = call_user_func( $attributes['args'][ $key ]['sanitize_callback'], $value, $this, $key );
     805                                        $sanitized_value = call_user_func( $attributes['args'][ $key ]['sanitize_callback'], $value, $this, $key );
     806                                        if ( is_wp_error( $sanitized_value ) ) {
     807                                                $invalid_params[ $key ] = $sanitized_value->get_error_message();
     808                                        } else {
     809                                                $this->params[ $type ][ $key ] = $sanitized_value;
     810                                        }
     811
    804812                                }
    805813                        }
    806814                }
    807                 return null;
    808         }
     815                if( $invalid_params )
     816                        return new WP_Error( 'rest_invalid_param', sprintf( __( 'Invalid parameter(s): %s' ), implode( ', ', array_keys( $invalid_params ) ) ), array( 'status' => 400, 'params' => $invalid_params ) );
     817                return null
     818;       }
    809819
    810820        /**
    811821         * Checks whether this request is valid according to its attributes.
  • src/wp-includes/rest-api/class-wp-rest-server.php

     
    866866                                        $check_required = $request->has_valid_params();
    867867                                        if ( is_wp_error( $check_required ) ) {
    868868                                                $response = $check_required;
     869                                        } else {
     870                                                $check_sanitized = $request->sanitize_params();
     871                                                if ( is_wp_error( $check_sanitized ) ) {
     872                                                        $response = $check_sanitized;
     873                                                }
    869874                                        }
    870 
    871                                         $request->sanitize_params();
    872875                                }
    873876
    874877                                if ( ! is_wp_error( $response ) ) {