resume_plugin() WordPress Function

The resume_plugin() function is used to resume a paused or inactive WordPress plugin. This function is typically used when a plugin has been paused or deactivated due to an error. By resuming the plugin, you can often fix the error and continue using the plugin.

resume_plugin( string $plugin, string $redirect = '' ) #

Tries to resume a single plugin.


Description

If a redirect was provided, we first ensure the plugin does not throw fatal errors anymore.

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


Top ↑

Parameters

$plugin

(string)(Required)Single plugin to resume.

$redirect

(string)(Optional) URL to redirect to.

Default value: ''


Top ↑

Return

(bool|WP_Error) True on success, false if $plugin was not paused, WP_Error on failure.


Top ↑

Source

File: wp-admin/includes/plugin.php

function resume_plugin( $plugin, $redirect = '' ) {
	/*
	 * We'll override this later if the plugin could be resumed without
	 * creating a fatal error.
	 */
	if ( ! empty( $redirect ) ) {
		wp_redirect(
			add_query_arg(
				'_error_nonce',
				wp_create_nonce( 'plugin-resume-error_' . $plugin ),
				$redirect
			)
		);

		// Load the plugin to test whether it throws a fatal error.
		ob_start();
		plugin_sandbox_scrape( $plugin );
		ob_clean();
	}

	list( $extension ) = explode( '/', $plugin );

	$result = wp_paused_plugins()->delete( $extension );

	if ( ! $result ) {
		return new WP_Error(
			'could_not_resume_plugin',
			__( 'Could not resume the plugin.' )
		);
	}

	return true;
}


Top ↑

Changelog

Changelog
VersionDescription
5.2.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.