Transformers
1 year ago
BaseLocationCountryRuleProcessor.php
2 years ago
BaseLocationStateRuleProcessor.php
2 years ago
ComparisonOperation.php
2 years ago
ContextPluginsRuleProcessor.php
1 year ago
EvaluateAndGetStatus.php
2 years ago
EvaluateOverrides.php
1 year ago
EvaluationLogger.php
1 year ago
FailRuleProcessor.php
2 years ago
GetRuleProcessor.php
2 years ago
GetRuleProcessorForContext.php
1 year ago
IsEcommerceRuleProcessor.php
2 years ago
IsWooExpressRuleProcessor.php
2 years ago
NotRuleProcessor.php
2 years ago
NoteStatusRuleProcessor.php
2 years ago
OnboardingProfileRuleProcessor.php
2 years ago
OptionRuleProcessor.php
2 years ago
OrRuleProcessor.php
2 years ago
OrderCountRuleProcessor.php
2 years ago
OrdersProvider.php
2 years ago
PassRuleProcessor.php
2 years ago
PluginVersionRuleProcessor.php
2 years ago
PluginsActivatedRuleProcessor.php
2 years ago
ProductCountRuleProcessor.php
1 year ago
PublishAfterTimeRuleProcessor.php
2 years ago
PublishBeforeTimeRuleProcessor.php
2 years ago
RuleEvaluator.php
1 year ago
RuleProcessorInterface.php
2 years ago
StoredStateRuleProcessor.php
2 years ago
StoredStateSetupForProducts.php
2 years ago
TotalPaymentsVolumeProcessor.php
1 year ago
WCAdminActiveForProvider.php
2 years ago
WCAdminActiveForRuleProcessor.php
2 years ago
WooCommerceAdminUpdatedRuleProcessor.php
2 years ago
PluginsActivatedRuleProcessor.php
82 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Rule processor for sending when the provided plugins are activated. |
| 4 | */ |
| 5 | |
| 6 | namespace Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors; |
| 7 | |
| 8 | defined( 'ABSPATH' ) || exit; |
| 9 | |
| 10 | use Automattic\WooCommerce\Admin\PluginsProvider\PluginsProvider; |
| 11 | |
| 12 | /** |
| 13 | * Rule processor for sending when the provided plugins are activated. |
| 14 | */ |
| 15 | class PluginsActivatedRuleProcessor implements RuleProcessorInterface { |
| 16 | |
| 17 | /** |
| 18 | * The plugins provider. |
| 19 | * |
| 20 | * @var PluginsProviderInterface |
| 21 | */ |
| 22 | protected $plugins_provider; |
| 23 | |
| 24 | /** |
| 25 | * Constructor. |
| 26 | * |
| 27 | * @param PluginsProviderInterface $plugins_provider The plugins provider. |
| 28 | */ |
| 29 | public function __construct( $plugins_provider = null ) { |
| 30 | $this->plugins_provider = null === $plugins_provider |
| 31 | ? new PluginsProvider() |
| 32 | : $plugins_provider; |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Process the rule. |
| 37 | * |
| 38 | * @param object $rule The specific rule being processed by this rule processor. |
| 39 | * @param object $stored_state Stored state. |
| 40 | * |
| 41 | * @return bool Whether the rule passes or not. |
| 42 | */ |
| 43 | public function process( $rule, $stored_state ) { |
| 44 | if ( ! is_countable( $rule->plugins ) || 0 === count( $rule->plugins ) ) { |
| 45 | return false; |
| 46 | } |
| 47 | |
| 48 | $active_plugin_slugs = $this->plugins_provider->get_active_plugin_slugs(); |
| 49 | |
| 50 | foreach ( $rule->plugins as $plugin_slug ) { |
| 51 | if ( ! is_string( $plugin_slug ) ) { |
| 52 | $logger = wc_get_logger(); |
| 53 | $logger->warning( |
| 54 | __( 'Invalid plugin slug provided in the plugins activated rule.', 'woocommerce' ) |
| 55 | ); |
| 56 | return false; |
| 57 | } |
| 58 | |
| 59 | if ( ! in_array( $plugin_slug, $active_plugin_slugs, true ) ) { |
| 60 | return false; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | return true; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Validates the rule. |
| 69 | * |
| 70 | * @param object $rule The rule to validate. |
| 71 | * |
| 72 | * @return bool Pass/fail. |
| 73 | */ |
| 74 | public function validate( $rule ) { |
| 75 | if ( ! isset( $rule->plugins ) || ! is_array( $rule->plugins ) ) { |
| 76 | return false; |
| 77 | } |
| 78 | |
| 79 | return true; |
| 80 | } |
| 81 | } |
| 82 |