Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions components/BlockParser/class-wp-block-parser-error.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace WordPress\DataLiberation\BlockMarkup;

use WP_Block_Parser_Error;
use WP_Error;
use WP_HTML_Tag_Processor;

/**
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
17 changes: 17 additions & 0 deletions components/Polyfill/wordpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Loading