Skip to content

Commit

Permalink
Add debug function to print all available blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
ronilaukkarinen committed Dec 17, 2024
1 parent 20a53da commit 34dca33
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### [Unreleased]

* Add debug function to print all available blocks

### 9.4.7: 2024-12-04

* Fix body styles leaking to wp-admin
Expand Down
18 changes: 17 additions & 1 deletion functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
// Accepts both string (all*/none-options only) and array (options + specific blocks)
'allowed_blocks' => [
'post' => 'all-core-blocks',
'page' => [],
'page' => 'all',
// 'page' => [
// 'all-acf-blocks',
// 'core/paragraph',
Expand All @@ -168,6 +168,22 @@
define( 'THEME_SETTINGS', $theme_settings );
} ); // end action after_setup_theme

/**
* Debug function to print all available blocks
*/
function debug_print_all_blocks() {
$blocks = \WP_Block_Type_Registry::get_instance()->get_all_registered();
$block_names = array_map(function($block) {
return "'" . $block->name . "',";
}, $blocks);
echo '<pre>' . implode("\n", $block_names) . '</pre>';
die();
}

// Uncomment the following line to see all available blocks:
// add_action('init', __NAMESPACE__ . '\\debug_print_all_blocks');


/**
* Required files
*/
Expand Down
1 change: 1 addition & 0 deletions inc/hooks/gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* Restrict blocks to only allowed blocks in the settings
*/
function allowed_block_types( $allowed_blocks, $editor_context ) { // phpcs:ignore

// If no allowed blocks are defined or it is set to none, return an empty array
if ( empty( THEME_SETTINGS['allowed_blocks'] ) || 'none' === THEME_SETTINGS['allowed_blocks'] ) {
return [];
Expand Down

0 comments on commit 34dca33

Please sign in to comment.