Skip to content

Commit 0bfc842

Browse files
committed
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. git-svn-id: https://develop.svn.wordpress.org/trunk@55910 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 559e6ce commit 0bfc842

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/wp-includes/blocks.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,13 +326,15 @@ function register_block_type_from_metadata( $file_or_folder, $args = array() ) {
326326
trailingslashit( $file_or_folder ) . 'block.json' :
327327
$file_or_folder;
328328

329-
if ( ! file_exists( $metadata_file ) ) {
329+
$is_core_block = str_starts_with( $file_or_folder, ABSPATH . WPINC );
330+
331+
if ( ! $is_core_block && ! file_exists( $metadata_file ) ) {
330332
return false;
331333
}
332334

333335
// Try to get metadata from the static cache for core blocks.
334336
$metadata = false;
335-
if ( str_starts_with( $file_or_folder, ABSPATH . WPINC ) ) {
337+
if ( $is_core_block ) {
336338
$core_block_name = str_replace( ABSPATH . WPINC . '/blocks/', '', $file_or_folder );
337339
if ( ! empty( $core_blocks_meta[ $core_block_name ] ) ) {
338340
$metadata = $core_blocks_meta[ $core_block_name ];

0 commit comments

Comments
 (0)