Opened 8 days ago
Last modified 8 days ago
#65897 assigned enhancement
Surface community-contributed patterns from the Pattern Directory in the editor (opt-in)
| Reported by: | ugyensupport | Owned by: | ugyensupport |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Editor | Version: | |
| Severity: | normal | Keywords: | has-patch needs-testing has-unit-tests |
| Cc: | Focuses: |
Description (last modified by )
The block editor's Patterns inserter loads remote patterns from the WordPress.org Pattern Directory, but only two curated slices:
_load_remote_block_patterns()— thecorekeyword (id 11)_load_remote_featured_patterns()— theFeaturedcategory (id 26)
The much larger pool of community-contributed patterns — the ?curation=community view on wordpress.org/patterns (~90k patterns) — is never exposed in the editor. To use one today, a user has to leave the editor, browse the directory on wordpress.org, and copy/paste the pattern back: a broken flow for what is otherwise a first-class inserter feature.
The omission is deliberate — the community collection is large and unmoderated, so core curates what it surfaces. This enhancement preserves that default while giving themes, plugins, and site owners a supported, first-class way to opt in.
Approach
Add a third remote loader, _load_remote_community_patterns(), alongside the two existing ones, registering results under a new community block-pattern category.
Because loading the uncurated collection by default would regress both performance and the out-of-the-box quality bar, it is opt-in and disabled by default, behind a new filter:
<?php // Surface community patterns in the inserter. add_filter( 'load_remote_community_block_patterns', '__return_true' );
With the filter off (the default), behaviour is byte-for-byte unchanged and no extra directory request is made. The change is inert until explicitly enabled — the key point for review.
Why here
The three remote loaders are invoked lazily, once, from WP_REST_Block_Patterns_Controller::get_items() — the REST call the editor makes to populate the inserter. Adding the community loader in the same block gives it the exact same lifecycle, caching, and should_load_remote_block_patterns gate as the existing loaders. No new hook, no front-end cost, no change to the non-editor request path.
Changes
wp-includes/block-patterns.php
- Register a new
communitypattern category (label "Community"), next tofeatured. - Add
_load_remote_community_patterns(), mirroring_load_remote_featured_patterns(): honoursshould_load_remote_block_patterns, adds the opt-inload_remote_community_block_patternsfilter (defaultfalse), requests the general directory collection (nokeyword/category), and registers each result under thecommunitycategory with apattern-directory/communitysource and acommunity/name prefix.
wp-includes/rest-api/endpoints/class-wp-rest-block-patterns-controller.php
- Call
_load_remote_community_patterns()in the existing lazy-load block inget_items().
tests/phpunit/tests/blocks/loadRemoteCommunityPatterns.php (new)
- Covers: no directory request when the filter is off; registration under the
communitycategory with thepattern-directory/communitysource when opted in; and theshould_load_remote_block_patternsgate still winning when opted in. Uses a registry-swap fixture and apre_http_requestmock (mirroringrest-pattern-directory-controller.phptests), so it never hits the network. Passes locally —OK (3 tests, 6 assertions).
Testing
Default (filter off) — no behaviour change
- Add no filter.
- Open the editor and the Patterns inserter.
- Confirm there is no "Community" category and the inserter behaves exactly as on trunk (optionally, that no directory request is made for the community collection).
Opt-in (filter on) — community patterns appear
- Add the
load_remote_community_block_patterns→__return_truefilter shown above. - Reload the editor and open the Patterns inserter.
- A "Community" category appears, populated from the directory.
- Insert one; confirm it inserts as editable blocks (not rendered HTML) matching the directory pattern.
Remote-load gate still respected
- Keep the opt-in filter on and also add:
<?php add_filter( 'should_load_remote_block_patterns', '__return_false' );
- Reload the inserter. The "Community" category should be absent — the master remote-load gate wins, consistent with
coreandfeatured.
Open questions / notes
- Opt-in vs. UI toggle. This lands the plumbing as an opt-in filter. Whether the end goal is opt-in only, or a surfaced UI toggle, is a product call for the Editor component — the inserter UI itself lives in the Gutenberg repo, so a companion issue there may be warranted.
- Grouping. Results are grouped into the
communitycategory for a predictable inserter section; preserving each pattern's own directory categories instead is a reasonable refinement to discuss. - Batch size.
per_pageis capped at 24 to keep the first uncached inserter load responsive; pagination / lazy fetch is a natural follow-up. @sinceis currently7.2.0and should be adjusted to whatever version this lands in.
Attachments (2)
Change History (7)
This ticket was mentioned in PR #13103 on WordPress/wordpress-develop by @ugyensupport.
8 days ago
#1
@ugyensupport commented on PR #13103:
8 days ago
#3
Tested locally on a fresh WordPress install with this patch applied and the opt-in filter enabled:
add_filter( 'load_remote_community_block_patterns', '__return_true' );
Before/after of the block editor's Patterns inserter:
Before — stock behaviour: the category list goes *Call to action → Contact*, with no Community category.
After — with the filter enabled, a Community category appears (between *Call to action* and *Contact*) and is populated with patterns pulled live from the WordPress.org Pattern Directory.
With the filter off (the default), the category does not appear and no extra directory request is made — behaviour is unchanged. The bundled test Tests_Blocks_LoadRemoteCommunityPatterns passes: OK (3 tests, 6 assertions).
@ugyensupport commented on PR #13103:
8 days ago
#5
Cross-linking a follow-up for the browsing experience: the on-demand *search + load-more* over the full Pattern Directory (including the community collection) is proposed as a Gutenberg feature in WordPress/gutenberg#81771, since that UI is client-side (the inserter renders only registered patterns today).
This PR remains the minimal server-side opt-in — registering a community category. If the Gutenberg browsing UI in #81771 lands, this can be reduced to just the category registration, or superseded by it.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)


## What
Adds a third remote pattern loader,
_load_remote_community_patterns(), alongside the existing_load_remote_block_patterns()(core keyword) and_load_remote_featured_patterns()(featured category), registering results under a newcommunityblock-pattern category.Loading the uncurated community collection is opt-in and disabled by default, behind a new
load_remote_community_block_patternsfilter. With the filter off, behavior is unchanged and no extra directory request is made.Enable it with:
add_filter( 'load_remote_community_block_patterns', '__return_true' );## Why
The inserter only exposes the curated
core/featuredslices; the larger pool of community-contributed patterns is not reachable from the editor. This provides a supported, first-class opt-in without regressing the default out-of-the-box experience.## Testing
tests/phpunit/tests/blocks/loadRemoteCommunityPatterns.php(OK (3 tests, 6 assertions)), covering: no request when disabled, registration undercommunitywhen enabled, and theshould_load_remote_block_patternsgate still winning.---
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request.