Plugin_Upgrader::active_before() WordPress Method

The Plugin_Upgrader::active_before() method is called before a plugin is updated. This is a useful place to do any checks or tasks that need to be done before the plugin is updated.

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

Turns on maintenance mode before attempting to background update an active plugin.


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 active_before( $response, $plugin ) {
		if ( is_wp_error( $response ) ) {
			return $response;
		}

		// Only enable maintenance mode when in cron (background update).
		if ( ! wp_doing_cron() ) {
			return $response;
		}

		$plugin = isset( $plugin['plugin'] ) ? $plugin['plugin'] : '';

		// Only run if plugin is active.
		if ( ! is_plugin_active( $plugin ) ) {
			return $response;
		}

		// Change to maintenance mode. Bulk edit handles this separately.
		if ( ! $this->bulk ) {
			$this->maintenance_mode( true );
		}

		return $response;
	}


Top ↑

Changelog

Changelog
VersionDescription
5.4.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.