BlockPatterns
in package
BlockPatterns Registration class.
Facilitates the batch registration of block patterns, making it easier for theme and plugin developers to add custom block patterns to the WordPress block editor. This class leverages the BlockPattern module for each pattern's registration, ensuring a consistent and straightforward process.
Tags
Table of Contents
Methods
- set() : void
- Registers multiple block patterns in bulk.
Methods
set()
Registers multiple block patterns in bulk.
public
static set([array<string|int, mixed> $block_patterns = [] ]) : void
This method streamlines the registration of custom block patterns by accepting an array of pattern definitions. Each definition specifies the pattern's properties and content, allowing for a quick and organized setup.
Example usage:
BlockPatterns::set([
[
'name' => 'custom-pattern',
'properties' => [
'title' => __('Custom Pattern', 'text-domain'),
'content' => '<!-- wp:paragraph --><p>Hello World</p><!-- /wp:paragraph -->',
'categories' => ['custom-category'],
'keywords' => ['example'],
],
],
...
]);
Parameters
- $block_patterns : array<string|int, mixed> = []
-
An array of block pattern definitions. Each definition is an associative array that includes 'name' and 'properties', where 'properties' is an array that can include 'title', 'content', 'categories', 'keywords', and other block pattern attributes.