make_site_theme_from_oldschool( string $theme_name, string $template ): bool
- Since
- 1.5.0
- Source
wp-admin/includes/upgrade.php:3379
Description
}
Compatibility
- WordPress
- since 1.5.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_namestring- The name of the theme.
$templatestring- The directory name of the theme.
Return value
bool
Performance profile
How much work a call to make_site_theme_from_oldschool() 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
- Scaling
- Scales with input
- Instructions
- 18–54
- Plugin surface
- None
- Called by
- 1
Reads or writes the filesystem via file_exists().
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 151.
Nothing here hands control to plugin code.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- filesystemfilesystem access
file_exists()called directly - optionoption read or write
get_option()one call below make_site_theme_from_oldschool() - serializeserialisation
maybe_unserialize()one call below make_site_theme_from_oldschool()
Further down the call graph this can also reach hook, cache, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 5 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost make_site_theme_from_oldschool() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!file_exists() | 18 | get_home_path(), file_exists() |
file_exists() | 36–37 | get_home_path(), file_exists(), __get_option(), file_get_contents() |
file_exists() && $oldfile !== "index.php" && !copy() | 39 | get_home_path(), file_exists(), copy() |
file_exists() && $oldfile === "index.php" && !copy() | 49 | get_home_path(), file_exists(), file(), copy() |
file_exists() | 53–54 | get_home_path(), file_exists(), __get_option(), file_get_contents(), fopen(), fwrite(), fwrite(), fclose() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 151 | 18–54 | 13 | |
| 8.5 | 151 | 18–54 | 13 | |
| 8.4 | 151 | 18–54 | 13 | 18 fewer instructions than PHP 8.3 |
| 8.3 | 169 | 18–55 | 13 | |
| 8.2 | 169 | 18–55 | 13 | |
| 8.1 | 169 | 18–55 | 13 | |
| 7.4 | 169 | 18–55 | 13 |
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.
Uses · 3
- get_home_path()Gets the absolute filesystem path to the root of the WordPress installation.
- str_contains()Polyfill for `str_contains()` function added in PHP 8.0.
- __get_option()Utility version of get_option that is private to installation/upgrade.
Used by · 1
- make_site_theme()Creates a site theme.
Source code
function make_site_theme_from_oldschool( $theme_name, $template ) { $home_path = get_home_path(); $site_dir = WP_CONTENT_DIR . "/themes/$template"; $default_dir = WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME; if ( ! file_exists( "$home_path/index.php" ) ) { return false; } /* * Copy files from the old locations to the site theme. * TODO: This does not copy arbitrary include dependencies. Only the standard WP files are copied. */ $files = array( 'index.php' => 'index.php', 'wp-layout.css' => 'style.css', 'wp-comments.php' => 'comments.php', 'wp-comments-popup.php' => 'comments-popup.php', ); foreach ( $files as $oldfile => $newfile ) { if ( 'index.php' === $oldfile ) { $oldpath = $home_path; } else { $oldpath = ABSPATH; } // Check to make sure it's not a new index. if ( 'index.php' === $oldfile ) { $index = implode( '', file( "$oldpath/$oldfile" ) ); if ( str_contains( $index, 'WP_USE_THEMES' ) ) { if ( ! copy( "$default_dir/$oldfile", "$site_dir/$newfile" ) ) { return false; } // Don't copy anything. continue; } } if ( ! copy( "$oldpath/$oldfile", "$site_dir/$newfile" ) ) { return false; } chmod( "$site_dir/$newfile", 0777 ); // Update the blog header include in each file. $lines = explode( "\n", implode( '', file( "$site_dir/$newfile" ) ) ); if ( $lines ) { $f = fopen( "$site_dir/$newfile", 'w' ); foreach ( $lines as $line ) { if ( preg_match( '/require.*wp-blog-header/', $line ) ) { $line = '//' . $line; } // Update stylesheet references. $line = str_replace( "<?php echo __get_option('siteurl'); ?>/wp-layout.css", "<?php bloginfo('stylesheet_url'); ?>", $line ); // Update comments template inclusion. $line = str_replace( "<?php include(ABSPATH . 'wp-comments.php'); ?>", '<?php comments_template(); ?>', $line ); fwrite( $f, "{$line}\n" ); } fclose( $f ); } } // Add a theme header. $header = "/*\n" . "Theme Name: $theme_name\n" . 'Theme URI: ' . __get_option( 'siteurl' ) . "\n" .Changelog
Introduced in 1.5.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.9.7 tag, from
src/wp-admin/includes/upgrade.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.