Skip to content

Abilities API: Insert hooked blocks into the raw content of core/content-query. - #16287

Open
jorgefilipecosta wants to merge 2 commits into
WordPress:trunkfrom
jorgefilipecosta:fix/content-query-block-hooks
Open

jorgefilipecosta wants to merge 2 commits into
WordPress:trunkfrom
jorgefilipecosta:fix/content-query-block-hooks

Conversation

@jorgefilipecosta

@jorgefilipecosta jorgefilipecosta commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Follow up to #16028 (comment)

What

  • content.rendered of core/content-query includes the blocks hooked through Block Hooks, but content.raw was the stored markup, so a client editing the raw content could not remove a hooked block, and adding it by hand rendered it twice.
  • content.raw now includes the hooked blocks, and each anchor block lists them in metadata.ignoredHookedBlocks.
  • Blocks hooked as the first or last child of the post content have no anchor block in the content; their ignored list stays in the _wp_ignored_hooked_blocks post meta and is not returned.
  • content.rendered is unchanged and renders each hooked block once.

How

  • class-wp-abilities-content.php: new get_raw_content() runs the raw content through apply_block_hooks_to_content_from_post_object() with insert_hooked_blocks_and_set_ignored_hooked_blocks_metadata; empty content is returned as is.
  • wpRegisterCoreContentAbility.php: tests for each hooked position, content without hooks (block and classic), and posts that already list the hooked block as ignored (anchor metadata and post meta).

The change and this description were drafted with AI assistance (Claude Code) and reviewed by me.

Testing

Verify unit tests are passing:

vendor/bin/phpunit tests/phpunit/tests/abilities-api/wpRegisterCoreContentAbility.php

Trac ticket: https://core.trac.wordpress.org/ticket/66847

…tent-query`.

The rendered content of a post includes the blocks hooked to its blocks through Block Hooks, but the raw content held only the stored markup. A client that edited the raw content could not remove a hooked block, and adding it by hand rendered it twice.

The raw content now includes the hooked blocks, and each anchor block lists them in its `metadata.ignoredHookedBlocks` attribute.
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props jorgefilipecosta.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant