Make WordPress Core

Changes between Version 1 and Version 2 of Ticket #38583, comment 20


Ignore:
Timestamp:
10/11/2017 04:47:33 PM (8 years ago)
Author:
mnelson4
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #38583, comment 20

    v1 v2  
    3333I'm not sure if other plugin developers or users with custom endpoints will experience the same issue.
    3434
    35 I'd suggest: if `$args['properties']` is empty inside `rest_sanitize_value_from_schema`, that no validation should occur (for backward compatibility, that was the previous behaviour), instead of only considering an empty object valid (current behaviour).
    36 
    37 ie, inside `rest_sanitize_value_from_schema`, replace the code that deals with args of type object with this
    38 {{{#!php
    39 if ( 'object' === $args['type'] ) {
    40                 if ($value instanceof stdClass) {
    41                         $value = (array)$value;
    42                 }
    43                 if (! is_array($value)) {
    44                         return array();
    45                 }
    46                 if (isset($args['properties'])) {// <--- new
    47                         foreach ($value as $property => $v) {
    48                                 if (! isset($args['properties'][$property])) {
    49                                         unset($value[$property]);
    50                                         continue;
    51                                 }
    52                                 $value[$property] = rest_sanitize_value_from_schema($v, $args['properties'][$property]);
    53                         }
    54                 }// <---- new
    55 }}}
     35--- I removed my code suggestion. I now think @TimothyBlynJacobs 's original approach, to have an `additionalProperties` argument, is best.