Refactor WCA plugin version check to run on 'woocommerce_init' hook (https://github.com/woocommerce/woocommerce-admin/pull/6217)

This commit is contained in:
Ilyas Foo 2021-02-04 17:24:05 +08:00 committed by GitHub
parent 88d72c88cd
commit e44835aa41
1 changed files with 19 additions and 8 deletions

View File

@ -49,14 +49,9 @@ class Package {
// Avoid double initialization when the feature plugin is in use.
if ( defined( 'WC_ADMIN_VERSION_NUMBER' ) ) {
self::$active_version = WC_ADMIN_VERSION_NUMBER;
$update_version = new DeactivatePlugin();
if ( version_compare( WC_ADMIN_VERSION_NUMBER, self::VERSION, '<' ) ) {
if ( method_exists( $update_version, 'possibly_add_note' ) ) {
$update_version::possibly_add_note();
}
} else {
$update_version::delete_note();
}
// Check version after WooCommerce is initialized.
add_action( 'woocommerce_init', array( __CLASS__, 'check_outdated_wca_plugin' ) );
// Register a deactivation hook for the feature plugin.
register_deactivation_hook( WC_ADMIN_PLUGIN_FILE, array( __CLASS__, 'on_deactivation' ) );
@ -126,4 +121,20 @@ class Package {
$update_version = new DeactivatePlugin();
$update_version::delete_note();
}
/**
* Checks if embedded WCA version is newer than standalone WCA
* and adds/removes DeactivatePlugin note as necessary.
*/
public static function check_outdated_wca_plugin() {
$update_version = new DeactivatePlugin();
if ( version_compare( WC_ADMIN_VERSION_NUMBER, self::VERSION, '<' ) ) {
if ( method_exists( $update_version, 'possibly_add_note' ) ) {
$update_version::possibly_add_note();
}
} else {
$update_version::delete_note();
}
}
}