Plugin_Upgrader::deactivate_plugin_before_upgrade

Advertisement

Summery Summery

Deactivates a plugin before it is upgraded.

Syntax Syntax

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

Description Description

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

Parameters Parameters

$return

(Required) Upgrade offer return.

$plugin

(Required) Plugin package arguments.

Return Return

(bool|WP_Error) The passed in $return param or WP_Error.

Source Source

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

		$working_directory = str_replace( $wp_filesystem->wp_content_dir(), trailingslashit( WP_CONTENT_DIR ), $source );
		if ( ! is_dir( $working_directory ) ) { // Sanity check, if the above fails, let's not prevent installation.
			return $source;
		}

		// Check that the folder contains at least 1 valid plugin.
		$files = glob( $working_directory . '*.php' );
		if ( $files ) {
			foreach ( $files as $file ) {
				$info = get_plugin_data( $file, false, false );
				if ( ! empty( $info['Name'] ) ) {
					$this->new_plugin_data = $info;
					break;
				}
			}
		}

		if ( empty( $this->new_plugin_data ) ) {
			return new WP_Error( 'incompatible_archive_no_plugins', $this->strings['incompatible_archive'], __( 'No valid plugins were found.' ) );
		}

		$requires_php = isset( $info['RequiresPHP'] ) ? $info['RequiresPHP'] : null;

Advertisement

Changelog Changelog

Changelog
Version Description
4.1.0 Added a return value.
2.8.0 Introduced.

Advertisement

Leave a Reply