Support

Account

Home Forums Gutenberg Does ACF 6 support the $args variant of register_block_type?

Unread

Does ACF 6 support the $args variant of register_block_type?

  • According to the documentation the WordPress function register_block_type supports a variant to blocks.json, where instead you supply two arguments: a string with the block name, and an $args array with the rest of the arguments. When registering an ACF Gutenberg block within a class I need to define the render callback as a method of the class. The $args way of registering a block seems ideal because I could then pass a class scoped render function.

    However, this doesn’t work. The block gets registered in the backend but doesn’t appear in the Gutenberg frontend.

    A simple example is:

    class Block {
    
        public function render() {
            echo "Block rendered!!";
        }
    
        public function register_block() {
            register_block_type( "my-blocks/text", [
                "name" => "my-blocks/text",
                "title" => "Text",
                "category" => "layout",
                "icon" => "editor-alignleft",
                "apiVersion" => 2,
                "acf" => [
                    "mode" => "preview",
                    "renderCallback" => [ $this, "render" ],
                ]
            ] );
        }
    
        public function  __construct() {
            add_action( 'init', [ $this, 'register_block' ] );
        }
    
    }

    Does ACF 6 only support registering blocks by using an actual block.json file?

    (currently using ACF Pro, v6.1.4)

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.