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

Yoast / wordpress-seo / d6112f48a78380ef0e30c3424c33b8a053eaa052

14 Apr 2025 01:30PM UTC coverage: 52.454% (-2.1%) from 54.594%
d6112f48a78380ef0e30c3424c33b8a053eaa052

Pull #22077

github

web-flow
Merge 68bb84799 into b621a6397
Pull Request #22077: Drop compatibility with PHP 7.2 and 7.3

7827 of 13877 branches covered (56.4%)

Branch coverage included in aggregate %.

29025 of 56379 relevant lines covered (51.48%)

42277.18 hits per line

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

86.96
/src/integrations/admin/indexing-tool-integration.php
1
<?php
2

3
namespace Yoast\WP\SEO\Integrations\Admin;
4

5
use WPSEO_Addon_Manager;
6
use WPSEO_Admin_Asset_Manager;
7
use Yoast\WP\SEO\Conditionals\Migrations_Conditional;
8
use Yoast\WP\SEO\Conditionals\No_Tool_Selected_Conditional;
9
use Yoast\WP\SEO\Conditionals\Yoast_Tools_Page_Conditional;
10
use Yoast\WP\SEO\Helpers\Indexable_Helper;
11
use Yoast\WP\SEO\Helpers\Indexing_Helper;
12
use Yoast\WP\SEO\Helpers\Product_Helper;
13
use Yoast\WP\SEO\Helpers\Short_Link_Helper;
14
use Yoast\WP\SEO\Integrations\Integration_Interface;
15
use Yoast\WP\SEO\Presenters\Admin\Indexing_Error_Presenter;
16
use Yoast\WP\SEO\Presenters\Admin\Indexing_List_Item_Presenter;
17
use Yoast\WP\SEO\Routes\Importing_Route;
18
use Yoast\WP\SEO\Routes\Indexing_Route;
19
use Yoast\WP\SEO\Services\Importing\Importable_Detector_Service;
20

21
/**
22
 * Class Indexing_Tool_Integration. Bridge to the Javascript indexing tool on Yoast SEO Tools page.
23
 *
24
 * @package Yoast\WP\SEO\Integrations\Admin
25
 */
26
class Indexing_Tool_Integration implements Integration_Interface {
27

28
        /**
29
         * Represents the admin asset manager.
30
         *
31
         * @var WPSEO_Admin_Asset_Manager
32
         */
33
        protected $asset_manager;
34

35
        /**
36
         * Represents the indexables helper.
37
         *
38
         * @var Indexable_Helper
39
         */
40
        protected $indexable_helper;
41

42
        /**
43
         * The short link helper.
44
         *
45
         * @var Short_Link_Helper
46
         */
47
        protected $short_link_helper;
48

49
        /**
50
         * Represents the indexing helper.
51
         *
52
         * @var Indexing_Helper
53
         */
54
        protected $indexing_helper;
55

56
        /**
57
         * The addon manager.
58
         *
59
         * @var WPSEO_Addon_Manager
60
         */
61
        protected $addon_manager;
62

63
        /**
64
         * The product helper.
65
         *
66
         * @var Product_Helper
67
         */
68
        protected $product_helper;
69

70
        /**
71
         * The Importable Detector service.
72
         *
73
         * @var Importable_Detector_Service
74
         */
75
        protected $importable_detector;
76

77
        /**
78
         * The Importing Route class.
79
         *
80
         * @var Importing_Route
81
         */
82
        protected $importing_route;
83

84
        /**
85
         * Returns the conditionals based on which this integration should be active.
86
         *
87
         * @return array The array of conditionals.
88
         */
89
        public static function get_conditionals() {
2✔
90
                return [
2✔
91
                        Migrations_Conditional::class,
2✔
92
                        No_Tool_Selected_Conditional::class,
2✔
93
                        Yoast_Tools_Page_Conditional::class,
2✔
94
                ];
2✔
95
        }
96

97
        /**
98
         * Indexing_Integration constructor.
99
         *
100
         * @param WPSEO_Admin_Asset_Manager   $asset_manager       The admin asset manager.
101
         * @param Indexable_Helper            $indexable_helper    The indexable helper.
102
         * @param Short_Link_Helper           $short_link_helper   The short link helper.
103
         * @param Indexing_Helper             $indexing_helper     The indexing helper.
104
         * @param WPSEO_Addon_Manager         $addon_manager       The addon manager.
105
         * @param Product_Helper              $product_helper      The product helper.
106
         * @param Importable_Detector_Service $importable_detector The importable detector.
107
         * @param Importing_Route             $importing_route     The importing route.
108
         */
109
        public function __construct(
2✔
110
                WPSEO_Admin_Asset_Manager $asset_manager,
111
                Indexable_Helper $indexable_helper,
112
                Short_Link_Helper $short_link_helper,
113
                Indexing_Helper $indexing_helper,
114
                WPSEO_Addon_Manager $addon_manager,
115
                Product_Helper $product_helper,
116
                Importable_Detector_Service $importable_detector,
117
                Importing_Route $importing_route
118
        ) {
119
                $this->asset_manager       = $asset_manager;
2✔
120
                $this->indexable_helper    = $indexable_helper;
2✔
121
                $this->short_link_helper   = $short_link_helper;
2✔
122
                $this->indexing_helper     = $indexing_helper;
2✔
123
                $this->addon_manager       = $addon_manager;
2✔
124
                $this->product_helper      = $product_helper;
2✔
125
                $this->importable_detector = $importable_detector;
2✔
126
                $this->importing_route     = $importing_route;
2✔
127
        }
128

129
        /**
130
         * Register hooks.
131
         *
132
         * @return void
133
         */
134
        public function register_hooks() {
2✔
135
                \add_action( 'wpseo_tools_overview_list_items_internal', [ $this, 'render_indexing_list_item' ], 10 );
2✔
136
                \add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ], 10 );
2✔
137
        }
138

139
        /**
140
         * Enqueues the required scripts.
141
         *
142
         * @return void
143
         */
144
        public function enqueue_scripts() {
2✔
145
                $this->asset_manager->enqueue_script( 'indexation' );
2✔
146
                $this->asset_manager->enqueue_style( 'admin-css' );
2✔
147
                $this->asset_manager->enqueue_style( 'monorepo' );
2✔
148

149
                $data = [
2✔
150
                        'disabled'                    => ! $this->indexable_helper->should_index_indexables(),
2✔
151
                        'amount'                      => $this->indexing_helper->get_filtered_unindexed_count(),
2✔
152
                        'firstTime'                   => ( $this->indexing_helper->is_initial_indexing() === true ),
2✔
153
                        'errorMessage'                => $this->render_indexing_error(),
2✔
154
                        'restApi'                     => [
2✔
155
                                'root'                => \esc_url_raw( \rest_url() ),
2✔
156
                                'indexing_endpoints'  => $this->get_indexing_endpoints(),
2✔
157
                                'importing_endpoints' => $this->get_importing_endpoints(),
2✔
158
                                'nonce'               => \wp_create_nonce( 'wp_rest' ),
2✔
159
                        ],
2✔
160
                ];
2✔
161

162
                /**
163
                 * Filter: 'wpseo_indexing_data' Filter to adapt the data used in the indexing process.
164
                 *
165
                 * @param array $data The indexing data to adapt.
166
                 */
167
                $data = \apply_filters( 'wpseo_indexing_data', $data );
2✔
168

169
                $this->asset_manager->localize_script( 'indexation', 'yoastIndexingData', $data );
2✔
170
        }
171

172
        /**
173
         * The error to show if optimization failed.
174
         *
175
         * @return string The error to show if optimization failed.
176
         */
177
        protected function render_indexing_error() {
×
178
                $presenter = new Indexing_Error_Presenter(
×
179
                        $this->short_link_helper,
×
180
                        $this->product_helper,
×
181
                        $this->addon_manager
×
182
                );
×
183

184
                return $presenter->present();
×
185
        }
186

187
        /**
188
         * Determines if the site has a valid Premium subscription.
189
         *
190
         * @return bool If the site has a valid Premium subscription.
191
         */
192
        protected function has_valid_premium_subscription() {
×
193
                return $this->addon_manager->has_valid_subscription( WPSEO_Addon_Manager::PREMIUM_SLUG );
×
194
        }
195

196
        /**
197
         * Renders the indexing list item.
198
         *
199
         * @return void
200
         */
201
        public function render_indexing_list_item() {
4✔
202
                if ( \current_user_can( 'manage_options' ) ) {
4✔
203
                        // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- The output is correctly escaped in the presenter.
204
                        echo new Indexing_List_Item_Presenter( $this->short_link_helper );
2✔
205
                }
206
        }
207

208
        /**
209
         * Retrieves a list of the indexing endpoints to use.
210
         *
211
         * @return array The endpoints.
212
         */
213
        protected function get_indexing_endpoints() {
2✔
214
                $endpoints = [
2✔
215
                        'prepare'            => Indexing_Route::FULL_PREPARE_ROUTE,
2✔
216
                        'terms'              => Indexing_Route::FULL_TERMS_ROUTE,
2✔
217
                        'posts'              => Indexing_Route::FULL_POSTS_ROUTE,
2✔
218
                        'archives'           => Indexing_Route::FULL_POST_TYPE_ARCHIVES_ROUTE,
2✔
219
                        'general'            => Indexing_Route::FULL_GENERAL_ROUTE,
2✔
220
                        'indexablesComplete' => Indexing_Route::FULL_INDEXABLES_COMPLETE_ROUTE,
2✔
221
                        'post_link'          => Indexing_Route::FULL_POST_LINKS_INDEXING_ROUTE,
2✔
222
                        'term_link'          => Indexing_Route::FULL_TERM_LINKS_INDEXING_ROUTE,
2✔
223
                ];
2✔
224

225
                $endpoints = \apply_filters( 'wpseo_indexing_endpoints', $endpoints );
2✔
226

227
                $endpoints['complete'] = Indexing_Route::FULL_COMPLETE_ROUTE;
2✔
228

229
                return $endpoints;
2✔
230
        }
231

232
        /**
233
         * Retrieves a list of the importing endpoints to use.
234
         *
235
         * @return array The endpoints.
236
         */
237
        protected function get_importing_endpoints() {
2✔
238
                $available_actions   = $this->importable_detector->detect_importers();
2✔
239
                $importing_endpoints = [];
2✔
240

241
                foreach ( $available_actions as $plugin => $types ) {
2✔
242
                        foreach ( $types as $type ) {
2✔
243
                                $importing_endpoints[ $plugin ][] = $this->importing_route->get_endpoint( $plugin, $type );
2✔
244
                        }
245
                }
246

247
                return $importing_endpoints;
2✔
248
        }
249
}
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