' );
+ * $processor = \WordPress\HTML\WP_HTML_Processor::create_fragment( '' );
* false === $processor->next_tag();
- * WP_HTML_Processor::ERROR_UNSUPPORTED === $processor->get_last_error();
+ * \WordPress\HTML\WP_HTML_Processor::ERROR_UNSUPPORTED === $processor->get_last_error();
*
* @return string|null The last error, if one exists, otherwise null.
* @see self::ERROR_UNSUPPORTED
@@ -685,7 +691,7 @@ public function next_token(): bool {
*
* Example:
*
- * $p = WP_HTML_Processor::create_fragment( '
' );
+ * $p = \WordPress\HTML\WP_HTML_Processor::create_fragment( '
' );
* $p->next_tag( array( 'tag_name' => 'div', 'tag_closers' => 'visit' ) );
* $p->is_tag_closer() === false;
*
@@ -729,7 +735,7 @@ public function is_virtual(): bool {
*
* Example:
*
- * $processor = WP_HTML_Processor::create_fragment( '' );
+ * $processor = \WordPress\HTML\WP_HTML_Processor::create_fragment( '' );
* $processor->next_tag( 'img' );
* true === $processor->matches_breadcrumbs( array( 'figure', 'img' ) );
* true === $processor->matches_breadcrumbs( array( 'span', 'figure', 'img' ) );
@@ -1002,7 +1008,7 @@ public function step( $node_to_process = self::PROCESS_NEXT_NODE ): bool {
*
* Example
*
- * $processor = WP_HTML_Processor::create_fragment( '
' );
+ * $processor = \WordPress\HTML\WP_HTML_Processor::create_fragment( '
' );
* $processor->next_tag( 'IMG' );
* $processor->get_breadcrumbs() === array( 'HTML', 'BODY', 'P', 'STRONG', 'EM', 'IMG' );
*
@@ -1016,7 +1022,7 @@ public function get_breadcrumbs(): ?array {
*
* Example:
*
- * $processor = WP_HTML_Processor::create_fragment( '' );
+ * $processor = \WordPress\HTML\WP_HTML_Processor::create_fragment( '' );
* // The processor starts in the BODY context, meaning it has depth from the start: HTML > BODY.
* 2 === $processor->get_current_depth();
*
@@ -1045,8 +1051,8 @@ public function get_current_depth(): int {
*
* This method assumes that the given HTML snippet is found in BODY context.
* For normalizing full documents or fragments found in other contexts, create
- * a new processor using {@see WP_HTML_Processor::create_fragment} or
- * {@see WP_HTML_Processor::create_full_parser} and call {@see WP_HTML_Processor::serialize}
+ * a new processor using {@see \WordPress\HTML\WP_HTML_Processor::create_fragment} or
+ * {@see \WordPress\HTML\WP_HTML_Processor::create_full_parser} and call {@see \WordPress\HTML\WP_HTML_Processor::serialize}
* on the created instances.
*
* Many aspects of an input HTML fragment may be changed during normalization.
@@ -1063,13 +1069,13 @@ public function get_current_depth(): int {
*
* Example:
*
- * echo WP_HTML_Processor::normalize( 'One syntax < <> "oddities"
*
* @param string $html Input HTML to normalize.
@@ -1085,7 +1091,7 @@ public static function normalize( string $html ): ?string {
/**
* Returns normalized HTML for a fragment by serializing it.
*
- * This differs from {@see WP_HTML_Processor::normalize} in that it starts with
+ * This differs from {@see \WordPress\HTML\WP_HTML_Processor::normalize} in that it starts with
* a specific HTML Processor, which _must_ not have already started scanning;
* it must be in the initial ready state and will be in the completed state once
* serialization is complete.
@@ -1104,15 +1110,15 @@ public static function normalize( string $html ): ?string {
*
* Example:
*
- * $processor = WP_HTML_Processor::create_fragment( 'One syntax < <> "oddities"
*
@@ -1282,13 +1288,13 @@ protected function serialize_token(): string {
* Parses next element in the 'initial' insertion mode.
*
* This internal function performs the 'initial' insertion mode
- * logic for the generalized WP_HTML_Processor::step() function.
+ * logic for the generalized \WordPress\HTML\WP_HTML_Processor::step() function.
*
* @return bool Whether an element was found.
* @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
*
* @see https://html.spec.whatwg.org/#the-initial-insertion-mode
- * @see WP_HTML_Processor::step
+ * @see \WordPress\HTML\WP_HTML_Processor::step
*
* @since 6.7.0
*
@@ -1356,13 +1362,13 @@ private function step_initial(): bool {
* Parses next element in the 'before html' insertion mode.
*
* This internal function performs the 'before html' insertion mode
- * logic for the generalized WP_HTML_Processor::step() function.
+ * logic for the generalized \WordPress\HTML\WP_HTML_Processor::step() function.
*
* @return bool Whether an element was found.
* @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
*
* @see https://html.spec.whatwg.org/#the-before-html-insertion-mode
- * @see WP_HTML_Processor::step
+ * @see \WordPress\HTML\WP_HTML_Processor::step
*
* @since 6.7.0
*
@@ -1456,13 +1462,13 @@ private function step_before_html(): bool {
* Parses next element in the 'before head' insertion mode.
*
* This internal function performs the 'before head' insertion mode
- * logic for the generalized WP_HTML_Processor::step() function.
+ * logic for the generalized \WordPress\HTML\WP_HTML_Processor::step() function.
*
* @return bool Whether an element was found.
* @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
*
* @see https://html.spec.whatwg.org/#the-before-head-insertion-mode
- * @see WP_HTML_Processor::step
+ * @see \WordPress\HTML\WP_HTML_Processor::step
*
* @since 6.7.0 Stub implementation.
*
@@ -1556,13 +1562,13 @@ private function step_before_head(): bool {
* Parses next element in the 'in head' insertion mode.
*
* This internal function performs the 'in head' insertion mode
- * logic for the generalized WP_HTML_Processor::step() function.
+ * logic for the generalized \WordPress\HTML\WP_HTML_Processor::step() function.
*
* @return bool Whether an element was found.
* @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
*
* @see https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inhead
- * @see WP_HTML_Processor::step
+ * @see \WordPress\HTML\WP_HTML_Processor::step
*
* @since 6.7.0
*
@@ -1785,13 +1791,13 @@ private function step_in_head(): bool {
* Parses next element in the 'in head noscript' insertion mode.
*
* This internal function performs the 'in head noscript' insertion mode
- * logic for the generalized WP_HTML_Processor::step() function.
+ * logic for the generalized \WordPress\HTML\WP_HTML_Processor::step() function.
*
* @return bool Whether an element was found.
* @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
*
* @see https://html.spec.whatwg.org/#parsing-main-inheadnoscript
- * @see WP_HTML_Processor::step
+ * @see \WordPress\HTML\WP_HTML_Processor::step
*
* @since 6.7.0 Stub implementation.
*
@@ -1889,13 +1895,13 @@ private function step_in_head_noscript(): bool {
* Parses next element in the 'after head' insertion mode.
*
* This internal function performs the 'after head' insertion mode
- * logic for the generalized WP_HTML_Processor::step() function.
+ * logic for the generalized \WordPress\HTML\WP_HTML_Processor::step() function.
*
* @return bool Whether an element was found.
* @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
*
* @see https://html.spec.whatwg.org/#the-after-head-insertion-mode
- * @see WP_HTML_Processor::step
+ * @see \WordPress\HTML\WP_HTML_Processor::step
*
* @since 6.7.0 Stub implementation.
*
@@ -2038,13 +2044,13 @@ private function step_after_head(): bool {
* Parses next element in the 'in body' insertion mode.
*
* This internal function performs the 'in body' insertion mode
- * logic for the generalized WP_HTML_Processor::step() function.
+ * logic for the generalized \WordPress\HTML\WP_HTML_Processor::step() function.
*
* @return bool Whether an element was found.
* @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
*
* @see https://html.spec.whatwg.org/#parsing-main-inbody
- * @see WP_HTML_Processor::step
+ * @see \WordPress\HTML\WP_HTML_Processor::step
*
* @since 6.4.0
*
@@ -3093,13 +3099,13 @@ private function step_in_body(): bool {
* Parses next element in the 'in table' insertion mode.
*
* This internal function performs the 'in table' insertion mode
- * logic for the generalized WP_HTML_Processor::step() function.
+ * logic for the generalized \WordPress\HTML\WP_HTML_Processor::step() function.
*
* @return bool Whether an element was found.
* @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
*
* @see https://html.spec.whatwg.org/#parsing-main-intable
- * @see WP_HTML_Processor::step
+ * @see \WordPress\HTML\WP_HTML_Processor::step
*
* @since 6.7.0
*
@@ -3360,13 +3366,13 @@ private function step_in_table(): bool {
* Parses next element in the 'in table text' insertion mode.
*
* This internal function performs the 'in table text' insertion mode
- * logic for the generalized WP_HTML_Processor::step() function.
+ * logic for the generalized \WordPress\HTML\WP_HTML_Processor::step() function.
*
* @return bool Whether an element was found.
* @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
*
* @see https://html.spec.whatwg.org/#parsing-main-intabletext
- * @see WP_HTML_Processor::step
+ * @see \WordPress\HTML\WP_HTML_Processor::step
*
* @since 6.7.0 Stub implementation.
*
@@ -3379,13 +3385,13 @@ private function step_in_table_text(): bool {
* Parses next element in the 'in caption' insertion mode.
*
* This internal function performs the 'in caption' insertion mode
- * logic for the generalized WP_HTML_Processor::step() function.
+ * logic for the generalized \WordPress\HTML\WP_HTML_Processor::step() function.
*
* @return bool Whether an element was found.
* @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
*
* @see https://html.spec.whatwg.org/#parsing-main-incaption
- * @see WP_HTML_Processor::step
+ * @see \WordPress\HTML\WP_HTML_Processor::step
*
* @since 6.7.0
*
@@ -3464,13 +3470,13 @@ private function step_in_caption(): bool {
* Parses next element in the 'in column group' insertion mode.
*
* This internal function performs the 'in column group' insertion mode
- * logic for the generalized WP_HTML_Processor::step() function.
+ * logic for the generalized \WordPress\HTML\WP_HTML_Processor::step() function.
*
* @return bool Whether an element was found.
* @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
*
* @see https://html.spec.whatwg.org/#parsing-main-incolgroup
- * @see WP_HTML_Processor::step
+ * @see \WordPress\HTML\WP_HTML_Processor::step
*
* @since 6.7.0
*
@@ -3576,13 +3582,13 @@ private function step_in_column_group(): bool {
* Parses next element in the 'in table body' insertion mode.
*
* This internal function performs the 'in table body' insertion mode
- * logic for the generalized WP_HTML_Processor::step() function.
+ * logic for the generalized \WordPress\HTML\WP_HTML_Processor::step() function.
*
* @return bool Whether an element was found.
* @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
*
* @see https://html.spec.whatwg.org/#parsing-main-intbody
- * @see WP_HTML_Processor::step
+ * @see \WordPress\HTML\WP_HTML_Processor::step
*
* @since 6.7.0
*
@@ -3684,13 +3690,13 @@ private function step_in_table_body(): bool {
* Parses next element in the 'in row' insertion mode.
*
* This internal function performs the 'in row' insertion mode
- * logic for the generalized WP_HTML_Processor::step() function.
+ * logic for the generalized \WordPress\HTML\WP_HTML_Processor::step() function.
*
* @return bool Whether an element was found.
* @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
*
* @see https://html.spec.whatwg.org/#parsing-main-intr
- * @see WP_HTML_Processor::step
+ * @see \WordPress\HTML\WP_HTML_Processor::step
*
* @since 6.7.0
*
@@ -3799,13 +3805,13 @@ private function step_in_row(): bool {
* Parses next element in the 'in cell' insertion mode.
*
* This internal function performs the 'in cell' insertion mode
- * logic for the generalized WP_HTML_Processor::step() function.
+ * logic for the generalized \WordPress\HTML\WP_HTML_Processor::step() function.
*
* @return bool Whether an element was found.
* @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
*
* @see https://html.spec.whatwg.org/#parsing-main-intd
- * @see WP_HTML_Processor::step
+ * @see \WordPress\HTML\WP_HTML_Processor::step
*
* @since 6.7.0
*
@@ -3907,13 +3913,13 @@ private function step_in_cell(): bool {
* Parses next element in the 'in select' insertion mode.
*
* This internal function performs the 'in select' insertion mode
- * logic for the generalized WP_HTML_Processor::step() function.
+ * logic for the generalized \WordPress\HTML\WP_HTML_Processor::step() function.
*
* @return bool Whether an element was found.
* @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
*
* @see https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inselect
- * @see WP_HTML_Processor::step
+ * @see \WordPress\HTML\WP_HTML_Processor::step
*
* @since 6.7.0
*
@@ -4091,13 +4097,13 @@ private function step_in_select(): bool {
* Parses next element in the 'in select in table' insertion mode.
*
* This internal function performs the 'in select in table' insertion mode
- * logic for the generalized WP_HTML_Processor::step() function.
+ * logic for the generalized \WordPress\HTML\WP_HTML_Processor::step() function.
*
* @return bool Whether an element was found.
* @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
*
* @see https://html.spec.whatwg.org/#parsing-main-inselectintable
- * @see WP_HTML_Processor::step
+ * @see \WordPress\HTML\WP_HTML_Processor::step
*
* @since 6.7.0
*
@@ -4158,13 +4164,13 @@ private function step_in_select_in_table(): bool {
* Parses next element in the 'in template' insertion mode.
*
* This internal function performs the 'in template' insertion mode
- * logic for the generalized WP_HTML_Processor::step() function.
+ * logic for the generalized \WordPress\HTML\WP_HTML_Processor::step() function.
*
* @return bool Whether an element was found.
* @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
*
* @see https://html.spec.whatwg.org/#parsing-main-intemplate
- * @see WP_HTML_Processor::step
+ * @see \WordPress\HTML\WP_HTML_Processor::step
*
* @since 6.7.0 Stub implementation.
*
@@ -4293,13 +4299,13 @@ private function step_in_template(): bool {
* Parses next element in the 'after body' insertion mode.
*
* This internal function performs the 'after body' insertion mode
- * logic for the generalized WP_HTML_Processor::step() function.
+ * logic for the generalized \WordPress\HTML\WP_HTML_Processor::step() function.
*
* @return bool Whether an element was found.
* @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
*
* @see https://html.spec.whatwg.org/#parsing-main-afterbody
- * @see WP_HTML_Processor::step
+ * @see \WordPress\HTML\WP_HTML_Processor::step
*
* @since 6.7.0 Stub implementation.
*
@@ -4377,13 +4383,13 @@ private function step_after_body(): bool {
* Parses next element in the 'in frameset' insertion mode.
*
* This internal function performs the 'in frameset' insertion mode
- * logic for the generalized WP_HTML_Processor::step() function.
+ * logic for the generalized \WordPress\HTML\WP_HTML_Processor::step() function.
*
* @return bool Whether an element was found.
* @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
*
* @see https://html.spec.whatwg.org/#parsing-main-inframeset
- * @see WP_HTML_Processor::step
+ * @see \WordPress\HTML\WP_HTML_Processor::step
*
* @since 6.7.0 Stub implementation.
*
@@ -4499,13 +4505,13 @@ private function step_in_frameset(): bool {
* Parses next element in the 'after frameset' insertion mode.
*
* This internal function performs the 'after frameset' insertion mode
- * logic for the generalized WP_HTML_Processor::step() function.
+ * logic for the generalized \WordPress\HTML\WP_HTML_Processor::step() function.
*
* @return bool Whether an element was found.
* @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
*
* @see https://html.spec.whatwg.org/#parsing-main-afterframeset
- * @see WP_HTML_Processor::step
+ * @see \WordPress\HTML\WP_HTML_Processor::step
*
* @since 6.7.0 Stub implementation.
*
@@ -4579,13 +4585,13 @@ private function step_after_frameset(): bool {
* Parses next element in the 'after after body' insertion mode.
*
* This internal function performs the 'after after body' insertion mode
- * logic for the generalized WP_HTML_Processor::step() function.
+ * logic for the generalized \WordPress\HTML\WP_HTML_Processor::step() function.
*
* @return bool Whether an element was found.
* @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
*
* @see https://html.spec.whatwg.org/#the-after-after-body-insertion-mode
- * @see WP_HTML_Processor::step
+ * @see \WordPress\HTML\WP_HTML_Processor::step
*
* @since 6.7.0 Stub implementation.
*
@@ -4643,13 +4649,13 @@ private function step_after_after_body(): bool {
* Parses next element in the 'after after frameset' insertion mode.
*
* This internal function performs the 'after after frameset' insertion mode
- * logic for the generalized WP_HTML_Processor::step() function.
+ * logic for the generalized \WordPress\HTML\WP_HTML_Processor::step() function.
*
* @return bool Whether an element was found.
* @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
*
* @see https://html.spec.whatwg.org/#the-after-after-frameset-insertion-mode
- * @see WP_HTML_Processor::step
+ * @see \WordPress\HTML\WP_HTML_Processor::step
*
* @since 6.7.0 Stub implementation.
*
@@ -4711,13 +4717,13 @@ private function step_after_after_frameset(): bool {
* Parses next element in the 'in foreign content' insertion mode.
*
* This internal function performs the 'in foreign content' insertion mode
- * logic for the generalized WP_HTML_Processor::step() function.
+ * logic for the generalized \WordPress\HTML\WP_HTML_Processor::step() function.
*
* @return bool Whether an element was found.
* @throws WP_HTML_Unsupported_Exception When encountering unsupported HTML input.
*
* @see https://html.spec.whatwg.org/#parsing-main-inforeign
- * @see WP_HTML_Processor::step
+ * @see \WordPress\HTML\WP_HTML_Processor::step
*
* @since 6.7.0 Stub implementation.
*
@@ -5212,7 +5218,7 @@ public function get_token_type(): ?string {
*
* Example:
*
- * $p = WP_HTML_Processor::create_fragment( 'Test
' );
+ * $p = \WordPress\HTML\WP_HTML_Processor::create_fragment( 'Test
' );
* $p->next_token() === true;
* $p->get_attribute( 'data-test-id' ) === '14';
* $p->get_attribute( 'enabled' ) === true;
@@ -5345,7 +5351,7 @@ public function has_class( $wanted_class ): ?bool {
*
* Example:
*
- * $p = WP_HTML_Processor::create_fragment( "" );
+ * $p = \WordPress\HTML\WP_HTML_Processor::create_fragment( "
" );
* $p->next_tag();
* foreach ( $p->class_list() as $class_name ) {
* echo "{$class_name} ";
@@ -5691,7 +5697,7 @@ private function generate_implied_end_tags( ?string $except_for_this_element = n
* @since 6.4.0
* @since 6.7.0 Full spec support.
*
- * @see WP_HTML_Processor::generate_implied_end_tags
+ * @see \WordPress\HTML\WP_HTML_Processor::generate_implied_end_tags
* @see https://html.spec.whatwg.org/#generate-implied-end-tags
*/
private function generate_implied_end_tags_thoroughly(): void {
@@ -6567,5 +6573,5 @@ protected static function get_encoding( string $label ): ?string {
*
* @access private
*/
- const CONSTRUCTOR_UNLOCK_CODE = 'Use WP_HTML_Processor::create_fragment() instead of calling the class constructor directly.';
+ const CONSTRUCTOR_UNLOCK_CODE = 'Use \WordPress\HTML\WP_HTML_Processor::create_fragment() instead of calling the class constructor directly.';
}
diff --git a/components/HTML/class-wp-html-span.php b/components/HTML/class-wp-html-span.php
index 44fefe82..64678a8d 100644
--- a/components/HTML/class-wp-html-span.php
+++ b/components/HTML/class-wp-html-span.php
@@ -1,4 +1,6 @@
start;
* $length = $attributes['src']->length;
- * $modifications[] = new WP_HTML_Text_Replacement( $start, $length, $new_value );
+ * $modifications[] = new \WordPress\HTML\WP_HTML_Text_Replacement( $start, $length, $new_value );
*
* // Correspondingly, something like this will appear in this array.
* $lexical_updates = array(
@@ -3725,7 +3734,7 @@ public function get_modifiable_text(): string {
*/
public function set_modifiable_text( string $plaintext_content ): bool {
if ( self::STATE_TEXT_NODE === $this->parser_state ) {
- $this->lexical_updates['modifiable text'] = new WP_HTML_Text_Replacement(
+ $this->lexical_updates['modifiable text'] = new \WordPress\HTML\WP_HTML_Text_Replacement(
$this->text_starts_at,
$this->text_length,
htmlspecialchars( $plaintext_content, ENT_QUOTES | ENT_HTML5 )
@@ -3744,7 +3753,7 @@ public function set_modifiable_text( string $plaintext_content ): bool {
return false;
}
- $this->lexical_updates['modifiable text'] = new WP_HTML_Text_Replacement(
+ $this->lexical_updates['modifiable text'] = new \WordPress\HTML\WP_HTML_Text_Replacement(
$this->text_starts_at,
$this->text_length,
$plaintext_content
@@ -3773,7 +3782,7 @@ public function set_modifiable_text( string $plaintext_content ): bool {
return false;
}
- $this->lexical_updates['modifiable text'] = new WP_HTML_Text_Replacement(
+ $this->lexical_updates['modifiable text'] = new \WordPress\HTML\WP_HTML_Text_Replacement(
$this->text_starts_at,
$this->text_length,
$plaintext_content
@@ -3790,7 +3799,7 @@ static function ( $tag_match ) {
$plaintext_content
);
- $this->lexical_updates['modifiable text'] = new WP_HTML_Text_Replacement(
+ $this->lexical_updates['modifiable text'] = new \WordPress\HTML\WP_HTML_Text_Replacement(
$this->text_starts_at,
$this->text_length,
$plaintext_content
@@ -3816,7 +3825,7 @@ static function ( $tag_match ) {
* @todo It would be useful to prefix a multiline replacement text
* with a newline, but not necessary. This is for aesthetics.
*/
- $this->lexical_updates['modifiable text'] = new WP_HTML_Text_Replacement(
+ $this->lexical_updates['modifiable text'] = new \WordPress\HTML\WP_HTML_Text_Replacement(
$this->text_starts_at,
$this->text_length,
$plaintext_content
@@ -3950,7 +3959,7 @@ public function set_attribute( $name, $value ): bool {
* Result:
*/
$existing_attribute = $this->attributes[ $comparable_name ];
- $this->lexical_updates[ $comparable_name ] = new WP_HTML_Text_Replacement(
+ $this->lexical_updates[ $comparable_name ] = new \WordPress\HTML\WP_HTML_Text_Replacement(
$existing_attribute->start,
$existing_attribute->length,
$updated_attribute
@@ -3968,7 +3977,7 @@ public function set_attribute( $name, $value ): bool {
*
* Result:
*/
- $this->lexical_updates[ $comparable_name ] = new WP_HTML_Text_Replacement(
+ $this->lexical_updates[ $comparable_name ] = new \WordPress\HTML\WP_HTML_Text_Replacement(
$this->tag_name_starts_at + $this->tag_name_length,
0,
' ' . $updated_attribute
@@ -4048,7 +4057,7 @@ public function remove_attribute( $name ): bool {
*
* Result:
*/
- $this->lexical_updates[ $name ] = new WP_HTML_Text_Replacement(
+ $this->lexical_updates[ $name ] = new \WordPress\HTML\WP_HTML_Text_Replacement(
$this->attributes[ $name ]->start,
$this->attributes[ $name ]->length,
''
@@ -4056,7 +4065,7 @@ public function remove_attribute( $name ): bool {
// Removes any duplicated attributes if they were also present.
foreach ( $this->duplicate_attributes[ $name ] ?? array() as $attribute_token ) {
- $this->lexical_updates[] = new WP_HTML_Text_Replacement(
+ $this->lexical_updates[] = new \WordPress\HTML\WP_HTML_Text_Replacement(
$attribute_token->start,
$attribute_token->length,
''
diff --git a/components/HTML/class-wp-html-text-replacement.php b/components/HTML/class-wp-html-text-replacement.php
index e94d271e..0a19ee00 100644
--- a/components/HTML/class-wp-html-text-replacement.php
+++ b/components/HTML/class-wp-html-text-replacement.php
@@ -1,4 +1,6 @@
=7.2"
},
"autoload": {
+ "psr-4": {
+ "WordPress\\HTML\\": "."
+ },
"classmap": [
"./"
],
diff --git a/components/HTML/html5-named-character-references.php b/components/HTML/html5-named-character-references.php
index 53b773d6..cf26c6e6 100644
--- a/components/HTML/html5-named-character-references.php
+++ b/components/HTML/html5-named-character-references.php
@@ -1,5 +1,7 @@
serialize();
$serialized = trim(
str_replace(
diff --git a/components/Merge/Validate/BlockMarkupMergeValidator.php b/components/Merge/Validate/BlockMarkupMergeValidator.php
index ca17be17..9ff62238 100644
--- a/components/Merge/Validate/BlockMarkupMergeValidator.php
+++ b/components/Merge/Validate/BlockMarkupMergeValidator.php
@@ -4,7 +4,7 @@
use ReflectionClass;
use WordPress\DataLiberation\BlockMarkup\BlockMarkupProcessor;
-use WP_HTML_Processor;
+use WordPress\HTML\WP_HTML_Processor;
class BlockMarkupMergeValidator implements MergeValidator {
@@ -55,7 +55,7 @@ public function validate( $html ) {
private function assert_html_is_structurally_sound( $html ) {
$html .= '
';
- $html_processor = WP_HTML_Processor::create_fragment( $html );
+ $html_processor = \WordPress\HTML\WP_HTML_Processor::create_fragment( $html );
/**
* Make the is_virtual() method public to enable deeper inspection.
diff --git a/components/Polyfill/wordpress.php b/components/Polyfill/wordpress.php
index 5bc8773c..7084c089 100644
--- a/components/Polyfill/wordpress.php
+++ b/components/Polyfill/wordpress.php
@@ -2,7 +2,10 @@
/**
* Polyfills WordPress core functions for running in non-WordPress environments
*/
+namespace WordPress\Polyfill;
+// This may be loaded twice if Polyfills are included before WordPress, but that's fine.
+// There are no function declarations in that file, only a global variable.
if (
! isset( $html5_named_character_references ) &&
file_exists( __DIR__ . '/../HTML/html5-named-character-references.php' )
@@ -10,213 +13,233 @@
require_once __DIR__ . '/../HTML/html5-named-character-references.php';
}
+// @TODO: Wrap in namespaces before merging:
if ( ! class_exists( 'WP_Block_Parser' ) ) {
require_once __DIR__ . '/../BlockParser/class-wp-block-parser-block.php';
require_once __DIR__ . '/../BlockParser/class-wp-block-parser-frame.php';
require_once __DIR__ . '/../BlockParser/class-wp-block-parser.php';
}
-if ( ! function_exists( '_doing_it_wrong' ) ) {
- $GLOBALS['_doing_it_wrong_messages'] = array();
- function _doing_it_wrong( $method, $message, $version ) {
- $GLOBALS['_doing_it_wrong_messages'][] = $message;
+$GLOBALS['_doing_it_wrong_messages'] = array();
+function _doing_it_wrong( $method, $message, $version ) {
+ if ( function_exists( '\\_doing_it_wrong' ) ) {
+ return call_user_func_array( '\\_doing_it_wrong', func_get_args() );
}
+ $GLOBALS['_doing_it_wrong_messages'][] = $message;
}
-if ( ! class_exists( 'WP_Exception' ) ) {
- class WP_Exception extends Exception {
+function wp_trigger_error( $function_name, $message, $error_level = E_USER_NOTICE ) {
+ if ( function_exists( '\\wp_trigger_error' ) ) {
+ return call_user_func_array( '\\wp_trigger_error', func_get_args() );
}
-}
-if ( ! function_exists( 'wp_trigger_error' ) ) {
- function wp_trigger_error( $function_name, $message, $error_level = E_USER_NOTICE ) {
- if ( ! empty( $function_name ) ) {
- $message = sprintf( '%s(): %s', $function_name, $message );
- }
+ if ( ! empty( $function_name ) ) {
+ $message = sprintf( '%s(): %s', $function_name, $message );
+ }
- if ( E_USER_ERROR === $error_level ) {
- throw new WP_Exception( $message );
+ if ( E_USER_ERROR === $error_level ) {
+ if ( ! class_exists( '\WP_Exception' ) ) {
+ class WP_Exception extends \Exception {
+ }
}
-
- trigger_error( $message, $error_level );
+ throw new WP_Exception( $message );
}
+
+ trigger_error( $message, $error_level );
}
-if ( ! function_exists( 'wp_kses_uri_attributes' ) ) {
- function wp_kses_uri_attributes() {
- return array();
+function wp_kses_uri_attributes() {
+ if ( function_exists( '\\wp_kses_uri_attributes' ) ) {
+ return call_user_func_array( '\\wp_kses_uri_attributes', func_get_args() );
}
+ return array();
}
-if ( ! function_exists( '__' ) ) {
- function __( $input ) {
- return $input;
+function __( $input ) {
+ if ( function_exists( '\\__' ) ) {
+ return call_user_func_array( '\\__', func_get_args() );
}
+ return $input;
}
-if ( ! function_exists( 'esc_attr' ) ) {
- function esc_attr( $input ) {
- return htmlspecialchars( $input );
+function esc_attr( $input ) {
+ if ( function_exists( '\\esc_attr' ) ) {
+ return call_user_func_array( '\\esc_attr', func_get_args() );
}
+ return htmlspecialchars( $input );
}
-if ( ! function_exists( 'esc_html' ) ) {
- function esc_html( $input ) {
- return htmlspecialchars( $input );
+function esc_html( $input ) {
+ if ( function_exists( '\\esc_html' ) ) {
+ return call_user_func_array( '\\esc_html', func_get_args() );
}
+ return htmlspecialchars( $input );
}
-if ( ! function_exists( 'esc_url' ) ) {
- function esc_url( $url ) {
- return htmlspecialchars( $url );
+function esc_url( $url ) {
+ if ( function_exists( '\\esc_url' ) ) {
+ return call_user_func_array( '\\esc_url', func_get_args() );
}
+ return htmlspecialchars( $url );
}
-if ( ! function_exists( 'add_filter' ) ) {
- function add_filter( $hook_name, $callback, $priority = 10, $accepted_args = 1 ) {
- global $wp_filter;
- if ( ! isset( $wp_filter ) ) {
- $wp_filter = array();
- }
- if ( ! isset( $wp_filter[ $hook_name ] ) ) {
- $wp_filter[ $hook_name ] = array();
- }
- if ( ! isset( $wp_filter[ $hook_name ][ $priority ] ) ) {
- $wp_filter[ $hook_name ][ $priority ] = array();
- }
- $wp_filter[ $hook_name ][ $priority ][] = array(
- 'function' => $callback,
- 'accepted_args' => $accepted_args,
- );
+function add_filter( $hook_name, $callback, $priority = 10, $accepted_args = 1 ) {
+ global $wp_filter;
+ if ( function_exists( '\\add_filter' ) ) {
+ return call_user_func_array( '\\add_filter', func_get_args() );
+ }
- return true;
+ if ( ! isset( $wp_filter ) ) {
+ $wp_filter = array();
+ }
+ if ( ! isset( $wp_filter[ $hook_name ] ) ) {
+ $wp_filter[ $hook_name ] = array();
+ }
+ if ( ! isset( $wp_filter[ $hook_name ][ $priority ] ) ) {
+ $wp_filter[ $hook_name ][ $priority ] = array();
}
+ $wp_filter[ $hook_name ][ $priority ][] = array(
+ 'function' => $callback,
+ 'accepted_args' => $accepted_args,
+ );
+
+ return true;
}
-if ( ! function_exists( 'add_action' ) ) {
- function add_action( $hook_name, $callback, $priority = 10, $accepted_args = 1 ) {
- return add_filter( $hook_name, $callback, $priority, $accepted_args );
+function add_action( $hook_name, $callback, $priority = 10, $accepted_args = 1 ) {
+ if ( function_exists( '\\add_action' ) ) {
+ return call_user_func_array( '\\add_action', func_get_args() );
}
+ return add_filter( $hook_name, $callback, $priority, $accepted_args );
}
-if ( ! function_exists( 'apply_filters' ) ) {
- function apply_filters( $hook_name, $value ) {
- global $wp_filter;
- if ( ! isset( $wp_filter[ $hook_name ] ) ) {
- return $value;
- }
- $args = func_get_args();
- array_shift( $args ); // Remove hook name
-
- ksort( $wp_filter[ $hook_name ] );
- foreach ( $wp_filter[ $hook_name ] as $priority => $functions ) {
- foreach ( $functions as $function ) {
- $args[0] = $value;
- $value = call_user_func_array( $function['function'], array_slice( $args, 0, $function['accepted_args'] ) );
- }
- }
+function apply_filters( $hook_name, $value ) {
+ global $wp_filter;
+ if ( function_exists( '\\apply_filters' ) ) {
+ return call_user_func_array( '\\apply_filters', func_get_args() );
+ }
+ if ( ! isset( $wp_filter[ $hook_name ] ) ) {
return $value;
}
-}
+ $args = func_get_args();
+ array_shift( $args ); // Remove hook name
-if ( ! function_exists( 'do_action' ) ) {
- function do_action( $hook_name ) {
- global $wp_filter;
- if ( ! isset( $wp_filter[ $hook_name ] ) ) {
- return;
- }
- $args = func_get_args();
- array_shift( $args ); // Remove hook name
-
- ksort( $wp_filter[ $hook_name ] );
- foreach ( $wp_filter[ $hook_name ] as $priority => $functions ) {
- foreach ( $functions as $function ) {
- call_user_func_array( $function['function'], array_slice( $args, 0, $function['accepted_args'] ) );
- }
+ ksort( $wp_filter[ $hook_name ] );
+ foreach ( $wp_filter[ $hook_name ] as $priority => $functions ) {
+ foreach ( $functions as $function ) {
+ $args[0] = $value;
+ $value = call_user_func_array( $function['function'], array_slice( $args, 0, $function['accepted_args'] ) );
}
}
+
+ return $value;
}
-if ( ! function_exists( 'parse_blocks' ) ) {
- function parse_blocks( $input ) {
- $parser = new WP_Block_Parser();
+function do_action( $hook_name ) {
+ global $wp_filter;
+ if ( function_exists( '\\do_action' ) ) {
+ return call_user_func_array( '\\do_action', func_get_args() );
+ }
- return $parser->parse( $input );
+ if ( ! isset( $wp_filter[ $hook_name ] ) ) {
+ return;
}
-}
+ $args = func_get_args();
+ array_shift( $args ); // Remove hook name
-if ( ! function_exists( 'serialize_blocks' ) ) {
- function serialize_blocks( $blocks ) {
- return implode( '', array_map( 'serialize_block', $blocks ) );
+ ksort( $wp_filter[ $hook_name ] );
+ foreach ( $wp_filter[ $hook_name ] as $priority => $functions ) {
+ foreach ( $functions as $function ) {
+ call_user_func_array( $function['function'], array_slice( $args, 0, $function['accepted_args'] ) );
+ }
}
}
-if ( ! function_exists( 'serialize_block' ) ) {
- function serialize_block( $block ) {
- $block_content = '';
-
- $index = 0;
- foreach ( $block['innerContent'] as $chunk ) {
- $block_content .= is_string( $chunk ) ? $chunk : serialize_block( $block['innerBlocks'][ $index ++ ] );
- }
+function parse_blocks( $input ) {
+ if ( function_exists( '\\parse_blocks' ) ) {
+ return call_user_func_array( '\\parse_blocks', func_get_args() );
+ }
+ $parser = new \WordPress\BlockParser\WP_Block_Parser();
- if ( ! is_array( $block['attrs'] ) ) {
- $block['attrs'] = array();
- }
+ return $parser->parse( $input );
+}
- return get_comment_delimited_block_content(
- $block['blockName'],
- $block['attrs'],
- $block_content
- );
+function serialize_blocks( $blocks ) {
+ if ( function_exists( '\\serialize_blocks' ) ) {
+ return call_user_func_array( '\\serialize_blocks', func_get_args() );
}
+ return implode( '', array_map( 'serialize_block', $blocks ) );
}
-if ( ! function_exists( 'get_comment_delimited_block_content' ) ) {
- function get_comment_delimited_block_content( $block_name, $block_attributes, $block_content ) {
- if ( is_null( $block_name ) ) {
- return $block_content;
- }
-
- $serialized_block_name = strip_core_block_namespace( $block_name );
- $serialized_attributes = empty( $block_attributes ) ? '' : serialize_block_attributes( $block_attributes ) . ' ';
+function serialize_block( $block ) {
+ if ( function_exists( '\\serialize_block' ) ) {
+ return call_user_func_array( '\\serialize_block', func_get_args() );
+ }
+ $block_content = '';
- if ( empty( $block_content ) ) {
- return sprintf( '', $serialized_block_name, $serialized_attributes );
- }
+ $index = 0;
+ foreach ( $block['innerContent'] as $chunk ) {
+ $block_content .= is_string( $chunk ) ? $chunk : serialize_block( $block['innerBlocks'][ $index ++ ] );
+ }
- return sprintf(
- '%s',
- $serialized_block_name,
- $serialized_attributes,
- $block_content,
- $serialized_block_name
- );
+ if ( ! is_array( $block['attrs'] ) ) {
+ $block['attrs'] = array();
}
+
+ return get_comment_delimited_block_content(
+ $block['blockName'],
+ $block['attrs'],
+ $block_content
+ );
}
-if ( ! function_exists( 'strip_core_block_namespace' ) ) {
- function strip_core_block_namespace( $block_name = null ) {
- if ( is_string( $block_name ) && strncmp( $block_name, 'core/', strlen( 'core/' ) ) === 0 ) {
- return substr( $block_name, 5 );
- }
+function get_comment_delimited_block_content( $block_name, $block_attributes, $block_content ) {
+ if ( function_exists( '\\get_comment_delimited_block_content' ) ) {
+ return call_user_func_array( '\\get_comment_delimited_block_content', func_get_args() );
+ }
+ if ( is_null( $block_name ) ) {
+ return $block_content;
+ }
+
+ $serialized_block_name = strip_core_block_namespace( $block_name );
+ $serialized_attributes = empty( $block_attributes ) ? '' : serialize_block_attributes( $block_attributes ) . ' ';
- return $block_name;
+ if ( empty( $block_content ) ) {
+ return sprintf( '', $serialized_block_name, $serialized_attributes );
}
+
+ return sprintf(
+ '%s',
+ $serialized_block_name,
+ $serialized_attributes,
+ $block_content,
+ $serialized_block_name
+ );
}
+function strip_core_block_namespace( $block_name = null ) {
+ if ( function_exists( '\\strip_core_block_namespace' ) ) {
+ return call_user_func_array( '\\strip_core_block_namespace', func_get_args() );
+ }
+ if ( is_string( $block_name ) && strncmp( $block_name, 'core/', strlen( 'core/' ) ) === 0 ) {
+ return substr( $block_name, 5 );
+ }
-if ( ! function_exists( 'serialize_block_attributes' ) ) {
- function serialize_block_attributes( $block_attributes ) {
- $encoded_attributes = json_encode( $block_attributes, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
- $encoded_attributes = preg_replace( '/--/', '\\u002d\\u002d', $encoded_attributes );
- $encoded_attributes = preg_replace( '/', '\\u003c', $encoded_attributes );
- $encoded_attributes = preg_replace( '/>/', '\\u003e', $encoded_attributes );
- $encoded_attributes = preg_replace( '/&/', '\\u0026', $encoded_attributes );
- // Regex: /\\"/
- $encoded_attributes = preg_replace( '/\\\\"/', '\\u0022', $encoded_attributes );
+ return $block_name;
+}
- return $encoded_attributes;
+function serialize_block_attributes( $block_attributes ) {
+ if ( function_exists( '\\serialize_block_attributes' ) ) {
+ return call_user_func_array( '\\serialize_block_attributes', func_get_args() );
}
+ $encoded_attributes = json_encode( $block_attributes, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
+ $encoded_attributes = preg_replace( '/--/', '\\u002d\\u002d', $encoded_attributes );
+ $encoded_attributes = preg_replace( '/', '\\u003c', $encoded_attributes );
+ $encoded_attributes = preg_replace( '/>/', '\\u003e', $encoded_attributes );
+ $encoded_attributes = preg_replace( '/&/', '\\u0026', $encoded_attributes );
+ // Regex: /\\"/
+ $encoded_attributes = preg_replace( '/\\\\"/', '\\u0022', $encoded_attributes );
+
+ return $encoded_attributes;
}
diff --git a/components/XML/Tests/XMLProcessorTest.php b/components/XML/Tests/XMLProcessorTest.php
index cf20183e..3b00ca2d 100644
--- a/components/XML/Tests/XMLProcessorTest.php
+++ b/components/XML/Tests/XMLProcessorTest.php
@@ -1486,7 +1486,7 @@ public function __construct( $xml ) {
*/
public function insert_after( $new_xml ) {
$this->set_bookmark( 'here' );
- $this->lexical_updates[] = new WP_HTML_Text_Replacement(
+ $this->lexical_updates[] = new \WordPress\HTML\WP_HTML_Text_Replacement(
$this->bookmarks['here']->start + $this->bookmarks['here']->length,
0,
$new_xml
diff --git a/components/XML/XMLDecoder.php b/components/XML/XMLDecoder.php
index a68f7bdf..524b28b8 100644
--- a/components/XML/XMLDecoder.php
+++ b/components/XML/XMLDecoder.php
@@ -2,7 +2,7 @@
namespace WordPress\XML;
-use WP_HTML_Decoder;
+use WordPress\HTML\WP_HTML_Decoder;
/**
* XML API: WP_XML_Decoder class
diff --git a/components/XML/XMLProcessor.php b/components/XML/XMLProcessor.php
index 3f70f707..639a8165 100644
--- a/components/XML/XMLProcessor.php
+++ b/components/XML/XMLProcessor.php
@@ -2,10 +2,12 @@
namespace WordPress\XML;
-use WP_HTML_Span;
-use WP_HTML_Text_Replacement;
+use WordPress\HTML\WP_HTML_Span;
+use WordPress\HTML\WP_HTML_Text_Replacement;
use function WordPress\Encoding\utf8_codepoint_at;
+use function WordPress\Polyfill\_doing_it_wrong;
+use function WordPress\Polyfill\__;
/**
* XML API: XMLProcessor class
@@ -624,7 +626,7 @@ class XMLProcessor {
* // sourced from the lazily-parsed XML recognizer.
* $start = $attributes['src']->start;
* $length = $attributes['src']->length;
- * $modifications[] = new WP_HTML_Text_Replacement( $start, $length, $new_value );
+ * $modifications[] = new \WordPress\HTML\WP_HTML_Text_Replacement( $start, $length, $new_value );
*
* // Correspondingly, something like this will appear in this array.
* $lexical_updates = array(
@@ -3491,7 +3493,7 @@ public function set_modifiable_text( $new_value ) {
switch ( $this->parser_state ) {
case self::STATE_TEXT_NODE:
case self::STATE_COMMENT:
- $this->lexical_updates[] = new WP_HTML_Text_Replacement(
+ $this->lexical_updates[] = new \WordPress\HTML\WP_HTML_Text_Replacement(
$this->text_starts_at,
$this->text_length,
// @TODO: Audit this in details. Is this too naive? Or is it actually safe?
@@ -3501,7 +3503,7 @@ public function set_modifiable_text( $new_value ) {
return true;
case self::STATE_CDATA_NODE:
- $this->lexical_updates[] = new WP_HTML_Text_Replacement(
+ $this->lexical_updates[] = new \WordPress\HTML\WP_HTML_Text_Replacement(
$this->text_starts_at,
$this->text_length,
// @TODO: Audit this in details. Is this too naive? Or is it actually safe?
@@ -3598,7 +3600,7 @@ public function set_attribute( $namespace, $local_name, $value ) {
* Result:
*/
$existing_attribute = $this->attributes[ $name ];
- $this->lexical_updates[ $name ] = new WP_HTML_Text_Replacement(
+ $this->lexical_updates[ $name ] = new \WordPress\HTML\WP_HTML_Text_Replacement(
$existing_attribute->start,
$existing_attribute->length,
$updated_attribute
@@ -3616,7 +3618,7 @@ public function set_attribute( $namespace, $local_name, $value ) {
*
* Result:
*/
- $this->lexical_updates[ $name ] = new WP_HTML_Text_Replacement(
+ $this->lexical_updates[ $name ] = new \WordPress\HTML\WP_HTML_Text_Replacement(
$this->tag_name_starts_at + $this->tag_name_length,
0,
' ' . $updated_attribute
@@ -3673,7 +3675,7 @@ public function remove_attribute( $namespace, $local_name ) {
*
* Result:
*/
- $this->lexical_updates[ $name ] = new WP_HTML_Text_Replacement(
+ $this->lexical_updates[ $name ] = new \WordPress\HTML\WP_HTML_Text_Replacement(
$this->attributes[ $name ]->start,
$this->attributes[ $name ]->length,
''
@@ -4474,5 +4476,5 @@ private function bail( string $message, $reason = self::ERROR_UNSUPPORTED ) {
*
* @access private
*/
- const CONSTRUCTOR_UNLOCK_CODE = 'Use WP_HTML_Processor::create_fragment() instead of calling the class constructor directly.';
+ const CONSTRUCTOR_UNLOCK_CODE = 'Use \WordPress\HTML\WP_HTML_Processor::create_fragment() instead of calling the class constructor directly.';
}
diff --git a/composer.json b/composer.json
index 51f88cf0..c87ad316 100644
--- a/composer.json
+++ b/composer.json
@@ -69,7 +69,9 @@
"WordPress\\Zip\\": "components/Zip/",
"WordPress\\HttpServer\\": "components/HttpServer/",
"WordPress\\CORSProxy\\": "components/CORSProxy/",
- "WordPress\\Git\\": "components/Git/"
+ "WordPress\\Git\\": "components/Git/",
+ "WordPress\\HTML\\": "components/HTML/",
+ "WordPress\\BlockParser\\": "components/BlockParser/"
}
},
"scripts": {
diff --git a/examples/create-wp-site/import-markdown-directory.php b/examples/create-wp-site/import-markdown-directory.php
index 348737a2..27c6f805 100644
--- a/examples/create-wp-site/import-markdown-directory.php
+++ b/examples/create-wp-site/import-markdown-directory.php
@@ -19,6 +19,8 @@
use function WordPress\DataLiberation\URL\is_child_url_of;
use function WordPress\Filesystem\wp_join_unix_paths;
+use function WordPress\Polyfill\add_action;
+use function WordPress\Polyfill\add_filter;
if ( file_exists( '/wordpress/wp-load.php' ) ) {
require_once '/wordpress/wp-load.php';
diff --git a/plugins/static-files-editor/plugin.php b/plugins/static-files-editor/plugin.php
index fc954dba..dfd713e5 100644
--- a/plugins/static-files-editor/plugin.php
+++ b/plugins/static-files-editor/plugin.php
@@ -1072,7 +1072,7 @@ private static function parse_local_file( $content, $format ) {
break;
case 'html':
$converter = new AnnotatedBlockMarkupConsumer(
- WP_HTML_Processor::create_fragment( $content )
+ \WordPress\HTML\WP_HTML_Processor::create_fragment( $content )
);
break;
case 'md':