apply_filters( ‘upgrader_pre_install’, bool|WP_Error $response, array $hook_extra )

Filters the installation response before the installation has started.

Description

Returning a value that could be evaluated as a WP_Error will effectively short-circuit the installation, returning that value instead.

Parameters

$responsebool|WP_Error
Installation response.
$hook_extraarray
Extra arguments passed to hooked filters.

Source

$res = apply_filters( 'upgrader_pre_install', true, $args['hook_extra'] );

Changelog

VersionDescription
2.8.0Introduced.

User Contributed Notes

  1. Skip to note 2 content

    If you want to keep the current version and the previous version in the database (for debugging purposes)-

    <?php
    function wpdocs_plugin_store_previous_version( $upgrader_object, $options ) {
    	if ( 'update' === $options['action'] && 'plugin' === $options['type'] ) {
    		foreach ( $options['plugins'] as $plugin ) {
    			if ( plugin_basename( $plugin ) === 'wpdocs-plugin/wpdocs-plugin.php' ) {
    				update_option( 'wpdocs-plugin_previous_version', WPDOCS_PLUGIN_VER );
    			}
    		}
    	}
    }
    	
    function wpdocs_plugin_store_new_version( $upgrader_object, $options ) {
    	if ( 'update' === $options['action'] && 'plugin' === $options['type'] ) {
    		foreach ( $options['plugins'] as $plugin ) {
    			if ( plugin_basename( $plugin ) === 'wpdocs-plugin/wpdocs-plugin.php' ) {
    				update_option( 'wpdocs-plugin_previous_version', get_option( 'wpdocs-plugin_previous_version' ) );
    				update_option( 'wpdocs-plugin_current_version', WPDOCS_PLUGIN_VER );
    			}
    		}
    	}
    }
    
    add_action( 'upgrader_pre_install', 'wpdocs_plugin_store_previous_version', 10, 2 );
    add_action( 'upgrader_process_complete', 'wpdocs_plugin_store_new_version', 10, 2 );

You must log in before being able to contribute a note or feedback.