WP_Block_Pattern_Categories_Registry::register()publicWP 5.5.0

Registers a pattern category.

Метод класса: WP_Block_Pattern_Categories_Registry{}

Хуков нет.

Возвращает

true|false. True if the pattern was registered with success and false otherwise.

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

$WP_Block_Pattern_Categories_Registry = new WP_Block_Pattern_Categories_Registry();
$WP_Block_Pattern_Categories_Registry->register( $category_name, $category_properties );
$category_name(строка) (обязательный)
Pattern category name including namespace.
$category_properties(массив) (обязательный)

List of properties for the block pattern category.

  • label(строка)
    Required. A human-readable label for the pattern category.

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

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

Код WP_Block_Pattern_Categories_Registry::register() WP 6.5.2

public function register( $category_name, $category_properties ) {
	if ( ! isset( $category_name ) || ! is_string( $category_name ) ) {
		_doing_it_wrong(
			__METHOD__,
			__( 'Block pattern category name must be a string.' ),
			'5.5.0'
		);
		return false;
	}

	$category = array_merge(
		array( 'name' => $category_name ),
		$category_properties
	);

	$this->registered_categories[ $category_name ] = $category;

	// If the category is registered inside an action other than `init`, store it
	// also to a dedicated array. Used to detect deprecated registrations inside
	// `admin_init` or `current_screen`.
	if ( current_action() && 'init' !== current_action() ) {
		$this->registered_categories_outside_init[ $category_name ] = $category;
	}

	return true;
}