This documentation describes unreleased changes on the main branch.

#[Block]

Attribute on classes.

use Saij\WpAppFramework\Block\Block;

Declares a server-side rendered block. The class is a service with a public render() method returning the block's HTML; its parameters are matched by type: the block attribute class, string (the rendered inner blocks) and WP_Block, besides values of ancestors marked with #[Context].

Arguments

#[Block(string $name, string $title, BlockCategory|CustomBlockCategory $category, string $icon = '', string $description = '', array $keywords = [], array $usesContext = [], bool $excerptWrapper = false, ?array $parent = null, ?array $ancestor = null)]
ParameterTypeDefaultDescription
namestringrequiredBlock name without namespace, e.g. "hero"; registered in the namespace of the theme or plugin (extra.wp-app-framework.namespace), e.g. "sections/hero".
titlestringrequiredTitle of the block in the inserter and the block inspector.
categoryBlockCategory|CustomBlockCategoryrequiredA category of WordPress or a case of an enum of the theme or plugin that implements CustomBlockCategory.
iconstring''Name of a Dashicon, e.g. cover-image; '' for the default icon.
descriptionstring''Description shown in the inserter and the block inspector.
keywordslist<string>[]Search terms for the inserter.
usesContextlist<string>[]Context values of other blocks the block reads from WP_Block::$context, e.g. "postId"; values of blocks of the same theme or plugin are read with #[Context] parameters of render().
excerptWrapperboolfalseAdd the block to excerpt_allowed_wrapper_blocks: automatic excerpts include its allowed inner blocks, as for core/group. Requires render() to accept string $content.
parentlist<class-string|CoreBlock|string>|nullnullThe block can only be inserted directly into these blocks: block classes of the same theme or plugin, core blocks, other blocks by full name; null for anywhere.
ancestorlist<class-string|CoreBlock|string>|nullnullThe block can only be inserted somewhere inside these blocks; same values as $parent.