Add Guards to "Deactivate Plugin" Note Handlers (https://github.com/woocommerce/woocommerce-admin/pull/6532)
* Add packgage state check to deactivate-plugin note * Add changelog entry * Add method to check if notes are initialized * Update guard to check if notes are initialized * Add testing instructions
This commit is contained in:
parent
0ebccd674b
commit
f1bac7d787
|
@ -2,6 +2,44 @@
|
|||
|
||||
## Unreleased
|
||||
|
||||
### Add Guards to "Deactivate Plugin" Note Handlers #6532
|
||||
|
||||
#### Test incompatible WooCommerce version
|
||||
|
||||
- Install and activate Woocommerce 4.7
|
||||
- See that the Woocommerce Admin plugin is deactivated.
|
||||
- Add the Deactivate Plugin note via SQL.
|
||||
|
||||
```
|
||||
INSERT INTO `wp_wc_admin_notes` (`name`, `type`, `locale`, `title`, `content`, `content_data`, `status`, `source`, `date_created`, `date_reminder`, `is_snoozable`, `layout`, `image`, `is_deleted`, `icon`) VALUES ( 'wc-admin-deactivate-plugin', 'info', 'en_US', 'Deactivate old WooCommerce Admin version', 'Your current version of WooCommerce Admin is outdated and a newer version is included with WooCommerce. We recommend deactivating the plugin and using the stable version included with WooCommerce.', '{}', 'unactioned', 'woocommerce-admin', '2021-03-08 01:26:44', NULL, 0, 'plain', '', 0, 'info');
|
||||
```
|
||||
|
||||
- See that the note is in the inbox
|
||||
- Activate the Woocommerce Admin plugin.
|
||||
- See that Woocommerce Admin immediately de-activates without a fatal error.
|
||||
- See that the note remains in inbox
|
||||
|
||||
#### Test compatible WooCommerce version
|
||||
|
||||
- Deactivate the Woocommerce Admin plugin.
|
||||
- Install and activate the latest Woocommerce version.
|
||||
- Add the Deactivate Plugin note via SQL.
|
||||
|
||||
```
|
||||
INSERT INTO `wp_wc_admin_notes` (`name`, `type`, `locale`, `title`, `content`, `content_data`, `status`, `source`, `date_created`, `date_reminder`, `is_snoozable`, `layout`, `image`, `is_deleted`, `icon`) VALUES ( 'wc-admin-deactivate-plugin', 'info', 'en_US', 'Deactivate old WooCommerce Admin version', 'Your current version of WooCommerce Admin is outdated and a newer version is included with WooCommerce. We recommend deactivating the plugin and using the stable version included with WooCommerce.', '{}', 'unactioned', 'woocommerce-admin', '2021-03-08 01:26:44', NULL, 0, 'plain', '', 0, 'info');
|
||||
```
|
||||
|
||||
- Activate the Woocommerce Admin plugin.
|
||||
- See that note is **not** in the inbox
|
||||
- Add the Deactivate Plugin note via SQL.
|
||||
|
||||
```
|
||||
INSERT INTO `wp_wc_admin_notes` (`name`, `type`, `locale`, `title`, `content`, `content_data`, `status`, `source`, `date_created`, `date_reminder`, `is_snoozable`, `layout`, `image`, `is_deleted`, `icon`) VALUES ( 'wc-admin-deactivate-plugin', 'info', 'en_US', 'Deactivate old WooCommerce Admin version', 'Your current version of WooCommerce Admin is outdated and a newer version is included with WooCommerce. We recommend deactivating the plugin and using the stable version included with WooCommerce.', '{}', 'unactioned', 'woocommerce-admin', '2021-03-08 01:26:44', NULL, 0, 'plain', '', 0, 'info');
|
||||
```
|
||||
|
||||
- De-activate the Woocommerce Admin plugin.
|
||||
- See that note is **not** in the inbox
|
||||
|
||||
### Add legacy report items to new navigation #6507
|
||||
|
||||
1. Enable the new navigation experience.
|
||||
|
|
|
@ -103,6 +103,7 @@ Release and roadmap notes are available on the [WooCommerce Developers Blog](htt
|
|||
- Fix: Associated Order Number for refunds was hidden #6428
|
||||
- Add: Remove Mollie promo note on install #6510
|
||||
- Add: Remote Inbox Notifications rule to trigger when WooCommerce Admin is upgraded. #6040
|
||||
- Fix: Add guard to "Deactivate Plugin" note handlers to prevent fatal error. #6532
|
||||
- Feature: Increase target audience for business feature step. #6508
|
||||
- Fix: Crash of Analytics > Settings page when Gutenberg is installed. #6540
|
||||
- Dev: Store profiler - Added MailPoet to Business Details step #6503
|
||||
|
|
|
@ -118,6 +118,10 @@ class Package {
|
|||
* Add deactivation hook for versions of the plugin that don't have the deactivation note.
|
||||
*/
|
||||
public static function on_deactivation() {
|
||||
if ( ! self::is_notes_initialized() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$update_version = new DeactivatePlugin();
|
||||
$update_version::delete_note();
|
||||
}
|
||||
|
@ -127,6 +131,11 @@ class Package {
|
|||
* and adds/removes DeactivatePlugin note as necessary.
|
||||
*/
|
||||
public static function check_outdated_wca_plugin() {
|
||||
|
||||
if ( ! self::is_notes_initialized() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$update_version = new DeactivatePlugin();
|
||||
|
||||
if ( version_compare( WC_ADMIN_VERSION_NUMBER, self::VERSION, '<' ) ) {
|
||||
|
@ -137,4 +146,16 @@ class Package {
|
|||
$update_version::delete_note();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if notes have been initialized.
|
||||
*/
|
||||
private static function is_notes_initialized() {
|
||||
try {
|
||||
\WC_Data_Store::load( 'admin-note' );
|
||||
} catch ( \Exception $e ) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue