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
PluginVersionRuleProcessor.php
95 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Rule processor for sending when the provided plugin is activated and |
| 4 | * matches the specified version. |
| 5 | */ |
| 6 | |
| 7 | namespace Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors; |
| 8 | |
| 9 | defined( 'ABSPATH' ) || exit; |
| 10 | |
| 11 | use Automattic\WooCommerce\Admin\PluginsProvider\PluginsProvider; |
| 12 | |
| 13 | /** |
| 14 | * Rule processor for sending when the provided plugin is activated and |
| 15 | * matches the specified version. |
| 16 | */ |
| 17 | class PluginVersionRuleProcessor implements RuleProcessorInterface { |
| 18 | |
| 19 | /** |
| 20 | * Plugins provider instance. |
| 21 | * |
| 22 | * @var PluginsProviderInterface |
| 23 | */ |
| 24 | private $plugins_provider; |
| 25 | |
| 26 | |
| 27 | /** |
| 28 | * Constructor. |
| 29 | * |
| 30 | * @param PluginsProviderInterface $plugins_provider The plugins provider. |
| 31 | */ |
| 32 | public function __construct( $plugins_provider = null ) { |
| 33 | $this->plugins_provider = null === $plugins_provider |
| 34 | ? new PluginsProvider() |
| 35 | : $plugins_provider; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Process the rule. |
| 40 | * |
| 41 | * @param object $rule The specific rule being processed by this rule processor. |
| 42 | * @param object $stored_state Stored state. |
| 43 | * |
| 44 | * @return bool Whether the rule passes or not. |
| 45 | */ |
| 46 | public function process( $rule, $stored_state ) { |
| 47 | $active_plugin_slugs = $this->plugins_provider->get_active_plugin_slugs(); |
| 48 | /** |
| 49 | * Filters a plugin dependency’s slug before matching to the WordPress.org slug format. |
| 50 | * |
| 51 | * @since 9.0.0 |
| 52 | * |
| 53 | * @param string $plugin_name requested plugin name |
| 54 | */ |
| 55 | $plugin_name = apply_filters( 'wp_plugin_dependencies_slug', $rule->plugin ); |
| 56 | |
| 57 | if ( ! in_array( $plugin_name, $active_plugin_slugs, true ) ) { |
| 58 | return false; |
| 59 | } |
| 60 | |
| 61 | $plugin_data = $this->plugins_provider->get_plugin_data( $plugin_name ); |
| 62 | |
| 63 | if ( ! is_array( $plugin_data ) || ! array_key_exists( 'Version', $plugin_data ) ) { |
| 64 | return false; |
| 65 | } |
| 66 | |
| 67 | $plugin_version = $plugin_data['Version']; |
| 68 | |
| 69 | return version_compare( $plugin_version, $rule->version, $rule->operator ); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Validates the rule. |
| 74 | * |
| 75 | * @param object $rule The rule to validate. |
| 76 | * |
| 77 | * @return bool Pass/fail. |
| 78 | */ |
| 79 | public function validate( $rule ) { |
| 80 | if ( ! isset( $rule->plugin ) ) { |
| 81 | return false; |
| 82 | } |
| 83 | |
| 84 | if ( ! isset( $rule->version ) ) { |
| 85 | return false; |
| 86 | } |
| 87 | |
| 88 | if ( ! isset( $rule->operator ) ) { |
| 89 | return false; |
| 90 | } |
| 91 | |
| 92 | return true; |
| 93 | } |
| 94 | } |
| 95 |