[wp-trac] [WordPress Trac] #58699: Post ID and post type block context no longer available to all 'render_block_context' filters

WordPress Trac noreply at wordpress.org
Mon Jul 3 04:31:25 UTC 2023


#58699: Post ID and post type block context no longer available to all
'render_block_context' filters
--------------------------+-----------------------------
 Reporter:  dlh           |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  trunk
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 In [https://github.com/WordPress/gutenberg/pull/50313 GB 50313] (synced to
 core in [56065]), the post template block was updated so that the
 `postType` and `postId` context values are provided via the
 `render_block_context` filter, rather than passed directly to the
 `WP_Block` instance.

 This change is not fully compatible with existing code that filters
 `render_block_context` and targets the post template block. Previously, it
 was always possible to derive additional context for the block from the
 post ID or type because those values were already in the block context
 when `render_block_context` was applied. Now, the post ID and type aren't
 available to filters until, realistically, priority 11 or later, since the
 new filter is hooked into `render_block_context` "just in time" at
 priority 10, making it likely to be the last function added to the filter
 and the last to run.

 I recognize the benefits of the filter outlined in the GB PR and can
 understand that those benefits might be worth incurring some backwards
 incompatibility. Still, I think a good-faith effort can be made to
 minimize that incompatibility by using a low priority such as 0 for the
 new filter. This lower priority would help ensure that most existing
 `render_block_context` filters, including those at the default priority of
 10, continue to have access to the post ID and type values in the context
 array.

 The linked PR changes the priority for the context filter in the post
 template block. I have no experience with the comment template filter,
 but, seeing a similar update to that block in the same core commit, I've
 made the same change in priority there.

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


More information about the wp-trac mailing list