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
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_versionstringBlock API version.$titlestringHuman-readable block type label.$categorystring|nullBlock type category classification, used in search interfaces to arrange block types by category.$parentstring[]|nullSetting parent lets a block require that it is only available when nested within the specified blocks.$ancestorstring[]|nullSetting ancestor makes a block available only inside the specified block types at any position of the ancestor's block subtree.$allowed_blocksstring[]|nullLimits which block types can be inserted as children of this block type.$iconstring|nullBlock type icon.$descriptionstringA detailed block type description.$keywordsstring[]Additional keywords to produce block type as result in search interfaces.$textdomainstring|nullThe translation textdomain.$stylesarray[]Alternative block styles.$variationsarray[]Block variations.$selectorsarrayCustom CSS selectors for theme.json style generation.$supportsarray|nullSupported features.$examplearray|nullStructured data for the block preview.$render_callbackcallable|nullBlock type render callback.$variation_callbackcallable|nullBlock type variations callback.$attributesarray|nullBlock type attributes property schemas.$uses_contextstring[]Context values inherited by blocks of this type.$provides_contextstring[]|nullContext 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
- Scaling
- Constant
- Instructions
- 8
- Plugin surface
- None
- Called by
- 1
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5. The body compiles to 8.
Nothing here hands control to plugin code.
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.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 8 | ->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
- WP_Block_Type::set_props()Sets block type properties.
Used by · 1
- WP_Block_Type_Registry::register()Registers a block type.
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.
Signature, return type and hooks compared across 5 parsed releases.
allowed_blocks, variation_callback, and view_style_handles properties.from the docblockblock_hooks property.from the docblockselectors property.from the docblockeditor_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 docblockancestor property.from the docblockview_script property.from the docblockvariations property.from the docblockapi_version property.from the docblocktitle, category, parent, icon, description, keywords, textdomain, styles, supports, example, uses_context, and provides_context properties.from the docblockAbout 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.