Plugin_Upgrader::deactivate_plugin_before_upgrade()
Deactivates a plugin before it is upgraded.
Hooked to the upgrader_pre_install filter by Plugin_Upgrader::upgrade().
Method of the class: Plugin_Upgrader{}
No Hooks.
Return
true|false|WP_Error
. The original $response parameter or WP_Error.
Usage
$Plugin_Upgrader = new Plugin_Upgrader(); $Plugin_Upgrader->deactivate_plugin_before_upgrade( $response, $plugin );
- $response(true|false|WP_Error) (required)
- The installation response before the installation has started.
- $plugin(array) (required)
- Plugin package arguments.
Changelog
Since 2.8.0 | Introduced. |
Since 4.1.0 | Added a return value. |
Plugin_Upgrader::deactivate_plugin_before_upgrade() Plugin Upgrader::deactivate plugin before upgrade code WP 6.6.2
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; }