PluginProbe
Gutenberg / 16.2.0
Gutenberg v16.2.0
24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 All 403 releases
← All changes | packages/block-serialization-default-parser/class-wp-block-parser.php +17 -8 23.7.0 → 16.2.0 View file →
@@ -35,9 +35,9 @@
35 35 /**
36 36 * List of parsed blocks
37 37 *
38 38 * @since 5.0.0
39 - * @var array[]
39 + * @var WP_Block_Parser_Block[]
40 40 */
41 41 public $output;
42 42
43 43 /**
@@ -48,8 +48,16 @@
48 48 */
49 49 public $stack;
50 50
51 51 /**
52 + * Empty associative array, here due to PHP quirks
53 + *
54 + * @since 4.4.0
55 + * @var array empty associative array
56 + */
57 + public $empty_attrs;
58 +
59 + /**
52 60 * Parses a document and returns a list of block structures
53 61 *
54 62 * When encountering an invalid parse will return a best-effort
55 63 * parse. In contrast to the specification parser this does not
@@ -60,12 +68,13 @@
60 68 * @param string $document Input document being parsed.
61 69 * @return array[]
62 70 */
63 71 public function parse( $document ) {
64 - $this->document = $document;
65 - $this->offset = 0;
66 - $this->output = array();
67 - $this->stack = array();
72 + $this->document = $document;
73 + $this->offset = 0;
74 + $this->output = array();
75 + $this->stack = array();
76 + $this->empty_attrs = json_decode( '{}', true );
68 77
69 78 while ( $this->proceed() ) {
70 79 continue;
71 80 }
@@ -277,9 +286,9 @@
277 286 * are associative arrays. If we use `array()` we get a JSON `[]`
278 287 */
279 288 $attrs = $has_attrs
280 289 ? json_decode( $matches['attrs'][0], /* as-associative */ true )
281 - : array();
290 + : $this->empty_attrs;
282 291
283 292 /*
284 293 * This state isn't allowed
285 294 * This is an error
@@ -302,15 +311,15 @@
302 311 /**
303 312 * Returns a new block object for freeform HTML
304 313 *
305 314 * @internal
306 - * @since 5.0.0
315 + * @since 3.9.0
307 316 *
308 317 * @param string $inner_html HTML content of block.
309 318 * @return WP_Block_Parser_Block freeform block object.
310 319 */
311 320 public function freeform( $inner_html ) {
312 - return new WP_Block_Parser_Block( null, array(), array(), $inner_html, array( $inner_html ) );
321 + return new WP_Block_Parser_Block( null, $this->empty_attrs, array(), $inner_html, array( $inner_html ) );
313 322 }
314 323
315 324 /**
316 325 * Pushes a length of text from the input document