-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Blocks: Move blocks reregister function to standalone file
- Loading branch information
Showing
2 changed files
with
48 additions
and
37 deletions.
There are no files selected for viewing
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
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' ); |
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