Search by

concept-image / wp-blocks

concept-image

ACF blocks for Acorn WordPress themes: registration from config, block editor templates, allowed block types and locking, and publishable base blocks (Tailwind).

Package info

gitlab.com/concept-image-public/wp-blocks

Issues

pkg:composer/concept-image/wp-blocks

Statistics

Installs: 2 638

Dependents: 3

Suggesters: 0

Stars: 0

3.3.3 2026-12-01 09:21 UTC

This package is auto-updated.

Last update: 2026-12-01 08:21:35 UTC


README

WP Blocks

ACF blocks and editor rules for Acorn WordPress themes

ACF blocks for Acorn WordPress themes (Bedrock + Sage), part of the Concept Image stack and required by concept-image/wp-starter-theme:

  • registration of ACF blocks from config/blocks.php (a block.json plus a Blade view component each);
  • block editor rules per front page, page template or post type: block template, allowed block types, who can lock or unlock blocks;
  • publishable base blocks (hero, text, text and image, image, video, accordion, three columns, form) and a front page hero: ACF Composer field groups, view components, Tailwind 4 views and block.json files, built on the shared core components of concept-image/wp-core-ui (<x-core.section>, <x-core.container>, <x-core.heading>).

Requirements

  • PHP 8.3+
  • Roots Acorn 6.1+
  • ACF Pro 6.6+ (blocks use ACF Blocks V3: "acf": {"blockVersion": 3}), log1x/acf-composer 3.4+
  • The base block views use wp-starter-theme's components and directives (<x-image>, <x-breadcrumb>, <x-wysiwyg>, @filled) and its Tailwind theme (bg-primary, bg-secondary, container), and the core components of concept-image/wp-core-ui (<x-core.section>, <x-core.heading>), published into the theme by wp acorn core-ui:install. wp-starter-theme requires wp-core-ui.

Installation

wp-starter-theme installs it. Otherwise:

composer require concept-image/wp-blocks
wp acorn vendor:publish --tag=wp-blocks-config    # config/blocks.php
wp acorn vendor:publish --tag=wp-blocks-base      # base blocks: field groups, components, views, block.json
wp acorn core-ui:install                          # core components the base views use (concept-image/wp-core-ui)
wp acorn vendor:publish --tag=wp-blocks-component # optional: project-wide base class (see "Block components")
wp acorn vendor:publish --tag=wp-blocks-ai --force      # optional: Claude Code skill and rules at the Bedrock root

Published files belong to the project; publishing again only adds missing files, unless you pass --force.

How it works

On init, each block of blocks_to_register is registered with register_block_type(). That needs two things:

  • resources/blocks-json/{dir}/{block}/block.json (an ACF block: "acf": {…});
  • the view component App\View\Components\Blocks\{Dir}\{Block} (PascalCase: front-page/fp-hero → Blocks\FrontPage\FpHero).

ACF renders the block. It sets up the block's fields so get_field() reads them, then calls the component, which echoes its view. The component is resolved through the container.

Block components

Every block component implements ConceptImage\WpBlocks\Contracts\BlockComponent (render(): View); other classes are refused with a _doing_it_wrong() notice. Blocks get it by extending the package's abstract ConceptImage\WpBlocks\View\AcfBlockComponent, which implements the interface and holds the shared logic: fields, anchor and rendering, updated with composer.

use ConceptImage\WpBlocks\View\AcfBlockComponent;

class FpHero extends AcfBlockComponent
{
    protected string $viewName = 'front-page.fp-hero';      // resources/views/components/blocks/front-page/fp-hero.blade.php
    protected string $prefix = 'fp_hero_';                  // ACF Composer field keys: field_fp_hero_{name}
    protected array $fields = ['title', 'content', 'image'];  // each one becomes a view variable (empty values: null)

    protected function getCustomDatas(): array              // more view variables
    {
        return ['links' => $this->links()];
    }
}

The view also receives $anchor: the block's HTML anchor, sanitized and escaped. Always print it quoted: @if ($anchor) id="{{ $anchor }}" @endif. The base views do this through <x-core.section :anchor="$anchor">.

Project-wide customization (rarely needed). When every block must change the same way, publish an intermediate class and make the project's blocks extend it instead of the package class:

wp acorn vendor:publish --tag=wp-blocks-component   # app/View/Components/ACFBlockComponent.php
namespace App\View\Components;

use ConceptImage\WpBlocks\View\AcfBlockComponent as BaseAcfBlockComponent;

abstract class ACFBlockComponent extends BaseAcfBlockComponent
{
    // Example: read the anchor from an ACF field
    protected function getAnchor(): array
    {
        return ['anchor' => $this->sanitizeAnchor(get_field('anchor')['anchor_id'] ?? null)];
    }
}

The package's protected methods are getAnchor(), sanitizeAnchor(), getFields(), getField(), getCustomDatas() and getViewName().

Migrating from 2.x

wp acorn blocks:migrate --dry-run   # what would change
wp acorn blocks:migrate             # do it (commit first)

The command:

  • app/View/Components/ACFBlockComponent.php, unchanged 2.x copy: deleted, and the block components extending it now extend ConceptImage\WpBlocks\View\AcfBlockComponent directly.
  • Customized copy: rewritten as the intermediate class described above. It extends the package class and keeps only the methods the project changed or added (compared with 2.x, formatting ignored), and its blocks keep extending it. The 2.x anchor expression is rewritten to $this->sanitizeAnchor(…).
  • Block views: @if ($anchor) {{ $anchor }} @endif becomes @if ($anchor) id="{{ $anchor }}" @endif.
  • Review list: other $anchor uses, raw {!! $… !!} output in block views (WYSIWYG fields need <x-wysiwyg> / wp_kses_post(); oEmbed HTML is fine), and a customized render().
  • Notes: the new optional config keys, leftover 2.x SCSS, and a direct concept-image/wp-blocks requirement.

--path= targets another theme directory (default: the active theme).

Configuration (config/blocks.php)

KeyDefaultDescription
blocks_json_pathnullFolder of the block.json folders. null means the theme's resources/blocks-json.
blocks_to_registerbase blocks, front-page-hero['dir' => ['block-name', …]]
allowed_block_typesdefault: base blocks, front-page: acf/front-page-hero + default minus acf/base-heroBlock names per context: default, front-page, a page template (template-landing) or a post type. Missing contexts fall back to default.
templatedefault: acf/base-hero, front-page: acf/front-page-heroBlocks inserted in a new post, per context
block_default_configlocked (move, remove)Attributes of the template blocks
core_blocksnullAllow core/* blocks with the theme blocks. null means the opposite of wp-starter-theme's theme.disable.core_blocks.
exclude_core_blocks[]Core blocks never allowed
authorize_role_to_edit_front_page['administrator']Other roles get no blocks on the front page
lock_capabilitymanage_optionsCapability needed to lock or unlock blocks

How a context is chosen: the front page first, then the page template (if it is configured), then the post type (if it is configured), and otherwise default.

merge:<context> in a list adds another context's blocks, and |except: removes some of them:

'allowed_block_types' => [
    'default' => ['acf/base-hero', 'acf/base-text', 'acf/base-form'],
    'news' => ['acf/news-hero', 'merge:default|except:acf/base-hero,acf/base-form'],
],

Core components

The base blocks are built on three class-based Blade components from concept-image/wp-core-ui (required by wp-starter-theme, not by this package): wp acorn core-ui:install publishes them into the theme (app/View/Components/Core, resources/views/components/core), where the project owns them. They hold the shared Tailwind classes, so a spacing, width or title change is made once for every block. Each class keeps its classes in a protected property: edit it in the theme, the classes you pass on the tag are added after. Their full documentation is in the wp-core-ui README and its wp-core-ui Claude Code skill; a summary:

ComponentPropsClasses
<x-core.section>anchor, background (default, primary, secondary)$base (padding), $backgrounds; wraps its content in <x-core.container>
<x-core.container>size (default, form, large, screen: the --container-max-width-* tokens)$base (container), $sizes
<x-core.heading>level (1 to 4: the <hN> tag, default 2), size (xl, lg, base, sm; default: the level's size)$base, $sizes, $levels (default size of each level)
<x-core.section :anchor="$anchor" :background="$background_color">
    <x-core.heading :level="3" size="lg">{{ $title }}</x-core.heading>  {{-- an h3 that looks like an h2 --}}
</x-core.section>

A class you pass that conflicts with a component class (text-xl against the size's text-fluid-h2) isn't sure to win: use size, or Tailwind's important modifier (!text-xl). For a different style on the front page only, use a front: variant in the component's classes ('lg' => 'text-fluid-h2 front:text-fluid-h1 …'), declared in the theme's CSS:

@custom-variant front (&:where(.home *)); /* WordPress adds .home to <body> on the front page */

Adding a block

wp acorn make:block FrontPage/FpHero   # concept-image/wp-make-block: field group, component, view, block.json

The command adds 'front-page' => ['fp-hero'] to blocks_to_register, and acf/fp-hero to the front-page context of allowed_block_types (default when there is no context named after the directory). Add it to template yourself if new posts should start with it.

Security

The base views follow these rules. Apply them to your own blocks:

  • Anchors are quoted (id="{{ $anchor }}"). An unquoted anchor lets a contributor inject attributes (stored XSS).
  • WYSIWYG content goes through <x-wysiwyg>, which applies wp_kses_post(). get_field() returns unescaped HTML.
  • Link URLs go through sanitize_url(), which drops javascript: URLs, then Blade's {{ }} (not esc_url(): its &#038; would be encoded twice). target="_blank" gets rel="noopener".
  • Text uses {{ }}. The oEmbed HTML of the video block is WordPress' own, for its allow-listed providers.

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 knows how blocks are registered, configured and written ("add a block to the news post type", "why is the inserter empty on the front page") without reading the package:

  • .claude/skills/wp-blocks/: the wp-blocks skill (where block files live, config/blocks.php, block components, safe views, common tasks, 2.x migration);
  • .claude/rules/wp-blocks/: rules loaded by path (wp-blocks.md always; the others for the theme's config/blocks.php, block views, and block classes, field groups and block.json files).

wp-starter-theme's wp acorn starter:ai publishes them with the other packages' files. Otherwise, and after a package update:

wp acorn vendor:publish --tag=wp-blocks-ai --force      # skill and rules
wp acorn vendor:publish --tag=wp-blocks-skill --force   # skill only (wp-blocks-rules: rules only)

Development

composer ci   # Pint, Larastan (level max on src/, level 5 on the published app/ stubs), Pest (Testbench + Brain Monkey)

Without PHP's dom/xml/mbstring extensions on the host: docker run --rm -u "$(id -u):$(id -g)" -v "$PWD":/app -w /app composer:2 composer ci.

The published stubs (app/) are autoloaded in tests (App\ → app/) and follow the theme's Pint preset.

Changelog

Please refer to CHANGELOG for more information.

License

Please refer to LICENSE for more information.

Credits