• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Yoast / wordpress-seo / 7cd8af37a7bbbd7b964cfa8db91dfdc0d3c167de

27 Mar 2026 10:12AM UTC coverage: 52.787% (-1.1%) from 53.917%
7cd8af37a7bbbd7b964cfa8db91dfdc0d3c167de

Pull #23062

github

web-flow
Merge 77b1c5f2b into 70d176237
Pull Request #23062: Register Yoast SEO abilities about analysis scores

8535 of 16034 branches covered (53.23%)

Branch coverage included in aggregate %.

143 of 307 new or added lines in 5 files covered. (46.58%)

794 existing lines in 37 files now uncovered.

33679 of 63936 relevant lines covered (52.68%)

46793.79 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/ai-generator/user-interface/ai-generator-integration.php
1
<?php
2

3
namespace Yoast\WP\SEO\AI_Generator\User_Interface;
4

5
use WPSEO_Addon_Manager;
6
use WPSEO_Admin_Asset_Manager;
7
use Yoast\WP\SEO\AI\Consent\Application\Consent_Endpoints_Repository;
8
use Yoast\WP\SEO\AI\Free_Sparks\Application\Free_Sparks_Endpoints_Repository;
9
use Yoast\WP\SEO\AI\Generator\Application\Generator_Endpoints_Repository;
10
use Yoast\WP\SEO\AI_HTTP_Request\Infrastructure\API_Client;
11
use Yoast\WP\SEO\Conditionals\AI_Conditional;
12
use Yoast\WP\SEO\Conditionals\AI_Editor_Conditional;
13
use Yoast\WP\SEO\Helpers\Current_Page_Helper;
14
use Yoast\WP\SEO\Helpers\Options_Helper;
15
use Yoast\WP\SEO\Helpers\User_Helper;
16
use Yoast\WP\SEO\Integrations\Integration_Interface;
17
use Yoast\WP\SEO\Introductions\Application\Ai_Fix_Assessments_Upsell;
18
use Yoast\WP\SEO\Introductions\Infrastructure\Introductions_Seen_Repository;
19

20
/**
21
 * Ai_Generator_Integration class.
22
 */
23
class Ai_Generator_Integration implements Integration_Interface {
24

25
        /**
26
         * Represents the admin asset manager.
27
         *
28
         * @var WPSEO_Admin_Asset_Manager
29
         */
30
        private $asset_manager;
31

32
        /**
33
         * Represents the add-on manager.
34
         *
35
         * @var WPSEO_Addon_Manager
36
         */
37
        private $addon_manager;
38

39
        /**
40
         * Holds the API client instance.
41
         *
42
         * @var API_Client
43
         */
44
        private $api_client;
45

46
        /**
47
         * Represents the current page helper.
48
         *
49
         * @var Current_Page_Helper
50
         */
51
        private $current_page_helper;
52

53
        /**
54
         * Represents the options manager.
55
         *
56
         * @var Options_Helper
57
         */
58
        private $options_helper;
59

60
        /**
61
         * Represents the user helper.
62
         *
63
         * @var User_Helper
64
         */
65
        private $user_helper;
66

67
        /**
68
         * Represents the introductions seen repository.
69
         *
70
         * @var Introductions_Seen_Repository
71
         */
72
        private $introductions_seen_repository;
73

74
        /**
75
         * Represents the endpoints repository.
76
         *
77
         * @var Generator_Endpoints_Repository
78
         */
79
        private $generator_endpoints_repository;
80

81
        /**
82
         * Represents the consent endpoints repository.
83
         *
84
         * @var Consent_Endpoints_Repository
85
         */
86
        private $consent_endpoints_repository;
87

88
        /**
89
         * Represents the free sparks endpoints repository.
90
         *
91
         * @var Free_Sparks_Endpoints_Repository
92
         */
93
        private $free_sparks_endpoints_repository;
94

95
        /**
96
         * Returns the conditionals based in which this loadable should be active.
97
         *
98
         * @return array<string>
99
         */
UNCOV
100
        public static function get_conditionals() {
×
UNCOV
101
                return [ AI_Conditional::class, AI_Editor_Conditional::class ];
×
102
        }
103

104
        /**
105
         * Constructs the class.
106
         *
107
         * @param WPSEO_Admin_Asset_Manager        $asset_manager                    The admin asset manager.
108
         * @param WPSEO_Addon_Manager              $addon_manager                    The addon manager.
109
         * @param API_Client                       $api_client                       The API client.
110
         * @param Current_Page_Helper              $current_page_helper              The current page helper.
111
         * @param Options_Helper                   $options_helper                   The options helper.
112
         * @param User_Helper                      $user_helper                      The user helper.
113
         * @param Introductions_Seen_Repository    $introductions_seen_repository    The introductions seen repository.
114
         * @param Generator_Endpoints_Repository   $generator_endpoints_repository   The Generator endpoints repository.
115
         * @param Consent_Endpoints_Repository     $consent_endpoints_repository     The Consent endpoints repository.
116
         * @param Free_Sparks_Endpoints_Repository $free_sparks_endpoints_repository The Free Sparks endpoints repository.
117
         */
UNCOV
118
        public function __construct(
×
119
                WPSEO_Admin_Asset_Manager $asset_manager,
120
                WPSEO_Addon_Manager $addon_manager,
121
                API_Client $api_client,
122
                Current_Page_Helper $current_page_helper,
123
                Options_Helper $options_helper,
124
                User_Helper $user_helper,
125
                Introductions_Seen_Repository $introductions_seen_repository,
126
                Generator_Endpoints_Repository $generator_endpoints_repository,
127
                Consent_Endpoints_Repository $consent_endpoints_repository,
128
                Free_Sparks_Endpoints_Repository $free_sparks_endpoints_repository
129
        ) {
UNCOV
130
                $this->asset_manager                    = $asset_manager;
×
UNCOV
131
                $this->addon_manager                    = $addon_manager;
×
UNCOV
132
                $this->api_client                       = $api_client;
×
UNCOV
133
                $this->current_page_helper              = $current_page_helper;
×
UNCOV
134
                $this->options_helper                   = $options_helper;
×
UNCOV
135
                $this->user_helper                      = $user_helper;
×
UNCOV
136
                $this->introductions_seen_repository    = $introductions_seen_repository;
×
UNCOV
137
                $this->generator_endpoints_repository   = $generator_endpoints_repository;
×
UNCOV
138
                $this->consent_endpoints_repository     = $consent_endpoints_repository;
×
UNCOV
139
                $this->free_sparks_endpoints_repository = $free_sparks_endpoints_repository;
×
140
        }
141

142
        /**
143
         * Initializes the integration.
144
         *
145
         * This is the place to register hooks and filters.
146
         *
147
         * @return void
148
         */
UNCOV
149
        public function register_hooks() {
×
UNCOV
150
                \add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
×
151
                // Enqueue after Elementor_Premium integration, which re-registers the assets.
UNCOV
152
                \add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'enqueue_assets' ], 11 );
×
153
        }
154

155
        /**
156
         * Gets the subscription status for Yoast SEO Premium and Yoast WooCommerce SEO.
157
         *
158
         * @return array<string, bool>
159
         */
UNCOV
160
        public function get_product_subscriptions() {
×
UNCOV
161
                return [
×
UNCOV
162
                        'premiumSubscription'     => $this->addon_manager->has_valid_subscription( WPSEO_Addon_Manager::PREMIUM_SLUG ),
×
UNCOV
163
                        'wooCommerceSubscription' => $this->addon_manager->has_valid_subscription( WPSEO_Addon_Manager::WOOCOMMERCE_SLUG ),
×
UNCOV
164
                ];
×
165
        }
166

167
        /**
168
         * Returns the data that should be passed to the script.
169
         *
170
         * @return array<string|array<string>>
171
         */
UNCOV
172
        public function get_script_data() {
×
UNCOV
173
                $user_id = $this->user_helper->get_current_user_id();
×
174

UNCOV
175
                $endpoints = $this->generator_endpoints_repository->get_all_endpoints()
×
UNCOV
176
                        ->merge_with(
×
UNCOV
177
                                $this->consent_endpoints_repository->get_all_endpoints(),
×
UNCOV
178
                        )->merge_with(
×
UNCOV
179
                                $this->free_sparks_endpoints_repository->get_all_endpoints(),
×
UNCOV
180
                        )->to_paths_array();
×
181

UNCOV
182
                return [
×
UNCOV
183
                        'hasConsent'           => $this->user_helper->get_meta( $user_id, '_yoast_wpseo_ai_consent', true ),
×
UNCOV
184
                        'productSubscriptions' => $this->get_product_subscriptions(),
×
UNCOV
185
                        'hasSeenIntroduction'  => $this->introductions_seen_repository->is_introduction_seen( $user_id, AI_Fix_Assessments_Upsell::ID ),
×
UNCOV
186
                        'requestTimeout'       => $this->api_client->get_request_timeout(),
×
UNCOV
187
                        'isFreeSparks'         => $this->options_helper->get( 'ai_free_sparks_started_on', null ) !== null,
×
UNCOV
188
                        'endpoints'            => $endpoints,
×
UNCOV
189
                ];
×
190
        }
191

192
        /**
193
         * Enqueues the required assets.
194
         *
195
         * @return void
196
         */
UNCOV
197
        public function enqueue_assets() {
×
198

UNCOV
199
                $this->asset_manager->enqueue_script( 'ai-generator' );
×
UNCOV
200
                $this->asset_manager->localize_script( 'ai-generator', 'wpseoAiGenerator', $this->get_script_data() );
×
UNCOV
201
                $this->asset_manager->enqueue_style( 'ai-generator' );
×
202
        }
203
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc