Make WordPress Core


Ignore:
Timestamp:
09/06/2023 12:58:47 PM (7 months ago)
Author:
spacedmonkey
Message:

Themes: Remove unnecessary check if file exists in the theme functions.

Previously, several functions and methods in themes api were designed to check for the existence of files in a child theme before falling back to the parent theme. However, these checks did not consider whether the current theme was a child theme or not, resulting in unnecessary file existence checks for non-child themes. Check to see if stylesheet directory matches the template directory before doing the file exists. This optimization helps reduce unnecessary file system access, as file existence checks can be resource-intensive in PHP.

The following functions and methods have been updated as part of this enhancement:

  • WP_Theme::get_file_path
  • get_theme_file_path
  • get_theme_file_uri

Props spacedmonkey, flixos90, sabernhardt, 10upsimon, mukesh27.
Fixes #59279.

File:
1 edited

Legend:

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

    r56180 r56523  
    15571557        if ( empty( $file ) ) {
    15581558            $path = $stylesheet_directory;
    1559         } elseif ( file_exists( $stylesheet_directory . '/' . $file ) ) {
     1559        } elseif ( $stylesheet_directory !== $template_directory && file_exists( $stylesheet_directory . '/' . $file ) ) {
    15601560            $path = $stylesheet_directory . '/' . $file;
    15611561        } else {
Note: See TracChangeset for help on using the changeset viewer.