diff --git a/docs/reference-guides/block-api/block-bindings.md b/docs/reference-guides/block-api/block-bindings.md index c82729f34440de..4f28e564e9da07 100644 --- a/docs/reference-guides/block-api/block-bindings.md +++ b/docs/reference-guides/block-api/block-bindings.md @@ -251,79 +251,6 @@ add_filter( This filter also affects which blocks and attributes are available for Pattern Overrides, as both features share the same underlying supported attributes configuration. -### Accessing Pattern Override values in dynamic blocks - -When creating a dynamic block that supports Pattern Overrides, you can access the override values within your `render_callback` function. The Pattern block (`core/block`) provides override values to nested blocks via the `pattern/overrides` context. - -**Step 1: Register your block with the required context and supported attributes** - -```php -add_action( 'init', function() { - // Register supported attributes for pattern overrides - add_filter( - 'block_bindings_supported_attributes_my-plugin/my-block', - function ( $supported_attributes ) { - $supported_attributes[] = 'title'; - $supported_attributes[] = 'description'; - return $supported_attributes; - } - ); - - register_block_type( 'my-plugin/my-block', array( - 'attributes' => array( - 'title' => array( 'type' => 'string', 'default' => '' ), - 'description' => array( 'type' => 'string', 'default' => '' ), - 'metadata' => array( 'type' => 'object' ), - ), - // Declare that you need the pattern/overrides context - 'uses_context' => array( 'pattern/overrides' ), - 'render_callback' => 'my_block_render_callback', - ) ); -} ); -``` - -**Step 2: Access override values in your render callback** - -The override values are stored in `$block->context['pattern/overrides']` as an associative array. The keys are block metadata names (assigned when enabling overrides), and the values are arrays of attribute overrides. - -```php -function my_block_render_callback( $attributes, $content, $block ) { - // Get the block's metadata name (set when enabling overrides) - $block_name = $attributes['metadata']['name'] ?? null; - - // Get the pattern overrides from context - $overrides = array(); - if ( $block_name && isset( $block->context['pattern/overrides'][ $block_name ] ) ) { - $overrides = $block->context['pattern/overrides'][ $block_name ]; - } - - // Get attribute values, preferring overrides when available - // Note: An empty string in overrides means "reset to default" - $title = $attributes['title']; - if ( isset( $overrides['title'] ) && $overrides['title'] !== '' ) { - $title = $overrides['title']; - } - - $description = $attributes['description']; - if ( isset( $overrides['description'] ) && $overrides['description'] !== '' ) { - $description = $overrides['description']; - } - - return sprintf( - '
%s