Title: New block type registration APIs to improve performance in WordPress 6.7
Author: Felix Arntz
Published: October 17, 2024

---

 [  ](https://profiles.wordpress.org/flixos90/) [Felix Arntz](https://profiles.wordpress.org/flixos90/)
5:22 pm _on_ October 17, 2024     
Tags: [6-7 ( 75 )](https://make.wordpress.org/core/tag/6-7/),
[dev-notes ( 650 )](https://make.wordpress.org/core/tag/dev-notes/), [dev-notes-6-7 ( 15 )](https://make.wordpress.org/core/tag/dev-notes-6-7/)

# New block type registration APIs to improve performance in WordPress 6.7

WordPress 6.7 introduces a new function `wp_register_block_metadata_collection()`
which allows plugins to improve the performance of registering their blockBlock 
Block is the abstract term used to describe units of markup that, composed together,
form the content or layout of a webpage using the WordPress editor. The idea combines
concepts of what in the past may have achieved with shortcodes, custom HTML, and
embed discovery into a single consistent API and user experience. types, especially
for plugins that register multiple block types.

## Expanding WordPress CoreCore Core is the set of software required to run WordPress. The Core Development Team builds WordPress. behavior to plugins

Since WordPress 6.1, WordPress Core has included a mechanism to improve performance
for loading all of the built-in block types: As part of the build process, the individual`
block.json` files are being parsed into a single `blocks-json.php` file that returns
all of their data in an array. **This notably enhances performance by avoiding many
costly filesystem and JSONJSON JSON, or JavaScript Object Notation, is a minimal,
readable format for structuring data. It is used primarily to transmit data between
a server and web application, as an alternative to XML. operations on every single
WordPress request.** See [#55005](https://core.trac.wordpress.org/ticket/55005) 
and [its dev note](https://make.wordpress.org/core/2022/10/07/improved-php-performance-for-core-blocks-registration/)
for context on the original change.

The way this mechanism was implemented only worked for WordPress Core itself though.
Plugins so far have not been able to achieve the same benefits. Especially for plugins
that include many block types themselves, this effectively meant a performance penalty.
This is going to change as part of WordPress 6.7.

## Registering block metadata collections

Plugins can now optionally register a PHPPHP The web scripting language in which
WordPress is primarily architected. WordPress requires PHP 7.4 or higher “manifest”
file, which includes all the metadata for their block types. For any block type 
that is being registered, WordPress Core will now check whether such a manifest 
file is present covering the block type, and if so, it will use the data from the
manifest file instead of reading and parsing the block type’s `block.json` file 
directly.

In order to use this new capabilitycapability A **capability** is permission to 
perform one or more types of task. Checking if a user has a capability is performed
by the `current_user_can` function. Each user of a WordPress site might have some
permissions but not others, depending on their role. For example, users who have
the Author role usually have permission to edit their own posts (the “edit_posts”
capability), but not permission to edit other users’ posts (the “edit_others_posts”
capability)., pluginPlugin A plugin is a piece of software containing a group of
functions that can be added to a WordPress website. They can extend functionality
or add new features to your WordPress websites. WordPress plugins are written in
the PHP programming language and integrate seamlessly with WordPress. These can 
be free in the WordPress.org Plugin Directory [https://wordpress.org/plugins/](https://wordpress.org/plugins/)
or can be cost-based plugin from a third-party. developers need to use the new `
wp_register_block_metadata_collection()` function, which takes two parameters:

 * `$path`: The base path in which block files for the collection reside.
 * `$manifest`: The path to the manifest file for the collection.

Every `block.json` file that is supposed to be part of the collection must reside
within the provided `$path`, within its own directory matching the block type name(
without the block namespace). Please see the [full example](https://make.wordpress.org/core/2024/10/17/new-block-type-registration-apis-to-improve-performance-in-wordpress-6-7/?output_format=md#full-example)
for further clarification.

Note that registering block metadata collections does not replace the need to register
individual block types at this point. You will still need to call `register_block_type()`
or `register_block_type_from_metadata()` for every block type that is part of a 
collection. Usage of the new function is optional to help performance, but it is
strongly recommended particularly for plugins that register several block types.
Please continue reading for additional tooling to facilitate this process.

### Automatically generating a block metadata collection manifest

Plugin developers are responsible for generating and maintaining the manifest file
they register for their plugin’s block types metadata collection. To make this process
simple, a new [command `build-blocks-manifest`](https://www.npmjs.com/package/@wordpress/scripts#build-blocks-manifest)
has been implemented as part of the [`@wordpress/scripts` NPM package](https://www.npmjs.com/package/@wordpress/scripts),
released as part of version 30.3.0.

The `wp-scripts build-blocks-manifest` command accepts two arguments:

 * `--input`: The directory in which the block types reside. The default for this
   is “build”.
 * `--output`: The file path for where to store the built block metadata collection
   manifest. The default for this is “build/blocks-manifest.php”.

Effectively, the arguments for this command are equivalent to the parameters for`
wp_register_block_metadata_collection()`: The `--input` argument is the equivalent
of the `$path` parameter, and the `--output` argument is the equivalent of the `
$manifest` parameter.

### Full example

For this example, let’s say you have a plugin `my-block-library` that registers 
3 block types:

 * `my-block-library/pricing`
 * `my-block-library/services`
 * `my-block-library/testimonial`

The source code for these block types is implemented in the plugin’s `src` directory,
more specifically in directories as follows:

 * `src/pricing` for the `my-block-library/pricing` block.
 * `src/services` for the `my-block-library/services` block.
 * `src/testimonial` for the `my-block-library/testimonial` block.

By using the existing `wp-scripts build` command, the code gets built into the plugin’s`
build` directory, with the same subdirectories for each block type.

After running the build, you can use the new `wp-scripts build-blocks-manifest` 
command. Since the plugin is using the default location for its block types, you
don’t need to pass any arguments to the command. Simply run `wp-scripts build-blocks-
manifest`, and it will read the `block.json` metadata for all three blocks from 
the `build` directory and combine them into a `build/blocks-manifest.php` file.

The manifest file will look something like this:

    ```php
    <?php
    // This file is generated. Do not modify it manually.
    return array(
    	'pricing' => array( /* Block metadata. */ ),
    	'services' => array( /* Block metadata. */ ),
    	'testimonial' => array( /* Block metadata. */ )
    );
    ```

You can use the same two commands in the future, whenever you have made changes 
to the block types and their implementation:

    ```bash
    wp-scripts build
    wp-scripts build-blocks-manifest
    ```

With the manifest file generated, you can now register the block metadata collection
as follows:

    ```php
    wp_register_block_metadata_collection(
    	WP_PLUGIN_DIR . '/my-block-library/build',
    	WP_PLUGIN_DIR . '/my-block-library/build/blocks-manifest.php'
    );
    ```

Last but not least, don’t forget to register the actual block types:

    ```php
    register_block_type_from_metadata( WP_PLUGIN_DIR . '/my-block-library/build/pricing' );
    register_block_type_from_metadata( WP_PLUGIN_DIR . '/my-block-library/build/services' );
    register_block_type_from_metadata( WP_PLUGIN_DIR . '/my-block-library/build/testimonial' );
    ```

And that’s already it, you have everything in place for improved performance of 
the plugin’s block types registration.

## Summary and further reading

The new `wp_register_block_metadata_collection()` and its tooling support in `@wordpress/
scripts` are a powerful combination to improve performance of register block types
from your plugin. They make the process almost effortless, so if your plugin registers
block types, please consider incorporating this approach into your development workflow
and plugin codebase.

Please see the following links for further reading:

 * TracTrac An open source project by Edgewall Software that serves as a bug tracker
   and project management tool for WordPress. ticketticket Created for both bug 
   reports and feature development on the bug tracker. [#62002](https://core.trac.wordpress.org/ticket/62002)
   for implementing the `wp_register_block_metadata_collection()` function.
 * GutenbergGutenberg The Gutenberg project is the new Editor Interface for WordPress.
   The editor improves the process and experience of creating new content, making
   writing rich content much simpler. It uses ‘blocks’ to add richness rather than
   shortcodes, custom HTML etc. [https://wordpress.org/gutenberg/](https://wordpress.org/gutenberg/)
   pull request [#65866](https://github.com/WordPress/gutenberg/pull/65866) for 
   implementing the `wp-scripts build-blocks-manifest` command.

_Props [@gziolo](https://profiles.wordpress.org/gziolo/) and [@mreishus](https://profiles.wordpress.org/mreishus/)
for review and proofreading._

[#6-7](https://make.wordpress.org/core/tag/6-7/), [#dev-notes](https://make.wordpress.org/core/tag/dev-notes/),
[#dev-notes-6-7](https://make.wordpress.org/core/tag/dev-notes-6-7/)

### Share this:

 * [  Threads ](https://make.wordpress.org/core/2024/10/17/new-block-type-registration-apis-to-improve-performance-in-wordpress-6-7/?share=threads)
 * [  Mastodon ](https://make.wordpress.org/core/2024/10/17/new-block-type-registration-apis-to-improve-performance-in-wordpress-6-7/?share=mastodon)
 * [  Bluesky ](https://make.wordpress.org/core/2024/10/17/new-block-type-registration-apis-to-improve-performance-in-wordpress-6-7/?share=bluesky)
 * [  X ](https://make.wordpress.org/core/2024/10/17/new-block-type-registration-apis-to-improve-performance-in-wordpress-6-7/?share=x)
 * [  Facebook ](https://make.wordpress.org/core/2024/10/17/new-block-type-registration-apis-to-improve-performance-in-wordpress-6-7/?share=facebook)
 * [  LinkedIn ](https://make.wordpress.org/core/2024/10/17/new-block-type-registration-apis-to-improve-performance-in-wordpress-6-7/?share=linkedin)

 1.  ![](https://secure.gravatar.com/avatar/494d0b64c5d0f3d52e6b346e68fa1977ae0b74b10642d7f3f4fff1c90d6c7a10?
     s=32&d=mm&r=g)
 2.   [wongjn](https://profiles.wordpress.org/wongjn/)  6:14 pm _on_ October 17, 2024
 3.  Could themes be supported in this please? I see in `WP_Block_Metadata_Registry::
     register_collection()` that it explcitly checks that the paths must be in the `
     plugins` or `wp-includes` folders.
 4.   * ![](https://secure.gravatar.com/avatar/a60abe9a2c42fe5cf2117b88aac2eab186f0ea3c969f1f4a29d4a09d831153b8?
        s=32&d=mm&r=g)
      *  [Felix Arntz](https://profiles.wordpress.org/flixos90/)  7:26 pm _on_ October
        17, 2024
      * This is worth discussing, feel free to open a CoreCore Core is the set of software
        required to run WordPress. The Core Development Team builds WordPress. TracTrac
        An open source project by Edgewall Software that serves as a bug tracker and
        project management tool for WordPress. ticketticket Created for both bug reports
        and feature development on the bug tracker. for this.
      * The reason this was not included initially is that it is discouraged for themes
        to register blockBlock Block is the abstract term used to describe units of
        markup that, composed together, form the content or layout of a webpage using
        the WordPress editor. The idea combines concepts of what in the past may have
        achieved with shortcodes, custom HTML, and embed discovery into a single consistent
        API and user experience. types, so only Core or plugins should register block
        types. That said, the other APIs do not technically prevent themes from using
        them, so it’s worth considering.
         - ![](https://secure.gravatar.com/avatar/a61af5cd9a78137214c3f0b276a3d07bdb931397f4d7861ce6b818fd062b542d?
           s=32&d=mm&r=g)
         -  [Greg Ziółkowski](https://profiles.wordpress.org/gziolo/)  7:19 am _on_
           October 18, 2024
         - It should be perfectly fine to allow registering blockBlock Block is the
           abstract term used to describe units of markup that, composed together, 
           form the content or layout of a webpage using the WordPress editor. The 
           idea combines concepts of what in the past may have achieved with shortcodes,
           custom HTML, and embed discovery into a single consistent API and user experience.
           type collections from the theme. At some point, we added the support for
           individual block types to integrate with themes. In practice, it was possible
           with WP hooksHooks In WordPress theme and development, hooks are functions
           that can be applied to an action or a Filter in WordPress. Actions are functions
           performed when a certain event occurs in WordPress. Filters allow you to
           modify certain functions. Arguments used to hook both filters and actions
           look the same. to register block type in themes, so we decided to make the
           experience smoother while keep recommeding locating block types in plugins.
            * ![](https://secure.gravatar.com/avatar/1718b7c2f2afc31b4e94805b6f1f6ae2b802cc4c696f99b11fde2186006c82c9?
              s=32&d=mm&r=g)
            *  [Pascal Birchler](https://profiles.wordpress.org/swissspidy/)  10:55
              pm _on_ October 21, 2024
            * Agreed. Just because it’s discouraged doesn’t mean it should be forbidden(
              in this particular function only, FWIW). It also causes issues for developers
              using symlinks, see [https://wordpress.slack.com/archives/C02QB2JS7/p1729539333146749](https://wordpress.slack.com/archives/C02QB2JS7/p1729539333146749)
            * Themes in the repo won’t be allowed to have blocks in them anyway, and
              for custom projects developers should have the freedom to do this, even
              if it’s semantically not the best place.
      * ![](https://secure.gravatar.com/avatar/32a72213be1308473f692b1dccfc44607bd88f11ea92f3ceaefef4b91f1fe4b3?
        s=32&d=mm&r=g)
      *  [Adam Wood](https://profiles.wordpress.org/adamwood/)  1:46 am _on_ October
        23, 2024
      * +1
 5.  ![](https://secure.gravatar.com/avatar/a0bfa1a9c6e19765563b5c64e77d0ab0ebb58f8b90a094375990c9fd7dfb608c?
     s=32&d=mm&r=g)
 6.   [Nicolas Juen](https://profiles.wordpress.org/rahe/)  8:49 am _on_ October 18,
     2024
 7.  Hi,
      Is this will be implemented for the theme.jsonJSON JSON, or JavaScript Object
     Notation, is a minimal, readable format for structuring data. It is used primarily
     to transmit data between a server and web application, as an alternative to XML.?
 8.  Isn’t it easier now to transform block.json to block.php ? And have a process 
     to generate the block.json file from script ?
 9.  Nicolas,
 10.  * ![](https://secure.gravatar.com/avatar/a60abe9a2c42fe5cf2117b88aac2eab186f0ea3c969f1f4a29d4a09d831153b8?
        s=32&d=mm&r=g)
      *  [Felix Arntz](https://profiles.wordpress.org/flixos90/)  1:19 pm _on_ October
        18, 2024
      * This would definitely be possible and would help performance a lot too. There’s
        actually a GutenbergGutenberg The Gutenberg project is the new Editor Interface
        for WordPress. The editor improves the process and experience of creating new
        content, making writing rich content much simpler. It uses ‘blocks’ to add 
        richness rather than shortcodes, custom HTML etc.
         [https://wordpress.org/gutenberg/](https://wordpress.org/gutenberg/)
        issue for it already: [https://github.com/WordPress/gutenberg/issues/45616](https://github.com/WordPress/gutenberg/issues/45616)
         - ![](https://secure.gravatar.com/avatar/a0bfa1a9c6e19765563b5c64e77d0ab0ebb58f8b90a094375990c9fd7dfb608c?
           s=32&d=mm&r=g)
         -  [Nicolas Juen](https://profiles.wordpress.org/rahe/)  2:49 pm _on_ October
           18, 2024
         - This could be great, theme.jsonJSON JSON, or JavaScript Object Notation,
           is a minimal, readable format for structuring data. It is used primarily
           to transmit data between a server and web application, as an alternative
           to XML. files are getting bigger and bigger.
 11. ![](https://secure.gravatar.com/avatar/865d90ad698b325440361a71943d729f8ad5c44c66a6d65c5a046a8323ac7ced?
     s=32&d=mm&r=g)
 12.  [Ryan Welcher](https://profiles.wordpress.org/welcher/)  2:48 pm _on_ October
     18, 2024
 13. [@flixos90](https://profiles.wordpress.org/flixos90/) is there a suite I can use
     to test the change in performance after implementing this new function?
 14.  * ![](https://secure.gravatar.com/avatar/a60abe9a2c42fe5cf2117b88aac2eab186f0ea3c969f1f4a29d4a09d831153b8?
        s=32&d=mm&r=g)
      *  [Felix Arntz](https://profiles.wordpress.org/flixos90/)  5:49 pm _on_ October
        18, 2024
      * There are several alternatives to measure PHPPHP The web scripting language
        in which WordPress is primarily architected. WordPress requires PHP 7.4 or 
        higher performance, so no one-size-fits-all approach. We have documented the
        ones we most commonly use for performance assessments in [https://make.wordpress.org/performance/handbook/measuring-performance/](https://make.wordpress.org/performance/handbook/measuring-performance/).
        Hope that helps!
         - ![](https://secure.gravatar.com/avatar/865d90ad698b325440361a71943d729f8ad5c44c66a6d65c5a046a8323ac7ced?
           s=32&d=mm&r=g)
         -  [Ryan Welcher](https://profiles.wordpress.org/welcher/)  5:58 pm _on_ October
           18, 2024
         - Thanks!
 15. ![](https://secure.gravatar.com/avatar/3f114144ed76d2646be286d6d9c8f7aa519f75a026ef444f611436ec42c00b55?
     s=32&d=mm&r=g)
 16.  [CodeMilitant](https://profiles.wordpress.org/codemilitant/)  7:16 pm _on_ October
     28, 2024
 17. In the block.jsonJSON JSON, or JavaScript Object Notation, is a minimal, readable
     format for structuring data. It is used primarily to transmit data between a server
     and web application, as an alternative to XML. file, or the register_block_type_from_metadata,
     or the register_block_type functions, can we setup a “true” arg for enqueueing
     javascripts in the footer, and a “version” arg.
 18. This will make registering and enqueueing these scripts much cleaner.
 19. I would prefer to see both of these in the block.json file to keep the PHPPHP 
     The web scripting language in which WordPress is primarily architected. WordPress
     requires PHP 7.4 or higher code as clean as possible and centralize all these 
     args into one file. It will be easier for everyone to understand.
 20. Something like this:
      “editorScript”: “file:./editor-block.js”, “[date|wp]”, “
     true”, “editorStyle”: “file:./editor-block.css”, “[date|wp]”, “script”: “file:./
     frontend.js, true”, “[date|wp]”, “true”, “style”: “file:./style.css”, “[date|wp]”,
 21. date == filemtime
      wp == WordPress version true == enqueue in footer
 22.  * ![](https://secure.gravatar.com/avatar/a61af5cd9a78137214c3f0b276a3d07bdb931397f4d7861ce6b818fd062b542d?
        s=32&d=mm&r=g)
      *  [Greg Ziółkowski](https://profiles.wordpress.org/gziolo/)  9:31 am _on_ October
        30, 2024
      * Great feedback! Some similar ideas are tracked on GitHubGitHub GitHub is a 
        website that offers online implementation of git repositories that can easily
        be shared, copied and modified by other developers. Public repositories are
        free to host, private repositories require a paid subscription. GitHub introduced
        the concept of the ‘pull request’ where code changes done in branches by contributors
        can be reviewed and discussed before being merged by the repository owner. 
        [https://github.com/](https://github.com/): [https://github.com/WordPress/gutenberg/issues/46954](https://github.com/WordPress/gutenberg/issues/46954).
        It was previously discussed also on TracTrac An open source project by Edgewall
        Software that serves as a bug tracker and project management tool for WordPress.
        [https://core.trac.wordpress.org/ticket/54018](https://core.trac.wordpress.org/ticket/54018)
        and eventually closed when view scripts became deferred by default.
         - ![](https://secure.gravatar.com/avatar/3f114144ed76d2646be286d6d9c8f7aa519f75a026ef444f611436ec42c00b55?
           s=32&d=mm&r=g)
         -  [CodeMilitant](https://profiles.wordpress.org/codemilitant/)  6:59 pm _on_
           October 31, 2024
         - What do you mean by “eventually closed when view scripts became deferred
           by default”?
         - These ideas were proposed years ago. What’s the hold up? This will streamline
           the code and make building new plugins a breeze. It doesn’t seem that difficult
           since it’s just a JSONJSON JSON, or JavaScript Object Notation, is a minimal,
           readable format for structuring data. It is used primarily to transmit data
           between a server and web application, as an alternative to XML. file. WordPress
           is more than capable of parsing JSON.
 23. ![](https://secure.gravatar.com/avatar/cb5b245a028aa345ab6835aae50c1291df42f366680f845f93cbbd496958a569?
     s=32&d=mm&r=g)
 24.  [Jorgu5](https://profiles.wordpress.org/internetoholik/)  1:24 pm _on_ November
     9, 2024
 25. Do you guys have any benchmarks for the actual performance difference ?

Comments are closed.

# Post navigation

[← Summary, Dev Chat, October 16, 2024](https://make.wordpress.org/core/2024/10/17/summary-dev-chat-october-16-2024/)

[Updates to user-interface components in WordPress 6.7 →](https://make.wordpress.org/core/2024/10/18/editor-components-updates-in-wordpress-6-7/)