From 0bfc842f807582906bc119eb62aff6bd1c1e8dea Mon Sep 17 00:00:00 2001 From: Jonny Harris Date: Tue, 13 Jun 2023 11:44:14 +0000 Subject: [PATCH] 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 --- src/wp-includes/blocks.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index 3bdcdcc452..41b8430f98 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -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 ];