Result array:
[context] => Array
(
[postId] => 7
[postType] => page
)
[available_context:protected] => Array
(
[postId] => 7
[postType] => page
[align] => wide
)
| <?php | |
| /** | |
| * Plugin Name: WPP Group Context | |
| * Version: 0.1 | |
| * Author: Mukesh Panchal | |
| * License: GPL2 | |
| */ | |
| namespace WPP_Group_Context; | |
| use \WP_HTML_Tag_Processor; | |
| // If this file is called directly, abort. | |
| if ( ! defined( 'WPINC' ) ) { | |
| die; | |
| } | |
| add_filter( | |
| 'render_block_context', | |
| function( $context, $block, $parent ) { | |
| // Merge current context into the parent's context. | |
| if ( $parent ) { | |
| $context = array_merge( $parent->context, $context ); | |
| } | |
| if ( 'core/group' === $block['blockName'] ) { | |
| $context['align'] = $block['attrs']['align'] ?? ''; | |
| } | |
| return $context; | |
| }, | |
| 10, | |
| 3 | |
| ); | |
| function auto_sizes_filter_image_tag( string $content, array $parsed_block, $block ): string { | |
| echo '<pre>'; | |
| print_r( $block->context ); | |
| echo '</pre>'; | |
| echo '<pre>'; | |
| print_r( $block->available_context ); | |
| echo '</pre>'; | |
| return $content; | |
| } | |
| add_filter( 'render_block_core/image', __NAMESPACE__ . '\\auto_sizes_filter_image_tag', 10, 3 ); |