From 59b066ef11ee36693652649079b191784583b38b Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Fri, 7 Oct 2022 15:46:12 +0000 Subject: [PATCH] Blocks: Avoid extra calls to `realpath()` in block scripts and styles registration. This affects: * `register_block_script_handle()` * `register_block_style_handle()` Both functions set a variable with this code: {{{ $wpinc_path_norm = wp_normalize_path( realpath( ABSPATH . WPINC ) ); }}} That value never changes during page load, so we can save it to a static variable. By doing so, we can avoid ~200 calls to `realpath()` and `wp_normalize_path()`, or even more if third-party plugins register scripts or styles. Follow-up to [52291], [52939], [54290], [54291], [54309], [54327]. Props aristath, mukesh27, SergeyBiryukov. Fixes #56758. Built from https://develop.svn.wordpress.org/trunk@54415 git-svn-id: http://core.svn.wordpress.org/trunk@53974 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/blocks.php | 11 +++++++++-- wp-includes/version.php | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/wp-includes/blocks.php b/wp-includes/blocks.php index d6db591bc6..30219f3ca0 100644 --- a/wp-includes/blocks.php +++ b/wp-includes/blocks.php @@ -129,7 +129,11 @@ function register_block_script_handle( $metadata, $field_name, $index = 0 ) { } // Path needs to be normalized to work in Windows env. - $wpinc_path_norm = wp_normalize_path( realpath( ABSPATH . WPINC ) ); + static $wpinc_path_norm = ''; + if ( ! $wpinc_path_norm ) { + $wpinc_path_norm = wp_normalize_path( realpath( ABSPATH . WPINC ) ); + } + $theme_path_norm = wp_normalize_path( get_theme_file_path() ); $script_path_norm = wp_normalize_path( realpath( dirname( $metadata['file'] ) . '/' . $script_path ) ); @@ -182,7 +186,10 @@ function register_block_style_handle( $metadata, $field_name, $index = 0 ) { return false; } - $wpinc_path_norm = wp_normalize_path( realpath( ABSPATH . WPINC ) ); + static $wpinc_path_norm = ''; + if ( ! $wpinc_path_norm ) { + $wpinc_path_norm = wp_normalize_path( realpath( ABSPATH . WPINC ) ); + } $is_core_block = isset( $metadata['file'] ) && 0 === strpos( $metadata['file'], $wpinc_path_norm ); // Skip registering individual styles for each core block when a bundled version provided. diff --git a/wp-includes/version.php b/wp-includes/version.php index f46a6ffb02..6283f568a7 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.1-beta3-54414'; +$wp_version = '6.1-beta3-54415'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.