Skip to content

Custom Block Pattern

Loïc Antignac edited this page Sep 5, 2022 · 1 revision

Once the the plugin is created, the declaration(s) can be added:

<?php
/**
 * Plugin Name:       Example Custom Block Pattern
 * Author:            My Name
 * Text Domain:       wax-custom-content
 * Domain Path:       /languages
 */
defined( 'ABSPATH' ) || exit;

// If you already have an autoload (for example if you are on Bedrock) you can remove these 3 lines, otherwise leave them.
if ( is_readable( __DIR__ . '/vendor/autoload.php' ) ) {
	require __DIR__ . '/vendor/autoload.php';
}

use Webaxones\Core\Entities\Entities;

Webaxones\Core\Library::init( 'webaxones-content' );

/**
 * Add custom block pattern: MyPatterns
 */
$declarations[] = [
	'entity'   => 'Webaxones\Core\Editor\Categories\BlockCategory',
	'labels'   => [
		'title' => _x( 'Custom category', 'Custom block category name', 'webaxones-content' ),
	],
	'settings' => [
		'slug' => 'webaxones_custom_category',
	],
];

Entities::process( $declarations );

Settings

As for all entities, settings starts with the slug key which identifies the entity and must be unique.

Clone this wiki locally