Make WordPress Core

Opened 6 weeks ago

Closed 6 weeks ago

Last modified 6 weeks ago

#61495 closed enhancement (fixed)

Block Hooks: Refactor update_ignored_hooked_blocks_postmeta to use meta_input

Reported by: tomjcafferkey's profile tomjcafferkey Owned by: bernhard-reiter's profile Bernhard Reiter
Milestone: 6.7 Priority: normal
Severity: normal Version: 6.6
Component: General Keywords: has-patch has-unit-tests
Focuses: Cc:

Description

The function update_ignored_hooked_blocks_postmeta uses the core function update_post_meta() to write _wp_ignored_hooked_blocks data to the database during an operation that is preparing a post to be inserted.

Since we have access to the incoming changes that is being prepared we can remove this database operation in favour of writing the data to the post object provided under meta_input.

Doing this means two things:

  1. It allows us to store postmeta for new posts that are about to be created since they don't have an ID yet (which is information update_post_meta() needs).
  2. The core controller will take care of updating postmeta in a more predictable pattern.

Change History (4)

This ticket was mentioned in PR #6885 on WordPress/wordpress-develop by @tomjcafferkey.


6 weeks ago
#1

  • Keywords has-patch has-unit-tests added

This is a prerequisite to adding hooked blocks to template parts at positions first_child and last_child https://github.com/WordPress/wordpress-develop/pull/6867

It's necessary because unlike wp_navigation post, the wp_template_part posts won't have a database entry upon first save meaning that update_post_meta won't work. To circumvent this we are now setting meta information on the $post stdClass object via the meta_input field which will get saved as post meta when its created/updated in the database.

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

#2 @Bernhard Reiter
6 weeks ago

  • Milestone changed from Awaiting Review to 6.7

#3 @Bernhard Reiter
6 weeks ago

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

In 58578:

Block Hooks: Refactor controller filter to use meta_input.

Prior to this changeset, the function update_ignored_hooked_blocks_postmeta() used the core function update_post_meta() to write _wp_ignored_hooked_blocks data to the database during an operation that is preparing a post to be inserted.

Since we have access to the incoming changes that are being prepared we can remove this database operation in favour of writing the data to the post object provided under meta_input.

Doing this means two things:

  1. It allows us to store postmeta for new posts that are about to be created since they don't have an ID yet (which is information update_post_meta() needs).
  2. The core controller will take care of updating postmeta in a more predictable pattern.

Props tomjcafferkey, bernhard-reiter.
Fixes #61495.

Note: See TracTickets for help on using tickets.