wppaste
WordPress

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

Since
5.0.0, 5.5.0, 5.6.0, 5.8.0, 5.9.0, 6.0.0, 6.1.0, 6.3.0, 6.4.0, 6.5.0
Source
wp-includes/class-wp-block-type.php:347
Constructor.

Description

Will populate object properties from the provided arguments.

Compatibility

WordPress
since 6.5.0
PHP
7.4–8.6-dev
  • 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), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$block_typestring
Block type name including namespace.
$argsarray|stringoptional
Array or string of arguments for registering a block type. Any arguments may be defined, however the ones described below are supported by default. Default empty array.Default: array()
  • $api_versionstring

    Block API version.
  • $titlestring

    Human-readable block type label.
  • $categorystring|null

    Block type category classification, used in search interfaces to arrange block types by category.
  • $parentstring[]|null

    Setting parent lets a block require that it is only available when nested within the specified blocks.
  • $ancestorstring[]|null

    Setting ancestor makes a block available only inside the specified block types at any position of the ancestor's block subtree.
  • $allowed_blocksstring[]|null

    Limits which block types can be inserted as children of this block type.
  • $iconstring|null

    Block type icon.
  • $descriptionstring

    A detailed block type description.
  • $keywordsstring[]

    Additional keywords to produce block type as result in search interfaces.
  • $textdomainstring|null

    The translation textdomain.
  • $stylesarray[]

    Alternative block styles.
  • $variationsarray[]

    Block variations.
  • $selectorsarray

    Custom CSS selectors for theme.json style generation.
  • $supportsarray|null

    Supported features.
  • $examplearray|null

    Structured data for the block preview.
  • $render_callbackcallable|null

    Block type render callback.
  • $variation_callbackcallable|null

    Block type variations callback.
  • $attributesarray|null

    Block type attributes property schemas.
  • $uses_contextstring[]

    Context values inherited by blocks of this type.
  • $provides_contextstring[]|null

    Context provided by blocks of this type.
  • $block_hooksstring[]

    Block hooks.
  • $editor_script_handlesstring[]

    Block type editor only script handles.
  • $script_handlesstring[]

    Block type front end and editor script handles.
  • $view_script_handlesstring[]

    Block type front end only script handles.
  • $editor_style_handlesstring[]

    Block type editor only style handles.
  • $style_handlesstring[]

    Block type front end and editor style handles.
  • $view_style_handlesstring[]

    Block type front end only style handles.

Performance profile

How much work a call to WP_Block_Type::__construct() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Trivial

Touches nothing outside its own arguments.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
8

Executed per call on PHP 8.5. The body compiles to 8.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
1

1 place in core call this, so the cost is paid more often than your own code shows.

What one call costs · 1 distinct outcome

One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Block_Type::__construct() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always8->set_props()

Across PHP versions

Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 8 instructions, 8 executed per call, 0 branches. The work does not change between versions.

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 1

Used by · 1

Source code

	public function __construct( $block_type, $args = array() ) {		$this->name = $block_type; 		$this->set_props( $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.

6.5.0
Added the allowed_blocks, variation_callback, and view_style_handles properties.from the docblock
6.4.0
Added the block_hooks property.from the docblock
6.3.0
Added the selectors property.from the docblock
6.1.0
Added the editor_script_handles, script_handles, view_script_handles, editor_style_handles, and style_handles properties.
Deprecated the editor_script, script, view_script, editor_style, and style properties.from the docblock
6.0.0
Added the ancestor property.from the docblock
5.9.0
Added the view_script property.from the docblock
5.8.0
Added the variations property.from the docblock
5.6.0
Added the api_version property.from the docblock
5.5.0
Added the title, category, parent, icon, description, keywords, textdomain, styles, supports, example, uses_context, and provides_context properties.from the docblock
5.0.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/class-wp-block-type.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.