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/Agent/Admin.php +198 -96 3.0.6 → 3.2.2 View file →
@@ -9,16 +9,20 @@
9 9 defined('ABSPATH') || die('No direct access.');
10 10
11 11 use Extendify\Agent\Controllers\ChatHistoryController;
12 12 use Extendify\Agent\Controllers\TourController;
13 -use Extendify\Agent\Controllers\WorkflowHistoryController;
14 13 use Extendify\Config;
14 +use Extendify\Constants;
15 +use Extendify\Mcp\Profile as McpProfile;
15 16 use Extendify\Shared\Services\Escaper;
17 +use Extendify\Shared\Services\HttpClient;
16 18 use Extendify\Agent\TagBlocks;
17 19 use Extendify\Agent\TagTemplateParts;
18 -use Extendify\Agent\Controllers\SiteNavigationController;
20 +use Extendify\Agent\WooProductImages;
21 +use Extendify\Agent\AbilitiesDiscovery;
19 22 use Extendify\PartnerData;
20 23 use Extendify\Shared\DataProvider\ProductsData;
24 +use Extendify\SiteVisibility;
21 25
22 26 /**
23 27 * This class handles any file loading for the admin area.
24 28 */
@@ -33,19 +37,35 @@
33 37 {
34 38 \add_action('admin_enqueue_scripts', [$this, 'loadScriptsAndStyles']);
35 39 \add_action('wp_enqueue_scripts', [$this, 'loadScriptsAndStyles']);
36 40 ChatHistoryController::init();
37 - WorkflowHistoryController::init();
38 41
39 42 // Tag blocks so we can identify them later
40 43 TagBlocks::init();
41 44 TagTemplateParts::init();
42 45
43 - // Add the site navigation ids to the navigation blocks
44 - SiteNavigationController::init();
46 + Skeleton::init();
47 +
48 + WooProductImages::init();
49 +
50 + \add_action('extendify_agent_suggestions_refresh', [$this, 'refreshSuggestions']);
45 51 }
46 52
47 53 /**
54 + * Where the agent panel mounts — docked-left only on the onboarding front end.
55 + *
56 + * @return string
57 + */
58 + public static function agentPosition()
59 + {
60 + $agentOnboarding = PartnerData::setting('useAgentOnboarding') ||
61 + Config::preview('agent-onboarding') ||
62 + constant('EXTENDIFY_DEVMODE');
63 +
64 + return $agentOnboarding && !is_admin() ? 'docked-left' : 'floating';
65 + }
66 +
67 + /**
48 68 * Adds various JS scripts and styles
49 69 *
50 70 * @return void
51 71 */
@@ -50,8 +70,14 @@
50 70 * @return void
51 71 */
52 72 public function loadScriptsAndStyles()
53 73 {
74 + // The Customizer preview iframe is a front-end render, so this fires
75 + // there too — but the Agent only belongs on the live, top-level page.
76 + if (is_customize_preview() || McpProfile::isOwnScreen()) {
77 + return;
78 + }
79 +
54 80 $version = constant('EXTENDIFY_DEVMODE') ? uniqid() : Config::$version;
55 81 $scriptAssetPath = EXTENDIFY_PATH . 'public/build/' . Config::$assetManifest['extendify-agent.php'];
56 82 $fallback = [
57 83 'dependencies' => [],
@@ -90,14 +116,15 @@
90 116 (bool) use_block_editor_for_post($this->getCurrentPostId()) :
91 117 false,
92 118 'isOnEditorOrFSE' => $this->isGutenbergOrFse(),
93 119 'activePlugins' => array_values(\get_option('active_plugins', [])),
94 - // Whether the user is using the vibes experience or not.
95 - 'isUsingVibes' => (bool) file_exists(EXTENDIFY_PATH . 'src/Launch/_data/block-style-variations.json') &&
96 - version_compare(wp_get_theme("extendable")->get('Version'), '2.0.32', '>='),
120 + // The accessor also reads a key set by the IMAGIFY_API_KEY constant.
121 + 'hasImagifyApiKey' => function_exists('get_imagify_option') && (bool) \get_imagify_option('api_key'),
122 + 'isUsingVibes' => version_compare((string) wp_get_theme('extendable')->get('Version'), '2.0.32', '>='),
97 123 'siteTitle' => \esc_attr(\get_bloginfo('name')),
98 124 'siteDescription' => \esc_attr(\get_bloginfo('description')),
99 125 'themePresets' => $this->getThemePresets(),
126 + 'presetSlugs' => $this->getPresetSlugs(),
100 127 ];
101 128 $recommendations = ProductsData::get() ?? [];
102 129 $pluginRecommendations = array_filter($recommendations, function ($item) {
103 130 return in_array('ai-agent', $item['slots'] ?? [], true) && $item['ctaType'] === 'plugin';
@@ -112,8 +139,10 @@
112 139 }, $pluginRecommendations));
113 140 $agentContext = [
114 141 'availableAdminPages' => get_option('_transient_extendify_admin_pages_menu', []),
115 142 'pluginRecommendations' => $mappedPluginRecommendations,
143 + 'sitePublished' => SiteVisibility::isPublished(),
144 + 'comingSoonEnabled' => (bool) PartnerData::setting('useComingSoon'),
116 145 ];
117 146 $abilities = [
118 147 'canEditPost' => (bool) \current_user_can('edit_post', \get_queried_object_id()),
119 148 // TODO: this may be true for a user, while they still can't edit every post
@@ -136,24 +165,32 @@
136 165 Config::$slug . '-agent-scripts',
137 166 'window.extAgentData = ' . \wp_json_encode([
138 167 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
139 168 'startOnboarding' => isset($_GET['extendify-launch-success']) && $agentOnboarding,
140 - 'agentPosition' => $agentOnboarding && !is_admin() ? 'docked-left' : 'floating',
169 + 'agentPosition' => self::agentPosition(),
141 170 // Add context about where they are
142 171 'context' => $context,
143 - // Context that the Agent might need when returning a response,
144 - // but not for handling the workflow.
172 + // Material a workflow may want; each declares the keys it reads.
145 173 'agentContext' => $agentContext,
146 174 // List of abilities the AI can perform for this user.
147 175 // For example, we could check whether their theme has variations.
148 176 'abilities' => $abilities,
149 - // List of suggestions the AI can make for this user.
150 - // For example, we could check whether they need to set up a specific plugin.
177 + // Registered WordPress Abilities (6.9+) this user may run.
178 + 'wpAbilities' => AbilitiesDiscovery::discover(),
179 + // The domain card reads only the register-domain record.
151 180 'suggestions' => $this->getSuggestions(),
181 + 'domainsSuggestionSettings' => [
182 + 'showPrimary' => (bool) PartnerData::setting('showPrimaryDomainRecommendationAgent'),
183 + 'showSecondary' => (bool) PartnerData::setting('showSecondaryDomainRecommendationAgent'),
184 + 'stagingSites' => PartnerData::setting('stagingSites'),
185 + 'searchUrl' => PartnerData::setting('domainSearchURL'),
186 + ],
152 187 'chatHistory' => ChatHistoryController::getChatHistory(),
153 - 'workflowHistory' => WorkflowHistoryController::getWorkflowHistory(),
154 188 'userData' => [
155 189 'tourData' => \wp_json_encode(TourController::get()->get_data()),
190 + 'domainsRecommendationsActivities' => \wp_json_encode(
191 + \get_option('extendify_domains_recommendations_activities', null)
192 + ),
156 193 ],
157 194 ]),
158 195 'before'
159 196 );
@@ -258,8 +295,85 @@
258 295 'colorPairs' => $colorPairs,
259 296 ];
260 297 }
261 298
299 + /**
300 + * Preset slugs per design-token family across every origin. Feeds the Agent's
301 + * block-attribute schema so the model picks named tokens, not raw CSS.
302 + *
303 + * @return array<string,string[]>
304 + */
305 + private function getPresetSlugs()
306 + {
307 + if (!function_exists('wp_get_global_settings')) {
308 + return [];
309 + }
310 +
311 + $color = \wp_get_global_settings(['color']);
312 + $typography = \wp_get_global_settings(['typography']);
313 +
314 + return [
315 + 'color' => $this->originSlugs($color, 'palette', 'defaultPalette'),
316 + 'colorValues' => $this->originValues($color, 'palette', 'defaultPalette', 'color'),
317 + 'gradient' => $this->originSlugs($color, 'gradients', 'defaultGradients'),
318 + 'fontSize' => $this->originSlugs($typography, 'fontSizes', 'defaultFontSizes'),
319 + 'fontFamily' => $this->originSlugs($typography, 'fontFamilies', 'defaultFontFamilies'),
320 + ];
321 + }
322 +
323 + /**
324 + * Slug => value, so a colour written as its own hex finds the token naming it.
325 + *
326 + * @return array<string, string>
327 + */
328 + private function originValues($node, $listKey, $defaultKey, $valueKey)
329 + {
330 + $list = $node[$listKey] ?? [];
331 +
332 + $origins = ['custom', 'theme'];
333 + if (($node[$defaultKey] ?? true) !== false) {
334 + $origins[] = 'default';
335 + }
336 +
337 + $values = [];
338 + foreach ($origins as $origin) {
339 + foreach ($list[$origin] ?? [] as $item) {
340 + if (isset($item['slug'], $item[$valueKey])) {
341 + $values[(string) $item['slug']] = (string) $item[$valueKey];
342 + }
343 + }
344 + }
345 +
346 + return $values;
347 + }
348 +
349 + /**
350 + * Preset slugs from a settings node's origin buckets; drops the `default`
351 + * origin when the theme opted the family out.
352 + *
353 + * @return string[]
354 + */
355 + private function originSlugs($node, $listKey, $defaultKey)
356 + {
357 + $list = $node[$listKey] ?? [];
358 +
359 + $origins = ['custom', 'theme'];
360 + if (($node[$defaultKey] ?? true) !== false) {
361 + $origins[] = 'default';
362 + }
363 +
364 + $slugs = [];
365 + foreach ($origins as $origin) {
366 + foreach ($list[$origin] ?? [] as $item) {
367 + if (isset($item['slug'])) {
368 + $slugs[] = (string) $item['slug'];
369 + }
370 + }
371 + }
372 +
373 + return array_values(array_unique($slugs));
374 + }
375 +
262 376 private static function extractColorSlug(string $value)
263 377 {
264 378 if (preg_match('/var\(--wp--preset--color--([^)]+)\)/', $value, $m)) {
265 379 return $m[1];
@@ -366,90 +480,78 @@
366 480 * @return array
367 481 */
368 482 private function getSuggestions()
369 483 {
370 - return [
371 - [
372 - 'id' => 'publish-this-page',
373 - 'icon' => 'published',
374 - 'message' => __('Publish this page', 'extendify-local'),
375 - 'workflowId' => 'update-post-status',
376 - 'source' => 'plugin',
377 - 'available' => ['context' => ['postStatus' => 'draft']],
378 - ],
379 - [
380 - 'id' => 'unpublish-this-page',
381 - 'icon' => 'drafts',
382 - 'message' => __('Unpublish this page', 'extendify-local'),
383 - 'workflowId' => 'update-post-status',
384 - 'source' => 'plugin',
385 - 'available' => ['context' => ['postStatus' => 'publish', 'isFrontPage' => false]],
386 - ],
387 - [
388 - 'id' => 'change-site-title',
389 - 'icon' => 'edit',
390 - 'message' => __('Change website title', 'extendify-local'),
391 - 'workflowId' => 'edit-wp-setting',
392 - 'source' => 'plugin',
393 - 'available' => ['abilities' => ['canEditSettings']],
394 - ],
395 - [
396 - 'id' => 'change-theme-colors',
397 - 'icon' => 'styles',
398 - 'message' => __('Change website colors', 'extendify-local'),
399 - 'workflowId' => 'change-theme-variation',
400 - 'source' => 'plugin',
401 - 'available' => ['context' => ['hasThemeVariations']],
402 - ],
403 - [
404 - 'id' => 'change-theme-fonts',
405 - 'icon' => 'typography',
406 - 'message' => __('Change website fonts', 'extendify-local'),
407 - 'workflowId' => 'change-theme-fonts-variation',
408 - 'source' => 'plugin',
409 - 'available' => ['context' => ['hasThemeVariations']],
410 - ],
411 - [
412 - 'id' => 'change-site-style',
413 - 'icon' => 'styles',
414 - 'message' => __('Change website style', 'extendify-local'),
415 - 'workflowId' => 'change-site-vibes',
416 - 'source' => 'plugin',
417 - 'available' => ['abilities' => ['canEditThemes'], 'context' => ['isUsingVibes']],
418 - ],
419 - [
420 - 'id' => 'edit-text-on-this-page',
421 - 'icon' => 'edit',
422 - 'message' => __('Edit text on this page', 'extendify-local'),
423 - 'workflowId' => 'edit-post-strings',
424 - 'source' => 'plugin',
425 - 'available' => ['abilities' => ['canEditPost'], 'context' => ['postId', 'usingBlockEditor']],
426 - ],
427 - [
428 - 'id' => 'change-website-animation',
429 - 'icon' => 'swatch',
430 - 'message' => __('Change website animation', 'extendify-local'),
431 - 'workflowId' => 'change-animation',
432 - 'source' => 'plugin',
433 - 'available' => ['abilities' => ['canEditSettings']],
434 - ],
435 - [
436 - 'id' => 'change-website-logo',
437 - 'icon' => 'siteLogo',
438 - 'message' => __('Change website logo', 'extendify-local'),
439 - 'workflowId' => 'update-logo',
440 - 'source' => 'plugin',
441 - 'available' => ['abilities' => ['canEditSettings', 'canUploadMedia']],
442 - ],
443 - [
444 - 'id' => 'change-website-browser-icon',
445 - 'icon' => 'siteLogo',
446 - 'message' => __('Change website browser icon', 'extendify-local'),
447 - 'workflowId' => 'update-site-icon',
448 - 'source' => 'plugin',
449 - 'available' => ['abilities' => ['canEditSettings', 'canUploadMedia']],
450 - ],
451 - ];
484 + $locale = \get_locale();
485 + $cached = \get_option('extendify_agent_suggestions_' . $locale);
486 +
487 + if (!is_array($cached) || !isset($cached['fetchedAt'])) {
488 + return $this->refreshSuggestions($locale) ?? [];
489 + }
490 +
491 + $age = time() - $cached['fetchedAt'];
492 + if ($age > DAY_IN_SECONDS) {
493 + if (!\wp_next_scheduled('extendify_agent_suggestions_refresh', [$locale])) {
494 + \wp_schedule_single_event(time(), 'extendify_agent_suggestions_refresh', [$locale]);
495 + if (\is_admin()) {
496 + \spawn_cron();
497 + }
498 + }
499 + }
500 +
501 + return $cached['data'] ?? [];
502 + }
503 +
504 + /**
505 + * Fetch suggestions from the API and persist them.
506 + * Called synchronously on cold start and via wp-cron when cache is stale.
507 + *
508 + * @param string $locale - Locale to fetch (cron may run in a different site locale).
509 + * @return array|null
510 + */
511 + public function refreshSuggestions($locale)
512 + {
513 + // When the refresh runs via wp-cron, the active locale may differ from the cached entry's locale.
514 + // Switch so HttpClient sends the matching wp_language and the response lands in the right cache key.
515 + $needSwitch = $locale !== \get_locale();
516 + if ($needSwitch) {
517 + \switch_to_locale($locale);
518 + }
519 +
520 + $response = HttpClient::post(
521 + Constants::AI_HOST . '/api/agent/suggestions',
522 + [],
523 + null,
524 + true
525 + );
526 +
527 + if ($needSwitch) {
528 + \restore_previous_locale();
529 + }
530 +
531 + $optionKey = 'extendify_agent_suggestions_' . $locale;
532 +
533 + if ($response['code'] !== 200) {
534 + // Back off: stamp the cache as fetched ~23h ago so we retry in ~1h instead of every request.
535 + $cached = \get_option($optionKey);
536 + \update_option(
537 + $optionKey,
538 + [
539 + 'data' => is_array($cached) ? ($cached['data'] ?? []) : [],
540 + 'fetchedAt' => time() - (DAY_IN_SECONDS - HOUR_IN_SECONDS),
541 + ],
542 + false
543 + );
544 + return null;
545 + }
546 +
547 + $suggestions = $response['response']['suggestions'] ?? [];
548 + \update_option(
549 + $optionKey,
550 + ['data' => $suggestions, 'fetchedAt' => time()],
551 + false
552 + );
553 + return $suggestions;
452 554 }
453 555
454 556 /**
455 557 * Check if the user is in the Gutenberg or FSE editor.