Make WordPress Core


Ignore:
Timestamp:
06/17/2020 03:20:02 AM (5 years ago)
Author:
TimothyBlynJacobs
Message:

REST API: Only register one block renderer route.

Every block has a different set of attributes. These attributes are specified as a JSON Schema object. Previously, every block registered its own block renderer route using its attributes for the schema. This allowed for the attributes to be validated using the built in endpoint validation rules. It had the unfortunate side effect, however, of creating a large number of nearly identical REST API routes, one for each dynamic block. Each registered route has a performance impact. As the number of server side blocks goes up, this becomes more and more of an issue.

Now, we register a single block renderer route and dynamically validate the attributes based on the selected block.

Fixes #48079.
Props gziolo, TimothyBlynJacobs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-schema-setup.php

    r47250 r48069  
    121121            '/wp/v2/comments/(?P<id>[\\d]+)',
    122122            '/wp/v2/search',
    123             '/wp/v2/block-renderer/(?P<name>core/archives)',
    124             '/wp/v2/block-renderer/(?P<name>core/block)',
    125             '/wp/v2/block-renderer/(?P<name>core/calendar)',
    126             '/wp/v2/block-renderer/(?P<name>core/categories)',
    127             '/wp/v2/block-renderer/(?P<name>core/latest-comments)',
    128             '/wp/v2/block-renderer/(?P<name>core/latest-posts)',
    129             '/wp/v2/block-renderer/(?P<name>core/rss)',
    130             '/wp/v2/block-renderer/(?P<name>core/search)',
    131             '/wp/v2/block-renderer/(?P<name>core/shortcode)',
    132             '/wp/v2/block-renderer/(?P<name>core/social-link)',
    133             '/wp/v2/block-renderer/(?P<name>core/tag-cloud)',
     123            '/wp/v2/block-renderer/(?P<name>[a-z0-9-]+/[a-z0-9-]+)',
    134124            '/wp/v2/settings',
    135125            '/wp/v2/themes',
Note: See TracChangeset for help on using the changeset viewer.