From 0f1544dabc37c961a143edb197412a7316bea11a Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Thu, 13 Dec 2018 09:54:25 +0000 Subject: [PATCH] Blocks: Introduce `register_block_type()`, `unregister_block_type()`, and `get_dynamic_blocks()` functions. These helper functions allow easy access to the global block registry. Merges [43743] from the 5.0 branch to trunk. See #45109. Built from https://develop.svn.wordpress.org/trunk@44109 git-svn-id: http://core.svn.wordpress.org/trunk@43939 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/blocks.php | 53 +++++++++++++++++++++++++++++++++++++++++ wp-includes/version.php | 2 +- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/wp-includes/blocks.php b/wp-includes/blocks.php index b04696d591..2ec3a07e3e 100644 --- a/wp-includes/blocks.php +++ b/wp-includes/blocks.php @@ -7,6 +7,39 @@ * @since 5.0.0 */ +/** + * Registers a block type. + * + * @since 5.0.0 + * + * @param string|WP_Block_Type $name Block type name including namespace, or alternatively a + * complete WP_Block_Type instance. In case a WP_Block_Type + * is provided, the $args parameter will be ignored. + * @param array $args { + * Optional. Array of block type arguments. Any arguments may be defined, however the + * ones described below are supported by default. Default empty array. + * + * @type callable $render_callback Callback used to render blocks of this block type. + * } + * @return WP_Block_Type|false The registered block type on success, or false on failure. + */ +function register_block_type( $name, $args = array() ) { + return WP_Block_Type_Registry::get_instance()->register( $name, $args ); +} + +/** + * Unregisters a block type. + * + * @since 5.0.0 + * + * @param string|WP_Block_Type $name Block type name including namespace, or alternatively a + * complete WP_Block_Type instance. + * @return WP_Block_Type|false The unregistered block type on success, or false on failure. + */ +function unregister_block_type( $name ) { + return WP_Block_Type_Registry::get_instance()->unregister( $name ); +} + /** * Determine whether a post or content string has blocks. * @@ -59,3 +92,23 @@ function has_block( $block_type, $post = null ) { return false !== strpos( $post, '