WP_Block_List
- Since
- 5.5.0
- Source
wp-includes/class-wp-block-list.php:14
Class representing a list of block instances.
Compatibility
- WordPress
- since 5.5.0
- 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).
Properties · 3
$blocksarray[]|WP_Block[]protected- Original array of parsed block data, or block instances.
$available_contextarrayprotected- All available context of the current hierarchy.
$registryWP_Block_Type_Registryprotected- Block type registry to use in constructing block instances.
Methods · 11
- __construct()Constructor.
- offsetExists()Returns true if a block exists by the specified block offset, or false otherwise.
- offsetGet()Returns the value by the specified block offset.
- offsetSet()Assign a block value by the specified block offset.
- offsetUnset()Unset a block.
- rewind()Rewinds back to the first element of the Iterator.
- current()Returns the current element of the block list.
- key()Returns the key of the current element of the block list.
- next()Moves the current position of the block list to the next element.
- valid()Checks if current position is valid.
- count()Returns the count of blocks in the list.
Source code
#[AllowDynamicProperties]class WP_Block_List implements Iterator, ArrayAccess, Countable { /** * Original array of parsed block data, or block instances. * * @since 5.5.0 * @var array[]|WP_Block[] */ protected $blocks; /** * All available context of the current hierarchy. * * @since 5.5.0 * @var array */ protected $available_context; /** * Block type registry to use in constructing block instances. * * @since 5.5.0 * @var WP_Block_Type_Registry */ protected $registry; /** * Constructor. * * Populates object properties from the provided block instance argument. * * @since 5.5.0 * * @param array[]|WP_Block[] $blocks Array of parsed block data, or block instances. * @param array $available_context Optional array of ancestry context values. * @param WP_Block_Type_Registry $registry Optional block type registry. */ public function __construct( $blocks, $available_context = array(), $registry = null ) { if ( ! $registry instanceof WP_Block_Type_Registry ) { $registry = WP_Block_Type_Registry::get_instance(); } $this->blocks = $blocks; $this->available_context = $available_context; $this->registry = $registry; } /** * Returns true if a block exists by the specified block offset, or false * otherwise. * * @since 5.5.0 * * @link https://www.php.net/manual/en/arrayaccess.offsetexists.php * * @param int $offset Offset of block to check for. * @return bool Whether block exists. */ #[ReturnTypeWillChange] public function offsetExists( $offset ) { return isset( $this->blocks[ $offset ] ); } /** * Returns the value by the specified block offset. * * @since 5.5.0 * * @link https://www.php.net/manual/en/arrayaccess.offsetget.php * * @param int $offset Offset of block value to retrieve. * @return WP_Block|null Block value if exists, or null. */ #[ReturnTypeWillChange] public function offsetGet( $offset ) { $block = $this->blocks[ $offset ]; if ( isset( $block ) && is_array( $block ) ) { $block = new WP_Block( $block, $this->available_context, $this->registry );Changelog
Introduced in 5.5.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/class-wp-block-list.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.