concept-image / wp-make-block
Acorn commands that scaffold concept-image/wp-blocks ACF blocks (view component, field group, Blade view, block.json, script module) and publish ready-made advanced blocks.
Requires
- php: >=8.4
- concept-image/php-file-editor: ^0.2
- concept-image/wp-blocks: ^3.0
- log1x/acf-composer: ^3.4
- roots/acorn: ^6.4
Requires (Dev)
- brain/monkey: ^2.6
- larastan/larastan: ^3.0
- laravel/pint: ^1.18
- orchestra/testbench: ^10.0|^11.0
- pestphp/pest: ^4.0|^5.0
- pestphp/pest-plugin-arch: ^4.0|^5.0
- php-stubs/acf-pro-stubs: ^6.0
- szepeviktor/phpstan-wordpress: ^2.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Scaffold ACF blocks for Acorn WordPress themes
Acorn commands for concept-image/wp-blocks themes (Bedrock +
Sage), part of the Concept Image stack:
make:block: one command generates a block's view component, ACF Composer field group, Tailwind Blade view,block.jsonand, optionally, a script module;advanced-block: publishes ready-made blocks: an Embla Carousel slider and a team grid.
Requirements
- PHP 8.3+
- Roots Acorn 6.1+
- ACF Pro 6.6+ (blocks use ACF Blocks V3:
"acf": {"blockVersion": 3}),log1x/acf-composer3.4+ concept-image/wp-blocks3+ (generated blocks extend itsAcfBlockComponent)concept-image/php-file-editor0.1 (installed with the package; editsconfig/blocks.php). Until it is on Packagist,composer.jsonloads it from a path repository (../php-file-editor): remove that repository once it is published.- The core components of
concept-image/wp-core-ui(required by wp-starter-theme) published in the theme: the generated views use<x-core.section>and<x-core.heading>(wp acorn core-ui:install; run it again beforemake:blockifcore-ui:cleanremoved them) - The generated views use wp-core-ui's components (
<x-core.image>,<x-core.wysiwyg>…) and wp-starter-theme's directives (@filled) and Tailwind theme.
Installation
In the theme, as a development dependency:
composer require --dev concept-image/wp-make-block
Creating a block
Run it in the theme, inside the project container:
wp acorn make:block FrontPage/FpHero
| Generated | Path |
|---|---|
View component, extends ConceptImage\WpBlocks\View\AcfBlockComponent | app/View/Components/Blocks/FrontPage/FpHero.php |
| ACF Composer field group | app/Fields/Blocks/FrontPage/FpHero.php |
| Blade view | resources/views/components/blocks/front-page/fp-hero.blade.php |
block.json | resources/blocks-json/front-page/fp-hero/block.json |
Script module (--script) | resources/scripts/src/modules/fp-hero.ts |
Options:
--script: also creates the script module;--no-register: doesn't touchconfig/blocks.php, prints the lines to add instead;--force: overwrites existing files. Without it, the command stops when the component exists, and skips any other file that exists (it says which ones);--fields=: ACF fields to add, as comma-separated snake_case slugs (see below). Without it, an interactive run asks for them one by one ("Champ ACF (vide pour terminer)", empty answer to finish);-nor an empty--fields=adds none.
make:block-acf FrontPage/FpHero creates the field group alone (with --force and --fields= too).
ACF fields from their slugs
wp acorn make:block FrontPage/FpHero --fields=title,subtitle,cover_image,is_featured,event_date,items,cta_link -n
Each slug becomes an acf-builder call appended to the field group's add* chain (before its ;), and is added to
the component's $fields (a repeater is listed, its sub-fields aren't):
$fpHero
->addText('title', [ /* the stub's field, kept */ ])
->addText('subtitle', [
'label' => 'Subtitle',
'required' => 0,
])
->addImage('cover_image', [
'label' => 'Cover image',
'required' => 0,
])
->addTrueFalse('is_featured', [ /* … */ ])
->addDatePicker('event_date', [ /* … */ ])
->addRepeater('items', [
'label' => 'Éléments',
'required' => 0,
])
//
->endRepeater()
->addLink('cta_link', [ /* … */ ]);
The method comes from an is_ / has_ prefix (true/false), then from the exact slug or its suffix after the last
_ (compound suffixes first: date_time, button_group, true_false, page_link); anything else is a text
field. The label is fixed for an exact name (title → 'Titre'), else the humanized slug (hero_title →
'Hero title').
Names (exact or *_name) | Method | Fixed label |
|---|---|---|
text / title | addText | 'Texte' / 'Titre' |
textarea | addTextarea | 'Texte long' |
desc / content | addWysiwyg | 'Description' / 'Contenu' |
email, mail | addEmail | 'Email' |
number, count | addNumber | 'Nombre' |
image / icon / avatar / thumbnail | addImage | 'Image' / 'Icône' / 'Avatar' / 'Image mise en avant' |
images, gallery | addGallery | 'Galerie d\'images' |
file | addFile | 'Fichier' |
oembed | addOembed | 'oEmbed' |
range | addRange | 'Range' |
select, checkbox, radio, button_group | addSelect, addCheckbox, addRadio, addButtonGroup | computed |
true_false, bool, boolean, is_*, has_* | addTrueFalse | computed |
date_time, datetime | addDateTimePicker | 'Date et heure' |
date / time | addDatePicker / addTimePicker | 'Date' / 'Heure' |
page_link | addPageLink | 'Lien vers la page' |
link / url | addLink / addUrl | 'Lien' / 'URL' |
items, repeater | addRepeater … ->endRepeater() | 'Éléments' |
A slug the field group already uses (the stub's title, sub-fields included) is skipped with a notice. An invalid
slug stops the command before anything is written. When a file can't be edited (an overridden stub without
Builder::make() and a single return $group->build();, or without $fields = [...]), the code is printed to add by
hand. The edits run after generation, so overridden stubs keep working.
The command registers the block in the theme's config/blocks.php. The section is the directory of the name
(FrontPage/FpHero → front-page):
'blocks_to_register' => [
'front-page' => ['fp-hero'], // the group is created when missing
],
'allowed_block_types' => [
'front-page' => [/* … */ 'acf/fp-hero'], // the context named after the section, else 'default'
],
Entries already there are left alone, and the comments and layout of the file are kept. When the config is cached
(wp acorn config:cache), the cache is cleared. With --no-register, or when the file or one of these arrays is
missing, the command prints the lines to add by hand instead.
With --script, load the module from resources/scripts/src/load-modules.ts:
if (document.querySelector('[data-fp-hero]')) {
(await import('./modules/fp-hero.ts')).default();
}
Naming
The name must be Directory/Block: wp-blocks resolves blocks_to_register['front-page']['fp-hero'] to the
class App\View\Components\Blocks\FrontPage\FpHero. Kebab-case (front-page/fp-hero) is accepted.
FrontPage/FpHero | |
|---|---|
| Block type | acf/fp-hero |
blocks_to_register key | front-page |
Component $viewName | front-page.fp-hero |
| Field group | fp_hero |
Component $prefix | fp_hero_ (field keys field_fp_hero_{field}) |
The generated block
- The component lists the view's fields in
$fields(titleto start with) and adds computed data ingetCustomDatas(). - The view is wrapped in
<x-core.section :anchor="$anchor">and prints its title with<x-core.heading>: the anchor is sanitized by wp-blocks and printed quoted, and spacing, container and title styles come from the core components (the theme's copies, published by wp-core-ui), so they are changed once for every block. Use<x-core.heading :level="3" size="lg">rather than heading classes in the view. - When you add fields, keep the views safe:
- WYSIWYG goes through
<x-core.wysiwyg>; - links are printed with
{{ sanitize_url($url) }}, which dropsjavascript:URLs, and skipped when it returns''; target="_blank"getsrel="noopener".
- WYSIWYG goes through
block.jsonenables anchors and uses a valid dashicon. Change itstitle,iconandkeywords.
Overriding the stubs
Copy a stub from vendor/concept-image/wp-make-block/src/Console/stubs to the theme's stubs/ folder and edit
it: block-view-component.stub, block-acf.stub, block-view.stub, block-json.stub, block-script.stub.
Keep the placeholders:
- component:
{{ namespace }},{{ class }},{{ view }},{{ prefix }} - field group:
{{ field }},{{ builder }},{{ block }} - view and script:
{{ name }},{{ slug }} block.json:{{ name }}
To make every block extend a project class (wp-blocks' optional wp-blocks-component), override
block-view-component.stub.
Advanced blocks
wp acorn advanced-block # choose
wp acorn advanced-block slider
wp acorn advanced-block team
The command publishes the block's files into the theme's app/ and resources/. It keeps files that already
exist unless you pass --force, and then registers the block in config/blocks.php like make:block
(--no-register to print the lines instead).
| Block | Type | Contents |
|---|---|---|
slider | acf/base-slider | Title and slides (image, title, optional link). Embla Carousel (loop, drag free) with prev/next buttons, hidden when every slide fits. Tailwind only, no CSS to import. |
team | acf/base-team | Title and members (image, name, job, LinkedIn link, e-mail obfuscated with antispambot()). |
The slider needs embla-carousel. The command offers to run npm install embla-carousel in the theme. Use
--no-install, or run it without interaction (-n), to skip that; it then prints the command to run. Then add
to resources/scripts/src/load-modules.ts:
if (document.querySelector('[data-slider]')) {
(await import('./modules/slider.ts')).default();
}
Published files belong to the project: package updates don't change them.
Claude Code
Bedrock projects have no Laravel Boost, so the package publishes its AI guidance straight into the Bedrock root,
where Claude Code loads it on its own. An agent then creates blocks with make:block ("add a hero block to the
front page") and knows the naming rules without reading the package:
.claude/skills/wp-make-block/: thewp-make-blockskill (commands and options, generated files, registration, naming, stub overrides, advanced blocks, pitfalls);.claude/rules/wp-make-block/: rules loaded by path (wp-make-block.mdalways;stubs.mdfor the theme'sstubs/).
wp-starter-theme's wp acorn starter:ai publishes them with the other packages' guidance. On their own, or after a
package update:
wp acorn vendor:publish --tag=wp-make-block-ai --force # skill and rules
wp acorn vendor:publish --tag=wp-make-block-skill --force # skill only (wp-make-block-rules: rules only)
Development
composer ci # Pint, Larastan (max on src/, level 5 on advanced/), Pest
Without dom, xml and mbstring on the host:
docker run --rm -u "$(id -u):$(id -g)" -v "$PWD/..":/work -w /work/wp-make composer:2 composer ci (the parent is
mounted for the ../php-file-editor path repository).
Changelog
Please refer to CHANGELOG for more information, including the upgrade from 2.x.
Contributing
Please refer to CONTRIBUTING for more information.
License
Please refer to LICENSE for more information.
Credits
- Banner icon: Toys icons created by Magnific - Flaticon