Home>

I want the block editor to display only the blocks added using the advance custom field (ACF).

I've added a new block to the block editor using ACF.

add_action ('acf/init','my_acf_init');
function my_acf_init () {
    if (function_exists ('acf_register_block')) {
        acf_register_block (array (
            'name' =>'original_block',
            'title' =>"original block", // block name
            'description' =>"original block template", // block description
            'render_callback' =>'render_originalblock', // Callback
            'category' =>'formatting',
            'icon' =>'admin-comments',
            'keywords' =>array ('test'),
        ));
    }
}

It is displayed normally on the post page, but I decided to hide it because it is unnecessary except for the block added by ACF when adding the block.
I found out that I could set a whitelist with the allowed_block_types filter, so I tried to set a filter, but it didn't work.

An example that didn't work

add_filter ('allowed_block_types','custom_allowed_block_types');
function custom_allowed_block_types ($allowed_block_types) {
return $allowed_block_types;
  $allowed_block_types = array (
    // General block
    'core/paragraph', // paragraph
    'original_block',
  );
  return $allowed_block_types;
}


With the above settings, the paragraph was displayed, but the added original_block was not displayed.

What I tried

The value to put in allowed_block_types
original_block
formatting/original_block
core/original_block
I tried to do it, but it didn't work.
I checked the source of ACF

register_block_type ($block ['name'], array (
            'attributes' =>acf_get_block_type_default_attributes ($block),
            'render_callback' =>'acf_render_block_callback',
        ));
code


Since it was, it seems that the name specified by block is used for the registration itself.

Supplementary information (FW/tool version, etc.)

Wordpress 5.3.3
Advanced Custom Fields PRO 5.9.3

  • Answer # 1

    For the time being, in the block name_can not use
    You can use half-width alphanumeric lowercase letters---only

    WordPress register_block_type register processing
    '/ ^ [a-z0-9-] + \/[a-z0-9-] + $/'If it doesn't match, it will fail.
    If you are using WordPress register_block_type
    You should be doing something like giving a namespace or renaming it on the ACF side.

    I don't know how to actually do it because the source of ACF Pro version cannot be confirmed.