WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

WP_Block_Type_Registry::register() public WP 5.0.0

Registers a block type.

{} Это метод класса: WP_Block_Type_Registry{}

Хуков нет.

Возвращает

WP_Block_Type/false. The registered block type on success, or false on failure.

Использование

$WP_Block_Type_Registry = new WP_Block_Type_Registry();
$WP_Block_Type_Registry->register( $name, $args );
$name(строка/WP_Block_Type) (обязательный)
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.
$args(массив)

Array of block type arguments. Accepts any public property of WP_Block_Type. Any arguments may be defined, however the ones described below are supported by default.

  • render_callback(callable)
    Callback used to render blocks of this block type.

  • attributes(массив)
    Block attributes mapping, property name to schema.

По умолчанию: empty array

Список изменений

С версии 5.0.0 Введена.

Код WP_Block_Type_Registry::register() WP 5.5.3

<?php
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 ) ) {
		$message = __( 'Block type names must be strings.' );
		_doing_it_wrong( __METHOD__, $message, '5.0.0' );
		return false;
	}

	if ( preg_match( '/[A-Z]+/', $name ) ) {
		$message = __( 'Block type names must not contain uppercase characters.' );
		_doing_it_wrong( __METHOD__, $message, '5.0.0' );
		return false;
	}

	$name_matcher = '/^[a-z0-9-]+\/[a-z0-9-]+$/';
	if ( ! preg_match( $name_matcher, $name ) ) {
		$message = __( 'Block type names must contain a namespace prefix. Example: my-plugin/my-custom-block-type' );
		_doing_it_wrong( __METHOD__, $message, '5.0.0' );
		return false;
	}

	if ( $this->is_registered( $name ) ) {
		/* translators: %s: Block name. */
		$message = sprintf( __( 'Block type "%s" is already registered.' ), $name );
		_doing_it_wrong( __METHOD__, $message, '5.0.0' );
		return false;
	}

	if ( ! $block_type ) {
		$block_type = new WP_Block_Type( $name, $args );
	}

	$this->registered_block_types[ $name ] = $block_type;

	return $block_type;
}