PluginProbe
Extendify / 3.2.2
Extendify v3.2.2
3.2.2 3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 All 128 releases
← All changes | app/Config.php +85 -73 0.10.1 → 3.2.2 View file →
@@ -1,5 +1,6 @@
1 1 <?php
2 +
2 3 /**
3 4 * The App details file
4 5 */
5 6
@@ -4,27 +5,31 @@
4 5 */
5 6
6 7 namespace Extendify;
7 8
9 +defined('ABSPATH') || die('No direct access.');
10 +
11 +use Extendify\Shared\Services\Sanitizer;
12 +
8 13 /**
9 14 * Controller for handling various app data
10 15 */
16 +
11 17 class Config
12 18 {
13 -
14 19 /**
15 - * Plugin name
20 + * Plugin slug
16 21 *
17 22 * @var string
18 23 */
19 - public static $name = '';
24 + public static $slug = 'extendify';
20 25
21 26 /**
22 - * Plugin slug
27 + * The JS/CSS asset manifest (with hashes)
23 28 *
24 - * @var string
29 + * @var array
25 30 */
26 - public static $slug = '';
31 + public static $assetManifest = [];
27 32
28 33 /**
29 34 * Plugin version
30 35 *
@@ -39,13 +44,13 @@
39 44 */
40 45 public static $apiVersion = 'v1';
41 46
42 47 /**
43 - * Whether this is the standalone plugin
48 + * Partner Id
44 49 *
45 - * @var boolean
50 + * @var string|null
46 51 */
47 - public static $standalone;
52 + public static $partnerId = null;
48 53
49 54 /**
50 55 * Whether to load Launch
51 56 *
@@ -50,18 +55,11 @@
50 55 * Whether to load Launch
51 56 *
52 57 * @var boolean
53 58 */
54 - public static $showOnboarding = false;
59 + public static $showLaunch = false;
55 60
56 61 /**
57 - * Whether to load Assist
58 - *
59 - * @var boolean
60 - */
61 - public static $showAssist = false;
62 -
63 - /**
64 62 * Plugin environment
65 63 *
66 64 * @var string
67 65 */
@@ -67,35 +65,37 @@
67 65 */
68 66 public static $environment = '';
69 67
70 68 /**
71 - * The partner plugin/theme
69 + * Host plugin
72 70 *
73 71 * @var string
74 72 */
75 - public static $sdkPartner = 'standalone';
73 + public static $requiredCapability = EXTENDIFY_REQUIRED_CAPABILITY;
76 74
77 75 /**
78 - * Host plugin
76 + * Plugin config
79 77 *
80 - * @var string
78 + * @var array
81 79 */
82 - public static $requiredCapability = 'manage_options';
80 + public static $config = [];
83 81
84 82 /**
85 - * Plugin config
83 + * Whether Launch was finished
86 84 *
87 - * @var array
85 + * @var boolean
88 86 */
89 - public static $config = [];
87 + public static $launchCompleted = false;
90 88
91 89 /**
92 - * Plugin completed status
90 + * Enabled preview features.
93 91 *
94 - * @var mixed
92 + * @var array
95 93 */
96 - public static $launchCompleted = 0;
94 + public static $previewFeatures = [];
97 95
96 + public static $enablePreviewFeatures = false;
97 +
98 98 /**
99 99 * Process the readme file to get version and name
100 100 *
101 101 * @return void
@@ -101,77 +101,89 @@
101 101 * @return void
102 102 */
103 103 public function __construct()
104 104 {
105 - self::$launchCompleted = get_option('extendify_onboarding_completed', 0);
105 + self::$partnerId = defined('EXTENDIFY_PARTNER_ID') ? constant('EXTENDIFY_PARTNER_ID') : null;
106 + $partnerData = PartnerData::getPartnerData();
106 107
107 - if (isset($GLOBALS['extendify_sdk_partner']) && $GLOBALS['extendify_sdk_partner']) {
108 - self::$sdkPartner = $GLOBALS['extendify_sdk_partner'];
109 - }
108 + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
109 + $readme = file_get_contents(EXTENDIFY_PATH . 'readme.txt');
110 110
111 - // Set up whether this is the standalone plugin instead of integrated.
112 - self::$standalone = self::$sdkPartner === 'standalone';
111 + preg_match('/Stable tag: ([0-9.:]+)/', $readme, $matches);
112 + self::$version = $matches[1];
113 113
114 - // TODO: Previous way to set the partner name - can remove in future.
115 - if (defined('EXTENDIFY_PARTNER_NAME')) {
116 - self::$sdkPartner = constant('EXTENDIFY_PARTNER_NAME');
117 - }
114 + self::$assetManifest = wp_json_file_decode(
115 + EXTENDIFY_PATH . 'public/build/manifest.json',
116 + ['associative' => true]
117 + );
118 118
119 - // Always use the partner ID if set as a constant.
120 - if (defined('EXTENDIFY_PARTNER_ID')) {
121 - self::$sdkPartner = constant('EXTENDIFY_PARTNER_ID');
119 + if (!get_option('extendify_first_installed_version')) {
120 + update_option('extendify_first_installed_version', Sanitizer::sanitizeText(self::$version));
122 121 }
123 122
124 - // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
125 - $readme = file_get_contents(EXTENDIFY_PATH . 'readme.txt');
123 + // Set up the Preview features
124 + // phpcs:ignore WordPress.Security.NonceVerification
125 + self::handlePreviewUrlOptIn($_GET);
126 126
127 - preg_match('/=== (.+) ===/', $readme, $matches);
128 - self::$name = $matches[1];
129 - self::$slug = strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', self::$name), '-'));
130 -
131 - preg_match('/Stable tag: ([0-9.:]+)/', $readme, $matches);
132 - self::$version = $matches[1];
133 -
134 127 // An easy way to check if we are in dev mode is to look for a dev specific file.
135 - $isDev = is_readable(EXTENDIFY_PATH . 'public/build/.devbuild');
128 + $isDev = is_readable(EXTENDIFY_PATH . '.devbuild');
136 129
137 130 self::$environment = $isDev ? 'DEVELOPMENT' : 'PRODUCTION';
138 - self::$showOnboarding = $this->showOnboarding();
139 - self::$showAssist = $isDev || self::$launchCompleted;
140 -
141 - // Add the config.
142 - // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
143 - $config = file_get_contents(EXTENDIFY_PATH . 'config.json');
144 - self::$config = json_decode($config, true);
131 + self::$launchCompleted = (bool) get_option('extendify_onboarding_completed', false);
132 + self::$showLaunch = $isDev ? true : ((bool) ($partnerData['showLaunch'] ?? false));
145 133 }
146 134
147 135 /**
148 - * Conditionally load Extendify Launch.
136 + * Retrieves the value of a preview setting.
149 137 *
150 - * @return boolean
138 + * This method first checks if the preview setting exists as a static property of the class.
139 + * If it does, it returns the value of that property. Otherwise, it looks for the
140 + * preview setting in the saved setting and returns its value if found.
141 + *
142 + * @param string $previewKey The key of the preview setting to retrieve.
143 + *
144 + * @return boolean The value of the setting if found or false if not found.
151 145 */
152 - private function showOnboarding()
146 + public static function preview(string $previewKey)
153 147 {
154 - // Always show it for dev mode.
155 148 if (self::$environment === 'DEVELOPMENT') {
156 149 return true;
157 150 }
158 151
159 - // Currently we require a flag to be set.
160 - if (!defined('EXTENDIFY_SHOW_ONBOARDING')) {
161 - return false;
152 + if (property_exists(self::class, $previewKey)) {
153 + return self::$previewFeatures[$previewKey];
162 154 }
163 155
164 - // Check if they disabled it and respect that.
165 - if (constant('EXTENDIFY_SHOW_ONBOARDING') === false) {
166 - return false;
156 + $previewFeatures = get_option('extendify_enable_preview_features_v1', []);
157 + return (bool) ($previewFeatures[$previewKey] ?? false);
158 + }
159 +
160 +
161 + /**
162 + * Processes preview features from URL parameters and enables them.
163 + *
164 + * This method checks for 'extendify-preview' parameters in the GET request
165 + * and enables the specified preview features. It supports both single feature
166 + * format (extendify-preview=feature1) and array format (extendify-preview[]=feature1).
167 + * All specified features are enabled and saved to the database.
168 + *
169 + * @param array $getParams The GET parameters that may contain 'extendify-preview' settings.
170 + *
171 + * @return void
172 + */
173 + protected static function handlePreviewUrlOptIn(array $getParams = [])
174 + {
175 + if (!isset($getParams['extendify-preview'])) {
176 + return;
167 177 }
168 178
169 - // time() will be truthy and 0 falsy.
170 - if (get_option('extendify_onboarding_skipped', 0)) {
171 - return false;
179 + $previewParam = $getParams['extendify-preview'];
180 + $features = is_array($previewParam) ? $previewParam : [$previewParam];
181 + self::$previewFeatures = get_option('extendify_enable_preview_features_v1', []);
182 +
183 + foreach ($features as $feature) {
184 + self::$previewFeatures[$feature] = true;
172 185 }
173 186
174 - // time() will be truthy and 0 falsy, so we reverse it.
175 - return !self::$launchCompleted;
187 + update_option('extendify_enable_preview_features_v1', Sanitizer::sanitizeArray(self::$previewFeatures));
176 188 }
177 189 }