Repository navigation
Conversation
GaryJones
left a comment
There was a problem hiding this comment.
Thanks for this, Faisal. A Query Loop variation is the right shape: themes keep control of the markup, and splitting out get_query_args() means the block and z_get_zone_query() follow the same rules. I checked the editor side against WordPress 6.4, our minimum, and its Post Template block already passes extra query keys such as zoninatorZone to the REST request, so the preview works there as well as on trunk.
A few changes before this can go in. The inline comments have the details and suggestions.
1. Version. 0.12.0 shipped without this, and the next release is 1.0.0. The new @since 0.12.0 tags and the "Since 0.12.0" in the docs need to say 1.0.0.
2. Always hook the preview filter. The variation always previews through /wp/v2/posts, but the filter is only added for post types that support zones. Hook rest_post_query unconditionally instead.
3. Tests. The front end is well covered, but the REST path needs more, because the new parameter now works on every /wp/v2/posts request, including logged-out ones. Please add:
- A request without
zoninatorZoneis left alone. Request/wp/v2/postswith a post outside any zone and assert the normal date order comes back. This is the REST twin oftest_other_query_loops_are_left_alone(). zoninatorZone=0returns no posts. This matchestest_block_without_a_zone_shows_no_posts()on the front end.- A logged-out request only sees published posts.
test_editor_preview_lists_zone_posts_in_zone_order()runs as an editor. Run a copy with no user and a private post in the zone, and assert only the published posts come back. That pins the boundary that matters for a public parameter. - The filter is always registered. Once it moves to
rest_post_query, asserthas_filter( 'rest_post_query', array( \Zoninator(), 'zone_block_rest_query' ) ), so a site that only enables zones for a custom post type still gets a filtered preview. - The second page. Render with a page size of 2 and
$_GET['query-1-page'] = 2, and assert only the third zone post shows. That proves the offset and paging survive the query swap.
4. Spinner and error accessibility. The spinner has no accessible name, and the error is a plain paragraph that nobody hears. There's a suggestion inline.
5. Docs.
docs/theme-developers.md: "Since 1.0.0", and the preview paragraph reworded for therest_post_querychange (suggestion inline).AGENTS.md: theclass-block.phpline mentionsrest_{post_type}_query; please change it torest_post_query.README.md: step 4 under the description still points people who don't want to write code at the widget only. One sentence there about the Zone Posts block would help block theme users find it.
- Mark the block's new code @SInCE 1.0.0 - Hook rest_post_query for the editor preview on every site - Announce the zone picker's loading and error states - Add REST, logged-out, filter and paging tests - Update the block docs, AGENTS.md and README.md Refs Automattic#233
|
Thanks for the review, Gary. All points are done in 01b6089. I also merged
Lint, PHPCS and the integration tests pass on single site and multisite (344 tests). |
01b6089 to
f68e4e8
Compare
|
Screenshots from a local test site (WordPress 7.3-alpha, Twenty Twenty-Five) running The zone on the Zones screen Front end, logged out The Zone Posts block lists the published posts in zone order and leaves out the draft. The normal Query Loop underneath lists the same site by date, for comparison. Editor, with the block selected The preview matches the front end, and the Zone panel shows the picker. Inserter |
|
Faisal, I've force-pushed to this branch, so your local copy will be out of date. To pick it up: What changed:
The integration tests pass locally on single site and multisite. |
Sites using block themes had no way to show a zone without code or the legacy widget. This adds a "Zone Posts" variation of the Query Loop block with a zone picker. The server swaps the block's query for the zone's query, so the front end and the editor preview list the zone's posts in zone order, with the same rules as z_get_zone_query(). Zones::get_query_args() is split out of get_query() so the block can reuse the same query args. The editor preview always reads /wp/v2/posts, so its filter is hooked on rest_post_query whichever post types support zones. Closes Automattic#217
f68e4e8 to
b916974
Compare
GaryJones
left a comment
There was a problem hiding this comment.
Thanks, Faisal. All the feedback is in, and CI is green on the rebased commit.




Summary
Sites with block themes had no way to show a zone without custom code or the legacy widget. This adds a "Zone Posts" variation of the Query Loop block with a zone picker in the block settings. The server swaps the block's query for the zone's query, so the front end and the editor preview both list the zone's posts in zone order, with the same rules as
z_get_zone_query().Fixes #217
Changes
src/class-zones.phpBefore:
After:
Why: The block needs the zone's query args, not a
WP_Query. Splitting them out keeps one source of truth for zone order, post status and post types.src/class-block.php(new)Why:
query_loop_block_query_varshandles the front end andrest_post_queryhandles the editor preview. The REST filter is hooked on every site, so the preview works even when zones only use a custom post type. Only Query Loops with azoninatorZonekey are touched. Only the paging args (per page, offset, page) are kept, so the zone order always wins. With no zone picked, the block shows no posts.js/zoninator-block.js(new)Registers the variation (
namespace: zoninator/zone-posts) and adds a "Zone" panel with a select that loads zones from/zoninator/v1/zones. The block only shows the Items per page, Offset and Max pages controls, since order and filters come from the zone. Loading and error states are announced to screen readers (VisuallyHiddenlabel,Notice). Plain JS onwindow.wp, so no build step is needed.Other
src/class-zoninator.php: wires the hooks and buildsBlock, like the other classes.docs/theme-developers.mdandAGENTS.md: document the block.tests/Integration/ZoninatorZoneBlockTest.php: covers zone order, drafts left out, page size, no zone, other Query Loops left alone, the editor preview REST request (with and without a zone, zone 0, logged out), the second page, the filter being registered, and the editor script.Testing
Test 1: Add the block
Result: the editor preview and the front end list the zone's published posts in zone order. The draft is not shown.
Test 2: Reorder the zone
Result: the block follows the new order.
Test 3: Normal Query Loop
Result: it works as before, with no Zone panel.
Unit and integration tests pass on single site and multisite. Also checked by hand on a WP 7.1, PHP 8.3 sandbox with Twenty Twenty-Five.
Known limit: the editor preview always reads
/wp/v2/posts. If a zone also holds pages or another post type, the preview only shows its posts, but the front end shows them all.Screenshots
New block, so there is no before state.