From aaffa2bcff2e4a7f7319d72002a71c57ffe64083 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 26 Sep 2022 13:07:14 +0000 Subject: [PATCH] General: Remove `file_exists()` checks after calling `realpath()`. `realpath()` already checks if the file exists, and returns `false` on failure. The additional `file_exists()` check is not necessary and can be removed, improving the performance. This commit simplifies the checks in two functions: * `register_block_type_from_metadata()` * `wp_json_file_decode()` Note: In both of these cases, the values are passed through `wp_normalize_path()` after `realpath()`, so if the file does not exist, the `false` value gets converted to an empty string. The updated checks work both for `false` and `''` values. Though this is a small tweak, it saves a lot of checks since one of the places we do this is when registering block styles, so it runs quite a few times on each page load. Reference: [https://www.php.net/manual/en/function.realpath.php PHP Manual: realpath()]. Follow-up to [51599], [54132], [54290], [54291]. Props aristath. Fixes #56654. Built from https://develop.svn.wordpress.org/trunk@54309 git-svn-id: http://core.svn.wordpress.org/trunk@53868 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/blocks.php | 2 +- wp-includes/functions.php | 3 ++- wp-includes/version.php | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/wp-includes/blocks.php b/wp-includes/blocks.php index 5aeb329d60..584493fd5b 100644 --- a/wp-includes/blocks.php +++ b/wp-includes/blocks.php @@ -442,7 +442,7 @@ function register_block_type_from_metadata( $file_or_folder, $args = array() ) { remove_block_asset_path_prefix( $metadata['render'] ) ) ); - if ( file_exists( $template_path ) ) { + if ( $template_path ) { /** * Renders the block on the server. * diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 3ec8523a90..36146132d7 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -4528,7 +4528,8 @@ function wp_check_jsonp_callback( $callback ) { function wp_json_file_decode( $filename, $options = array() ) { $result = null; $filename = wp_normalize_path( realpath( $filename ) ); - if ( ! file_exists( $filename ) ) { + + if ( ! $filename ) { trigger_error( sprintf( /* translators: %s: Path to the JSON file. */ diff --git a/wp-includes/version.php b/wp-includes/version.php index 9759e331d2..5ce081a4bc 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.1-beta1-54308'; +$wp_version = '6.1-beta1-54309'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.