PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / trunk
Yoast SEO – Advanced SEO with real-time guidance and built-in AI vtrunk
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
← All changes | src/ai/generator/user-interface/ai-generator-integration.php +29 -117 28.3 → trunk View file →
@@ -11,20 +11,15 @@
11 11 use Yoast\WP\SEO\AI\Generator\Application\Generator_Endpoints_Repository;
12 12 use Yoast\WP\SEO\AI\HTTP_Request\Infrastructure\API_Client;
13 13 use Yoast\WP\SEO\Conditionals\AI_Conditional;
14 14 use Yoast\WP\SEO\Conditionals\AI_Editor_Conditional;
15 -use Yoast\WP\SEO\Conditionals\MyYoast_Connection_Conditional;
16 -use Yoast\WP\SEO\Conditionals\New_Premium_Or_Free_AI_Conditional;
17 15 use Yoast\WP\SEO\Helpers\Current_Page_Helper;
18 16 use Yoast\WP\SEO\Helpers\Options_Helper;
19 -use Yoast\WP\SEO\Helpers\Short_Link_Helper;
20 17 use Yoast\WP\SEO\Helpers\User_Helper;
21 -use Yoast\WP\SEO\Integrations\Admin\Integrations_Page;
22 18 use Yoast\WP\SEO\Integrations\Integration_Interface;
23 19 use Yoast\WP\SEO\Introductions\Application\Ai_Fix_Assessments_Upsell;
24 20 use Yoast\WP\SEO\Introductions\Infrastructure\Introductions_Seen_Repository;
25 -use Yoast\WP\SEO\MyYoast_Client\User_Interface\Connection_Permission;
26 -use Yoast\WP\SEO\MyYoast_Client\User_Interface\Status_Presenter;
21 +use Yoast\WP\SEO\MyYoast_Client\User_Interface\Myyoast_Connection_Data_Presenter;
27 22
28 23 /**
29 24 * Ai_Generator_Integration class.
30 25 */
@@ -100,61 +95,37 @@
100 95 */
101 96 private $free_sparks_endpoints_repository;
102 97
103 98 /**
104 - * The MyYoast connection feature-flag conditional.
99 + * Builds the MyYoast connection payload for script data.
105 100 *
106 - * @var MyYoast_Connection_Conditional
101 + * @var Myyoast_Connection_Data_Presenter
107 102 */
108 - private $myyoast_connection_conditional;
103 + private $myyoast_connection_data_presenter;
109 104
110 105 /**
111 - * The MyYoast connection status presenter.
112 - *
113 - * @var Status_Presenter
114 - */
115 - private $status_presenter;
116 -
117 - /**
118 - * The short-link helper.
119 - *
120 - * @var Short_Link_Helper
121 - */
122 - private $short_link_helper;
123 -
124 - /**
125 - * The MyYoast connection-management permission check.
126 - *
127 - * @var Connection_Permission
128 - */
129 - private $connection_permission;
130 -
131 - /**
132 106 * Returns the conditionals based in which this loadable should be active.
133 107 *
134 108 * @return array<string>
135 109 */
136 110 public static function get_conditionals() {
137 - return [ AI_Conditional::class, AI_Editor_Conditional::class, New_Premium_Or_Free_AI_Conditional::class ];
111 + return [ AI_Conditional::class, AI_Editor_Conditional::class ];
138 112 }
139 113
140 114 /**
141 115 * Constructs the class.
142 116 *
143 - * @param WPSEO_Admin_Asset_Manager $asset_manager The admin asset manager.
144 - * @param WPSEO_Addon_Manager $addon_manager The addon manager.
145 - * @param API_Client $api_client The API client.
146 - * @param Current_Page_Helper $current_page_helper The current page helper.
147 - * @param Options_Helper $options_helper The options helper.
148 - * @param User_Helper $user_helper The user helper.
149 - * @param Introductions_Seen_Repository $introductions_seen_repository The introductions seen repository.
150 - * @param Generator_Endpoints_Repository $generator_endpoints_repository The Generator endpoints repository.
151 - * @param Consent_Endpoints_Repository $consent_endpoints_repository The Consent endpoints repository.
152 - * @param Free_Sparks_Endpoints_Repository $free_sparks_endpoints_repository The Free Sparks endpoints repository.
153 - * @param MyYoast_Connection_Conditional $myyoast_connection_conditional The MyYoast connection feature-flag conditional.
154 - * @param Status_Presenter $status_presenter The MyYoast connection status presenter.
155 - * @param Short_Link_Helper $short_link_helper The short-link helper.
156 - * @param Connection_Permission $connection_permission The MyYoast connection-management permission check.
117 + * @param WPSEO_Admin_Asset_Manager $asset_manager The admin asset manager.
118 + * @param WPSEO_Addon_Manager $addon_manager The addon manager.
119 + * @param API_Client $api_client The API client.
120 + * @param Current_Page_Helper $current_page_helper The current page helper.
121 + * @param Options_Helper $options_helper The options helper.
122 + * @param User_Helper $user_helper The user helper.
123 + * @param Introductions_Seen_Repository $introductions_seen_repository The introductions seen repository.
124 + * @param Generator_Endpoints_Repository $generator_endpoints_repository The Generator endpoints repository.
125 + * @param Consent_Endpoints_Repository $consent_endpoints_repository The Consent endpoints repository.
126 + * @param Free_Sparks_Endpoints_Repository $free_sparks_endpoints_repository The Free Sparks endpoints repository.
127 + * @param Myyoast_Connection_Data_Presenter $myyoast_connection_data_presenter The MyYoast connection data presenter.
157 128 */
158 129 public function __construct(
159 130 WPSEO_Admin_Asset_Manager $asset_manager,
160 131 WPSEO_Addon_Manager $addon_manager,
@@ -165,27 +136,21 @@
165 136 Introductions_Seen_Repository $introductions_seen_repository,
166 137 Generator_Endpoints_Repository $generator_endpoints_repository,
167 138 Consent_Endpoints_Repository $consent_endpoints_repository,
168 139 Free_Sparks_Endpoints_Repository $free_sparks_endpoints_repository,
169 - MyYoast_Connection_Conditional $myyoast_connection_conditional,
170 - Status_Presenter $status_presenter,
171 - Short_Link_Helper $short_link_helper,
172 - Connection_Permission $connection_permission
140 + Myyoast_Connection_Data_Presenter $myyoast_connection_data_presenter
173 141 ) {
174 - $this->asset_manager = $asset_manager;
175 - $this->addon_manager = $addon_manager;
176 - $this->api_client = $api_client;
177 - $this->current_page_helper = $current_page_helper;
178 - $this->options_helper = $options_helper;
179 - $this->user_helper = $user_helper;
180 - $this->introductions_seen_repository = $introductions_seen_repository;
181 - $this->generator_endpoints_repository = $generator_endpoints_repository;
182 - $this->consent_endpoints_repository = $consent_endpoints_repository;
183 - $this->free_sparks_endpoints_repository = $free_sparks_endpoints_repository;
184 - $this->myyoast_connection_conditional = $myyoast_connection_conditional;
185 - $this->status_presenter = $status_presenter;
186 - $this->short_link_helper = $short_link_helper;
187 - $this->connection_permission = $connection_permission;
142 + $this->asset_manager = $asset_manager;
143 + $this->addon_manager = $addon_manager;
144 + $this->api_client = $api_client;
145 + $this->current_page_helper = $current_page_helper;
146 + $this->options_helper = $options_helper;
147 + $this->user_helper = $user_helper;
148 + $this->introductions_seen_repository = $introductions_seen_repository;
149 + $this->generator_endpoints_repository = $generator_endpoints_repository;
150 + $this->consent_endpoints_repository = $consent_endpoints_repository;
151 + $this->free_sparks_endpoints_repository = $free_sparks_endpoints_repository;
152 + $this->myyoast_connection_data_presenter = $myyoast_connection_data_presenter;
188 153 }
189 154
190 155 /**
191 156 * Initializes the integration.
@@ -232,63 +197,10 @@
232 197 'hasSeenIntroduction' => $this->introductions_seen_repository->is_introduction_seen( $user_id, AI_Fix_Assessments_Upsell::ID ),
233 198 'requestTimeout' => $this->api_client->get_request_timeout(),
234 199 'isFreeSparks' => $this->options_helper->get( 'ai_free_sparks_started_on', null ) !== null,
235 200 'endpoints' => $endpoints,
236 - 'myyoastConnection' => $this->get_myyoast_connection_data(),
201 + 'myyoastConnection' => $this->myyoast_connection_data_presenter->present(),
237 202 ];
238 - }
239 -
240 - /**
241 - * Builds the read-only MyYoast connection payload used to pick the
242 - * "Yoast AI cannot reach your site" notification variant in the editor.
243 - *
244 - * Returns `null` when the feature flag is disabled, so the editor treats the
245 - * connection as unavailable and shows the informational-only variant. The
246 - * payload is deliberately minimal — no store, actions, or tokens reach the
247 - * editor; the connect call-to-action is just a nonce-protected link that
248 - * auto-starts the flow on the Integrations page in a new tab.
249 - *
250 - * @return array{isProvisioned: bool, canConnect: bool, connectUrl: string|null, learnMoreUrl: string}|null
251 - */
252 - public function get_myyoast_connection_data() {
253 - if ( ! $this->myyoast_connection_conditional->is_met() ) {
254 - return null;
255 - }
256 -
257 - $status = $this->status_presenter->present();
258 - $can_connect = $this->connection_permission->can_manage();
259 -
260 - return [
261 - 'isProvisioned' => \is_bool( $status['is_provisioned'] ) && $status['is_provisioned'],
262 - 'canConnect' => $can_connect,
263 - // Only users who can manage options can start the flow; for everyone
264 - // else the link is omitted and the editor shows the "ask your admin" variant.
265 - 'connectUrl' => ( $can_connect ) ? $this->get_connect_url() : null,
266 - 'learnMoreUrl' => $this->short_link_helper->get( 'https://yoa.st/ai-myyoast-connection' ),
267 - ];
268 - }
269 -
270 - /**
271 - * Builds the nonce-protected Integrations-page URL that auto-starts the
272 - * MyYoast connection flow when opened.
273 - *
274 - * The nonce keeps the auto-start trigger from being cross-site forgeable; the
275 - * Integrations page verifies it before kicking off the flow.
276 - *
277 - * Built with `add_query_arg()` + `wp_create_nonce()` rather than `wp_nonce_url()`:
278 - * the latter HTML-encodes the `&` separators for markup output, but this URL is
279 - * localized and assigned to a React `href`, where it isn't decoded — the browser
280 - * would then send `amp;start-myyoast-connection` as the query-arg name and the
281 - * flow would never start. This form keeps the separators as plain `&`.
282 - *
283 - * @return string The connect URL.
284 - */
285 - private function get_connect_url() {
286 - return \add_query_arg(
287 - '_wpnonce',
288 - \wp_create_nonce( 'wpseo-start-myyoast-connection' ),
289 - \self_admin_url( 'admin.php?page=' . Integrations_Page::PAGE . '&start-myyoast-connection=1' ),
290 - );
291 203 }
292 204
293 205 /**
294 206 * Enqueues the required assets.