Plugin_Upgrader::deactivate_plugin_before_upgrade() WordPress Method

The Plugin_Upgrader::deactivate_plugin_before_upgrade() method deactivates a plugin before upgrading it. This is useful for ensuring that the upgrade process does not cause any conflicts with the currently active version of the plugin.

Plugin_Upgrader::deactivate_plugin_before_upgrade( bool|WP_Error $response, array $plugin ) #

Deactivates a plugin before it is upgraded.


Description

Hooked to the ‘upgrader_pre_install’ filter by Plugin_Upgrader::upgrade().


Top ↑

Parameters

$response

(bool|WP_Error)(Required)The installation response before the installation has started.

$plugin

(array)(Required)Plugin package arguments.


Top ↑

Return

(bool|WP_Error) The original $response parameter or WP_Error.


Top ↑

Source

File: wp-admin/includes/class-plugin-upgrader.php

	public function deactivate_plugin_before_upgrade( $response, $plugin ) {

		if ( is_wp_error( $response ) ) { // Bypass.
			return $response;
		}

		// When in cron (background updates) don't deactivate the plugin, as we require a browser to reactivate it.
		if ( wp_doing_cron() ) {
			return $response;
		}

		$plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : '';
		if ( empty( $plugin ) ) {
			return new WP_Error( 'bad_request', $this->strings['bad_request'] );
		}

		if ( is_plugin_active( $plugin ) ) {
			// Deactivate the plugin silently, Prevent deactivation hooks from running.
			deactivate_plugins( $plugin, true );
		}

		return $response;
	}


Top ↑

Changelog

Changelog
VersionDescription
4.1.0Added a return value.
2.8.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.