wppaste
WordPress

resume_theme( string $theme, string $redirect = '' ): bool|WP_Error

Since
5.2.0
Source
wp-admin/includes/theme.php:1173
Tries to resume a single theme.

Description

If a redirect was provided and a functions.php file was found, we first ensure that functions.php file does not throw fatal errors anymore.

The way it works is by setting the redirection to the error before trying to include the file. If the theme fails, then the redirection will not be overwritten with the success message and the theme will not be resumed.

Compatibility

WordPress
since 5.2.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

$themestring
Single theme to resume.
$redirectstringoptional
URL to redirect to. Default empty string.Default: ''

Return value

bool|WP_Error
True on success, false if $theme was not paused, WP_Error on failure.

Performance profile

How much work a call to resume_theme() 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

Reaches the database via ->delete().

Scaling
Constant

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

Instructions
21–57

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • sqldatabase query->delete()called directly
  • hookthird-party callbacksapply_filters()one call below resume_theme()

Further down the call graph this can also reach option, cache, serialize, transient 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 · 4 distinct outcomes

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

WhenInstructionsCalls it makes
always21–30explode(), wp_paused_themes(), ->delete()
always28–37explode(), wp_paused_themes(), ->delete(), __()
!empty($redirect) && !empty($functions_path)47–50explode(), wp_create_nonce(), add_query_arg(), wp_redirect(), ob_start(), ob_clean(), wp_paused_themes(), ->delete()
!empty($redirect) && !empty($functions_path)54–57explode(), wp_create_nonce(), add_query_arg(), wp_redirect(), ob_start(), ob_clean(), wp_paused_themes(), ->delete(), __()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev6121–576
8.56121–576
8.46121–5766 fewer instructions than PHP 8.3
8.36721–636
8.26721–636
8.16721–636
7.46721–636

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 · 8

Source code

function resume_theme( $theme, $redirect = '' ) {	global $wp_stylesheet_path, $wp_template_path; 	list( $extension ) = explode( '/', $theme ); 	/*	 * We'll override this later if the theme could be resumed without	 * creating a fatal error.	 */	if ( ! empty( $redirect ) ) {		$functions_path = '';		if ( str_contains( $wp_stylesheet_path, $extension ) ) {			$functions_path = $wp_stylesheet_path . '/functions.php';		} elseif ( str_contains( $wp_template_path, $extension ) ) {			$functions_path = $wp_template_path . '/functions.php';		} 		if ( ! empty( $functions_path ) ) {			wp_redirect(				add_query_arg(					'_error_nonce',					wp_create_nonce( 'theme-resume-error_' . $theme ),					$redirect				)			); 			// Load the theme's functions.php to test whether it throws a fatal error.			ob_start();			if ( ! defined( 'WP_SANDBOX_SCRAPING' ) ) {				define( 'WP_SANDBOX_SCRAPING', true );			}			include $functions_path;			ob_clean();		}	} 	$result = wp_paused_themes()->delete( $extension ); 	if ( ! $result ) {		return new WP_Error(			'could_not_resume_theme',			__( 'Could not resume the theme.' )		);	} 	return true;}

Changelog

Introduced in 5.2.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/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.