Make WordPress Core


Ignore:
Timestamp:
11/14/2016 04:35:35 PM (8 years ago)
Author:
joehoyle
Message:

REST API: Validate and Sanitize registered meta based off the schema.

With the addition of Array support in our schema validation functions, it's now possible to use these in the meta validation and sanitization steps. Also, this increases the test coverage of using registered via meta the API significantly.

Fixes #38531.
Props rachelbaker, tharsheblows.

File:
1 edited

Legend:

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

    r39158 r39222  
    998998        if ( ! is_array( $value ) ) {
    999999            $value = preg_split( '/[\s,]+/', $value );
     1000        }
     1001        if ( ! wp_is_numeric_array( $value ) ) {
     1002            return new WP_Error( 'rest_invalid_param', sprintf( /* translators: 1: parameter, 2: type name */ __( '%1$s is not of type %2$s.' ), $param, 'array' ) );
    10001003        }
    10011004        foreach ( $value as $index => $v ) {
     
    11081111            $value[ $index ] = rest_sanitize_value_from_schema( $v, $args['items'] );
    11091112        }
     1113        // Normalize to numeric array so nothing unexpected
     1114        // is in the keys.
     1115        $value = array_values( $value );
    11101116        return $value;
    11111117    }
     
    11411147    }
    11421148
     1149    if ( 'string' === $args['type'] ) {
     1150        return strval( $value );
     1151    }
     1152
    11431153    return $value;
    11441154}
Note: See TracChangeset for help on using the changeset viewer.