BlockHooks final class
Minn\Runtime\BlockHooks · public/minn/src/Minn/Runtime/BlockHooks.php · 219 lines
The Block Hooks API on the engine's own front end: a plugin asks for its block to be inserted next to an anchor block in a template part or a pattern (WooCommerce puts the mini-cart after the navigation in a header), and the markup the renderer reads carries those insertions.
The facade owns the traversal (wp-api/blocks.php); this is the seam the theme blocks call, and it stays inert until a plugin actually hooks something, so a site without such a plugin parses nothing extra.
Constants and properties
| private | static ?array $single |
Public
| static | withSingleInstances(array $blocks, Closure $serialize): string# | Content's blocks written out by $serialize under the single-instance rule (apply_block_hooks_to_content): a hooked type that does not support multiple goes in at the first anchor position that names it only, and nowhere when the content has one already, however deep (probe taxonomy-blocks-user-doubts).
| ||||||
| static | nextPosition(): void# | The traversal moves on to the next anchor position (each before, after, first_child and last_child the visitors ask). | ||||||
| static | hooked(): array# | The blocks hooked to each anchor, by position (get_hooked_blocks), as the registered block types' block_hooks name them. @return array<string, array<string, list<string>>> | ||||||
| static | active(): bool# | Whether block hooks are registered (the runtime's functions are there only once it is up). | ||||||
| static | insert(array $anchor, string $position, array $hooked, mixed $context): string# | The blocks hooked to an anchor at a position (insert_hooked_blocks), each as the filters leave it, serialized; a type a filter suppresses, or one the anchor lists as ignored, goes in nothing (probe post-block-hooks).
| ||||||
| static | markIgnored(array $anchor, string $position, array $hooked, mixed $context): string# | The anchor's ignoredHookedBlocks with the types hooked to it at a position added (set_ignored_hooked_blocks_metadata): those a filter leaves standing, the list keeping the keys it had (probe post-block-hooks). Nothing is inserted: the markup is empty.
| ||||||
| static | registeredPattern(string $slug): ?string# | A plugin-registered pattern's content, hooks already applied by the registry, for a slug the theme does not carry. Null when the runtime is not up or nothing registered that name. | ||||||
| static | forPattern(string $markup, string $slug, array $blockTypes, array $categories): string# | A theme pattern's markup with its hooked blocks inserted, with the pattern array as the context (blockTypes and categories are how a plugin recognises a header pattern).
| ||||||
| static | forPost(string $content, int $postId): string# | A post's blocks with the blocks hooked to them, as the reference reads a navigation's or a synced pattern's (apply_block_hooks_to_content_from_post_object): the hooked blocks the post says to leave out left out; as stored with no WordPress layer to ask. |
Internals 3
Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.
| private | filtered(array $anchor, string $position, array $hooked, mixed $context): array# | The types hooked_block_types names for an anchor at a position, each with the block hooked_block and hooked_block_{type} make of it (null when one suppresses it).
@return list<array{0: string, 1: mixed}> | ||||||
| private | admitted(string $type): bool# | Whether a hooked type may go in at this position: always, unless it is single-instance and already in the content or put in at another position. | ||||||
| private | names(array $blocks): array# | Every block name in parsed blocks, however deep.
@return array<string, true> |
Nothing matches.