make_site_theme_from_default( string $theme_name, string $template ): void|false
- Since
- 1.5.0
- Source
wp-admin/includes/upgrade.php:3434
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
void|false
Performance profile
How much work a call to make_site_theme_from_default() 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
- 37–101
- Plugin surface
- None
- Called by
- 1
Reads or writes the filesystem via mkdir().
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 154.
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
mkdir()called directly - serializeserialisation
maybe_unserialize()one call below make_site_theme_from_default()
What one call costs · 17 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost make_site_theme_from_default() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!mkdir() | 37 | opendir(), file(), explode(), umask(), mkdir() |
$theme_file !== false && !is_dir() && !copy() | 42 | opendir(), readdir(), is_dir(), copy() |
mkdir() | 45 | opendir(), file(), explode(), umask(), mkdir(), opendir() |
$theme_file === false && !mkdir() | 47 | opendir(), readdir(), closedir(), file(), explode(), umask(), mkdir() |
mkdir() && $image === false | 55 | opendir(), file(), explode(), umask(), mkdir(), opendir(), readdir(), closedir() |
$theme_file === false && mkdir() | 55 | opendir(), readdir(), closedir(), file(), explode(), umask(), mkdir(), opendir() |
!mkdir() | 57–58 | opendir(), file(), explode(), fopen(), __get_option(), fclose(), umask(), mkdir() |
mkdir() | 65–66 | opendir(), file(), explode(), fopen(), __get_option(), fclose(), umask(), mkdir(), opendir() |
$theme_file === false && mkdir() && $image === false | 65 | opendir(), readdir(), closedir(), file(), explode(), umask(), mkdir(), opendir(), readdir(), closedir() |
$theme_file === false && !mkdir() | 67–68 | opendir(), readdir(), closedir(), file(), explode(), fopen(), __get_option(), fclose(), umask(), mkdir() |
mkdir() && $image !== false && !is_dir() && !copy() | 70 | opendir(), file(), explode(), umask(), mkdir(), opendir(), readdir(), is_dir(), copy() |
mkdir() && $image === false | 75–76 | opendir(), file(), explode(), fopen(), __get_option(), fclose(), umask(), mkdir(), opendir(), readdir(), closedir() |
5 further outcomes, up to 101 instructions
$theme_file === false && mkdir() | 75–76 | opendir(), readdir(), closedir(), file(), explode(), fopen(), __get_option(), fclose(), umask(), mkdir(), opendir() |
$theme_file === false && mkdir() && $image !== false && !is_dir() && !copy() | 80 | opendir(), readdir(), closedir(), file(), explode(), umask(), mkdir(), opendir(), readdir(), is_dir(), copy() |
$theme_file === false && mkdir() && $image === false | 85–86 | opendir(), readdir(), closedir(), file(), explode(), fopen(), __get_option(), fclose(), umask(), mkdir(), opendir(), readdir(), closedir() |
mkdir() && $image !== false && !is_dir() && !copy() | 90–91 | opendir(), file(), explode(), fopen(), __get_option(), fclose(), umask(), mkdir(), opendir(), readdir(), is_dir(), copy() |
$theme_file === false && mkdir() && $image !== false && !is_dir() && !copy() | 100–101 | opendir(), readdir(), closedir(), file(), explode(), fopen(), __get_option(), fclose(), umask(), mkdir(), opendir(), readdir(), is_dir(), copy() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 154 | 37–101 | 15 | |
| 8.5 | 154 | 37–101 | 15 | |
| 8.4 | 154 | 37–101 | 15 | 6 fewer instructions than PHP 8.3 |
| 8.3 | 160 | 40–104 | 15 | |
| 8.2 | 160 | 40–104 | 15 | 2 more instructions than PHP 8.1 |
| 8.1 | 158 | 35–137 | 15 | |
| 7.4 | 158 | 35–137 | 15 |
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 · 2
- __get_option()Utility version of get_option that is private to installation/upgrade.
- str_contains()Polyfill for `str_contains()` function added in PHP 8.0.
Used by · 1
- make_site_theme()Creates a site theme.
Source code
function make_site_theme_from_default( $theme_name, $template ) { $site_dir = WP_CONTENT_DIR . "/themes/$template"; $default_dir = WP_CONTENT_DIR . '/themes/' . WP_DEFAULT_THEME; /* * Copy files from the default theme to the site theme. * $files = array( 'index.php', 'comments.php', 'comments-popup.php', 'footer.php', 'header.php', 'sidebar.php', 'style.css' ); */ $theme_dir = @opendir( $default_dir ); if ( $theme_dir ) { while ( ( $theme_file = readdir( $theme_dir ) ) !== false ) { if ( is_dir( "$default_dir/$theme_file" ) ) { continue; } if ( ! copy( "$default_dir/$theme_file", "$site_dir/$theme_file" ) ) { return; } chmod( "$site_dir/$theme_file", 0777 ); } closedir( $theme_dir ); } // Rewrite the theme header. $stylelines = explode( "\n", implode( '', file( "$site_dir/style.css" ) ) ); if ( $stylelines ) { $f = fopen( "$site_dir/style.css", 'w' ); $headers = array( 'Theme Name:' => $theme_name, 'Theme URI:' => __get_option( 'url' ), 'Description:' => 'Your theme.', 'Version:' => '1', 'Author:' => 'You', ); foreach ( $stylelines as $line ) { foreach ( $headers as $header => $value ) { if ( str_contains( $line, $header ) ) { $line = $header . ' ' . $value; break; } } fwrite( $f, $line . "\n" ); } fclose( $f ); } // Copy the images. umask( 0 ); if ( ! mkdir( "$site_dir/images", 0777 ) ) { return false; } $images_dir = @opendir( "$default_dir/images" ); if ( $images_dir ) { while ( ( $image = readdir( $images_dir ) ) !== false ) { if ( is_dir( "$default_dir/images/$image" ) ) { continue; } if ( ! copy( "$default_dir/images/$image", "$site_dir/images/$image" ) ) { return; } chmod( "$site_dir/images/$image", 0777 ); } closedir( $images_dir ); }}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.7.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.