PluginProbe ʕ •ᴥ•ʔ
Superb Addons: Blocks, Patterns, Pre-built Pages, Sliders, Popups, Free Forms, Animations & More / 4.0.6
Superb Addons: Blocks, Patterns, Pre-built Pages, Sliders, Popups, Free Forms, Animations & More v4.0.6
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 4.0.0 trunk 1.0.0 2.0.0 2.0.1 2.0.2 2.0.3 3.0 3.0.1 3.0.2 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.2 3.1.3 3.2.0 3.2.1 3.2.2 3.2.4 3.2.5 3.2.7 3.2.8 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.4.5 3.4.6 3.5.0 3.5.1 3.5.2 3.5.3 3.5.4 3.5.6 3.5.7 3.5.8 3.5.9 3.6.0 3.6.1 3.6.2 3.7.0 3.7.1
superb-blocks / src / data / controllers / class-link-controller.php
superb-blocks / src / data / controllers Last commit date
class-cache-controller.php 3 weeks ago class-css-controller.php 3 weeks ago class-domainshift-controller.php 3 weeks ago class-key-controller.php 3 weeks ago class-link-controller.php 3 weeks ago class-log-controller.php 3 weeks ago class-option-controller.php 3 weeks ago class-rest-controller.php 3 weeks ago
class-link-controller.php
139 lines
1 <?php
2
3 namespace SuperbAddons\Data\Controllers;
4
5 defined('ABSPATH') || exit();
6
7 class LinkController
8 {
9 // Two upsell modal presentations: modal-direct (the standard layout) and
10 // modal-bonus (a compact layout with a lock icon and a discount callout).
11 const VARIANT_GROUP = 'modal-v2';
12
13 const VARIANT_MODAL_DIRECT = 'modal-direct';
14 const VARIANT_MODAL_BONUS = 'modal-bonus';
15
16 const SEED_OPTION = 'superbaddons_pre_activation';
17
18 // Delayed admin notice
19 // Bucketed independently
20 const NOTICE_GROUP = 'notice-v1';
21 const NOTICE_VARIANT_CONTROL = 'notice';
22 const NOTICE_VARIANT_ADV = 'notice-adv';
23 const NOTICE_SALT = 'notice';
24
25 const NOTICE_FILE_CONTROL = 'addons-notice.php';
26 const NOTICE_FILE_ADV = 'addons-notice-adv.php';
27
28 private static $cached = null;
29 private static $notice_variant = null;
30
31 /**
32 * @return array { active: bool, group: string, variant: string }
33 */
34 public static function GetState()
35 {
36 if (self::$cached !== null) {
37 return self::$cached;
38 }
39
40 // active is unconditionally true for every install. The JS link builder
41 // reads it to decide whether to append the su_exp/su_var params.
42 self::$cached = array(
43 'active' => true,
44 'group' => self::VARIANT_GROUP,
45 'variant' => self::ComputeBucket(),
46 );
47 return self::$cached;
48 }
49
50 public static function GetVariant()
51 {
52 $state = self::GetState();
53 return $state['variant'];
54 }
55
56 public static function GetLinkExpArgs($experiment = 'upsell')
57 {
58 if ($experiment === 'notice') {
59 return self::GetNoticeExpArgs();
60 }
61
62 $state = self::GetState();
63 if (empty($state['active'])) {
64 return array();
65 }
66 return array(
67 'su_exp' => $state['group'],
68 'su_var' => $state['variant'],
69 );
70 }
71
72 /**
73 * @return array { active: bool, group: string, variant: string, settingsLicenseUrl: string }
74 */
75 public static function GetJsConfig()
76 {
77 $state = self::GetState();
78 // Destination for the bonus modal's "Already purchased?" link: the
79 // settings License & Account tab where users activate their key. Both
80 // modal shells read it off this localized global.
81 $state['settingsLicenseUrl'] = admin_url('admin.php?page=superbaddons-settings#license');
82 return $state;
83 }
84
85 public static function Localize($handle)
86 {
87 wp_localize_script($handle, 'superbAddonsUpsell', self::GetJsConfig());
88 }
89
90 public static function GetNoticeVariant()
91 {
92 if (self::$notice_variant !== null) {
93 return self::$notice_variant;
94 }
95
96 // Salt the seed so the buckets are independent
97 $bucket = abs(crc32(self::NOTICE_SALT . '|' . self::SeedValue())) % 2;
98 self::$notice_variant = $bucket === 1 ? self::NOTICE_VARIANT_ADV : self::NOTICE_VARIANT_CONTROL;
99 return self::$notice_variant;
100 }
101
102 public static function GetNoticeContentFile()
103 {
104 return self::GetNoticeVariant() === self::NOTICE_VARIANT_ADV
105 ? self::NOTICE_FILE_ADV
106 : self::NOTICE_FILE_CONTROL;
107 }
108
109 public static function GetNoticeExpArgs()
110 {
111 return array(
112 'su_exp' => self::NOTICE_GROUP,
113 'su_var' => self::GetNoticeVariant(),
114 );
115 }
116
117 private static function ComputeBucket()
118 {
119 // Salted with the group name so this assignment is independent of the
120 // other seed-derived groupings (the earlier unsalted hash and the
121 // 'notice'-salted one).
122 // abs() is required: crc32() returns a negative int on 32-bit PHP.
123 $bucket = abs(crc32(self::VARIANT_GROUP . '|' . self::SeedValue())) % 2;
124 return $bucket === 1 ? self::VARIANT_MODAL_BONUS : self::VARIANT_MODAL_DIRECT;
125 }
126
127 private static function SeedValue()
128 {
129 $seed = get_option(self::SEED_OPTION, '');
130 // The seed option can be missing (e.g. removed by a full plugin reset).
131 // Fall back to a stable per-site value rather than writing on a read
132 // path or lumping every seedless install into one bucket.
133 if ($seed === '' || $seed === false) {
134 $seed = home_url();
135 }
136 return (string) $seed;
137 }
138 }
139