Skip to content

Commit

Permalink
Blocks: Reimplement block reregistering as hard-coded list
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed Feb 14, 2019
1 parent 517396c commit dfc8732
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,25 @@ function gutenberg_reregister_core_block_types() {
return;
}

$registry = WP_Block_Type_Registry::get_instance();
$block_names = array(
'archives.php' => 'core/archives',
'block.php' => 'core/block',
'calendar.php' => 'core/calendar',
'categories.php' => 'core/categories',
'latest-comments.php' => 'core/latest-comments',
'latest-posts.php' => 'core/latest-posts',
'rss.php' => 'core/rss',
'shortcode.php' => 'core/shortcode',
'search.php' => 'core/search',
);

$files = scandir( $blocks_dir );
foreach ( $files as $file ) {
$parts = pathinfo( $file );
$registry = WP_Block_Type_Registry::get_instance();

// Ignore all non-PHP files, subdirectories, path traversal.
if ( 'php' !== $parts['extension'] ) {
continue;
foreach ( $block_names as $file => $block_name ) {
if ( ! file_exists( $blocks_dir . $file ) ) {
return;
}

// Derive the assumed block name by file path.
$block_name = 'core/' . $parts['filename'];

if ( $registry->is_registered( $block_name ) ) {
$registry->unregister( $block_name );
}
Expand Down

0 comments on commit dfc8732

Please sign in to comment.