AdvancedCustomFields / AdvancedCustomFields/acf

Registering Gutenberg block with $args instead of block.json

Open
#815 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
945
Forks
197
PR merge metrics
No merged PRs in 30d

Description

Issue

When running register_block_type with a PHP array of arguments instead of a path to block.json ( i.e. using the $args method, as described by the documentation), the ACF Gutenberg block is not visible on the frontend.

(This is an issue for ACF Pro)

Steps to reproduce

With a fresh WordPress install, no plugins activated except ACF Pro, and a blank theme, if functions.php contains the following:

<?php
add_action( 'init', 'register_blocks' );
function register_blocks() {
    register_block_type("acf/test", [
        "title" => "Test ACF block",
        "description" => "A custom block.",
        "category" => "layout",
        "icon" => "editor-alignleft",
        "acf" => [
            "mode" => "auto",
            "renderTemplate" => __DIR__ . "/render.php",
        ],
        "align" => "full"
    ]);
)

the block is not available in the Gutenberg editor.

However if functions.php is changed to

<?php
add_action( 'init', 'register_blocks' );
function register_blocks() {
    register_block_type( __DIR__ . '/block.json' );
}

and a block.json file is created like so:

{
    "name": "acf/test",
    "title": "Test ACF block",
    "description": "A custom block.",
    "category": "layout",
    "icon": "editor-alignleft",
    "acf": {
        "mode": "auto",
        "renderTemplate": "render.php"
    },
    "align": "full"
}

the block is registered and is visible in the Gutenberg editor. This shows that registering the block with the PHP $args method does not work.

Expected behaviour

Registering through register_block_type with the PHP $args method should cause ACF blocks to be usable in the Gutenberg editor, the same as if the block.json method was used.

I filed a support ticket and the response indicated that ACF is supposed to support the $args method so I believe this is a bug.

Versions used

  • Wordpress 6.2
  • Advanced custom fields pro 6.1.4

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the functions.php examples and the register_block_type entry point, comparing the PHP $args registration with the block.json path registration. Reproduce the setup on WordPress 6.2 with ACF Pro 6.1.4 and confirm that the block becomes available in the Gutenberg editor when the PHP-array method is fixed.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.