Skip to content

Instantly share code, notes, and snippets.

@mukeshpanchal27
Created September 4, 2024 08:42
Show Gist options
  • Save mukeshpanchal27/db0749cbfbacf442049600285a2c3aef to your computer and use it in GitHub Desktop.
Save mukeshpanchal27/db0749cbfbacf442049600285a2c3aef to your computer and use it in GitHub Desktop.
WPP Group Context checking

WPP Group Context

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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment