[wp-trac] [WordPress Trac] #49926: Editor: Introduce WP_Block class

WordPress Trac noreply at wordpress.org
Thu Apr 16 19:35:56 UTC 2020


#49926: Editor: Introduce WP_Block class
-------------------------+-----------------------------
 Reporter:  aduth        |      Owner:  (none)
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Editor       |    Version:
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 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
 [https://github.com/WordPress/gutenberg/issues/19685 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 [https://github.com/WordPress/gutenberg/pull/21467
 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
 [https://developer.wordpress.org/reference/hooks/render_block_data/
 `render_block_data`] and
 [https://developer.wordpress.org/reference/hooks/render_block/
 `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_Block` class (see implementation from
 [https://github.com/WordPress/gutenberg/pull/21467 Gutenberg#21467] for
 initial reference)
 - `render_block` constructs `WP_Block` and largely defers to the
 implementation of a `WP_Block::render` (see implementation from
 [https://github.com/WordPress/gutenberg/pull/21467 Gutenberg#21467] for
 initial reference)
 - Consolidate `WP_Block_Type::render` and `WP_Block::render` (the former
 can likely pass-through to the latter)

 Note: [https://developer.wordpress.org/reference/functions/render_block/
 `render_block`] and `serialize_block` currently receive `$block` in the
 parsed array form. While I
 [https://github.com/WordPress/gutenberg/pull/21467#issuecomment-614202405
 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.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/49926>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list