Add remote inbox notifications rule that triggers when WCA is updated (https://github.com/woocommerce/woocommerce-admin/pull/6040)

* Add remote inbox notifications rule that triggers when WCA is updated

* Add changlog entry

* Note that `plugin_version` should be used to check the WCA version
This commit is contained in:
Bec Scott 2021-03-05 10:44:54 +10:00 committed by GitHub
parent 46d4a01791
commit 3c72bd4990
5 changed files with 71 additions and 2 deletions

View File

@ -97,6 +97,7 @@ Release and roadmap notes are available on the [WooCommerce Developers Blog](htt
- Add: Add a "rather not say" option to revenue in the profile wizard. #6475
- Dev: Added warning when WC-Admin is active but not being used #6453
- Add: Remove Mollie promo note on install #6510
- Add: Remote Inbox Notifications rule to trigger when WooCommerce Admin is upgraded. #6040
== 2.1.0 ==
@ -172,8 +173,6 @@ Release and roadmap notes are available on the [WooCommerce Developers Blog](htt
- Add: Allow users to install the PayU plugin in the payments setup task. #6332
- Fix: Persist the enabling of plugins in the payments setup task. #6332
== Changelog ==
== 1.9.0 1/15/2021 ==
- Fix: Add Customer Type column to the Orders report table. #5820

View File

@ -56,6 +56,8 @@ class GetRuleProcessor {
return new NoteStatusRuleProcessor();
case 'option':
return new OptionRuleProcessor();
case 'wca_updated':
return new WooCommerceAdminUpdatedRuleProcessor();
}
return new FailRuleProcessor();

View File

@ -425,3 +425,17 @@ This passes when the option value matches the value using the operation.
```
`option_name`, `value`, and `operation` are all required. `default` is not required and allows a default value to be used if the option does not exist.
### WCA updated
This passes when WooCommerce Admin has just been updated. The specs will be run
on update. Note that this doesn't provide a way to check the version number as
the `plugin_version` rule can be used to check for a specific version of the
WooCommerce Admin plugin.
```
{
type: "wca_updated"
}
```
No other values are needed.

View File

@ -19,6 +19,7 @@ use \Automattic\WooCommerce\Admin\Features\Onboarding;
class RemoteInboxNotificationsEngine {
const SPECS_OPTION_NAME = 'wc_remote_inbox_notifications_specs';
const STORED_STATE_OPTION_NAME = 'wc_remote_inbox_notifications_stored_state';
const WCA_UPDATED_OPTION_NAME = 'wc_remote_inbox_notifications_wca_updated';
/**
* Initialize the engine.
@ -34,6 +35,10 @@ class RemoteInboxNotificationsEngine {
10,
2
);
// Hook into WCA updated. This is hooked up here rather than in
// on_admin_init because that runs too late to hook into the action.
add_action( 'woocommerce_admin_updated', array( __CLASS__, 'run_on_woocommerce_admin_updated' ) );
}
/**
@ -96,6 +101,19 @@ class RemoteInboxNotificationsEngine {
}
}
/**
* Set an option indicating that WooCommerce Admin has just been updated,
* run the specs, then clear that option. This lets the
* WooCommerceAdminUpdatedRuleProcessor trigger on WCA update.
*/
public static function run_on_woocommerce_admin_updated() {
update_option( self::WCA_UPDATED_OPTION_NAME, true );
self::run();
update_option( self::WCA_UPDATED_OPTION_NAME, false );
}
/**
* Gets the stored state option, and does the initial set up if it doesn't
* already exist.

View File

@ -0,0 +1,36 @@
<?php
/**
* Rule processor for sending when WooCommerce Admin has been updated.
*/
namespace Automattic\WooCommerce\Admin\RemoteInboxNotifications;
defined( 'ABSPATH' ) || exit;
/**
* Rule processor for sending when WooCommerce Admin has been updated.
*/
class WooCommerceAdminUpdatedRuleProcessor implements RuleProcessorInterface {
/**
* Process the rule.
*
* @param object $rule The specific rule being processed by this rule processor.
* @param object $stored_state Stored state.
*
* @return bool Whether the rule passes or not.
*/
public function process( $rule, $stored_state ) {
return get_option( RemoteInboxNotificationsEngine::WCA_UPDATED_OPTION_NAME, false );
}
/**
* Validates the rule.
*
* @param object $rule The rule to validate.
*
* @return bool Pass/fail.
*/
public function validate( $rule ) {
return true;
}
}