Editor: Skip file_exist check for core blocks.

In `register_block_type_from_metadata` function, skip calling `file_exists` on core blocks. Core blocks are part of the codebase and will never not exist. Not calling this function is better for performance, as the file lookup can be expensive. 

Props spacedmonkey, joemcgill.
Fixes #58385.
Built from https://develop.svn.wordpress.org/trunk@55910


git-svn-id: http://core.svn.wordpress.org/trunk@55422 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
spacedmonkey 2023-06-13 11:46:27 +00:00
parent c5f2ee51d9
commit 68f97dcb83
2 changed files with 5 additions and 3 deletions

View File

@ -326,13 +326,15 @@ function register_block_type_from_metadata( $file_or_folder, $args = array() ) {
trailingslashit( $file_or_folder ) . 'block.json' :
$file_or_folder;
if ( ! file_exists( $metadata_file ) ) {
$is_core_block = str_starts_with( $file_or_folder, ABSPATH . WPINC );
if ( ! $is_core_block && ! file_exists( $metadata_file ) ) {
return false;
}
// Try to get metadata from the static cache for core blocks.
$metadata = false;
if ( str_starts_with( $file_or_folder, ABSPATH . WPINC ) ) {
if ( $is_core_block ) {
$core_block_name = str_replace( ABSPATH . WPINC . '/blocks/', '', $file_or_folder );
if ( ! empty( $core_blocks_meta[ $core_block_name ] ) ) {
$metadata = $core_blocks_meta[ $core_block_name ];

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.3-alpha-55909';
$wp_version = '6.3-alpha-55910';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.