Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter( 'render_block_context', function( $context, $parsed_block ) {
- if ( 'core/query' === $parsed_block['blockName'] ) {
- $context['helga/tacos'] = 'we love tacos';
- }
- return $context;
- }, 10, 2 );
- add_filter( 'block_type_metadata', function( $metadata ) {
- if ( 'core/query' === $metadata['name'] ) {
- $metadata['attributes'] ??= [];
- $metadata['attributes']['tacos'] = [
- 'type' => 'string',
- 'default' => 'default tacos',
- ];
- $metadata['providesContext'] ??= [];
- $metadata['providesContext']['helga/tacos'] = 'tacos';
- }
- if ( 'core/post-title' === $metadata['name'] ) {
- $metadata['usesContext'] ??= [];
- $metadata['usesContext'][] = 'helga/tacos';
- }
- return $metadata;
- } );
- add_filter( 'render_block_core/post-title', function( $block_content, $block, $instance) {
- $context = $instance->context['helga/tacos'] ?? 'no tacos'; // This is never set.
- return '<p>context $taco: ' . $context . '</p>';
- }, 10, 3 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement