Make WordPress Core

Opened 2 years ago

Closed 2 years ago

#55648 closed enhancement (fixed)

Correct serialize_block @param documentation according to what the function does

Reported by: manooweb's profile manooweb Owned by: audrasjb's profile audrasjb
Milestone: 6.0 Priority: normal
Severity: normal Version:
Component: Editor Keywords: has-patch assigned-for-commit commit
Focuses: docs Cc:

Description

It looks like the documentation of serialize_block() function doesn't corresponding on what the function really expects.

https://core.trac.wordpress.org/browser/trunk/src/wp-includes/blocks.php#L598

Indeed, documentation says we must provide a WP_Block_Parser_Block object while serialize_block() function tries to access to an array.

See for example
https://core.trac.wordpress.org/browser/trunk/src/wp-includes/blocks.php#L605
or
https://core.trac.wordpress.org/browser/trunk/src/wp-includes/blocks.php#L606

As serialize_blocks() function uses serialize_block() function the proposed patched also fixed serialize_blocks() function documentation.

In addition, we often need to parse blocks before serialize them like in _inject_theme_attribute_in_block_template_content() function https://core.trac.wordpress.org/browser/trunk/src/wp-includes/block-template-utils.php#L435

It also seems parse_blocks() using the default WP_Block_Parser returns representative array of WP_Block_Parser_Block object by casting object to array.

https://core.trac.wordpress.org/browser/trunk/src/wp-includes/blocks.php#L912
https://core.trac.wordpress.org/browser/trunk/src/wp-includes/class-wp-block-parser.php#L312
https://core.trac.wordpress.org/browser/trunk/src/wp-includes/class-wp-block-parser.php#L495

Attachments (1)

serialize-block-doc.diff (906 bytes) - added by manooweb 2 years ago.

Download all attachments as: .zip

Change History (5)

#1 @audrasjb
2 years ago

  • Milestone changed from Awaiting Review to 6.0
  • Owner set to audrasjb
  • Status changed from new to reviewing

#2 @audrasjb
2 years ago

  • Keywords assigned-for-commit added

Hi @manooweb and thanks for spotting this.
The patch looks good to me. Self assigning for final review and commit consideration.

#3 @audrasjb
2 years ago

  • Keywords commit added

Marking for commit.

#4 @audrasjb
2 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 53332:

Docs: Correct parameter types for serialize_block() and serialize_blocks().

This changeset clarifies the expected type for the first parameter passed to serialize_block() and serialize_blocks() functions.

Props manooweb.
Fixes #55648.
See #54729.

Note: See TracTickets for help on using tickets.