[wp-trac] [WordPress Trac] #59574: Blocks: No toggle shown for hooked blocks added via filter
WordPress Trac
noreply at wordpress.org
Thu May 23 18:33:28 UTC 2024
#59574: Blocks: No toggle shown for hooked blocks added via filter
--------------------------------------+------------------------------
Reporter: Bernhard Reiter | Owner: Bernhard Reiter
Type: defect (bug) | Status: closed
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: normal | Resolution: fixed
Keywords: has-patch has-unit-tests | Focuses:
--------------------------------------+------------------------------
Changes (by Bernhard Reiter):
* owner: (none) => Bernhard Reiter
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"58186" 58186]:
{{{
#!CommitTicketReference repository="" revision="58186"
Block Hooks API: Insert metadata at the same time as hooked blocks.
The Block Hooks UI relies on the `ignoredHookedBlocks` metadata when
determining whether to show the toggle in the Site Editor. The problem is
that for uncustomized templates we don't add this metadata.
Currently the visitor functions have a default callback of
`insert_hooked_blocks` and we only add the metadata when we're writing to
the database via an available filter in the template controller.
This changeset creates a new callback which both inserts the hooked blocks
and adds the `ignoredHookedBlocks` metadata to the anchor block, and uses
this new callback explicitly in the visitor functions that are run upon
reading from the database.
We continue to set the `ignoredHookedBlocks` metadata when writing to the
database, i.e. this operation happens twice. Although not ideal, this is
necessary to cover the following scenarios:
* When the user adds an anchor block within the editor, we still need to
add the `ignoredHookedBlocks` meta to it to prevent hooked blocks hooking
on to it unexpectedly on the frontend. This is required to keep parity
between the frontend and editor.
* When a user writes template data to the database directly through the
API (instead of the editor), we need to again ensure we're not inserting
hooked blocks unexpectedly.
It is worth noting that with this change, the first hooked block to insert
relative to its anchor block will be accepted. Any additional blocks of
the same type (e.g. a second `core/loginout` block) trying to hook onto
the same anchor block will be ignored, irrespective of the position.
Props tomjcafferkey, bernhard-reiter, gziolo.
Fixes #59574.
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/59574#comment:17>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list