Skip to content

Commit 15c86a8

Browse files
authored
Remove WP Block parser error (#187)
Removes the `WP_Block_Parser_Error` that is not a part of WordPress core and was invented in php-toolkit. Referencing it resulted in a crash in WordPress/wordpress-importer#207.
1 parent c417f2f commit 15c86a8

File tree

3 files changed

+29
-38
lines changed

3 files changed

+29
-38
lines changed

components/BlockParser/class-wp-block-parser-error.php

Lines changed: 0 additions & 26 deletions
This file was deleted.

components/DataLiberation/BlockMarkup/class-blockmarkupprocessor.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace WordPress\DataLiberation\BlockMarkup;
44

5-
use WP_Block_Parser_Error;
5+
use WP_Error;
66
use WP_HTML_Tag_Processor;
77

88
/**
@@ -113,9 +113,9 @@ public function get_token_type(): ?string {
113113
/**
114114
* Gets the most recent error encountered while parsing blocks
115115
*
116-
* @return WP_Block_Parser_Error|null The error message or null if no error
116+
* @return WP_Error|null The error message or null if no error
117117
*/
118-
public function get_last_error(): ?WP_Block_Parser_Error {
118+
public function get_last_error(): ?WP_Error {
119119
return $this->last_block_error;
120120
}
121121

@@ -362,9 +362,9 @@ public function next_token(): bool {
362362
$name_length = strspn( $text, 'abcdefghijklmnopqrstuwxvyzABCDEFGHIJKLMNOPRQSTUWXVYZ0123456789_-', $at );
363363
if ( 0 === $name_length ) {
364364
// This wasn't a block after all, just a regular comment.
365-
$this->last_block_error = new WP_Block_Parser_Error(
366-
sprintf( 'An HTML comment started with "wp:" that was not followed by a valid block name: %s', $text ),
367-
WP_Block_Parser_Error::TYPE_SUSPICIOUS_DELIMITER
365+
$this->last_block_error = new WP_Error(
366+
'suspicious-delimiter',
367+
sprintf( 'An HTML comment started with "wp:" that was not followed by a valid block name: %s', $text )
368368
);
369369

370370
return true;
@@ -404,9 +404,9 @@ public function next_token(): bool {
404404
if ( null === $attributes || ! is_array( $attributes ) ) {
405405
// This comment looked like a block comment, but the attributes didn't
406406
// parse as a JSON array. This means it wasn't a block after all.
407-
$this->last_block_error = new WP_Block_Parser_Error(
408-
sprintf( '%s could be parsed as a delimiter but JSON attributes were malformed: %s.', $name, $json_maybe ),
409-
WP_Block_Parser_Error::TYPE_SUSPICIOUS_DELIMITER
407+
$this->last_block_error = new WP_Error(
408+
'suspicious-delimiter',
409+
sprintf( '%s could be parsed as a delimiter but JSON attributes were malformed: %s.', $name, $json_maybe )
410410
);
411411

412412
return true;
@@ -423,9 +423,9 @@ public function next_token(): bool {
423423
if ( $this->block_closer ) {
424424
$popped = array_pop( $this->stack_of_open_blocks );
425425
if ( $popped !== $name ) {
426-
$this->last_block_error = new WP_Block_Parser_Error(
427-
sprintf( 'Block closer %s does not match the last opened block %s.', $name, $popped ),
428-
WP_Block_Parser_Error::TYPE_MISMATCHED_CLOSER
426+
$this->last_block_error = new WP_Error(
427+
'mismatched-closer',
428+
sprintf( 'Block closer %s does not match the last opened block %s.', $name, $popped )
429429
);
430430

431431
return false;

components/Polyfill/wordpress.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,23 @@
1212
require_once __DIR__ . '/../HTML/html5-named-character-references.php';
1313
}
1414

15+
if ( ! class_exists( 'WP_Error' ) ) {
16+
class WP_Error {
17+
public $code;
18+
public $message;
19+
public $data;
20+
21+
public function __construct( $code = '', $message = '', $data = '' ) {
22+
if ( empty( $code ) ) {
23+
return;
24+
}
25+
$this->code = $code;
26+
$this->message = $message;
27+
$this->data = $data;
28+
}
29+
}
30+
}
31+
1532
if ( ! class_exists( 'WP_Block_Parser' ) ) {
1633
require_once __DIR__ . '/../BlockParser/class-wp-block-parser-block.php';
1734
require_once __DIR__ . '/../BlockParser/class-wp-block-parser-frame.php';

0 commit comments

Comments
 (0)