PluginProbe
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More / 2.4.1
Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More v2.4.1
2.4.1 2.4.0 2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.2 2.2.1 2.2.0 2.1.2 2.1.1 trunk 0.0.1 0.0.2 0.0.3 0.0.4 0.0.5 0.0.6 0.0.7 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 All 68 releases
better-payment / includes / Classes / ProCompatibility.php

ProCompatibility.php in Better Payment – Instant Payments, Donations, Fundraising with Subscriptions & More 2.4.1, at includes/Classes/ProCompatibility.php

147 lines 5.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Better_Payment\Lite\Classes;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 /**
10 * The Lite ↔ Pro compatibility contract.
11 *
12 * Pro-feature code moves out of Lite in stages — expand, migrate, contract: a
13 * Lite release adds the hook, a Pro release takes the code over and announces it,
14 * and only a later Lite release deletes Lite's copy. The first hand-off (fourteen
15 * features, Pro 1.4.4) completed when MIN_PRO_VERSION reached 1.4.4 and Lite's
16 * copies were deleted; the machinery stays for the next one. Two things make it
17 * safe, and both live here.
18 *
19 * - provides(): Pro lists what it now ships itself on `better_payment/pro_provides`,
20 * and Lite skips its own copy of that feature. Without it a transition release
21 * registers the same Elementor control, stylesheet or schema twice — and a
22 * duplicate Elementor control id is an editor error, not a cosmetic one.
23 * - The outdated-Pro notice: neither plugin used to check the other's version,
24 * so a site could run a new Lite beside a Pro that still expects code Lite has
25 * removed. MIN_PRO_VERSION is raised in the Lite release that removes such code.
26 *
27 * Nothing an installed Pro calls directly (classes, methods, constants, partials)
28 * may be removed from Lite until MIN_PRO_VERSION is past the Pro release that
29 * stopped calling it. tests/Unit/ProCouplingContractTest.php lists those symbols
30 * and fails if one disappears.
31 *
32 * @since 2.4.0
33 */
34 final class ProCompatibility {
35
36 /**
37 * The oldest Better Payment Pro this Lite is known to work with.
38 */
39 const MIN_PRO_VERSION = '1.4.4';
40
41 /**
42 * Wire the admin notice.
43 *
44 * Hooked on both notice actions: Admin::hide_admin_notices() strips
45 * `admin_notices` on Better Payment screens and replays only
46 * `better_payment_admin_notices` there, and that action never fires anywhere
47 * else — so the notice prints exactly once on every screen.
48 *
49 * @return void
50 */
51 public static function register(): void {
52 add_action( 'admin_notices', array( __CLASS__, 'render_outdated_pro_notice' ) );
53 add_action( 'better_payment_admin_notices', array( __CLASS__, 'render_outdated_pro_notice' ) );
54 }
55
56 /**
57 * Whether the active Pro ships its own copy of a feature.
58 *
59 * Entitlement is read live on every call, like every other Pro gate, so a
60 * deactivated Pro immediately hands the feature back to Lite.
61 *
62 * @param string $feature Feature slug, e.g. 'campaign_theme_styles'.
63 * @return bool
64 */
65 public static function provides( string $feature ): bool {
66 $features = apply_filters( 'better_payment/pro_provides', array() );
67
68 return is_array( $features ) && in_array( $feature, $features, true );
69 }
70
71 /**
72 * Whether Pro is active on this request.
73 *
74 * @return bool
75 */
76 public static function pro_enabled(): bool {
77 return (bool) apply_filters( 'better_payment/pro_enabled', false );
78 }
79
80 /**
81 * Whether Lite's transitional copy of a Pro feature should run.
82 *
83 * True only for an active Pro that does not ship the feature itself — an
84 * older Pro during a hand-off. A free install never runs a Lite copy of Pro
85 * code: without Pro there is nothing to serve, and with a current Pro, Pro
86 * serves it. Every Lite copy of Pro code gates on this, never on provides()
87 * alone (`! provides()` is true on every free install).
88 *
89 * @param string $feature Feature slug.
90 * @return bool
91 */
92 public static function lite_copy_applies( string $feature ): bool {
93 return self::pro_enabled() && ! self::provides( $feature );
94 }
95
96 /**
97 * The installed Pro version, or '' when Pro is not loaded.
98 *
99 * @return string
100 */
101 public static function pro_version(): string {
102 return defined( 'BETTER_PAYMENT_PRO_VERSION' ) ? (string) BETTER_PAYMENT_PRO_VERSION : '';
103 }
104
105 /**
106 * Whether a Pro version is older than this Lite supports.
107 *
108 * An empty version means Pro is not installed, which is not "outdated".
109 *
110 * @param string $pro_version Installed Pro version.
111 * @param string $minimum Oldest supported version.
112 * @return bool
113 */
114 public static function is_pro_outdated( string $pro_version, string $minimum = self::MIN_PRO_VERSION ): bool {
115 if ( '' === $pro_version ) {
116 return false;
117 }
118
119 return version_compare( $pro_version, $minimum, '<' );
120 }
121
122 /**
123 * Print the "update Better Payment Pro" notice when it applies.
124 *
125 * @return void
126 */
127 public static function render_outdated_pro_notice(): void {
128 $pro_version = self::pro_version();
129
130 if ( ! self::is_pro_outdated( $pro_version ) || ! current_user_can( 'update_plugins' ) ) {
131 return;
132 }
133
134 printf(
135 '<div class="notice notice-warning better-payment-pro-outdated-notice"><p>%s</p></div>',
136 esc_html(
137 sprintf(
138 /* translators: 1: installed Better Payment Pro version, 2: minimum supported version. */
139 __( 'Better Payment Pro %1$s is older than this version of Better Payment supports. Please update Better Payment Pro to %2$s or newer so every Pro feature keeps working.', 'better-payment' ),
140 $pro_version,
141 self::MIN_PRO_VERSION
142 )
143 )
144 );
145 }
146 }
147