wppaste
WordPress

WP_Theme::__construct( string $theme_dir, string $theme_root, WP_Theme|null $_child = null )

Since
3.4.0
Source
wp-includes/class-wp-theme.php:251
Constructor for WP_Theme.

Compatibility

WordPress
since 3.4.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$theme_dirstring
Directory of the theme within the theme_root.
$theme_rootstring
Theme root.
$_childWP_Theme|nulloptional
If this theme is a parent theme, the child may be passed for validation purposes.Default: null

Performance profile

How much work a call to WP_Theme::__construct() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Heavy

Reads or writes the filesystem via file_exists().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
92–206

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 601.

Plugin surface
1 hook

Third-party callbacks on 'wp_cache_themes_persistently' run inside this call, and their cost is not bounded by anything here.

Called by
5

5 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksapply_filters()called directly
  • cacheobject cachewp_cache_add_global_groups()called directly
  • filesystemfilesystem accessfile_exists()called directly
  • transienttransientget_site_transient()one call below WP_Theme::__construct()

Further down the call graph this can also reach option, serialize and query. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 72 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Theme::__construct() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
$theme_root && file_exists() && is_readable() && !->get()92–96md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), wp_paused_themes(), ->get()
$theme_root && file_exists() && is_readable() && ->get() && is_wp_error() && isset($value)102–106md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), wp_paused_themes(), ->get(), is_wp_error()
$theme_root && file_exists() && is_readable() && ->is_block_theme() && !->get()102–106md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), ->is_block_theme(), wp_paused_themes(), ->get()
$theme_root && file_exists() && is_readable() && !->get()105–114md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), ->cache_add(), wp_paused_themes(), ->get()
$theme_root && file_exists() && is_readable() && !->get()105md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), wp_paused_themes(), ->get()
$theme_root && file_exists() && is_readable() && ->get()107–115md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), wp_paused_themes(), ->get(), is_wp_error(), __()
$theme_root && file_exists() && is_readable() && ->is_block_theme() && ->get() && is_wp_error() && isset($value)112–116md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), ->is_block_theme(), wp_paused_themes(), ->get(), is_wp_error()
$theme_root && !is_array($cache) && file_exists() && is_readable() && !->get()113–119md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), wp_paused_themes(), ->get(), ->is_block_theme(), ->get_block_template_folders(), ->cache_add()
$theme_root && file_exists() && is_readable() && ->get() && is_wp_error() && isset($value)115–124md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), ->cache_add(), wp_paused_themes(), ->get(), is_wp_error()
$theme_root && file_exists() && is_readable() && ->get() && is_wp_error() && isset($value)115md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), wp_paused_themes(), ->get(), is_wp_error()
$theme_root && file_exists() && is_readable() && ->is_block_theme() && !->get()115–124md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), ->is_block_theme(), ->cache_add(), wp_paused_themes(), ->get()
$theme_root && file_exists() && is_readable() && ->is_block_theme() && ->get()117–125md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), ->is_block_theme(), wp_paused_themes(), ->get(), is_wp_error(), __()
60 further outcomes, up to 206 instructions
$theme_root && file_exists() && is_readable() && !->get()118–123md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), ->cache_add(), wp_paused_themes(), ->get()
$theme_root && file_exists() && is_readable() && ->get()120–133md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), ->cache_add(), wp_paused_themes(), ->get(), is_wp_error(), __()
$theme_root && file_exists() && is_readable() && ->get()120–124md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), wp_paused_themes(), ->get(), is_wp_error(), __()
$theme_root && is_readable() && $parent_dir === "." && isset($directories) && !->get()121md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), search_theme_directories(), wp_paused_themes(), ->get()
$theme_root && !is_array($cache) && file_exists() && is_readable() && ->get() && is_wp_error() && isset($value)123–129md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), wp_paused_themes(), ->get(), is_wp_error(), ->is_block_theme(), ->get_block_template_folders(), ->cache_add()
$theme_root && !is_array($cache) && file_exists() && is_readable() && ->is_block_theme() && !->get()123–129md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), ->is_block_theme(), wp_paused_themes(), ->get(), ->is_block_theme(), ->get_block_template_folders(), ->cache_add()
$theme_root && file_exists() && is_readable() && ->is_block_theme() && ->get() && is_wp_error() && isset($value)125–134md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), ->is_block_theme(), ->cache_add(), wp_paused_themes(), ->get(), is_wp_error()
$theme_root && !is_array($cache) && file_exists() && is_readable() && !->get()126–137md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), ->cache_add(), wp_paused_themes(), ->get(), ->is_block_theme(), ->get_block_template_folders(), ->cache_add()
$theme_root && !is_array($cache) && file_exists() && is_readable() && !->get()126–128md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), wp_paused_themes(), ->get(), ->is_block_theme(), ->get_block_template_folders(), ->cache_add()
$theme_root && file_exists() && is_readable() && ->get() && is_wp_error() && isset($value)128–133md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), ->cache_add(), wp_paused_themes(), ->get(), is_wp_error()
$theme_root && !is_array($cache) && file_exists() && is_readable() && ->get()128–138md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), wp_paused_themes(), ->get(), is_wp_error(), __(), ->is_block_theme(), ->get_block_template_folders(), ->cache_add()
$theme_root && is_readable() && $parent_dir !== "." && !->get()129–132md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), search_theme_directories(), file_exists(), wp_paused_themes(), ->get()
$theme_root && !is_array($cache) && file_exists() && is_readable() && $_child instanceof130–134md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), __(), esc_html(), sprintf(), ->get_block_template_folders(), ->is_block_theme(), block_template_folders()
$theme_root && file_exists() && is_readable() && ->is_block_theme() && ->get()130–143md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), ->is_block_theme(), ->cache_add(), wp_paused_themes(), ->get(), is_wp_error(), __()
$theme_root && is_readable() && $parent_dir === "." && isset($directories) && ->get() && is_wp_error() && isset($value)131md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), search_theme_directories(), wp_paused_themes(), ->get(), is_wp_error()
$theme_root && file_exists() && is_readable() && ->get()133–142md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), ->cache_add(), wp_paused_themes(), ->get(), is_wp_error(), __()
$theme_root && !is_array($cache) && file_exists() && is_readable() && ->is_block_theme() && ->get() && is_wp_error() && isset($value)133–139md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), ->is_block_theme(), wp_paused_themes(), ->get(), is_wp_error(), ->is_block_theme(), ->get_block_template_folders(), ->cache_add()
$theme_root && is_readable() && $parent_dir === "." && isset($directories) && !->get()134–139md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), search_theme_directories(), ->cache_add(), wp_paused_themes(), ->get()
$theme_root && is_readable() && $parent_dir === "." && isset($directories) && ->get()136–140md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), search_theme_directories(), wp_paused_themes(), ->get(), is_wp_error(), __()
$theme_root && !is_array($cache) && file_exists() && is_readable() && ->get() && is_wp_error() && isset($value)136–147md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), ->cache_add(), wp_paused_themes(), ->get(), is_wp_error(), ->is_block_theme(), ->get_block_template_folders(), ->cache_add()
$theme_root && !is_array($cache) && file_exists() && is_readable() && ->get() && is_wp_error() && isset($value)136–138md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), wp_paused_themes(), ->get(), is_wp_error(), ->is_block_theme(), ->get_block_template_folders(), ->cache_add()
$theme_root && !is_array($cache) && file_exists() && is_readable() && ->is_block_theme() && !->get()136–147md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), ->is_block_theme(), ->cache_add(), wp_paused_themes(), ->get(), ->is_block_theme(), ->get_block_template_folders(), ->cache_add()
$theme_root && !is_array($cache) && file_exists() && is_readable() && ->is_block_theme() && ->get()138–148md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), ->is_block_theme(), wp_paused_themes(), ->get(), is_wp_error(), __(), ->is_block_theme(), ->get_block_template_folders(), ->cache_add()
$theme_root && is_readable() && $parent_dir !== "." && ->get() && is_wp_error() && isset($value)139–142md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), search_theme_directories(), file_exists(), wp_paused_themes(), ->get(), is_wp_error()
$theme_root && !is_array($cache) && file_exists() && is_readable() && !->get()139–146md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), ->cache_add(), wp_paused_themes(), ->get(), ->is_block_theme(), ->get_block_template_folders(), ->cache_add()
$theme_root && !is_array($cache) && file_exists() && is_readable() && ->is_block_theme() && $_child instanceof140–144md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), ->is_block_theme(), __(), esc_html(), sprintf(), ->get_block_template_folders(), ->is_block_theme(), block_template_folders()
$theme_root && !is_array($cache) && file_exists() && is_readable() && ->get()141–156md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), ->cache_add(), wp_paused_themes(), ->get(), is_wp_error(), __(), ->is_block_theme(), ->get_block_template_folders(), ->cache_add()
$theme_root && !is_array($cache) && file_exists() && is_readable() && ->get()141–147md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), wp_paused_themes(), ->get(), is_wp_error(), __(), ->is_block_theme(), ->get_block_template_folders(), ->cache_add()
$theme_root && is_readable() && $parent_dir !== "." && !->get()142–150md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), search_theme_directories(), file_exists(), ->cache_add(), wp_paused_themes(), ->get()
$theme_root && !is_array($cache) && is_readable() && $parent_dir === "." && isset($directories) && !->get()142–144md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), search_theme_directories(), wp_paused_themes(), ->get(), ->is_block_theme(), ->get_block_template_folders(), ->cache_add()
$theme_root && !is_array($cache) && file_exists() && is_readable() && $_child instanceof143md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), __(), esc_html(), sprintf(), ->get_block_template_folders(), ->is_block_theme(), block_template_folders()
$theme_root && is_readable() && $parent_dir === "." && isset($directories) && ->get() && is_wp_error() && isset($value)144–149md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), search_theme_directories(), ->cache_add(), wp_paused_themes(), ->get(), is_wp_error()
$theme_root && is_readable() && $parent_dir !== "." && ->get()144–151md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), search_theme_directories(), file_exists(), wp_paused_themes(), ->get(), is_wp_error(), __()
$theme_root && !is_array($cache) && file_exists() && is_readable() && ->is_block_theme() && ->get() && is_wp_error() && isset($value)146–157md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), ->is_block_theme(), ->cache_add(), wp_paused_themes(), ->get(), is_wp_error(), ->is_block_theme(), ->get_block_template_folders(), ->cache_add()
$theme_root && !is_array($cache) && is_readable() && $parent_dir === "."147–150md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), search_theme_directories(), __(), esc_html(), sprintf(), ->cache_add(), ->get_block_template_folders(), ->is_block_theme(), block_template_folders(), ->cache_add()
$theme_root && is_readable() && $parent_dir === "." && isset($directories) && ->get()149–158md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), search_theme_directories(), ->cache_add(), wp_paused_themes(), ->get(), is_wp_error(), __()
$theme_root && !is_array($cache) && file_exists() && is_readable() && ->get() && is_wp_error() && isset($value)149–156md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), ->cache_add(), wp_paused_themes(), ->get(), is_wp_error(), ->is_block_theme(), ->get_block_template_folders(), ->cache_add()
$theme_root && !is_array($cache) && is_readable() && $parent_dir !== "." && !->get()150–155md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), search_theme_directories(), file_exists(), wp_paused_themes(), ->get(), ->is_block_theme(), ->get_block_template_folders(), ->cache_add()
$theme_root && !is_array($cache) && file_exists() && is_readable() && ->is_block_theme() && ->get()151–166md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), ->is_block_theme(), ->cache_add(), wp_paused_themes(), ->get(), is_wp_error(), __(), ->is_block_theme(), ->get_block_template_folders(), ->cache_add()
$theme_root && is_readable() && $parent_dir !== "." && ->get() && is_wp_error() && isset($value)152–160md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), search_theme_directories(), file_exists(), ->cache_add(), wp_paused_themes(), ->get(), is_wp_error()
$theme_root && !is_array($cache) && is_readable() && $parent_dir === "." && isset($directories) && ->get() && is_wp_error() && isset($value)152–154md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), search_theme_directories(), wp_paused_themes(), ->get(), is_wp_error(), ->is_block_theme(), ->get_block_template_folders(), ->cache_add()
$theme_root && !is_array($cache) && file_exists() && is_readable() && ->get()154–165md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), ->cache_add(), wp_paused_themes(), ->get(), is_wp_error(), __(), ->is_block_theme(), ->get_block_template_folders(), ->cache_add()
$theme_root && !is_array($cache) && is_readable() && $parent_dir === "." && isset($directories) && !->get()155–162md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), search_theme_directories(), ->cache_add(), wp_paused_themes(), ->get(), ->is_block_theme(), ->get_block_template_folders(), ->cache_add()
$theme_root && is_readable() && $parent_dir !== "." && ->get()157–169md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), search_theme_directories(), file_exists(), ->cache_add(), wp_paused_themes(), ->get(), is_wp_error(), __()
$theme_root && !is_array($cache) && is_readable() && $parent_dir === "." && isset($directories) && ->get()157–163md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), search_theme_directories(), wp_paused_themes(), ->get(), is_wp_error(), __(), ->is_block_theme(), ->get_block_template_folders(), ->cache_add()
$theme_root && !is_array($cache) && is_readable() && $parent_dir !== "."158–161md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), search_theme_directories(), file_exists(), __(), esc_html(), sprintf(), ->cache_add(), ->get_block_template_folders(), ->is_block_theme(), block_template_folders(), ->cache_add()
$theme_root && !is_array($cache) && is_readable() && $parent_dir === "." && isset($directories) && $_child instanceof159md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), search_theme_directories(), __(), esc_html(), sprintf(), ->get_block_template_folders(), ->is_block_theme(), block_template_folders()
$theme_root && !is_array($cache) && is_readable() && $parent_dir !== "." && ->get() && is_wp_error() && isset($value)160–165md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), search_theme_directories(), file_exists(), wp_paused_themes(), ->get(), is_wp_error(), ->is_block_theme(), ->get_block_template_folders(), ->cache_add()
$theme_root && !is_array($cache) && is_readable() && $parent_dir !== "." && !->get()163–173md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), search_theme_directories(), file_exists(), ->cache_add(), wp_paused_themes(), ->get(), ->is_block_theme(), ->get_block_template_folders(), ->cache_add()
$theme_root && !is_array($cache) && is_readable() && $parent_dir === "." && isset($directories) && ->get() && is_wp_error() && isset($value)165–172md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), search_theme_directories(), ->cache_add(), wp_paused_themes(), ->get(), is_wp_error(), ->is_block_theme(), ->get_block_template_folders(), ->cache_add()
$theme_root && !is_array($cache) && is_readable() && $parent_dir !== "." && ->get()165–174md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), search_theme_directories(), file_exists(), wp_paused_themes(), ->get(), is_wp_error(), __(), ->is_block_theme(), ->get_block_template_folders(), ->cache_add()
$theme_root && !is_array($cache) && file_exists() && is_readable() && $_child instanceof166–170md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), __(), esc_html(), sprintf(), ->get_block_template_folders(), ->is_block_theme(), block_template_folders(), __(), esc_html(), sprintf(), ->cache_add(), ->get_block_template_folders(), ->is_block_theme(), block_template_folders()
$theme_root && !is_array($cache) && is_readable() && $parent_dir !== "." && $_child instanceof167–170md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), search_theme_directories(), file_exists(), __(), esc_html(), sprintf(), ->get_block_template_folders(), ->is_block_theme(), block_template_folders()
$theme_root && !is_array($cache) && is_readable() && $parent_dir === "." && isset($directories) && ->get()170–181md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), search_theme_directories(), ->cache_add(), wp_paused_themes(), ->get(), is_wp_error(), __(), ->is_block_theme(), ->get_block_template_folders(), ->cache_add()
$theme_root && !is_array($cache) && is_readable() && $parent_dir !== "." && ->get() && is_wp_error() && isset($value)173–183md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), search_theme_directories(), file_exists(), ->cache_add(), wp_paused_themes(), ->get(), is_wp_error(), ->is_block_theme(), ->get_block_template_folders(), ->cache_add()
$theme_root && !is_array($cache) && file_exists() && is_readable() && ->is_block_theme() && $_child instanceof176–180md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), ->is_block_theme(), __(), esc_html(), sprintf(), ->get_block_template_folders(), ->is_block_theme(), block_template_folders(), __(), esc_html(), sprintf(), ->cache_add(), ->get_block_template_folders(), ->is_block_theme(), block_template_folders()
$theme_root && !is_array($cache) && is_readable() && $parent_dir !== "." && ->get()178–192md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), search_theme_directories(), file_exists(), ->cache_add(), wp_paused_themes(), ->get(), is_wp_error(), __(), ->is_block_theme(), ->get_block_template_folders(), ->cache_add()
$theme_root && !is_array($cache) && file_exists() && is_readable() && $_child instanceof179md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), __(), esc_html(), sprintf(), ->get_block_template_folders(), ->is_block_theme(), block_template_folders(), __(), esc_html(), sprintf(), ->cache_add(), ->get_block_template_folders(), ->is_block_theme(), block_template_folders()
$theme_root && !is_array($cache) && is_readable() && $parent_dir === "." && isset($directories) && $_child instanceof195md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), search_theme_directories(), __(), esc_html(), sprintf(), ->get_block_template_folders(), ->is_block_theme(), block_template_folders(), __(), esc_html(), sprintf(), ->cache_add(), ->get_block_template_folders(), ->is_block_theme(), block_template_folders()
$theme_root && !is_array($cache) && is_readable() && $parent_dir !== "." && $_child instanceof203–206md5(), ->cache_get(), file_exists(), is_readable(), get_file_data(), array_search(), file_exists(), search_theme_directories(), file_exists(), __(), esc_html(), sprintf(), ->get_block_template_folders(), ->is_block_theme(), block_template_folders(), __(), esc_html(), sprintf(), ->cache_add(), ->get_block_template_folders(), ->is_block_theme(), block_template_folders()

This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev60192–20640
8.560192–20640
8.460192–2064013 fewer instructions than PHP 8.3
8.361495–21240
8.261495–21240
8.161495–212401 fewer instruction than PHP 7.4
7.461595–21240

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 1

One hook fires while WP_Theme::__construct() runs, in this order:

  1. apply_filters( wp_cache_themes_persistently )filterline 257 (+6 into the body)

    Filters whether to get the cache of the registered theme directories.

Uses · 16

Show all 16

Used by · 5

Source code

	public function __construct( $theme_dir, $theme_root, $_child = null ) {		global $wp_theme_directories; 		// Initialize caching on first run.		if ( ! isset( self::$persistently_cache ) ) {			/** This action is documented in wp-includes/theme.php */			self::$persistently_cache = apply_filters( 'wp_cache_themes_persistently', false, 'WP_Theme' );			if ( self::$persistently_cache ) {				wp_cache_add_global_groups( 'themes' );				if ( is_int( self::$persistently_cache ) ) {					self::$cache_expiration = self::$persistently_cache;				}			} else {				wp_cache_add_non_persistent_groups( 'themes' );			}		} 		// Handle a numeric theme directory as a string.		$theme_dir = (string) $theme_dir; 		$this->theme_root = $theme_root;		$this->stylesheet = $theme_dir; 		// Correct a situation where the theme is 'some-directory/some-theme' but 'some-directory' was passed in as part of the theme root instead.		if ( ! in_array( $theme_root, (array) $wp_theme_directories, true )			&& in_array( dirname( $theme_root ), (array) $wp_theme_directories, true )		) {			$this->stylesheet = basename( $this->theme_root ) . '/' . $this->stylesheet;			$this->theme_root = dirname( $theme_root );		} 		$this->cache_hash = md5( $this->theme_root . '/' . $this->stylesheet );		$theme_file       = $this->stylesheet . '/style.css'; 		$cache = $this->cache_get( 'theme' ); 		if ( is_array( $cache ) ) {			foreach ( array( 'block_template_folders', 'block_theme', 'errors', 'headers', 'template' ) as $key ) {				if ( isset( $cache[ $key ] ) ) {					$this->$key = $cache[ $key ];				}			}			if ( $this->errors ) {				return;			}			if ( isset( $cache['theme_root_template'] ) ) {				$theme_root_template = $cache['theme_root_template'];			}		} elseif ( ! file_exists( $this->theme_root . '/' . $theme_file ) ) {			$this->headers['Name'] = $this->stylesheet;			if ( ! file_exists( $this->theme_root . '/' . $this->stylesheet ) ) {				$this->errors = new WP_Error(					'theme_not_found',					sprintf(						/* translators: %s: Theme directory name. */						__( 'The theme directory "%s" does not exist.' ),						esc_html( $this->stylesheet )					)				);			} else {				$this->errors = new WP_Error( 'theme_no_stylesheet', __( 'Stylesheet is missing.' ) );			}			$this->template               = $this->stylesheet;			$this->block_theme            = false;			$this->block_template_folders = $this->default_template_folders;			$this->cache_add(				'theme',				array(					'block_template_folders' => $this->block_template_folders,					'block_theme'            => $this->block_theme,					'headers'                => $this->headers,					'errors'                 => $this->errors,					'stylesheet'             => $this->stylesheet,					'template'               => $this->template,				)			);			if ( ! file_exists( $this->theme_root ) ) { // Don't cache this one.				$this->errors->add( 'theme_root_missing', __( '<strong>Error:</strong> The themes directory is either empty or does not exist. Please check your installation.' ) );			}			return;

Changelog

Introduced in 3.4.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/class-wp-theme.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.