WordPress 4.7.1
[autoinstalls/wordpress.git] / wp-includes / rest-api / class-wp-rest-request.php
index 3c465babd05847aa13435addacd031858e605c9c..4dd0dc2090ac6726875107a799748b44a3c35825 100644 (file)
@@ -669,7 +669,12 @@ class WP_REST_Request implements ArrayAccess {
                        return true;
                }
 
-               $params = json_decode( $this->get_body(), true );
+               $body = $this->get_body();
+               if ( empty( $body ) ) {
+                       return true;
+               }
+
+               $params = json_decode( $body, true );
 
                /*
                 * Check for a parsing error.
@@ -818,17 +823,21 @@ class WP_REST_Request implements ArrayAccess {
                                continue;
                        }
                        foreach ( $this->params[ $type ] as $key => $value ) {
-                               // if no sanitize_callback was specified, default to rest_parse_request_arg
-                               // if a type was specified in the args.
-                               if ( ! isset( $attributes['args'][ $key ]['sanitize_callback'] ) && ! empty( $attributes['args'][ $key ]['type'] ) ) {
-                                       $attributes['args'][ $key ]['sanitize_callback'] = 'rest_parse_request_arg';
+                               if ( ! isset( $attributes['args'][ $key ] ) ) {
+                                       continue;
+                               }
+                               $param_args = $attributes['args'][ $key ];
+
+                               // If the arg has a type but no sanitize_callback attribute, default to rest_parse_request_arg.
+                               if ( ! array_key_exists( 'sanitize_callback', $param_args ) && ! empty( $param_args['type'] ) ) {
+                                       $param_args['sanitize_callback'] = 'rest_parse_request_arg';
                                }
-                               // Check if this param has a sanitize_callback added.
-                               if ( ! isset( $attributes['args'][ $key ] ) || empty( $attributes['args'][ $key ]['sanitize_callback'] ) ) {
+                               // If there's still no sanitize_callback, nothing to do here.
+                               if ( empty( $param_args['sanitize_callback'] ) ) {
                                        continue;
                                }
 
-                               $sanitized_value = call_user_func( $attributes['args'][ $key ]['sanitize_callback'], $value, $this, $key );
+                               $sanitized_value = call_user_func( $param_args['sanitize_callback'], $value, $this, $key );
 
                                if ( is_wp_error( $sanitized_value ) ) {
                                        $invalid_params[ $key ] = $sanitized_value->get_error_message();