AdvancedCustomFields / AdvancedCustomFields/acf

When creating an acf block, I cannot see the category (useful for block filters)

Open
#596 2 comments 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

Registering the example block in the documentation:

add_action('acf/init', function() {
    if( function_exists('acf_register_block_type') ) {
        // Register a testimonial block.
        acf_register_block_type(array(
            'name'              => 'testimonial',
            'title'             => __('Testimonial'),
            'description'       => __('A custom testimonial block.'),
            'render_template'   => 'template-parts/blocks/testimonial/testimonial.php',
            'category'          => 'formatting',
        ));
    }
});

And then filtering the allowed post types, the category appears as NULL instead of formatting:

add_filter( 'allowed_block_types_all', function ($allowed_blocks) {
    // Get widget blocks and registered by plugins blocks
    $registered_blocks = \WP_Block_Type_Registry::get_instance()->get_all_registered();
    // ⬇ Uncomment to see the category of each block
    echo '<pre>';
    var_dump($registered_blocks);
    echo '</pre>';
    wp_die();
});
["acf/testimonial"]=>
  object(WP_Block_Type)#17360 (21) {
    ["api_version"]=>
    int(1)
    ["name"]=>
    string(15) "acf/testimonial"
    ["title"]=>
    string(0) ""
    ["category"]=>
    NULL
    ["parent"]=>
    NULL
    ["icon"]=>
    NULL
    ["description"]=>
    string(0) ""
    ["keywords"]=>
    array(0) {
    }
    ["textdomain"]=>
    NULL
    ["styles"]=>
    array(0) {
    }
    ["variations"]=>
    array(0) {
    }
    ["supports"]=>
    NULL
    ["example"]=>
    NULL
    ["render_callback"]=>
    string(25) "acf_render_block_callback"
    ["attributes"]=>
    array(6) {
      ["id"]=>
      array(2) {
        ["type"]=>
        string(6) "string"
        ["default"]=>
        string(0) ""
      }
      ["name"]=>
      array(2) {
        ["type"]=>
        string(6) "string"
        ["default"]=>
        string(0) ""
      }
      ["data"]=>
      array(2) {
        ["type"]=>
        string(6) "object"
        ["default"]=>
        array(0) {
        }
      }
      ["align"]=>
      array(2) {
        ["type"]=>
        string(6) "string"
        ["default"]=>
        string(0) ""
      }
      ["mode"]=>
      array(2) {
        ["type"]=>
        string(6) "string"
        ["default"]=>
        string(0) ""
      }
      ["className"]=>
      array(1) {
        ["type"]=>
        string(6) "string"
      }
    }
    ["uses_context"]=>
    array(0) {
    }
    ["provides_context"]=>
    NULL
    ["editor_script"]=>
    NULL
    ["script"]=>
    NULL
    ["editor_style"]=>
    NULL
    ["style"]=>
    NULL
  }

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

Reproduce the issue with the documented PHP registration and inspect the values returned by WP_Block_Type_Registry through allowed_block_types_all. Trace how acf_register_block_type passes block metadata into the registered WP_Block_Type; done means the category is available as formatting rather than NULL. The payload names no source file or test, so locate the registration implementation and related tests first.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, wordpress
Domain
backend, content
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.