From 470911715d1108cc1c1f2e67c83b58fa1d56d6c8 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Thu, 3 Aug 2023 20:29:12 +0000 Subject: [PATCH] Themes: Avoid unnecessary check whether parent template file exists when not using a child theme. Prior to this change, the `locate_template()` function would unconditionally check whether the relevant template file exists in the parent theme, which for sites not using a child theme is an exact duplicate of the previous check. This is wasteful and has a small impact on performance since `file_exists()` checks have a cost. Props nihar007, thekt12, spacedmonkey, mukesh27. Fixes #58576. git-svn-id: https://develop.svn.wordpress.org/trunk@56357 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/template.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/template.php b/src/wp-includes/template.php index b9ac37d235..afc2ca6edf 100644 --- a/src/wp-includes/template.php +++ b/src/wp-includes/template.php @@ -707,7 +707,7 @@ function locate_template( $template_names, $load = false, $load_once = true, $ar if ( file_exists( STYLESHEETPATH . '/' . $template_name ) ) { $located = STYLESHEETPATH . '/' . $template_name; break; - } elseif ( file_exists( TEMPLATEPATH . '/' . $template_name ) ) { + } elseif ( is_child_theme() && file_exists( TEMPLATEPATH . '/' . $template_name ) ) { $located = TEMPLATEPATH . '/' . $template_name; break; } elseif ( file_exists( ABSPATH . WPINC . '/theme-compat/' . $template_name ) ) {