Make WordPress Core

Changeset 54309


Ignore:
Timestamp:
09/26/2022 01:05:30 PM (20 months ago)
Author:
SergeyBiryukov
Message:

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: PHP Manual: realpath().

Follow-up to [51599], [54132], [54290], [54291].

Props aristath.
Fixes #56654.

Location:
trunk/src/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/blocks.php

    r54290 r54309  
    443443            )
    444444        );
    445         if ( file_exists( $template_path ) ) {
     445        if ( $template_path ) {
    446446            /**
    447447             * Renders the block on the server.
  • trunk/src/wp-includes/functions.php

    r54299 r54309  
    45294529    $result   = null;
    45304530    $filename = wp_normalize_path( realpath( $filename ) );
    4531     if ( ! file_exists( $filename ) ) {
     4531
     4532    if ( ! $filename ) {
    45324533        trigger_error(
    45334534            sprintf(
Note: See TracChangeset for help on using the changeset viewer.