Yoast\WP\SEO\AI_Generator\User_Interface

Ai_Generator_Integration{} │ Yoast 1.0└─ Integration_Interface

Устарела с версии 28.4. Больше не поддерживается и может быть удалена. Рекомендуется заменить эту функцию на аналог.

Ai_Generator_Integration class.

Хуков нет.

Использование

$Ai_Generator_Integration = new Ai_Generator_Integration();
// use class methods

Методы

  1. public __construct(
  2. public enqueue_assets()
  3. public get_all_endpoints()
  4. public static get_conditionals()
  5. public get_myyoast_connection_data()
  6. public get_product_subscriptions()
  7. public add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] )
  8. public get_script_data()
  9. public register_hooks()
  10. ERROR: no method name found on line `* @param Options_Helper $options_helper The options helper.`
  11. ERROR: no method name found on line `* @codeCoverageIgnore`
  12. private get_connect_url()
  13. ERROR: no method name found on line `*/`
  14. ERROR: no method name found on line `* Initializes the integration.`

Список изменений

Устарела с 28.4

Код Ai_Generator_Integration{} Yoast 28.7

class Ai_Generator_Integration implements Integration_Interface {

	/**
	 * Represents the admin asset manager.
	 *
	 * @var WPSEO_Admin_Asset_Manager
	 */
	private $asset_manager;

	/**
	 * Represents the add-on manager.
	 *
	 * @var WPSEO_Addon_Manager
	 */
	private $addon_manager;

	/**
	 * Holds the API client instance.
	 *
	 * @var API_Client
	 */
	private $api_client;

	/**
	 * Represents the current page helper.
	 *
	 * @var Current_Page_Helper
	 */
	private $current_page_helper;

	/**
	 * Represents the options manager.
	 *
	 * @var Options_Helper
	 */
	private $options_helper;

	/**
	 * Represents the user helper.
	 *
	 * @var User_Helper
	 */
	private $user_helper;

	/**
	 * Represents the introductions seen repository.
	 *
	 * @var Introductions_Seen_Repository
	 */
	private $introductions_seen_repository;

	/**
	 * Represents the endpoints repository.
	 *
	 * @var Generator_Endpoints_Repository
	 */
	private $generator_endpoints_repository;

	/**
	 * Represents the consent endpoints repository.
	 *
	 * @var Consent_Endpoints_Repository
	 */
	private $consent_endpoints_repository;

	/**
	 * Represents the free sparks endpoints repository.
	 *
	 * @var Free_Sparks_Endpoints_Repository
	 */
	private $free_sparks_endpoints_repository;

	/**
	 * Builds the MyYoast connection payload for script data.
	 *
	 * @var Myyoast_Connection_Data_Presenter
	 */
	private $myyoast_connection_data_presenter;

	/**
	 * Returns the conditionals based in which this loadable should be active.
	 *
	 * @deprecated 28.4
	 * @codeCoverageIgnore
	 *
	 * @return array<string>
	 */
	public static function get_conditionals() {
		\_deprecated_function( __METHOD__, 'Yoast SEO 28.4' );
		return [ AI_Conditional::class, AI_Editor_Conditional::class, Old_Premium_AI_Conditional::class ];
	}

	/**
	 * Constructs the class.
	 *
	 * @deprecated 28.4
	 * @codeCoverageIgnore
	 *
	 * @param WPSEO_Admin_Asset_Manager        $asset_manager                    The admin asset manager.
	 * @param WPSEO_Addon_Manager              $addon_manager                    The addon manager.
	 * @param API_Client                       $api_client                       The API client.
	 * @param Current_Page_Helper              $current_page_helper              The current page helper.
	 * @param Options_Helper                   $options_helper                   The options helper.
	 * @param User_Helper                      $user_helper                      The user helper.
	 * @param Introductions_Seen_Repository    $introductions_seen_repository    The introductions seen repository.
	 * @param Generator_Endpoints_Repository   $generator_endpoints_repository   The Generator endpoints repository.
	 * @param Consent_Endpoints_Repository     $consent_endpoints_repository     The Consent endpoints repository.
	 * @param Free_Sparks_Endpoints_Repository $free_sparks_endpoints_repository The Free Sparks endpoints repository.
	 */
	public function __construct(
		WPSEO_Admin_Asset_Manager $asset_manager,
		WPSEO_Addon_Manager $addon_manager,
		API_Client $api_client,
		Current_Page_Helper $current_page_helper,
		Options_Helper $options_helper,
		User_Helper $user_helper,
		Introductions_Seen_Repository $introductions_seen_repository,
		Generator_Endpoints_Repository $generator_endpoints_repository,
		Consent_Endpoints_Repository $consent_endpoints_repository,
		Free_Sparks_Endpoints_Repository $free_sparks_endpoints_repository
	) {
		\_deprecated_function( __METHOD__, 'Yoast SEO 28.4' );
		$this->asset_manager                    = $asset_manager;
		$this->addon_manager                    = $addon_manager;
		$this->api_client                       = $api_client;
		$this->current_page_helper              = $current_page_helper;
		$this->options_helper                   = $options_helper;
		$this->user_helper                      = $user_helper;
		$this->introductions_seen_repository    = $introductions_seen_repository;
		$this->generator_endpoints_repository   = $generator_endpoints_repository;
		$this->consent_endpoints_repository     = $consent_endpoints_repository;
		$this->free_sparks_endpoints_repository = $free_sparks_endpoints_repository;
	}

	/**
	 * Initializes the integration.
	 *
	 * This is the place to register hooks and filters.
	 *
	 * @deprecated 28.4
	 * @codeCoverageIgnore
	 *
	 * @return void
	 */
	public function register_hooks() {
		\_deprecated_function( __METHOD__, 'Yoast SEO 28.4' );
		\add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
		// Enqueue after Elementor_Premium integration, which re-registers the assets.
		\add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'enqueue_assets' ], 11 );
	}

	/**
	 * Gets the subscription status for Yoast SEO Premium and Yoast WooCommerce SEO.
	 *
	 * @deprecated 28.4
	 * @codeCoverageIgnore
	 *
	 * @return array<string, bool>
	 */
	public function get_product_subscriptions() {
		\_deprecated_function( __METHOD__, 'Yoast SEO 28.4' );
		return [
			'premiumSubscription'     => $this->addon_manager->has_valid_subscription( WPSEO_Addon_Manager::PREMIUM_SLUG ),
			'wooCommerceSubscription' => $this->addon_manager->has_valid_subscription( WPSEO_Addon_Manager::WOOCOMMERCE_SLUG ),
		];
	}

	/**
	 * Returns the data that should be passed to the script.
	 *
	 * @deprecated 28.4
	 * @codeCoverageIgnore
	 *
	 * @return array<string|array<string>>
	 */
	public function get_script_data() {
		\_deprecated_function( __METHOD__, 'Yoast SEO 28.4' );
		$user_id = $this->user_helper->get_current_user_id();

		$endpoints = $this->generator_endpoints_repository->get_all_endpoints()
			->merge_with(
				$this->consent_endpoints_repository->get_all_endpoints(),
			)->merge_with(
				$this->free_sparks_endpoints_repository->get_all_endpoints(),
			)->to_paths_array();

		return [
			'hasConsent'           => $this->user_helper->get_meta( $user_id, '_yoast_wpseo_ai_consent', true ),
			'productSubscriptions' => $this->get_product_subscriptions(),
			'hasSeenIntroduction'  => $this->introductions_seen_repository->is_introduction_seen( $user_id, AI_Fix_Assessments_Upsell::ID ),
			'requestTimeout'       => $this->api_client->get_request_timeout(),
			'isFreeSparks'         => $this->options_helper->get( 'ai_free_sparks_started_on', null ) !== null,
			'endpoints'            => $endpoints,
			'myyoastConnection'    => $this->myyoast_connection_data_presenter->present(),
		];
	}

	/**
	 * Builds the read-only MyYoast connection payload used to pick the
	 * "Yoast AI cannot reach your site" notification variant in the editor.
	 *
	 * Returns `null` when the feature flag is disabled, so the editor treats the
	 * connection as unavailable and shows the informational-only variant. The
	 * payload is deliberately minimal — no store, actions, or tokens reach the
	 * editor; the connect call-to-action is just a nonce-protected link that
	 * auto-starts the flow on the Integrations page in a new tab.
	 *
	 * @deprecated 28.4
	 * @codeCoverageIgnore
	 *
	 * @return array{isProvisioned: bool, canConnect: bool, connectUrl: string|null, learnMoreUrl: string}|null
	 */
	public function get_myyoast_connection_data() {
		\_deprecated_function( __METHOD__, 'Yoast SEO 28.4' );
		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.
	 *
	 * The nonce keeps the auto-start trigger from being cross-site forgeable; the
	 * Integrations page verifies it before kicking off the flow.
	 *
	 * 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' ),
		);
	}

	/**
	 * Enqueues the required assets.
	 *
	 * @deprecated 28.4
	 * @codeCoverageIgnore
	 *
	 * @return void
	 */
	public function enqueue_assets() {
		\_deprecated_function( __METHOD__, 'Yoast SEO 28.4' );

		$this->asset_manager->enqueue_script( 'ai-generator' );
		$this->asset_manager->localize_script( 'ai-generator', 'wpseoAiGenerator', $this->get_script_data() );
		$this->asset_manager->enqueue_style( 'ai-generator' );
	}
}