[wp-trac] [WordPress Trac] #64118: `WP_Block_Type::render` doesn’t pass block instance argument to render_callback

WordPress Trac noreply at wordpress.org
Mon Oct 20 13:21:14 UTC 2025


#64118: `WP_Block_Type::render` doesn’t pass block instance argument to
render_callback
-----------------------------+-----------------------------
 Reporter:  Bernhard Reiter  |      Owner:  (none)
     Type:  defect (bug)     |     Status:  new
 Priority:  normal           |  Milestone:  Awaiting Review
Component:  General          |    Version:
 Severity:  normal           |   Keywords:
  Focuses:                   |
-----------------------------+-----------------------------
 The `WP_Block_Type` class has a `render` method that allows rendering an
 instance of a dynamic block, without actually creating a `WP_Block`
 instance. This can be used e.g. in combination with `WP_Block_Registry` to
 render an instance of a block whose name and attributes are known:

 {{{#!php
 $block_type = WP_Block_Type_Registry::get_instance()->get_registered(
 'core/some-block' );
 $output     = $block_type->render( array( 'someAttribute' =>
 $attribute_value ) );
 }}}

 Internally, `WP_Block_Type::render` [https://github.com/WordPress
 /wordpress-develop/blob/f6cf8fae73d98c29d51d7c70a687211f8dd7f6dc/src/wp-
 includes/class-wp-block-type.php#L473 calls the block type's
 `render_callback`]:

 {{{#!php
 return (string) call_user_func( $this->render_callback, $attributes,
 $content );
 }}}

 However, a block's `render_callback` can include a third argument: a
 `WP_Block` instance. The latter is [https://github.com/WordPress
 /wordpress-develop/blob/f6cf8fae73d98c29d51d7c70a687211f8dd7f6dc/src/wp-
 includes/class-wp-block.php#L599 passed to the callback] when invoked from
 `WP_Block::render`:

 {{{#!php
 $block_content = (string) call_user_func(
 $this->block_type->render_callback, $this->attributes, $block_content,
 $this );
 }}}

 This means that for a dynamic block whose render callback expects three
 arguments (including the `WP_Block` instance), calling
 `WP_Block_Type::render` will fail, since it does not pass the latter.

 ---

 An instance of this problem was observed and
 [https://wordpress.slack.com/archives/C02QB2JS7/p1760962525905939
 reported] by @ellatrix while preparing the [https://github.com/WordPress
 /wordpress-develop/pull/10355 package sync PR] for WordPress 6.9. It was
 caused by unit tests that created block markup for the synced pattern
 block (`core/block`). She [https://github.com/WordPress/wordpress-
 develop/pull/10355/commits/c4b7eb739d44bc0068c7c99eadb69e50ea3fdd00 fixed
 it by changing the tests] to create an actual `WP_Block` instance.

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


More information about the wp-trac mailing list