wppaste
WordPress

WP_Block_Type_Registry

Since
5.0.0
Source
wp-includes/class-wp-block-type-registry.php:15
Core class used for interacting with block types.

Compatibility

WordPress
since 5.0.0
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0).

Properties · 2

$registered_block_typesWP_Block_Type[]private
Registered block types, as $name => $instance pairs.
$instanceWP_Block_Type_Registry|nullprivate static
Container for the main instance of the class.

Methods · 7

Source code

#[AllowDynamicProperties]final class WP_Block_Type_Registry {	/**	 * Registered block types, as `$name => $instance` pairs.	 *	 * @since 5.0.0	 * @var WP_Block_Type[]	 */	private $registered_block_types = array(); 	/**	 * Container for the main instance of the class.	 *	 * @since 5.0.0	 * @var WP_Block_Type_Registry|null	 */	private static $instance = null; 	/**	 * Registers a block type.	 *	 * @since 5.0.0	 *	 * @see WP_Block_Type::__construct()	 *	 * @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. Accepts any public property	 *                                   of `WP_Block_Type`. See WP_Block_Type::__construct() for information	 *                                   on accepted arguments. Default empty array.	 * @return WP_Block_Type|false The registered block type on success, or false on failure.	 */	public function register( $name, $args = array() ) {		$block_type = null;		if ( $name instanceof WP_Block_Type ) {			$block_type = $name;			$name       = $block_type->name;		} 		if ( ! is_string( $name ) ) {			_doing_it_wrong(				__METHOD__,				__( 'Block type names must be strings.' ),				'5.0.0'			);			return false;		} 		if ( preg_match( '/[A-Z]+/', $name ) ) {			_doing_it_wrong(				__METHOD__,				__( 'Block type names must not contain uppercase characters.' ),				'5.0.0'			);			return false;		} 		$name_matcher = '/^[a-z0-9-]+\/[a-z0-9-]+$/';		if ( ! preg_match( $name_matcher, $name ) ) {			_doing_it_wrong(				__METHOD__,				__( 'Block type names must contain a namespace prefix. Example: my-plugin/my-custom-block-type' ),				'5.0.0'			);			return false;		} 		if ( $this->is_registered( $name ) ) {			_doing_it_wrong(				__METHOD__,				/* translators: %s: Block name. */				sprintf( __( 'Block type "%s" is already registered.' ), $name ),				'5.0.0'			);			return false;		} 		if ( ! $block_type ) {			$block_type = new WP_Block_Type( $name, $args );

Changelog

Introduced in 5.0.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.7.7 tag, from src/wp-includes/class-wp-block-type-registry.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.