Skip to content

Instantly share code, notes, and snippets.

@pbrocks
Last active March 22, 2021 22:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pbrocks/405542f085bad266bfc17015213a01fe to your computer and use it in GitHub Desktop.
Save pbrocks/405542f085bad266bfc17015213a01fe to your computer and use it in GitHub Desktop.
Use the `render_block` filter to show the elemental parts of a WordPress block.
<?php
add_filter( 'render_block', 'show_the_block_constituents', 10, 2 );
/**
* [show_the_block_constituents] Debug code for showing the parts of WP Blocks
*
* @param [string] $block_content
* @param [array] $block
* @return [string]
*/
function show_the_block_constituents( $block_content, $block ) {
if ( true === WP_DEBUG && current_user_can( 'administrator' ) ) {
$block_content = "<div class='wp-block' data-blockType='{$block['blockName']}'>{$block_content}</div>" . ( 'string' === gettype( $block['blockName'] ) ? '<pre><xmp> $block_content = ' . gettype( $block_content ) . " {$block['blockName']} " . print_r( $block, true ) . '</xmp></pre>' : '' );
}
return $block_content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment