WP_HTML_Processor::__construct( string $html, string|null $use_the_static_create_methods_instead = null )

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Use WP_HTML_Processor::create_fragment() instead.

Constructor.

Description

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

See also

Parameters

$htmlstringrequired
HTML to process.
$use_the_static_create_methods_insteadstring|nulloptional
This constructor should not be called manually.

Default:null

Source

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 ) {
			$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->state->stack_of_open_elements->set_pop_handler(
		function ( WP_HTML_Token $token ) {
			$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 );
		}
	);

	/*
	 * 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 ( $name ) {
		parent::release_bookmark( $name );
	};
}

Changelog

VersionDescription
6.4.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.