Make WordPress Core


Ignore:
Timestamp:
12/05/2024 11:17:36 AM (12 months ago)
Author:
cbravobernal
Message:

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.

Location:
branches/6.7
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/6.7

  • branches/6.7/src/wp-includes/blocks.php

    r59166 r59487  
    12181218    // Merge the existing post object with the updated post object to pass to the block hooks algorithm for context.
    12191219    $context          = (object) array_merge( (array) $existing_post, (array) $post );
     1220    $context          = new WP_Post( $context ); // Convert to WP_Post object.
    12201221    $serialized_block = apply_block_hooks_to_content( $markup, $context, 'set_ignored_hooked_blocks_metadata' );
    12211222    $root_block       = parse_blocks( $serialized_block )[0];
Note: See TracChangeset for help on using the changeset viewer.