Make WordPress Core


Ignore:
Timestamp:
11/21/2018 02:43:33 PM (8 years ago)
Author:
danielbachhuber
Message:

REST API: Preserve unknown, respect null in server-side block rendering.

  • Skips validation where there is no attribute definition, but keeps the attribute value. Previously, the attribute would be omitted from the attributes passed to render_callback. Notably, this resolves an issue where render_callback cannot receive a block's align and customClassName attribute values, since these are defined as a client-side filter.
  • Validates null as a proper value in its own right. Previously, a client implementation of a block could track {"attribute":null} as an explicitly empty value, and the server would wrongly initiate defaulting behavior. The new behavior will now only populate a default value if the attribute is not defined at all, including when unset in its being invalid per the attribute schema.

Props aduth, noisysocks, youknowriad.
See #45145 for the patch, #45098 for the original ticket.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/5.0/src/wp-includes/rest-api/endpoints/class-wp-rest-block-renderer-controller.php

    r43806 r43918  
    6262                                                                'additionalProperties' => false,
    6363                                                                'properties'           => $block_type->get_attributes(),
     64                                                                'default'              => array(),
    6465                                                        ),
    6566                                                        'post_id'    => array(
Note: See TracChangeset for help on using the changeset viewer.