Last active
March 22, 2021 22:53
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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