-
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: Re-register core blocks via build copy prefixing (#13521)
* Build Tools: Exclude build files from PHPCS * Blocks: Re-register core blocks via build copy prefixing * Blocks: Discover block overrides from built artifact * Blocks: Reimplement block reregistering as hard-coded list * Blocks: Modify priority for blocks registration during build * Blocks: Move blocks reregister function to standalone file * Comma comma comma comma comma chameleon * Update regex in webpack config to contain gutenberg as well * Update build plugin zip script to include block PHP files from the new location
- Loading branch information
Showing
14 changed files
with
148 additions
and
100 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
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
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 |
---|---|---|
|
@@ -143,5 +143,4 @@ function register_block_core_archives() { | |
) | ||
); | ||
} | ||
|
||
add_action( 'init', 'register_block_core_archives' ); |
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
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 |
---|---|---|
|
@@ -98,5 +98,4 @@ function register_block_core_categories() { | |
) | ||
); | ||
} | ||
|
||
add_action( 'init', 'register_block_core_categories' ); |
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
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
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 |
---|---|---|
|
@@ -133,5 +133,4 @@ function register_block_core_rss() { | |
) | ||
); | ||
} | ||
|
||
add_action( 'init', 'register_block_core_rss' ); |
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 |
---|---|---|
|
@@ -78,5 +78,4 @@ function register_block_core_search() { | |
) | ||
); | ||
} | ||
|
||
add_action( 'init', 'register_block_core_search' ); |
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 |
---|---|---|
|
@@ -28,5 +28,4 @@ function register_block_core_shortcode() { | |
) | ||
); | ||
} | ||
|
||
add_action( 'init', 'register_block_core_shortcode' ); |
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 |
---|---|---|
|
@@ -67,5 +67,4 @@ function register_block_core_tag_cloud() { | |
) | ||
); | ||
} | ||
|
||
add_action( 'init', 'register_block_core_tag_cloud' ); |
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
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