Skip to content

Commit

Permalink
Blocks: Move blocks reregister function to standalone file
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth authored and gziolo committed Mar 19, 2019
1 parent ea85dcf commit 5bad351
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 37 deletions.
47 changes: 47 additions & 0 deletions lib/blocks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
* Block registration functions.
*
* @package gutenberg
*/

/**
* Substitutes the implementation of a core-registered block type, if exists,
* with the built result from the plugin.
*/
function gutenberg_reregister_core_block_types() {
// Blocks directory may not exist if working from a fresh clone.
$blocks_dir = dirname( __FILE__ ) . '/../build/block-library/blocks/';
if ( ! file_exists( $blocks_dir ) ) {
return;
}

$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',
'legacy-widget.php' => 'core/legacy-widget',
'rss.php' => 'core/rss',
'shortcode.php' => 'core/shortcode',
'search.php' => 'core/search',
'tag-cloud.php' => 'core/tag-cloud',
);

$registry = WP_Block_Type_Registry::get_instance();

foreach ( $block_names as $file => $block_name ) {
if ( ! file_exists( $blocks_dir . $file ) ) {
return;
}

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

require $blocks_dir . $file;
}
}
add_action( 'init', 'gutenberg_reregister_core_block_types' );
38 changes: 1 addition & 37 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,45 +24,9 @@
require dirname( __FILE__ ) . '/rest-api.php';
}

require dirname( __FILE__ ) . '/blocks.php';
require dirname( __FILE__ ) . '/client-assets.php';
require dirname( __FILE__ ) . '/i18n.php';
require dirname( __FILE__ ) . '/demo.php';
require dirname( __FILE__ ) . '/widgets.php';
require dirname( __FILE__ ) . '/widgets-page.php';

/**
* Substitutes the implementation of a core-registered block type, if exists,
* with the built result from the plugin.
*/
function gutenberg_reregister_core_block_types() {
// Blocks directory may not exist if working from a fresh clone.
$blocks_dir = dirname( __FILE__ ) . '/../build/block-library/blocks/';
if ( ! file_exists( $blocks_dir ) ) {
return;
}
$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',
'legacy-widget.php' => 'core/legacy-widget',
'rss.php' => 'core/rss',
'shortcode.php' => 'core/shortcode',
'search.php' => 'core/search',
'tag-cloud.php' => 'core/tag-cloud',
);
$registry = WP_Block_Type_Registry::get_instance();
foreach ( $block_names as $file => $block_name ) {
if ( ! file_exists( $blocks_dir . $file ) ) {
return;
}
if ( $registry->is_registered( $block_name ) ) {
$registry->unregister( $block_name );
}
require $blocks_dir . $file;
}
}
add_action( 'init', 'gutenberg_reregister_core_block_types' );

0 comments on commit 5bad351

Please sign in to comment.