From 5c80577eee70785f57091bf0f685358119507010 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Thu, 24 Jul 2025 12:59:51 +0200 Subject: [PATCH 1/2] Wrap polyfills in namespaces --- .../Steps/scripts/import-content.php | 1 + .../AnnotatedBlockMarkupConsumer.php | 2 + .../EntityReader/EPubEntityReader.php | 1 + .../EntityReader/WXREntityReader.php | 1 + .../Importer/AttachmentDownloader.php | 1 + .../Importer/EntityImporter.php | 4 + .../DataLiberation/Importer/ImportSession.php | 1 + .../Importer/StreamImporter.php | 3 + components/Git/GitRepository.php | 1 + components/HTML/class-wp-html-processor.php | 4 + .../HTML/class-wp-html-tag-processor.php | 7 + components/HTML/class-wp-token-map.php | 3 + .../HttpClient/Middleware/HttpMiddleware.php | 5 +- components/Markdown/MarkdownImporter.php | 2 + components/Markdown/MarkdownProducer.php | 4 +- components/Polyfill/wordpress.php | 303 ++++++++++-------- components/XML/XMLProcessor.php | 2 + .../import-markdown-directory.php | 2 + 18 files changed, 203 insertions(+), 144 deletions(-) diff --git a/components/Blueprints/Steps/scripts/import-content.php b/components/Blueprints/Steps/scripts/import-content.php index bdbe1f32..4a32b6e7 100644 --- a/components/Blueprints/Steps/scripts/import-content.php +++ b/components/Blueprints/Steps/scripts/import-content.php @@ -19,6 +19,7 @@ use WordPress\Zip\ZipFilesystem; use function WordPress\Filesystem\wp_join_unix_paths; +use function WordPress\Filesystem\add_filter; require_once getenv('DOCROOT') . '/wp-load.php'; require_once getenv('DOCROOT') . '/php-toolkit.phar'; diff --git a/components/DataLiberation/DataFormatConsumer/AnnotatedBlockMarkupConsumer.php b/components/DataLiberation/DataFormatConsumer/AnnotatedBlockMarkupConsumer.php index bb4862b9..6a03e23a 100644 --- a/components/DataLiberation/DataFormatConsumer/AnnotatedBlockMarkupConsumer.php +++ b/components/DataLiberation/DataFormatConsumer/AnnotatedBlockMarkupConsumer.php @@ -3,6 +3,8 @@ namespace WordPress\DataLiberation\DataFormatConsumer; use WP_HTML_Processor; +use function WordPress\Polyfill\parse_blocks; +use function WordPress\Polyfill\serialize_block; /** * Converts a metadata-annotated block markup into block markup+metadata pair. diff --git a/components/DataLiberation/EntityReader/EPubEntityReader.php b/components/DataLiberation/EntityReader/EPubEntityReader.php index 9f93d96e..7bfa47a6 100644 --- a/components/DataLiberation/EntityReader/EPubEntityReader.php +++ b/components/DataLiberation/EntityReader/EPubEntityReader.php @@ -8,6 +8,7 @@ use WordPress\XML\XMLProcessor; use function WordPress\Filesystem\wp_join_unix_paths; +use function WordPress\Polyfill\_doing_it_wrong; /** * https://www.w3.org/AudioVideo/ebook/ diff --git a/components/DataLiberation/EntityReader/WXREntityReader.php b/components/DataLiberation/EntityReader/WXREntityReader.php index 0d5d8622..2c5c51ed 100644 --- a/components/DataLiberation/EntityReader/WXREntityReader.php +++ b/components/DataLiberation/EntityReader/WXREntityReader.php @@ -6,6 +6,7 @@ use WordPress\DataLiberation\ImportEntity; use WordPress\XML\XMLProcessor; use WordPress\XML\XMLUnsupportedException; +use function WordPress\Polyfill\_doing_it_wrong; /** * Data Liberation API: WP_WXR_Entity_Reader class diff --git a/components/DataLiberation/Importer/AttachmentDownloader.php b/components/DataLiberation/Importer/AttachmentDownloader.php index 055f44bc..a4d18737 100644 --- a/components/DataLiberation/Importer/AttachmentDownloader.php +++ b/components/DataLiberation/Importer/AttachmentDownloader.php @@ -8,6 +8,7 @@ use WordPress\HttpClient\Request; use function WordPress\Filesystem\wp_join_unix_paths; +use function WordPress\Polyfill\_doing_it_wrong; class AttachmentDownloader { private $client; diff --git a/components/DataLiberation/Importer/EntityImporter.php b/components/DataLiberation/Importer/EntityImporter.php index 21d94b2d..d17548d2 100644 --- a/components/DataLiberation/Importer/EntityImporter.php +++ b/components/DataLiberation/Importer/EntityImporter.php @@ -24,6 +24,10 @@ use InvalidArgumentException; use WordPress\DataLiberation\DataLiberationException; use WordPress\DataLiberation\ImportEntity; +use function WordPress\Polyfill\_doing_it_wrong; +use function WordPress\Polyfill\__; +use function WordPress\Polyfill\apply_filters; +use function WordPress\Polyfill\do_action; class EntityImporter { diff --git a/components/DataLiberation/Importer/ImportSession.php b/components/DataLiberation/Importer/ImportSession.php index 8874e145..1d108c94 100644 --- a/components/DataLiberation/Importer/ImportSession.php +++ b/components/DataLiberation/Importer/ImportSession.php @@ -7,6 +7,7 @@ use function get_all_post_meta_flat; use function is_wp_error; +use function WordPress\Polyfill\_doing_it_wrong; /** * Manages import session data in the WordPress database. diff --git a/components/DataLiberation/Importer/StreamImporter.php b/components/DataLiberation/Importer/StreamImporter.php index cbf86b62..335645c3 100644 --- a/components/DataLiberation/Importer/StreamImporter.php +++ b/components/DataLiberation/Importer/StreamImporter.php @@ -11,6 +11,9 @@ use WordPress\HttpClient\ByteStream\RequestReadStream; use function WordPress\DataLiberation\URL\is_child_url_of; +use function WordPress\Polyfill\_doing_it_wrong; +use function WordPress\Polyfill\apply_filters; +use function WordPress\Polyfill\do_action; /** * Idea: diff --git a/components/Git/GitRepository.php b/components/Git/GitRepository.php index 3efb4b1d..273b716b 100644 --- a/components/Git/GitRepository.php +++ b/components/Git/GitRepository.php @@ -14,6 +14,7 @@ use function WordPress\Filesystem\wp_unix_dirname; use function WordPress\Filesystem\wp_join_unix_paths; use function WordPress\Filesystem\wp_unix_path_resolve_dots; +use function WordPress\Polyfill\_doing_it_wrong; class GitRepository { diff --git a/components/HTML/class-wp-html-processor.php b/components/HTML/class-wp-html-processor.php index e394c19a..2efe4a81 100644 --- a/components/HTML/class-wp-html-processor.php +++ b/components/HTML/class-wp-html-processor.php @@ -1,4 +1,8 @@ $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 \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( '//', '\\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( '//', '\\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/XMLProcessor.php b/components/XML/XMLProcessor.php index 3f70f707..c0c5c192 100644 --- a/components/XML/XMLProcessor.php +++ b/components/XML/XMLProcessor.php @@ -6,6 +6,8 @@ use 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 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'; From 127b288e2aa86f728e15f6271ee12d58f37967bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Thu, 24 Jul 2025 14:15:49 +0200 Subject: [PATCH 2/2] Namespace WP_* classes --- .../class-wp-block-parser-block.php | 1 + .../class-wp-block-parser-error.php | 3 + .../class-wp-block-parser-frame.php | 1 + .../BlockParser/class-wp-block-parser.php | 2 + .../BlockMarkup/BlockMarkupProcessor.php | 4 +- .../AnnotatedBlockMarkupConsumer.php | 4 +- .../MarkupProcessorConsumer.php | 4 +- .../AnnotatedBlockMarkupProducer.php | 2 +- .../DataLiberationHTMLProcessor.php | 4 +- .../EntityReader/FilesystemEntityReader.php | 4 +- .../Tests/FilesystemEntityReaderTest.php | 2 +- .../Tests/HTMLEntityReaderTest.php | 4 +- .../Tests/MarkupProcessorConsumerTest.php | 8 +- .../DataLiberation/URL/URLInTextProcessor.php | 4 +- components/Filesystem/Tests/FunctionsTest.php | 1 - ...ass-wp-html-active-formatting-elements.php | 2 + .../HTML/class-wp-html-attribute-token.php | 2 + components/HTML/class-wp-html-decoder.php | 2 + .../HTML/class-wp-html-doctype-info.php | 2 + .../HTML/class-wp-html-open-elements.php | 5 + .../HTML/class-wp-html-processor-state.php | 2 + components/HTML/class-wp-html-processor.php | 144 +++++++++--------- components/HTML/class-wp-html-span.php | 2 + components/HTML/class-wp-html-stack-event.php | 2 + .../HTML/class-wp-html-tag-processor.php | 22 +-- .../HTML/class-wp-html-text-replacement.php | 2 + components/HTML/class-wp-html-token.php | 8 +- .../class-wp-html-unsupported-exception.php | 4 + components/HTML/class-wp-token-map.php | 2 + components/HTML/composer.json | 3 + .../HTML/html5-named-character-references.php | 2 + components/Markdown/MarkdownConsumer.php | 2 +- .../Markdown/Tests/MarkdownConsumerTest.php | 2 +- .../Validate/BlockMarkupMergeValidator.php | 4 +- components/Polyfill/wordpress.php | 2 +- components/XML/Tests/XMLProcessorTest.php | 2 +- components/XML/XMLDecoder.php | 2 +- components/XML/XMLProcessor.php | 18 +-- composer.json | 4 +- plugins/static-files-editor/plugin.php | 2 +- 40 files changed, 170 insertions(+), 122 deletions(-) diff --git a/components/BlockParser/class-wp-block-parser-block.php b/components/BlockParser/class-wp-block-parser-block.php index b5be53a0..0399d3b9 100644 --- a/components/BlockParser/class-wp-block-parser-block.php +++ b/components/BlockParser/class-wp-block-parser-block.php @@ -1,4 +1,5 @@ original_html ) as $block ) { if ( $block['blockName'] === null ) { - $html_converter = new MarkupProcessorConsumer( WP_HTML_Processor::create_fragment( $block['innerHTML'] ) ); + $html_converter = new MarkupProcessorConsumer( \WordPress\HTML\WP_HTML_Processor::create_fragment( $block['innerHTML'] ) ); $result = $html_converter->consume(); $block_markup .= $result->get_block_markup() . "\n"; $metadata = array_merge( $metadata, $result->get_all_metadata() ); diff --git a/components/DataLiberation/DataFormatConsumer/MarkupProcessorConsumer.php b/components/DataLiberation/DataFormatConsumer/MarkupProcessorConsumer.php index 8073c8da..219e03fa 100644 --- a/components/DataLiberation/DataFormatConsumer/MarkupProcessorConsumer.php +++ b/components/DataLiberation/DataFormatConsumer/MarkupProcessorConsumer.php @@ -6,8 +6,8 @@ use WordPress\DataLiberation\DataLiberationException; use WordPress\DataLiberation\Importer\ImportUtils; use WordPress\XML\XMLProcessor; -use WP_HTML_Processor; -use WP_HTML_Tag_Processor; +use WordPress\HTML\WP_HTML_Processor; +use WordPress\HTML\WP_HTML_Tag_Processor; /** * Creates block markup from a WP_HTML_Processor or WP_XML_Processor instance. diff --git a/components/DataLiberation/DataFormatProducer/AnnotatedBlockMarkupProducer.php b/components/DataLiberation/DataFormatProducer/AnnotatedBlockMarkupProducer.php index b340b28f..90b6bca0 100644 --- a/components/DataLiberation/DataFormatProducer/AnnotatedBlockMarkupProducer.php +++ b/components/DataLiberation/DataFormatProducer/AnnotatedBlockMarkupProducer.php @@ -3,7 +3,7 @@ namespace WordPress\DataLiberation\DataFormatProducer; use WordPress\DataLiberation\DataFormatConsumer\BlocksWithMetadata; -use WP_HTML_Tag_Processor; +use WordPress\HTML\WP_HTML_Tag_Processor; /** * Turns Block Markup + Metadata into a metadata-annotated Block Markup. diff --git a/components/DataLiberation/DataLiberationHTMLProcessor.php b/components/DataLiberation/DataLiberationHTMLProcessor.php index 2b05376a..782b0da3 100644 --- a/components/DataLiberation/DataLiberationHTMLProcessor.php +++ b/components/DataLiberation/DataLiberationHTMLProcessor.php @@ -2,8 +2,8 @@ namespace WordPress\DataLiberation; -use WP_HTML_Processor; -use WP_HTML_Tag_Processor; +use WordPress\HTML\WP_HTML_Processor; +use WordPress\HTML\WP_HTML_Tag_Processor; class DataLiberationHTMLProcessor extends WP_HTML_Processor { diff --git a/components/DataLiberation/EntityReader/FilesystemEntityReader.php b/components/DataLiberation/EntityReader/FilesystemEntityReader.php index 7b175e0c..c00f5b57 100644 --- a/components/DataLiberation/EntityReader/FilesystemEntityReader.php +++ b/components/DataLiberation/EntityReader/FilesystemEntityReader.php @@ -12,7 +12,7 @@ use WordPress\Filesystem\Visitor\FilesystemVisitor; use WordPress\Markdown\MarkdownConsumer; use WordPress\XML\XMLProcessor; -use WP_HTML_Processor; +use WordPress\HTML\WP_HTML_Processor; use function WordPress\Filesystem\wp_join_unix_paths; @@ -277,7 +277,7 @@ public function next_entity(): bool { $result = $converter->consume(); break; case 'html': - $converter = new MarkupProcessorConsumer( WP_HTML_Processor::create_fragment( $content ) ); + $converter = new MarkupProcessorConsumer( \WordPress\HTML\WP_HTML_Processor::create_fragment( $content ) ); $result = $converter->consume(); break; default: diff --git a/components/DataLiberation/Tests/FilesystemEntityReaderTest.php b/components/DataLiberation/Tests/FilesystemEntityReaderTest.php index 0631acfb..b1edcc97 100644 --- a/components/DataLiberation/Tests/FilesystemEntityReaderTest.php +++ b/components/DataLiberation/Tests/FilesystemEntityReaderTest.php @@ -153,7 +153,7 @@ private function assertMarkupMatches( $markup, $expected ) { } private function normalize_markup( $markup ) { - return WP_HTML_Processor::create_fragment( + return \WordPress\HTML\WP_HTML_Processor::create_fragment( preg_replace( '/\s+/', ' ', trim( $markup ) ) )->serialize(); } diff --git a/components/DataLiberation/Tests/HTMLEntityReaderTest.php b/components/DataLiberation/Tests/HTMLEntityReaderTest.php index 71c2fefe..b1ad623d 100644 --- a/components/DataLiberation/Tests/HTMLEntityReaderTest.php +++ b/components/DataLiberation/Tests/HTMLEntityReaderTest.php @@ -15,7 +15,7 @@ public function test_entity_reader() {

It is our pleasure to announce that WordPress 6.8 was released

Last week, WordPress 6.8 was released.

HTML; - $html_processor = WP_HTML_Processor::create_fragment( $html ); + $html_processor = \WordPress\HTML\WP_HTML_Processor::create_fragment( $html ); $producer = new MarkupProcessorConsumer( $html_processor ); $blocks_with_meta = $producer->consume(); @@ -70,7 +70,7 @@ public function test_entity_reader() { } private function normalize_markup( $markup ) { - $processor = WP_HTML_Processor::create_fragment( $markup ); + $processor = \WordPress\HTML\WP_HTML_Processor::create_fragment( $markup ); $serialized = $processor->serialize(); return $serialized; diff --git a/components/DataLiberation/Tests/MarkupProcessorConsumerTest.php b/components/DataLiberation/Tests/MarkupProcessorConsumerTest.php index 348968ce..d0153ad2 100644 --- a/components/DataLiberation/Tests/MarkupProcessorConsumerTest.php +++ b/components/DataLiberation/Tests/MarkupProcessorConsumerTest.php @@ -18,7 +18,7 @@ public function test_metadata_extraction() {

WordPress 6.8 was released

Last week, WordPress 6.8 was released. This release includes a new default theme, a new block editor experience, and a new block library. It also includes a new block editor experience, and a new block library.

HTML; - $consumer = new MarkupProcessorConsumer( new WP_HTML_Processor( $html ) ); + $consumer = new MarkupProcessorConsumer( \WordPress\HTML\WP_HTML_Processor::create_fragment( $html ) ); $blocks_with_meta = $consumer->consume(); $metadata = $blocks_with_meta->get_all_metadata(); $expected_metadata = array( @@ -37,14 +37,14 @@ public function test_metadata_extraction() { * @dataProvider provider_test_conversion */ public function test_html_to_blocks_conversion( $html, $expected ) { - $consumer = new MarkupProcessorConsumer( new WP_HTML_Processor( $html ) ); + $consumer = new MarkupProcessorConsumer( \WordPress\HTML\WP_HTML_Processor::create_fragment( $html ) ); $blocks_with_meta = $consumer->consume(); $this->assertEquals( $this->normalize_markup( $expected ), $this->normalize_markup( $blocks_with_meta->get_block_markup() ) ); } private function normalize_markup( $markup ) { - $processor = WP_HTML_Processor::create_fragment( $markup ); + $processor = \WordPress\HTML\WP_HTML_Processor::create_fragment( $markup ); $serialized = $processor->serialize(); $serialized = trim( str_replace( @@ -137,7 +137,7 @@ public static function provider_test_conversion() { public function test_html_to_blocks_excerpt() { $this->markTestSkipped( 'Skipping this test because of outdated fixture.' ); - // $consumer = new MarkupProcessorConsumer( WP_HTML_Processor::create_fragment( $input ) ); + // $consumer = new MarkupProcessorConsumer( \WordPress\HTML\WP_HTML_Processor::create_fragment( $input ) ); // $blocks_with_meta = $consumer->consume(); // $blocks = $blocks_with_meta->get_block_markup(); diff --git a/components/DataLiberation/URL/URLInTextProcessor.php b/components/DataLiberation/URL/URLInTextProcessor.php index 3311cf07..76faaaea 100644 --- a/components/DataLiberation/URL/URLInTextProcessor.php +++ b/components/DataLiberation/URL/URLInTextProcessor.php @@ -3,7 +3,7 @@ namespace WordPress\DataLiberation\URL; use WordPress\DataLiberation\BlockMarkup\URL; -use WP_HTML_Text_Replacement; +use WordPress\HTML\WP_HTML_Text_Replacement; /** * Finds string fragments that look like URLs and allow replacing them. @@ -278,7 +278,7 @@ public function set_raw_url( $new_url ) { $new_url = substr( $new_url, strpos( $new_url, '://' ) + 3 ); } $this->raw_url = $new_url; - $this->lexical_updates[ $this->url_starts_at ] = new WP_HTML_Text_Replacement( + $this->lexical_updates[ $this->url_starts_at ] = new \WordPress\HTML\WP_HTML_Text_Replacement( $this->url_starts_at, $this->url_length, $new_url diff --git a/components/Filesystem/Tests/FunctionsTest.php b/components/Filesystem/Tests/FunctionsTest.php index 05431e97..1b0f9a81 100644 --- a/components/Filesystem/Tests/FunctionsTest.php +++ b/components/Filesystem/Tests/FunctionsTest.php @@ -4,7 +4,6 @@ use function WordPress\Filesystem\wp_join_unix_paths; use function WordPress\Filesystem\wp_unix_dirname; -use ValueError; class FunctionsTest extends TestCase { public function testBasicPathJoining() { diff --git a/components/HTML/class-wp-html-active-formatting-elements.php b/components/HTML/class-wp-html-active-formatting-elements.php index 317f4089..54bfa5b3 100644 --- a/components/HTML/class-wp-html-active-formatting-elements.php +++ b/components/HTML/class-wp-html-active-formatting-elements.php @@ -1,4 +1,6 @@ next_tag( array( 'breadcrumbs' => array( 'DIV', 'FIGURE', 'IMG' ) ) ) ) { * $processor->add_class( 'responsive-image' ); * } @@ -52,7 +54,7 @@ * * Breadcrumbs represent the stack of open elements from the root * of the document or fragment down to the currently-matched node, - * if one is currently selected. Call WP_HTML_Processor::get_breadcrumbs() + * if one is currently selected. Call \WordPress\HTML\WP_HTML_Processor::get_breadcrumbs() * to inspect the breadcrumbs for a matched tag. * * Breadcrumbs can specify nested HTML structure and are equivalent @@ -179,7 +181,7 @@ class WP_HTML_Processor extends WP_HTML_Tag_Processor { * * @since 6.4.0 * - * @see WP_HTML_Processor::$release_internal_bookmark_on_destruct + * @see \WordPress\HTML\WP_HTML_Processor::$release_internal_bookmark_on_destruct * * @var int */ @@ -373,7 +375,7 @@ public static function create_full_parser( $html, $known_definite_encoding = 'UT * * @since 6.4.0 * - * @see WP_HTML_Processor::create_fragment() + * @see \WordPress\HTML\WP_HTML_Processor::create_fragment() * */ public function __construct( $html, $use_the_static_create_methods_instead = null ) { @@ -383,9 +385,9 @@ public function __construct( $html, $use_the_static_create_methods_instead = nul _doing_it_wrong( __METHOD__, sprintf( - /* translators: %s: WP_HTML_Processor::create_fragment(). */ + /* translators: %s: \WordPress\HTML\WP_HTML_Processor::create_fragment(). */ __( 'Call %s to create an HTML Processor instead of calling the constructor directly.' ), - 'WP_HTML_Processor::create_fragment()' + '\WordPress\HTML\WP_HTML_Processor::create_fragment()' ), '6.4.0' ); @@ -481,9 +483,9 @@ private function bail( string $message ) { * * Example * - * $processor = WP_HTML_Processor::create_fragment( '