PluginProbe
WooCommerce / 11.1.0
WooCommerce v11.1.0
11.1.0 11.1.0-rc.2 11.1.0-rc.1 11.1.0-beta.2 11.1.0-beta.1 11.0.1 11.0.0 11.0.0-rc.3 11.0.0-rc.2 11.0.0-rc.1 11.0.0-beta.2 11.0.0-beta.1 10.9.4 10.9.3 10.9.2 10.9.1 10.9.0 10.9.0-rc.1 10.9.0-beta.2 10.9.0-beta.1 10.8.1 10.8.0 10.8.0-rc.1 10.8.0-beta.2 10.8.0-beta.1 All 648 releases
woocommerce / src / Admin / RemoteSpecs / RuleProcessors / IsWooExpressRuleProcessor.php
IsWooExpressRuleProcessor.php
70 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Rule processor that passes (or fails) when the site is on a Woo Express plan.
4 *
5 * @package WooCommerce\Admin\Classes
6 */
7
8 namespace Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors;
9
10 defined( 'ABSPATH' ) || exit;
11
12 /**
13 * Rule processor that passes (or fails) when the site is on a Woo Express plan.
14 * You may optionally pass a plan name to target a specific Woo Express plan.
15 */
16 class IsWooExpressRuleProcessor implements RuleProcessorInterface {
17 /**
18 * Passes (or fails) based on whether the site is a Woo Express plan.
19 *
20 * @param object $rule The rule being processed by this rule processor.
21 * @param object $stored_state Stored state.
22 *
23 * @return bool The result of the operation.
24 */
25 public function process( $rule, $stored_state ) {
26 if ( ! function_exists( 'wc_calypso_bridge_is_woo_express_plan' ) ) {
27 return false === $rule->value;
28 }
29
30 // If the plan is undefined, only check if it's a Woo Express plan.
31 if ( ! isset( $rule->plan ) ) {
32 return wc_calypso_bridge_is_woo_express_plan() === $rule->value;
33 }
34
35 // If a plan name is defined, only evaluate the plan if we're on the Woo Express plan.
36 if ( wc_calypso_bridge_is_woo_express_plan() ) {
37 $fn = 'wc_calypso_bridge_is_woo_express_' . (string) $rule->plan . '_plan';
38 if ( function_exists( $fn ) ) {
39 return $fn() === $rule->value;
40 }
41
42 // If an invalid plan name is given, only evaluate the rule if we're targeting all plans other than the specified (invalid) one.
43 return false === $rule->value;
44 }
45
46 return false;
47 }
48
49 /**
50 * Validate the rule.
51 *
52 * @param object $rule The rule to validate.
53 *
54 * @return bool Pass/fail.
55 */
56 public function validate( $rule ) {
57 if ( ! isset( $rule->value ) ) {
58 return false;
59 }
60
61 if ( isset( $rule->plan ) ) {
62 if ( ! function_exists( 'wc_calypso_bridge_is_woo_express_plan' ) ) {
63 return false;
64 }
65 }
66
67 return true;
68 }
69 }
70