REST API: Allow schema sanitization_callback to be set to null to bypass fallback sanitization functions.

The logic in WP_REST_Request->sanitize_params() added in [39091] did not account for `null` or `false` being the sanitization_callback preventing overriding `rest_parse_request_arg()`. This fixes that oversight, allowing the built in sanitization function to be bypassed. See #38593.

Merges [39563] to the 4.7  branch.

Props kkoppenhaver, rachelbaker, jnylen0.
Fixes #39042.

Built from https://develop.svn.wordpress.org/branches/4.7@39642


git-svn-id: http://core.svn.wordpress.org/branches/4.7@39582 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Rachel Baker 2016-12-27 17:49:36 +00:00
parent 8780e40de2
commit bd0a38d439
2 changed files with 12 additions and 8 deletions

View File

@ -823,17 +823,21 @@ class WP_REST_Request implements ArrayAccess {
continue; continue;
} }
foreach ( $this->params[ $type ] as $key => $value ) { foreach ( $this->params[ $type ] as $key => $value ) {
// if no sanitize_callback was specified, default to rest_parse_request_arg if ( ! isset( $attributes['args'][ $key ] ) ) {
// if a type was specified in the args. continue;
if ( ! isset( $attributes['args'][ $key ]['sanitize_callback'] ) && ! empty( $attributes['args'][ $key ]['type'] ) ) {
$attributes['args'][ $key ]['sanitize_callback'] = 'rest_parse_request_arg';
} }
// Check if this param has a sanitize_callback added. $param_args = $attributes['args'][ $key ];
if ( ! isset( $attributes['args'][ $key ] ) || empty( $attributes['args'][ $key ]['sanitize_callback'] ) ) {
// 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';
}
// If there's still no sanitize_callback, nothing to do here.
if ( empty( $param_args['sanitize_callback'] ) ) {
continue; 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 ) ) { if ( is_wp_error( $sanitized_value ) ) {
$invalid_params[ $key ] = $sanitized_value->get_error_message(); $invalid_params[ $key ] = $sanitized_value->get_error_message();

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.7.1-alpha-39641'; $wp_version = '4.7.1-alpha-39642';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.