PluginProbe
Extendify / 3.2.3
Extendify v3.2.3
3.2.3 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 All 129 releases
← All changes | app/PartnerData.php +146 -14 3.1.4 → 3.2.3 View file →
@@ -59,12 +59,16 @@
59 59 'showSecondaryDomainRecommendationAgent' => false,
60 60 'domainTLDs' => ['com', 'net'],
61 61 'priorityDomainTLDs' => [],
62 62 'stagingSites' => ['wordpress'],
63 + 'trialDomains' => [],
63 64 'domainSearchURL' => '',
64 65 'showDraft' => false,
65 66 'showChat' => false,
66 67 'showAIPageCreation' => false,
68 + 'mcpConfig' => [],
69 + 'mcpWriteList' => [],
70 + 'mcpReadList' => [],
67 71 'enableImageImports-1-14-6' => false,
68 72 'disableLibraryAutoOpen' => false,
69 73 'enableApexDomain' => false,
70 74 'showLaunch' => false,
@@ -77,9 +81,8 @@
77 81 'showPartnerBranding' => false,
78 82 'disabledProducts' => [],
79 83 'customProducts' => [],
80 84 ],
81 - 'showPartnerNotifications' => false,
82 85 'license' => 'active',
83 86 'showAIAgents' => false,
84 87 'agentAbilitiesAllowlist' => [],
85 88 'showQuickEdit' => false,
@@ -98,8 +101,10 @@
98 101 'useAutoUpdate' => false,
99 102 'showLaunchUpdate' => false,
100 103 'activeTests' => [],
101 104 'showExtendifyCode' => false,
105 + 'useComingSoon' => false,
106 + 'useSearchEngineBlock' => false,
102 107 'extendifyCodeData' => [
103 108 'link' => '',
104 109 'title' => '',
105 110 'message' => '',
@@ -104,8 +109,10 @@
104 109 'title' => '',
105 110 'message' => '',
106 111 'cta-primary' => '',
107 112 ],
113 + 'customDesign' => null,
114 + 'strings' => [],
108 115 ];
109 116
110 117 // phpcs:disable Generic.Metrics.CyclomaticComplexity.MaxExceeded
111 118 /**
@@ -114,8 +121,16 @@
114 121 * @return void
115 122 */
116 123 public function __construct()
117 124 {
125 + self::load();
126 + }
127 +
128 + /**
129 + * @return void
130 + */
131 + public static function load()
132 + {
118 133 self::$id = defined('EXTENDIFY_PARTNER_ID') ? constant('EXTENDIFY_PARTNER_ID') : null;
119 134 $data = self::getPartnerData();
120 135 self::$config['showDomainBanner'] = ($data['showDomainBanner'] ?? self::$config['showDomainBanner']);
121 136 self::$config['showDomainTask'] = ($data['showDomainTask'] ?? self::$config['showDomainTask']);
@@ -130,8 +145,9 @@
130 145 self::$config['domainTLDs'] = ($data['domainTLDs'] ?? self::$config['domainTLDs']);
131 146 self::$config['priorityDomainTLDs'] = ($data['priorityDomainTLDs']
132 147 ?? self::$config['priorityDomainTLDs']);
133 148 self::$config['stagingSites'] = array_map('trim', ($data['stagingSites'] ?? self::$config['stagingSites']));
149 + self::$config['trialDomains'] = array_map('trim', ($data['trialDomains'] ?? self::$config['trialDomains']));
134 150 self::$config['domainSearchURL'] = ($data['domainSearchURL'] ?? self::$config['domainSearchURL']);
135 151 self::$logo = isset($data['logo'][0]['thumbnails']['large']['url'])
136 152 ? $data['logo'][0]['thumbnails']['large']['url']
137 153 : self::$logo;
@@ -149,8 +165,11 @@
149 165 'secondaryColor' => ($data['secondaryColor'] ?? ($data['backgroundColor'] ?? null)),
150 166 'secondaryColorText' => '#ffffff',
151 167 ];
152 168 self::$config['showAIPageCreation'] = ($data['showAIPageCreation'] ?? self::$config['showAIPageCreation']);
169 + self::$config['mcpConfig'] = ($data['mcpConfig'] ?? self::$config['mcpConfig']);
170 + self::$config['mcpWriteList'] = ($data['mcpWriteList'] ?? self::$config['mcpWriteList']);
171 + self::$config['mcpReadList'] = ($data['mcpReadList'] ?? self::$config['mcpReadList']);
153 172 self::$config['showLaunch'] = ($data['showLaunch'] ?? self::$config['showLaunch']);
154 173 self::$config['showLaunchTitle'] = ($data['showLaunchTitle'] ?? self::$config['showLaunchTitle']);
155 174 self::$config['deactivated'] = ($data['deactivated'] ?? self::$config['deactivated']);
156 175 self::$config['launchRedirectWebsite'] = ($data['launchRedirectWebsite']
@@ -165,10 +184,8 @@
165 184 ?? self::$config['productRecommendations']['disabledProducts']),
166 185 'customProducts' => ($data['productRecommendationCustomSlugs']
167 186 ?? self::$config['productRecommendations']['customProducts']),
168 187 ];
169 - self::$config['showPartnerNotifications'] = ($data['showPartnerNotifications']
170 - ?? self::$config['showPartnerNotifications']);
171 188 self::$config['license'] = ($data['license'] ?? self::$config['license']);
172 189 self::$config['showImprint'] = ($data['showImprint'] ?? self::$config['showImprint']);
173 190 self::$config['showLaunchQuestions'] = ($data['showLaunchQuestions'] ?? self::$config['showLaunchQuestions']);
174 191 self::$config['showAIAgents'] = ($data['showAIAgents'] ?? self::$config['showAIAgents']);
@@ -188,9 +205,14 @@
188 205 self::$config['useAutoUpdate'] = ($data['useAutoUpdate'] ?? self::$config['useAutoUpdate']);
189 206 self::$config['showLaunchUpdate'] = ($data['showLaunchUpdate'] ?? self::$config['showLaunchUpdate']);
190 207 self::$config['activeTests'] = ($data['activeTests'] ?? self::$config['activeTests']);
191 208 self::$config['showExtendifyCode'] = ($data['showExtendifyCode'] ?? self::$config['showExtendifyCode']);
209 + self::$config['useComingSoon'] = ($data['useComingSoon'] ?? self::$config['useComingSoon']);
210 + self::$config['useSearchEngineBlock'] = ($data['useSearchEngineBlock']
211 + ?? self::$config['useSearchEngineBlock']);
192 212 self::$config['extendifyCodeData'] = ($data['extendifyCodeData'] ?? self::$config['extendifyCodeData']);
213 + self::$config['customDesign'] = ($data['customDesign'] ?? self::$config['customDesign']);
214 + self::$config['strings'] = ($data['strings'] ?? self::$config['strings']);
193 215
194 216 // Add the job hook to fetch the partner data.
195 217 \add_action('extendify_fetch_partner_data', [self::class, 'fetchPartnerData']);
196 218 }
@@ -210,15 +232,12 @@
210 232 $partnerData = \get_option('extendify_partner_data_v2', 'empty');
211 233 if ($partnerData !== 'empty') {
212 234 // We have data, but if it's been 10 minutes, check for new data.
213 235 $partnerRefresh = \get_transient('extendify_partner_data_cache_check');
214 - if (!$partnerRefresh && \is_admin()) {
215 - \add_action('init', function () {
216 - if (!\wp_next_scheduled('extendify_fetch_partner_data')) {
217 - \wp_schedule_single_event(time(), 'extendify_fetch_partner_data');
218 - \spawn_cron();
219 - }
220 - });
236 + if (!$partnerRefresh && \is_user_logged_in()) {
237 + \did_action('init')
238 + ? self::scheduleRefresh()
239 + : \add_action('init', [self::class, 'scheduleRefresh']);
221 240 }
222 241
223 242 return array_merge(self::$config, $partnerData);
224 243 }
@@ -230,8 +249,49 @@
230 249 return $mergedData;
231 250 }
232 251
233 252 /**
253 + * A token request may be the only visitor a site gets, so it fetches a stale config itself.
254 + *
255 + * @return void
256 + */
257 + public static function refreshIfStale()
258 + {
259 + if (\get_transient('extendify_partner_data_cache_check')) {
260 + return;
261 + }
262 +
263 + // The 45s timeout the plugin gives its hosts is longer than a waiting MCP client allows.
264 + $brief = function ($args) {
265 + $args['timeout'] = 5;
266 + return $args;
267 + };
268 + \add_filter('http_request_args', $brief, 101);
269 + try {
270 + $fetched = self::fetchPartnerData();
271 + } finally {
272 + \remove_filter('http_request_args', $brief, 101);
273 + }
274 +
275 + if ($fetched) {
276 + self::load();
277 + }
278 + }
279 +
280 + /**
281 + * @return void
282 + */
283 + public static function scheduleRefresh()
284 + {
285 + if (\wp_next_scheduled('extendify_fetch_partner_data')) {
286 + return;
287 + }
288 +
289 + \wp_schedule_single_event(time(), 'extendify_fetch_partner_data');
290 + \spawn_cron();
291 + }
292 +
293 + /**
234 294 * Fetch or refresh the partner data
235 295 *
236 296 * @return array
237 297 */
@@ -274,12 +334,16 @@
274 334 }
275 335
276 336 $sanitizedData = array_merge(
277 337 Sanitizer::sanitizeUnknown($result['data']),
278 - ['consentTermsCustom' => \sanitize_text_field(htmlentities(
279 - ($result['data']['consentTermsCustom'] ?? ''),
280 - ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401
281 - ))]
338 + [
339 + 'consentTermsCustom' => \sanitize_text_field(htmlentities(
340 + ($result['data']['consentTermsCustom'] ?? ''),
341 + ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401
342 + )),
343 + 'customDesign' => self::sanitizeDesign($result['data']['customDesign'] ?? null),
344 + 'strings' => self::sanitizeStrings($result['data']['strings'] ?? null),
345 + ]
282 346 );
283 347
284 348 // Merge before persisting as this data is accessed directly elsewhere.
285 349 $mergedData = array_merge(self::$config, $sanitizedData);
@@ -285,8 +349,76 @@
285 349 $mergedData = array_merge(self::$config, $sanitizedData);
286 350 \update_option('extendify_partner_data_v2', $mergedData);
287 351
288 352 return $mergedData;
353 + }
354 +
355 + /**
356 + * Partner copy overriding the shipped strings.
357 + *
358 + * Which keys exist is the flow's to know, so only shape and text are checked here.
359 + *
360 + * @param mixed $strings The map as the partner-data response carried it.
361 + * @return array
362 + */
363 + public static function sanitizeStrings($strings)
364 + {
365 + return array_map(
366 + 'sanitize_text_field',
367 + self::designEntries($strings, '/^[a-zA-Z][a-zA-Z0-9]*$/', 'is_string')
368 + );
369 + }
370 +
371 + /**
372 + * A design carries GLSL, which the text sanitizers break, so only its shape is checked.
373 + *
374 + * Empty members are left out rather than kept: json_encode writes an empty
375 + * PHP array as [], and the page reads the design as an object.
376 + *
377 + * @param mixed $design The design as the partner-data response carried it.
378 + * @return array|null
379 + */
380 + private static function sanitizeDesign($design)
381 + {
382 + if (!is_array($design)) {
383 + return null;
384 + }
385 +
386 + $shader = ($design['shader'] ?? null);
387 + $logo = ($design['logo'] ?? null);
388 + $kept = array_filter([
389 + 'vars' => self::designEntries(
390 + ($design['vars'] ?? null),
391 + '/^--ext-(ui|tpl)-[a-z0-9-]+$/',
392 + function ($value) {
393 + // A CSS value is a string, but 0.88 is a natural way to write one.
394 + return is_string($value) || is_int($value) || is_float($value);
395 + }
396 + ),
397 + 'templates' => self::designEntries(($design['templates'] ?? null), '/^[A-Za-z0-9_-]+$/', 'is_string'),
398 + 'shader' => is_string($shader) ? \wp_check_invalid_utf8($shader) : '',
399 + 'logo' => is_string($logo) ? \esc_url_raw($logo) : '',
400 + ]);
401 +
402 + return $kept ?: null;
403 + }
404 +
405 + private static function designEntries($entries, $keyPattern, callable $accepts)
406 + {
407 + if (!is_array($entries)) {
408 + return [];
409 + }
410 +
411 + $kept = [];
412 + foreach ($entries as $key => $value) {
413 + if (!is_string($key) || !preg_match($keyPattern, $key) || !$accepts($value)) {
414 + continue;
415 + }
416 +
417 + $kept[$key] = is_string($value) ? \wp_check_invalid_utf8($value) : $value;
418 + }
419 +
420 + return $kept;
289 421 }
290 422
291 423 /**
292 424 * Return colors mapped as css variables