Ticket #37560: 37560.diff
File 37560.diff, 2.1 KB (added by , 9 years ago) |
---|
-
src/wp-includes/rest-api/class-wp-rest-request.php
793 793 794 794 $order = $this->get_parameter_order(); 795 795 796 $invalid_params = array(); 797 796 798 foreach ( $order as $type ) { 797 799 if ( empty( $this->params[ $type ] ) ) { 798 800 continue; … … 800 802 foreach ( $this->params[ $type ] as $key => $value ) { 801 803 // Check if this param has a sanitize_callback added. 802 804 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 804 812 } 805 813 } 806 814 } 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 ; } 809 819 810 820 /** 811 821 * Checks whether this request is valid according to its attributes. -
src/wp-includes/rest-api/class-wp-rest-server.php
866 866 $check_required = $request->has_valid_params(); 867 867 if ( is_wp_error( $check_required ) ) { 868 868 $response = $check_required; 869 } else { 870 $check_sanitized = $request->sanitize_params(); 871 if ( is_wp_error( $check_sanitized ) ) { 872 $response = $check_sanitized; 873 } 869 874 } 870 871 $request->sanitize_params();872 875 } 873 876 874 877 if ( ! is_wp_error( $response ) ) {