wppaste
WordPress

make_site_theme_from_default( string $theme_name, string $template ): void|false

Since
1.5.0
Source
wp-admin/includes/upgrade.php:3484
Creates a site theme from the default theme.

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

Reads or writes the filesystem via mkdir().

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
37–101

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
1

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

What it touches

  • filesystemfilesystem accessmkdir()called directly
  • serializeserialisationmaybe_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.

WhenInstructionsCalls it makes
!mkdir()37opendir(), file(), explode(), umask(), mkdir()
$theme_file !== false && !is_dir() && !copy()42opendir(), readdir(), is_dir(), copy()
mkdir()45opendir(), file(), explode(), umask(), mkdir(), opendir()
$theme_file === false && !mkdir()47opendir(), readdir(), closedir(), file(), explode(), umask(), mkdir()
mkdir() && $image === false55opendir(), file(), explode(), umask(), mkdir(), opendir(), readdir(), closedir()
$theme_file === false && mkdir()55opendir(), readdir(), closedir(), file(), explode(), umask(), mkdir(), opendir()
!mkdir()57–58opendir(), file(), explode(), fopen(), __get_option(), fclose(), umask(), mkdir()
mkdir()65–66opendir(), file(), explode(), fopen(), __get_option(), fclose(), umask(), mkdir(), opendir()
$theme_file === false && mkdir() && $image === false65opendir(), readdir(), closedir(), file(), explode(), umask(), mkdir(), opendir(), readdir(), closedir()
$theme_file === false && !mkdir()67–68opendir(), readdir(), closedir(), file(), explode(), fopen(), __get_option(), fclose(), umask(), mkdir()
mkdir() && $image !== false && !is_dir() && !copy()70opendir(), file(), explode(), umask(), mkdir(), opendir(), readdir(), is_dir(), copy()
mkdir() && $image === false75–76opendir(), file(), explode(), fopen(), __get_option(), fclose(), umask(), mkdir(), opendir(), readdir(), closedir()
5 further outcomes, up to 101 instructions
$theme_file === false && mkdir()75–76opendir(), readdir(), closedir(), file(), explode(), fopen(), __get_option(), fclose(), umask(), mkdir(), opendir()
$theme_file === false && mkdir() && $image !== false && !is_dir() && !copy()80opendir(), readdir(), closedir(), file(), explode(), umask(), mkdir(), opendir(), readdir(), is_dir(), copy()
$theme_file === false && mkdir() && $image === false85–86opendir(), readdir(), closedir(), file(), explode(), fopen(), __get_option(), fclose(), umask(), mkdir(), opendir(), readdir(), closedir()
mkdir() && $image !== false && !is_dir() && !copy()90–91opendir(), file(), explode(), fopen(), __get_option(), fclose(), umask(), mkdir(), opendir(), readdir(), is_dir(), copy()
$theme_file === false && mkdir() && $image !== false && !is_dir() && !copy()100–101opendir(), readdir(), closedir(), file(), explode(), fopen(), __get_option(), fclose(), umask(), mkdir(), opendir(), readdir(), is_dir(), copy()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev15437–10115
8.515437–10115
8.415437–101156 fewer instructions than PHP 8.3
8.316040–10415
8.216040–104152 more instructions than PHP 8.1
8.115835–13715
7.415835–13715

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

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.

  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 6.8.8 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.