From b92481faf391edb221f2aba7590287d36251dab1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Tue, 16 Sep 2025 11:50:15 +0200 Subject: [PATCH 1/2] Remove WP Block parser error --- .../class-wp-block-parser-error.php | 26 ------------------- .../class-blockmarkupprocessor.php | 24 ++++++++--------- 2 files changed, 12 insertions(+), 38 deletions(-) delete mode 100644 components/BlockParser/class-wp-block-parser-error.php diff --git a/components/BlockParser/class-wp-block-parser-error.php b/components/BlockParser/class-wp-block-parser-error.php deleted file mode 100644 index a1da89d42..000000000 --- a/components/BlockParser/class-wp-block-parser-error.php +++ /dev/null @@ -1,26 +0,0 @@ -type = $type; - parent::__construct( $message, 0, $previous ); - } - - public function get_type() { - return $this->type; - } -} diff --git a/components/DataLiberation/BlockMarkup/class-blockmarkupprocessor.php b/components/DataLiberation/BlockMarkup/class-blockmarkupprocessor.php index d882af4ac..d65d236bd 100644 --- a/components/DataLiberation/BlockMarkup/class-blockmarkupprocessor.php +++ b/components/DataLiberation/BlockMarkup/class-blockmarkupprocessor.php @@ -2,7 +2,7 @@ namespace WordPress\DataLiberation\BlockMarkup; -use WP_Block_Parser_Error; +use WP_Error; use WP_HTML_Tag_Processor; /** @@ -113,9 +113,9 @@ public function get_token_type(): ?string { /** * Gets the most recent error encountered while parsing blocks * - * @return WP_Block_Parser_Error|null The error message or null if no error + * @return WP_Error|null The error message or null if no error */ - public function get_last_error(): ?WP_Block_Parser_Error { + public function get_last_error(): ?WP_Error { return $this->last_block_error; } @@ -362,9 +362,9 @@ public function next_token(): bool { $name_length = strspn( $text, 'abcdefghijklmnopqrstuwxvyzABCDEFGHIJKLMNOPRQSTUWXVYZ0123456789_-', $at ); if ( 0 === $name_length ) { // This wasn't a block after all, just a regular comment. - $this->last_block_error = new WP_Block_Parser_Error( - sprintf( 'An HTML comment started with "wp:" that was not followed by a valid block name: %s', $text ), - WP_Block_Parser_Error::TYPE_SUSPICIOUS_DELIMITER + $this->last_block_error = new WP_Error( + 'suspicious-delimiter', + sprintf( 'An HTML comment started with "wp:" that was not followed by a valid block name: %s', $text ) ); return true; @@ -404,9 +404,9 @@ public function next_token(): bool { if ( null === $attributes || ! is_array( $attributes ) ) { // This comment looked like a block comment, but the attributes didn't // parse as a JSON array. This means it wasn't a block after all. - $this->last_block_error = new WP_Block_Parser_Error( - sprintf( '%s could be parsed as a delimiter but JSON attributes were malformed: %s.', $name, $json_maybe ), - WP_Block_Parser_Error::TYPE_SUSPICIOUS_DELIMITER + $this->last_block_error = new WP_Error( + 'suspicious-delimiter', + sprintf( '%s could be parsed as a delimiter but JSON attributes were malformed: %s.', $name, $json_maybe ) ); return true; @@ -423,9 +423,9 @@ public function next_token(): bool { if ( $this->block_closer ) { $popped = array_pop( $this->stack_of_open_blocks ); if ( $popped !== $name ) { - $this->last_block_error = new WP_Block_Parser_Error( - sprintf( 'Block closer %s does not match the last opened block %s.', $name, $popped ), - WP_Block_Parser_Error::TYPE_MISMATCHED_CLOSER + $this->last_block_error = new WP_Error( + 'mismatched-closer', + sprintf( 'Block closer %s does not match the last opened block %s.', $name, $popped ) ); return false; From ab4457660315120f9122410e012e4f6c17223c3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Zieli=C5=84ski?= Date: Tue, 16 Sep 2025 11:57:28 +0200 Subject: [PATCH 2/2] Polyfill WP_Error --- components/Polyfill/wordpress.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/components/Polyfill/wordpress.php b/components/Polyfill/wordpress.php index 48878767f..5123942cb 100644 --- a/components/Polyfill/wordpress.php +++ b/components/Polyfill/wordpress.php @@ -12,6 +12,23 @@ require_once __DIR__ . '/../HTML/html5-named-character-references.php'; } +if ( ! class_exists( 'WP_Error' ) ) { + class WP_Error { + public $code; + public $message; + public $data; + + public function __construct( $code = '', $message = '', $data = '' ) { + if ( empty( $code ) ) { + return; + } + $this->code = $code; + $this->message = $message; + $this->data = $data; + } + } +} + 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';