From fdfa70f30c8cfc0a5fbd4f9bcdf7eb355db519e5 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Mon, 23 Sep 2024 17:26:34 +0530 Subject: [PATCH 1/4] Update blocks.php --- src/wp-includes/blocks.php | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index 9e3e470304fb8..05cf24096fa5a 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -2090,29 +2090,8 @@ function render_block( $parsed_block ) { $context['postType'] = $post->post_type; } - /** - * Filters the default context provided to a rendered block. - * - * @since 5.5.0 - * @since 5.9.0 The `$parent_block` parameter was added. - * - * @param array $context Default context. - * @param array $parsed_block { - * An associative array of the block being rendered. See WP_Block_Parser_Block. - * - * @type string $blockName Name of block. - * @type array $attrs Attributes from block comment delimiters. - * @type array[] $innerBlocks List of inner blocks. An array of arrays that - * have the same structure as this one. - * @type string $innerHTML HTML from inside block comment delimiters. - * @type array $innerContent List of string fragments and null markers where - * inner blocks were found. - * } - * @param WP_Block|null $parent_block If this is a nested block, a reference to the parent block. - */ - $context = apply_filters( 'render_block_context', $context, $parsed_block, $parent_block ); + $block = new WP_Block( $parsed_block, $context, null, $parent_block ); - $block = new WP_Block( $parsed_block, $context ); return $block->render(); } From e5a9302a4ba8d44e8f60ba9b584cc962020ed2fe Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Mon, 23 Sep 2024 17:27:54 +0530 Subject: [PATCH 2/4] Update class-wp-block-list.php --- src/wp-includes/class-wp-block-list.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/class-wp-block-list.php b/src/wp-includes/class-wp-block-list.php index e1151e6745dfc..0e341e0449f38 100644 --- a/src/wp-includes/class-wp-block-list.php +++ b/src/wp-includes/class-wp-block-list.php @@ -41,18 +41,29 @@ class WP_Block_List implements Iterator, ArrayAccess, Countable { */ protected $registry; + /** + * Reference to the parent block. + * + * @since 6.7.0 + * @var WP_Block|null + * @access protected + */ + protected $parent_block; + /** * Constructor. * * Populates object properties from the provided block instance argument. * * @since 5.5.0 + * @since 6.7.0 Added the optional `$parent_block` argument. * * @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 WP_Block|null $parent_block Optional. If this is a nested block, a reference to the parent block. */ - public function __construct( $blocks, $available_context = array(), $registry = null ) { + public function __construct( $blocks, $available_context = array(), $registry = null, $parent_block = null ) { if ( ! $registry instanceof WP_Block_Type_Registry ) { $registry = WP_Block_Type_Registry::get_instance(); } @@ -60,6 +71,7 @@ public function __construct( $blocks, $available_context = array(), $registry = $this->blocks = $blocks; $this->available_context = $available_context; $this->registry = $registry; + $this->parent_block = $parent_block; } /** @@ -93,7 +105,7 @@ public function offsetGet( $offset ) { $block = $this->blocks[ $offset ]; 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->parent_block ); $this->blocks[ $offset ] = $block; } From 744aac968420fa82025e1c25317d5303e4b7eca2 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Mon, 23 Sep 2024 17:29:42 +0530 Subject: [PATCH 3/4] Update class-wp-block.php --- src/wp-includes/class-wp-block.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/class-wp-block.php b/src/wp-includes/class-wp-block.php index f7fd53dfc9710..e70981cf2ada5 100644 --- a/src/wp-includes/class-wp-block.php +++ b/src/wp-includes/class-wp-block.php @@ -112,6 +112,7 @@ class WP_Block { * its registered type will be assigned to the block's `context` property. * * @since 5.5.0 + * @since 6.7.0 Added the optional `$parent_block` argument. * * @param array $block { * An associative array of a single parsed block object. See WP_Block_Parser_Block. @@ -126,7 +127,7 @@ class WP_Block { * @param array $available_context Optional array of ancestry context values. * @param WP_Block_Type_Registry $registry Optional block type registry. */ - public function __construct( $block, $available_context = array(), $registry = null ) { + public function __construct( $block, $available_context = array(), $registry = null, $parent_block = null ) { $this->parsed_block = $block; $this->name = $block['blockName']; @@ -138,7 +139,7 @@ public function __construct( $block, $available_context = array(), $registry = n $this->block_type = $registry->get_registered( $this->name ); - $this->available_context = $available_context; + $this->available_context = apply_filters( 'render_block_context', $available_context, $block, $parent_block ); if ( ! empty( $this->block_type->uses_context ) ) { foreach ( $this->block_type->uses_context as $context_name ) { @@ -159,7 +160,7 @@ public function __construct( $block, $available_context = array(), $registry = n } } - $this->inner_blocks = new WP_Block_List( $block['innerBlocks'], $child_context, $registry ); + $this->inner_blocks = new WP_Block_List( $block['innerBlocks'], $child_context, $registry, $parent_block ); } if ( ! empty( $block['innerHTML'] ) ) { From 2d0e9ee18cb08980aea295856bf3c88c69cfe588 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Mon, 23 Sep 2024 17:36:40 +0530 Subject: [PATCH 4/4] Remove extra line. --- src/wp-includes/blocks.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index 05cf24096fa5a..e7e71fac44444 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -2092,7 +2092,6 @@ function render_block( $parsed_block ) { $block = new WP_Block( $parsed_block, $context, null, $parent_block ); - return $block->render(); }