Opened 6 years ago
Closed 5 years ago
#49926 closed enhancement (fixed)
Editor: Introduce WP_Block class
| Reported by: | | Owned by: | |
|---|---|---|---|
| Milestone: | 5.5 | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | Editor | Keywords: | has-patch has-unit-tests dev-feedback |
| Focuses: | Cc: |
Description
Related: https://github.com/WordPress/gutenberg/pull/21467
Related: #48104
Related: https://github.com/WordPress/gutenberg/issues/4671
The Gutenberg project is currently exploring the introduction of a new block context feature. As part of this effort and in order to make this context available as part of the existing render_callback function signature of block settings, in Gutenberg#21467 a new WP_Block class was introduced to serve the purpose of providing a first-class interface for plugins to interact with an instance of a block from within their own render callbacks.
Like in the browser client, this is intended to be distinct from the block value which is produced directly from the parser, and which is otherwise made available through existing low-level filters `render_block_data` and `render_block`.
See related discussion:
- https://github.com/WordPress/gutenberg/pull/21467#issuecomment-613635022
- https://github.com/WordPress/gutenberg/pull/21467#issuecomment-613893963
- https://github.com/WordPress/gutenberg/pull/21467#issuecomment-614202405
- https://github.com/WordPress/gutenberg/pull/21467#issuecomment-614536274
- https://github.com/WordPress/gutenberg/pull/21467#issuecomment-614667355
Proposed tasks:
- Introduce new
WP_Blockclass (see implementation from Gutenberg#21467 for initial reference) render_blockconstructsWP_Blockand largely defers to the implementation of aWP_Block::render(see implementation from Gutenberg#21467 for initial reference)- Consolidate
WP_Block_Type::renderandWP_Block::render(the former can likely pass-through to the latter)
Note: `render_block` and serialize_block currently receive $block in the parsed array form. While I remarked differently on the original pull request, I don't know that these actually need to change, since it seems rather sensible that these would except to receive blocks in their parsed forms. If one has access to a WP_Block instance and needs to create its rendered representation, the instance's render function can be used directly.
Feedback welcome: While the above can be considered a proposal of tasks, this is all very much subject to change.
Change History (9)
This ticket was mentioned in Slack in #core-php by aduth. View the logs.
6 years ago
#3
@
6 years ago
There have been a few iterations to block context in Gutenberg after the pull request referenced in the original comment.
Notably:
- The approach using
ArrayAccessto emulate backward-compatibility was not fully-compatible and was rolled back - A second attempt was made, where instead of trying to reuse the first argument, a new third argument is added to
render_callback
It's quite likely there will be further iterations to WP_Block in Gutenberg.
The most up-to-date version should be found at:
https://github.com/WordPress/gutenberg/blob/master/lib/class-wp-block.php
Up-to-date file history: https://github.com/WordPress/gutenberg/commits/master/lib/class-wp-block.php
This ticket was mentioned in PR #351 on WordPress/wordpress-develop by gziolo.
5 years ago #6
- Keywords has-patch has-unit-tests added
Trac ticket: https://core.trac.wordpress.org/ticket/49926
This PR ports the most up-to-date version of the WP_Block class added to Gutenberg:
https://github.com/WordPress/gutenberg/blob/master/lib/class-wp-block.php
It also adds a corresponding unit tests.
There is a follow-up backport necessary to wire this class when using new block context features as tracked in https://core.trac.wordpress.org/ticket/49927.
TimothyBJacobs commented on PR #351:
5 years ago #8
I think this needs @since comments on all the classes, methods, and properties not just for the file.
Related: #49927