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
This commit is contained in:
Sergey Biryukov 2022-09-26 13:07:14 +00:00
parent ec8368e14c
commit aaffa2bcff
3 changed files with 4 additions and 3 deletions

View File

@ -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.
*

View File

@ -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. */

View File

@ -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.