Make WordPress Core

Opened 4 weeks ago

Closed 4 weeks ago

Last modified 4 weeks ago

#59279 closed enhancement (fixed)

Unnecessarily check to see site is using a child theme in the theme functions.

Reported by: spacedmonkey's profile spacedmonkey Owned by: spacedmonkey's profile spacedmonkey
Milestone: 6.4 Priority: normal
Severity: normal Version: 4.7
Component: Themes Keywords: has-patch
Focuses: performance Cc:


Follow on from #58576 / [56357].

There are a number of functions methods that check to see if file exists in a child theme before falling back to parent theme. However these functions do not check to see if current theme. These functions include.

The function is_child_theme can not be used, as TEMPLATEPATH and STYLESHEETPATH, might be different from the result of get_stylesheet_directory() and get_template_directory(). These functions have filters.

Attachments (1)

Screenshot 2023-09-05 at 11.01.37.png (65.6 KB) - added by spacedmonkey 4 weeks ago.

Download all attachments as: .zip

Change History (9)

This ticket was mentioned in PR #5133 on WordPress/wordpress-develop by @spacedmonkey.

4 weeks ago

  • Keywords has-patch added

Only check to see if file exists if the current theme is a child theme. is_child_theme can not be used as get_stylesheet_directory has a filter.

Trac ticket:

#2 @spacedmonkey
4 weeks ago

We could maybe include _get_block_template_file in this.

#3 @spacedmonkey
4 weeks ago

Brenchmark data.

PHP 7.4.33, WordPress develop docker env. Trunk - [56512].

Theme - 2021

Trunk PR
Response Time (median) 54.37 54.08
wp-load-alloptions-query (median) 0.56 0.55
wp-before-template (median) 20.24 20.1
wp-template (median) 29.57 29.29
wp-total (median) 49.86 49.56

Theme 2022

Trunk PR
Response Time (median) 131.74 128.89
wp-load-alloptions-query (median) 0.59 0.58
wp-before-template (median) 82.09 79.87
wp-template (median) 44.99 44.79
wp-total (median) 127.35 124.57

Blackfire see a 6% improvement ( on 2022 theme )

This ticket was mentioned in Slack in #core-performance by spacedmonkey. View the logs.

4 weeks ago

#7 @spacedmonkey
4 weeks ago

  • Owner set to spacedmonkey
  • Resolution set to fixed
  • Status changed from new to closed

In 56523:

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.

Note: See TracTickets for help on using tickets.