Make WordPress Core

Opened 8 weeks ago

Closed 7 weeks ago

#62639 closed defect (bug) (fixed)

Block Hooks: Wrongly typed context when updating wp_navigation post meta

Reported by: bernhard-reiter's profile Bernhard Reiter Owned by: bernhard-reiter's profile Bernhard Reiter
Milestone: 6.7.2 Priority: normal
Severity: normal Version: trunk
Component: General Keywords: has-patch fixed-major dev-reviewed
Focuses: Cc:

Description

update_ignored_hooked_blocks_postmeta passes a $context argument to apply_block_hooks_to_content that is used by the hooked_block_types, hooked_block, and hooked_block_{$hooked_block_type} filters, if any.

Those filters allow extenders to conditionally insert hooked blocks, based on criteria that might involve the $context argument. For example, a filter might check if ( $context instanceof WP_Post && 'wp_navigation' === $context->post_type ) to limit insertion of a hooked block to Navigation blocks only.

While other functions that also call apply_block_hooks_to_content pass a correctly typed $context, update_ignored_hooked_blocks_postmeta passes a stdObject rather than a WP_Post instance. As a result, a criterion like in the above filter example will fail -- thus not correctly setting ignoredHookedBlocks metadata for the wp_navigation post object in question.

Change History (7)

This ticket was mentioned in PR #7941 on WordPress/wordpress-develop by @Bernhard Reiter.


8 weeks ago
#1

  • Keywords has-patch added

Discovered while working on #7898. Details to follow.

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

#2 follow-up: @Bernhard Reiter
7 weeks ago

Noting that the bug is present in 6.7.x, but not in 6.6.x. It was caused by [58578].

#3 @Bernhard Reiter
7 weeks ago

  • Owner set to Bernhard Reiter
  • Resolution set to fixed
  • Status changed from new to closed

In 59482:

Block Hooks: Fix context in update_ignored_hooked_blocks_postmeta.

Ensure that the $context arg passed from update_ignored_hooked_blocks_postmeta to apply_block_hooks_to_content (and from there, to filters such as hooked_block_types and hooked_block) has the correct type (WP_Post).

Filters hooked to hooked_block_types etc can typically include checks that conditionally insert a hooked block depending on $context. Prior to this changeset, a check like if ( $context instanceof WP_Post ) would incorrectly fail, as $context would be a stdClass instance rather than a WP_Post. As a consequence, a hooked block inside of a Navigation post object that was modified by the user would not be marked as ignored by update_ignored_hooked_blocks_postmeta, and thus be erroneosly re-inserted by the Block Hooks algorithm.

Props bernhard-reiter.
Fixes #62639.

#5 in reply to: ↑ 2 @Bernhard Reiter
7 weeks ago

  • Keywords fixed-major dev-feedback added
  • Resolution fixed deleted
  • Status changed from closed to reopened

Replying to Bernhard Reiter:

Noting that the bug is present in 6.7.x, but not in 6.6.x. It was caused by [58578].

Reopening to solicit approval by another Core Committer for backporting to the 6.7 branch.

#6 @cbravobernal
7 weeks ago

  • Keywords dev-reviewed added; dev-feedback removed

Reviewed and work as expected. Backporting to 6.7 branch.

#7 @cbravobernal
7 weeks ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 59487:

Block Hooks: Fix context in update_ignored_hooked_blocks_postmeta.

Ensure that the $context arg passed from update_ignored_hooked_blocks_postmeta to apply_block_hooks_to_content (and from there, to filters such as hooked_block_types and hooked_block) has the correct type (WP_Post).

Filters hooked to hooked_block_types etc can typically include checks that conditionally insert a hooked block depending on $context. Prior to this changeset, a check like if ( $context instanceof WP_Post ) would incorrectly fail, as $context would be a stdClass instance rather han a WP_Post. As a consequence, a hooked block inside of a Navigation post object that was modified by the user would not be marked as ignored by update_ignored_hooked_blocks_postmeta, and thus be erroneosly re-inserted by the Block Hooks algorithm.

Reviewed by cbravobernal.
Merges [59482] to the 6.7 branch.

Props bernhard-reiter.
Fixes #62639.

Note: See TracTickets for help on using tickets.