| 1 |
<?php |
| 2 |
/** |
| 3 |
* Block registration functions. |
| 4 |
* |
| 5 |
* @package gutenberg |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* Substitutes the implementation of a core-registered block type, if exists, |
| 10 |
* with the built result from the plugin. |
| 11 |
*/ |
| 12 |
function gutenberg_reregister_core_block_types() { |
| 13 |
// Blocks directory may not exist if working from a fresh clone. |
| 14 |
$blocks_dir = dirname( __FILE__ ) . '/../build/block-library/blocks/'; |
| 15 |
if ( ! file_exists( $blocks_dir ) ) { |
| 16 |
return; |
| 17 |
} |
| 18 |
|
| 19 |
$block_names = array( |
| 20 |
'archives.php' => 'core/archives', |
| 21 |
'block.php' => 'core/block', |
| 22 |
'calendar.php' => 'core/calendar', |
| 23 |
'categories.php' => 'core/categories', |
| 24 |
'latest-comments.php' => 'core/latest-comments', |
| 25 |
'latest-posts.php' => 'core/latest-posts', |
| 26 |
'legacy-widget.php' => 'core/legacy-widget', |
| 27 |
'rss.php' => 'core/rss', |
| 28 |
'shortcode.php' => 'core/shortcode', |
| 29 |
'search.php' => 'core/search', |
| 30 |
'tag-cloud.php' => 'core/tag-cloud', |
| 31 |
); |
| 32 |
|
| 33 |
$registry = WP_Block_Type_Registry::get_instance(); |
| 34 |
|
| 35 |
foreach ( $block_names as $file => $block_name ) { |
| 36 |
if ( ! file_exists( $blocks_dir . $file ) ) { |
| 37 |
return; |
| 38 |
} |
| 39 |
|
| 40 |
if ( $registry->is_registered( $block_name ) ) { |
| 41 |
$registry->unregister( $block_name ); |
| 42 |
} |
| 43 |
|
| 44 |
require $blocks_dir . $file; |
| 45 |
} |
| 46 |
} |
| 47 |
add_action( 'init', 'gutenberg_reregister_core_block_types' ); |
| 48 |
|