WP_Block_Type::__construct() WordPress Method

The WP_Block_Type::__construct() method is used to create a new block type object. A block type is a collection of related blocks.

WP_Block_Type::__construct( string $block_type, array|string $args = array() ) #

Constructor.


Description

Will populate object properties from the provided arguments.

Top ↑

See also


Top ↑

Parameters

$block_type

(string)(Required)Block type name including namespace.

$args

(array|string)(Optional)Array or string of arguments for registering a block type. Any arguments may be defined, however the ones described below are supported by default.

  • 'api_version'
    (string) Block API version.
  • 'title'
    (string) Human-readable block type label.
  • 'category'
    (string|null) Block type category classification, used in search interfaces to arrange block types by category.
  • 'parent'
    (array|null) Setting parent lets a block require that it is only available when nested within the specified blocks.
  • 'ancestor'
    (array|null) Setting ancestor makes a block available only inside the specified block types at any position of the ancestor's block subtree.
  • 'icon'
    (string|null) Block type icon.
  • 'description'
    (string) A detailed block type description.
  • 'keywords'
    (string[]) Additional keywords to produce block type as result in search interfaces.
  • 'textdomain'
    (string|null) The translation textdomain.
  • 'styles'
    (array) Alternative block styles.
  • 'variations'
    (array) Block variations.
  • 'supports'
    (array|null) Supported features.
  • 'example'
    (array|null) Structured data for the block preview.
  • 'render_callback'
    (callable|null) Block type render callback.
  • 'attributes'
    (array|null) Block type attributes property schemas.
  • 'uses_context'
    (array) Context values inherited by blocks of this type.
  • 'provides_context'
    (array|null) Context provided by blocks of this type.
  • 'editor_script'
    (string|null) Block type editor only script handle.
  • 'script'
    (string|null) Block type front end and editor script handle.
  • 'view_script'
    (string|null) Block type front end only script handle.
  • 'editor_style'
    (string|null) Block type editor only style handle.
  • 'style'
    (string|null) Block type front end and editor style handle.

Default value: array()


Top ↑

Source

File: wp-includes/class-wp-block-type.php

	public function __construct( $block_type, $args = array() ) {
		$this->name = $block_type;

		$this->set_props( $args );
	}


Top ↑

Changelog

Changelog
VersionDescription
6.0.0Added the ancestor property.
5.9.0Added the view_script property.
5.8.0Added the variations property.
5.6.0Added the api_version property.
5.5.0Added the title, category, parent, icon, description, keywords, textdomain, styles, supports, example, uses_context, and provides_context properties.
5.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.