WP_Block_Parser::add_block_from_stack()publicWP 5.0.0

Pushes the top block from the parsing stack to the output list.

Method of the class: WP_Block_Parser{}

No Hooks.

Return

null. Nothing (null).

Usage

$WP_Block_Parser = new WP_Block_Parser();
$WP_Block_Parser->add_block_from_stack( $end_offset );
$end_offset(int|null)
byte offset into document for where we should stop sending text output as HTML.
Default: null

Changelog

Since 5.0.0 Introduced.

WP_Block_Parser::add_block_from_stack() code WP 6.4.3

public function add_block_from_stack( $end_offset = null ) {
	$stack_top   = array_pop( $this->stack );
	$prev_offset = $stack_top->prev_offset;

	$html = isset( $end_offset )
		? substr( $this->document, $prev_offset, $end_offset - $prev_offset )
		: substr( $this->document, $prev_offset );

	if ( ! empty( $html ) ) {
		$stack_top->block->innerHTML     .= $html;
		$stack_top->block->innerContent[] = $html;
	}

	if ( isset( $stack_top->leading_html_start ) ) {
		$this->output[] = (array) $this->freeform(
			substr(
				$this->document,
				$stack_top->leading_html_start,
				$stack_top->token_start - $stack_top->leading_html_start
			)
		);
	}

	$this->output[] = (array) $stack_top->block;
}