Skip to content

Add Posts and Replies block using query_loop_block_query_vars#3036

Open
pfefferle wants to merge 8 commits intotrunkfrom
add/posts-and-replies-query-block
Open

Add Posts and Replies block using query_loop_block_query_vars#3036
pfefferle wants to merge 8 commits intotrunkfrom
add/posts-and-replies-query-block

Conversation

@pfefferle
Copy link
Member

@pfefferle pfefferle commented Mar 14, 2026

Related: #1213

Alternative to #3035 — uses a different architecture.

Proposed changes:

  • Add a lightweight activitypub/posts-and-replies block that renders a tab bar on any page (hidden from ActivityPub requests and feeds).
  • Instead of running custom queries, it hooks into the existing core/query block via the query_loop_block_query_vars filter.
  • The "Posts" tab (default) adds a posts_where clause to exclude posts containing the activitypub/reply block. The "Posts & Replies" tab shows all posts unfiltered.
  • Tab state is managed via a URL parameter (?filter=posts-and-replies), so pagination and Query Loop work naturally.
  • Users keep full control over the post template layout in the Site Editor since core/query is preserved as-is.

Comparison with #3035

#3035 (self-contained) This PR (query filter)
Query Custom WP_Query in render.php Hooks into core/query via query_loop_block_query_vars
Layout control Fixed (title + date + excerpt) Full Site Editor customization
Tab switching Instant (Interactivity API, pre-rendered) Page reload (URL parameter)
Pagination Shared across tabs Native, per-tab

Other information:

  • Have you written new tests for your changes, if applicable?

Testing instructions:

  • Start wp-env with npm run env-start.
  • Go to the Site Editor → Templates → "Author Archive (Fediverse)".
  • Verify the Posts and Replies block appears above the Query Loop block.
  • Visit an author archive page (e.g., /author/admin/).
  • Verify two tabs render: "Posts" (active by default) and "Posts & Replies".
  • Create a post that starts with the activitypub/reply block (Federated Reply).
  • On the "Posts" tab, verify the reply post is excluded.
  • Click "Posts & Replies" tab — page reloads with ?filter=posts-and-replies and the reply post appears.
  • The block can also be placed on other archive pages (category, tag, date, home) — not limited to author archives.
  • Verify pagination works correctly on both tabs.
  • Customize the Query Loop post template in the Site Editor (e.g., add featured image) — verify customizations appear on the frontend.

Changelog entry

  • Automatically create a changelog entry from the details below.
Changelog Entry Details

Significance

  • Patch
  • Minor
  • Major

Type

  • Added - for new features
  • Changed - for changes in existing functionality
  • Deprecated - for soon-to-be removed features
  • Removed - for now removed features
  • Fixed - for any bug fixes
  • Security - in case of vulnerabilities

Message

Add a "Posts and Replies" tab bar that filters between posts and replies, similar to Mastodon's profile view.

Alternative approach to #1213: instead of running custom queries, this
block renders a tab bar that controls a sibling core/query block via
the `query_loop_block_query_vars` filter.

The "Posts" tab (default) filters out posts containing the
`activitypub/reply` block. The "Posts & Replies" tab shows all posts.
Tab state is managed via a URL parameter (`?ap_tab=`), so pagination
and the Query Loop block work naturally without custom query logic.

This preserves full core/query customization in the Site Editor.

Related: #1213
@pfefferle pfefferle added the Enhancement New feature or request label Mar 14, 2026
Copilot AI review requested due to automatic review settings March 14, 2026 11:40
@pfefferle pfefferle self-assigned this Mar 14, 2026
@pfefferle pfefferle requested a review from a team March 14, 2026 11:40
@github-actions github-actions bot added the [Focus] Editor Changes to the ActivityPub experience in the block editor label Mar 14, 2026
- Replace ARIA role="tab" with nav + aria-current="page" since tabs
  are navigation links (page reloads), not JS-controlled panels.
- Reset pagination when switching tabs to avoid out-of-range pages.
- Use focus-visible instead of focus for cleaner keyboard indication.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new “Posts and Replies” block intended for author archive templates that provides a tab UI and filters the adjacent Query Loop via query_loop_block_query_vars, avoiding a custom WP_Query so users retain full Site Editor control over layout.

Changes:

  • Introduces activitypub/posts-and-replies block (editor placeholder + server-rendered tab bar + styles).
  • Hooks query_loop_block_query_vars to conditionally exclude “reply” posts by adding a posts_where clause.
  • Updates the plugin’s Fediverse author archive template to include the new block above the Query Loop.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/posts-and-replies/block.json Defines new dynamic block metadata.
src/posts-and-replies/index.js Registers the block (dynamic render, editor-only UI).
src/posts-and-replies/edit.js Editor placeholder/instructions for template placement.
src/posts-and-replies/render.php Server-rendered tab bar driven by ?ap_tab=....
src/posts-and-replies/style.scss Frontend styles for the tab bar.
includes/class-blocks.php Registers the block/template and adds Query Loop filtering + SQL where clause.
build/posts-and-replies/block.json Generated build artifact for block metadata.
build/posts-and-replies/index.js Generated build artifact for editor script bundle.
build/posts-and-replies/index.asset.php Generated build artifact for script dependencies/version.
build/posts-and-replies/render.php Generated build artifact for server render.
build/posts-and-replies/style-index.css Generated build artifact for styles.
build/posts-and-replies/style-index-rtl.css Generated build artifact for RTL styles.

You can also share your feedback on Copilot code review. Take the survey.

matticbot and others added 4 commits March 14, 2026 15:51
query_loop_block_query_vars never fires when the Query Loop uses
inherit:true — it clones the global WP_Query directly, skipping
build_query_vars_from_query_block() entirely. Switch to
pre_get_posts on the main query so the reply exclusion filter
applies to inherited queries on author archives.
@pfefferle pfefferle requested a review from jeherve March 17, 2026 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement New feature or request [Focus] Editor Changes to the ActivityPub experience in the block editor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants