WP_Block::refresh_context_dependents()

In this article

Updates the context for the current block and its inner blocks.

Description

The method updates the context of inner blocks, if any, by passing down any context values the block provides (provides_context).

If the block has inner blocks, the method recursively processes them by creating new instances of WP_Block for each inner block and updating their context based on the block’s provides_context property.

Source

public function refresh_context_dependents() {
	/*
	 * Merging the `$context` property here is not ideal, but for now needs to happen because of backward compatibility.
	 * Ideally, the `$context` property itself would not be filterable directly and only the `$available_context` would be filterable.
	 * However, this needs to be separately explored whether it's possible without breakage.
	 */
	$this->available_context = array_merge( $this->available_context, $this->context );

	if ( ! empty( $this->block_type->uses_context ) ) {
		foreach ( $this->block_type->uses_context as $context_name ) {
			if ( array_key_exists( $context_name, $this->available_context ) ) {
				$this->context[ $context_name ] = $this->available_context[ $context_name ];
			}
		}
	}

	$this->refresh_parsed_block_dependents();
}

Changelog

VersionDescription
6.8.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.