mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-27 11:38:01 +01:00
Blocks: Introduce register_block_type()
, unregister_block_type()
, and get_dynamic_blocks()
functions.
These helper functions allow easy access to the global block registry. See #45109. Built from https://develop.svn.wordpress.org/branches/5.0@43743 git-svn-id: http://core.svn.wordpress.org/branches/5.0@43572 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
22840639e8
commit
28310289bd
@ -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, '<!-- wp:' . $block_type . ' ' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of the names of all registered dynamic block types.
|
||||
*
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @return array Array of dynamic block names.
|
||||
*/
|
||||
function get_dynamic_block_names() {
|
||||
$dynamic_block_names = array();
|
||||
|
||||
$block_types = WP_Block_Type_Registry::get_instance()->get_all_registered();
|
||||
foreach ( $block_types as $block_type ) {
|
||||
if ( $block_type->is_dynamic() ) {
|
||||
$dynamic_block_names[] = $block_type->name;
|
||||
}
|
||||
}
|
||||
|
||||
return $dynamic_block_names;
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.0-alpha-43742';
|
||||
$wp_version = '5.0-alpha-43743';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
Reference in New Issue
Block a user