Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 13 additions & 24 deletions src/wp-includes/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -674,18 +674,6 @@ function render_block( $parsed_block ) {
return $pre_render;
}

$source_block = $parsed_block;

/**
* Filters the block being rendered in render_block(), before it's processed.
*
* @since 5.1.0
*
* @param array $parsed_block The block being rendered.
* @param array $source_block An un-modified copy of $parsed_block, as it appeared in the source content.
*/
$parsed_block = apply_filters( 'render_block_data', $parsed_block, $source_block );

$context = array();

if ( $post instanceof WP_Post ) {
Expand All @@ -707,19 +695,20 @@ function render_block( $parsed_block ) {
}
}

/**
* Filters the default context provided to a rendered block.
*
* @since 5.5.0
*
* @param array $context Default context.
* @param array $parsed_block Block being rendered, filtered by `render_block_data`.
*/
$context = apply_filters( 'render_block_context', $context, $parsed_block );

$block = new WP_Block( $parsed_block, $context );
$block = new WP_Block(
$parsed_block,
$context,
WP_Block_Type_Registry::get_instance(),
array(
'is_eager' => false,
)
);

return $block->render();
return $block->render(
array(
'filter_data' => true,
)
);
Copy link
Copy Markdown
Member Author

@noisysocks noisysocks Nov 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potentially these could be combined into one setting?

$block = new WP_Block(
	$parsed_block,
	$context,
	WP_Block_Type_Registry::get_instance(),
	array(
		'filter_on_render' => true,
	)
);

assert( ! isset( $block->name ) ); // Because `filter_on_render` was provided

$rendered_block = $block->render();

assert( isset( $block->name ) ); // Because `render()` was called

}

/**
Expand Down
27 changes: 20 additions & 7 deletions src/wp-includes/class-wp-block-list.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ class WP_Block_List implements Iterator, ArrayAccess, Countable {
*/
protected $registry;

/**
* Constructor options to use when creating nested WP_Block objects.
*
* @since 5.7.0
* @var array
* @access protected
*/
protected $options;

/**
* Constructor.
*
Expand All @@ -50,15 +59,13 @@ class WP_Block_List implements Iterator, ArrayAccess, Countable {
* @param array[]|WP_Block[] $blocks Array of parsed block data, or block instances.
* @param array $available_context Optional array of ancestry context values.
* @param WP_Block_Type_Registry $registry Optional block type registry.
* @param array $options Optional block options to pass along to WP_Block.
*/
public function __construct( $blocks, $available_context = array(), $registry = null ) {
if ( ! $registry instanceof WP_Block_Type_Registry ) {
$registry = WP_Block_Type_Registry::get_instance();
}

public function __construct( $blocks, $available_context = array(), $registry = null, $options = null ) {
$this->blocks = $blocks;
$this->available_context = $available_context;
$this->registry = $registry;
$this->registry = $registry ? $registry : WP_Block_Type_Registry::get_instance();
$this->options = $options;
}

/**
Expand Down Expand Up @@ -90,7 +97,13 @@ public function offsetGet( $index ) {
$block = $this->blocks[ $index ];

if ( isset( $block ) && is_array( $block ) ) {
$block = new WP_Block( $block, $this->available_context, $this->registry );
$block = new WP_Block(
$block,
$this->available_context,
$this->registry,
$this->options
);

$this->blocks[ $index ] = $block;
}

Expand Down
Loading