WP_HTML_Processor::__constructpublicWP 6.4.0

Constructor.

Do not use this method. Use the static creator methods instead.

Method of the class: WP_HTML_Processor{}

Internal function — this function is designed to be used by the kernel itself. It is not recommended to use this function in your code.

No Hooks.

Returns

null. Nothing (null).

Usage

$result = WP_HTML_Processor::__construct( $html, $use_the_static_create_methods_instead );
$html(string) (required)
HTML to process.
$use_the_static_create_methods_instead(string|null)
This constructor should not be called manually.
Default: null

Notes

Changelog

Since 6.4.0 Introduced.

WP_HTML_Processor::__construct() code WP 6.8.1

public function __construct( $html, $use_the_static_create_methods_instead = null ) {
	parent::__construct( $html );

	if ( self::CONSTRUCTOR_UNLOCK_CODE !== $use_the_static_create_methods_instead ) {
		_doing_it_wrong(
			__METHOD__,
			sprintf(
				/* translators: %s: WP_HTML_Processor::create_fragment(). */
				__( 'Call %s to create an HTML Processor instead of calling the constructor directly.' ),
				'<code>WP_HTML_Processor::create_fragment()</code>'
			),
			'6.4.0'
		);
	}

	$this->state = new WP_HTML_Processor_State();

	$this->state->stack_of_open_elements->set_push_handler(
		function ( WP_HTML_Token $token ): void {
			$is_virtual            = ! isset( $this->state->current_token ) || $this->is_tag_closer();
			$same_node             = isset( $this->state->current_token ) && $token->node_name === $this->state->current_token->node_name;
			$provenance            = ( ! $same_node || $is_virtual ) ? 'virtual' : 'real';
			$this->element_queue[] = new WP_HTML_Stack_Event( $token, WP_HTML_Stack_Event::PUSH, $provenance );

			$this->change_parsing_namespace( $token->integration_node_type ? 'html' : $token->namespace );
		}
	);

	$this->state->stack_of_open_elements->set_pop_handler(
		function ( WP_HTML_Token $token ): void {
			$is_virtual            = ! isset( $this->state->current_token ) || ! $this->is_tag_closer();
			$same_node             = isset( $this->state->current_token ) && $token->node_name === $this->state->current_token->node_name;
			$provenance            = ( ! $same_node || $is_virtual ) ? 'virtual' : 'real';
			$this->element_queue[] = new WP_HTML_Stack_Event( $token, WP_HTML_Stack_Event::POP, $provenance );

			$adjusted_current_node = $this->get_adjusted_current_node();

			if ( $adjusted_current_node ) {
				$this->change_parsing_namespace( $adjusted_current_node->integration_node_type ? 'html' : $adjusted_current_node->namespace );
			} else {
				$this->change_parsing_namespace( 'html' );
			}
		}
	);

	/*
	 * Create this wrapper so that it's possible to pass
	 * a private method into WP_HTML_Token classes without
	 * exposing it to any public API.
	 */
	$this->release_internal_bookmark_on_destruct = function ( string $name ): void {
		parent::release_bookmark( $name );
	};
}