myyoast_connection_conditional = $myyoast_connection_conditional; $this->status_presenter = $status_presenter; $this->connection_permission = $connection_permission; $this->short_link_helper = $short_link_helper; } /** * Returns the connection payload, or `null` when the feature flag is disabled. * * @return array{isProvisioned: bool, canConnect: bool, connectUrl: string|null, learnMoreUrl: string}|null */ public function present() { if ( ! $this->myyoast_connection_conditional->is_met() ) { return null; } $status = $this->status_presenter->present(); $can_connect = $this->connection_permission->can_manage(); return [ 'isProvisioned' => \is_bool( $status['is_provisioned'] ) && $status['is_provisioned'], 'canConnect' => $can_connect, // Only users who can manage options can start the flow; for everyone // else the link is omitted and the editor shows the "ask your admin" variant. 'connectUrl' => ( $can_connect ) ? $this->get_connect_url() : null, 'learnMoreUrl' => $this->short_link_helper->get( 'https://yoa.st/ai-myyoast-connection' ), ]; } /** * Builds the nonce-protected Integrations-page URL that auto-starts the * MyYoast connection flow when opened. * * Built with `add_query_arg()` + `wp_create_nonce()` rather than `wp_nonce_url()`: * the latter HTML-encodes the `&` separators for markup output, but this URL is * localized and assigned to a React `href`, where it isn't decoded — the browser * would then send `amp;start-myyoast-connection` as the query-arg name and the * flow would never start. This form keeps the separators as plain `&`. * * @return string The connect URL. */ private function get_connect_url() { return \add_query_arg( '_wpnonce', \wp_create_nonce( 'wpseo-start-myyoast-connection' ), \self_admin_url( 'admin.php?page=' . Integrations_Page::PAGE . '&start-myyoast-connection=1' ), ); } }