PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.6
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.6
28.6 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 All 130 releases
wordpress-seo / src / integrations / admin / integrations-page.php

integrations-page.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 28.6, at src/integrations/admin/integrations-page.php

290 lines 11.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Yoast\WP\SEO\Integrations\Admin;
4
5 use WPSEO_Admin_Asset_Manager;
6 use Yoast\WP\SEO\Conditionals\Abilities_API_Conditional;
7 use Yoast\WP\SEO\Conditionals\Admin_Conditional;
8 use Yoast\WP\SEO\Conditionals\Jetpack_Conditional;
9 use Yoast\WP\SEO\Conditionals\Third_Party\Elementor_Activated_Conditional;
10 use Yoast\WP\SEO\Dashboard\Infrastructure\Endpoints\Site_Kit_Consent_Management_Endpoint;
11 use Yoast\WP\SEO\Dashboard\Infrastructure\Integrations\Site_Kit;
12 use Yoast\WP\SEO\Helpers\Options_Helper;
13 use Yoast\WP\SEO\Integrations\Integration_Interface;
14 use Yoast\WP\SEO\MyYoast_Client\User_Interface\Integrations_Page_Script_Data as MyYoast_Connection_Script_Data;
15 use Yoast\WP\SEO\Schema\Application\Configuration\Schema_Configuration;
16
17 /**
18 * Integrations_Page class
19 */
20 class Integrations_Page implements Integration_Interface {
21
22 /**
23 * The page identifier of the integrations page.
24 *
25 * @var string
26 */
27 public const PAGE = 'wpseo_integrations';
28
29 /**
30 * The admin asset manager.
31 *
32 * @var WPSEO_Admin_Asset_Manager
33 */
34 private $admin_asset_manager;
35
36 /**
37 * The options helper.
38 *
39 * @var Options_Helper
40 */
41 private $options_helper;
42
43 /**
44 * The elementor conditional.
45 *
46 * @var Elementor_Activated_Conditional
47 */
48 private $elementor_conditional;
49
50 /**
51 * The jetpack conditional.
52 *
53 * @var Jetpack_Conditional
54 */
55 private $jetpack_conditional;
56
57 /**
58 * The site kit integration configuration data.
59 *
60 * @var Site_Kit
61 */
62 private $site_kit_integration_data;
63
64 /**
65 * The site kit consent management endpoint.
66 *
67 * @var Site_Kit_Consent_Management_Endpoint
68 */
69 private $site_kit_consent_management_endpoint;
70
71 /**
72 * The schema configuration.
73 *
74 * @var Schema_Configuration
75 */
76 private $schema_configuration;
77
78 /**
79 * The MyYoast connection script-data provider.
80 *
81 * @var MyYoast_Connection_Script_Data
82 */
83 private $myyoast_connection_script_data;
84
85 /**
86 * The Abilities API conditional.
87 *
88 * @var Abilities_API_Conditional
89 */
90 private $abilities_api_conditional;
91
92 /**
93 * {@inheritDoc}
94 */
95 public static function get_conditionals() {
96 return [ Admin_Conditional::class ];
97 }
98
99 /**
100 * Workouts_Integration constructor.
101 *
102 * @param WPSEO_Admin_Asset_Manager $admin_asset_manager The admin asset manager.
103 * @param Options_Helper $options_helper The options helper.
104 * @param Elementor_Activated_Conditional $elementor_conditional The elementor conditional.
105 * @param Jetpack_Conditional $jetpack_conditional The Jetpack conditional.
106 * @param Site_Kit $site_kit_integration_data The site kit integration
107 * configuration data.
108 * @param Site_Kit_Consent_Management_Endpoint $site_kit_consent_management_endpoint The site kit consent
109 * management endpoint.
110 * @param Schema_Configuration $schema_configuration The schema configuration.
111 * @param MyYoast_Connection_Script_Data $myyoast_connection_script_data The MyYoast connection
112 * script-data provider.
113 * @param Abilities_API_Conditional $abilities_api_conditional The Abilities API conditional.
114 */
115 public function __construct(
116 WPSEO_Admin_Asset_Manager $admin_asset_manager,
117 Options_Helper $options_helper,
118 Elementor_Activated_Conditional $elementor_conditional,
119 Jetpack_Conditional $jetpack_conditional,
120 Site_Kit $site_kit_integration_data,
121 Site_Kit_Consent_Management_Endpoint $site_kit_consent_management_endpoint,
122 Schema_Configuration $schema_configuration,
123 MyYoast_Connection_Script_Data $myyoast_connection_script_data,
124 Abilities_API_Conditional $abilities_api_conditional
125 ) {
126 $this->admin_asset_manager = $admin_asset_manager;
127 $this->options_helper = $options_helper;
128 $this->elementor_conditional = $elementor_conditional;
129 $this->jetpack_conditional = $jetpack_conditional;
130 $this->site_kit_integration_data = $site_kit_integration_data;
131 $this->site_kit_consent_management_endpoint = $site_kit_consent_management_endpoint;
132 $this->schema_configuration = $schema_configuration;
133 $this->myyoast_connection_script_data = $myyoast_connection_script_data;
134 $this->abilities_api_conditional = $abilities_api_conditional;
135 }
136
137 /**
138 * {@inheritDoc}
139 */
140 public function register_hooks() {
141 \add_filter( 'wpseo_submenu_pages', [ $this, 'add_submenu_page' ], 10 );
142 \add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ], 11 );
143 }
144
145 /**
146 * Adds the integrations submenu page.
147 *
148 * @param array $submenu_pages The Yoast SEO submenu pages.
149 *
150 * @return array The filtered submenu pages.
151 */
152 public function add_submenu_page( $submenu_pages ) {
153 $integrations_page = [
154 'wpseo_dashboard',
155 '',
156 \__( 'Integrations', 'wordpress-seo' ),
157 'wpseo_manage_options',
158 self::PAGE,
159 [ $this, 'render_target' ],
160 ];
161
162 \array_splice( $submenu_pages, 1, 0, [ $integrations_page ] );
163
164 return $submenu_pages;
165 }
166
167 /**
168 * Enqueue the integrations app.
169 *
170 * @return void
171 */
172 public function enqueue_assets() {
173 // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Date is not processed or saved.
174 if ( ! isset( $_GET['page'] ) || $_GET['page'] !== self::PAGE ) {
175 return;
176 }
177
178 $this->admin_asset_manager->enqueue_style( 'admin-css' );
179 $this->admin_asset_manager->enqueue_style( 'tailwind' );
180 $this->admin_asset_manager->enqueue_style( 'monorepo' );
181 $this->admin_asset_manager->enqueue_style( 'integrations-page' );
182
183 $this->admin_asset_manager->enqueue_script( 'integrations-page' );
184
185 $acf_seo_file = 'acf-content-analysis-for-yoast-seo/yoast-acf-analysis.php';
186 $acf_seo_file_github = 'yoast-acf-analysis/yoast-acf-analysis.php';
187 $algolia_file = 'wp-search-with-algolia/algolia.php';
188 $old_algolia_file = 'search-by-algolia-instant-relevant-results/algolia.php';
189
190 $schema_api_integrations = $this->schema_configuration->get_schema_api_integrations();
191
192 $woocommerce_seo_installed = $schema_api_integrations['woocommerce']['isInstalled'];
193 $woocommerce_seo_active = $schema_api_integrations['woocommerce']['isActive'];
194 $woocommerce_active = $schema_api_integrations['woocommerce']['isPrerequisiteActive'];
195 $woocommerce_seo_activate_url = $schema_api_integrations['woocommerce']['activationLink'];
196 $edd_active = $schema_api_integrations['edd']['isActive'];
197 $tec_active = $schema_api_integrations['tec']['isActive'];
198 $ssp_active = $schema_api_integrations['ssp']['isActive'];
199 $wp_recipe_maker_active = $schema_api_integrations['wp-recipe-maker']['isActive'];
200
201 $acf_seo_installed = \file_exists( \WP_PLUGIN_DIR . '/' . $acf_seo_file );
202 $acf_seo_github_installed = \file_exists( \WP_PLUGIN_DIR . '/' . $acf_seo_file_github );
203 $acf_seo_active = \is_plugin_active( $acf_seo_file );
204 $acf_seo_github_active = \is_plugin_active( $acf_seo_file_github );
205 $acf_active = \class_exists( 'acf' );
206 $algolia_active = \is_plugin_active( $algolia_file );
207 $old_algolia_active = \is_plugin_active( $old_algolia_file );
208 $mastodon_active = $this->is_mastodon_active();
209
210 if ( $acf_seo_installed ) {
211 $acf_seo_activate_url = \wp_nonce_url(
212 \self_admin_url( 'plugins.php?action=activate&plugin=' . $acf_seo_file ),
213 'activate-plugin_' . $acf_seo_file,
214 );
215 }
216 else {
217 $acf_seo_activate_url = \wp_nonce_url(
218 \self_admin_url( 'plugins.php?action=activate&plugin=' . $acf_seo_file_github ),
219 'activate-plugin_' . $acf_seo_file_github,
220 );
221 }
222
223 $acf_seo_install_url = \wp_nonce_url(
224 \self_admin_url( 'update.php?action=install-plugin&plugin=acf-content-analysis-for-yoast-seo' ),
225 'install-plugin_acf-content-analysis-for-yoast-seo',
226 );
227
228 $this->admin_asset_manager->localize_script(
229 'integrations-page',
230 'wpseoIntegrationsData',
231 [
232 'semrush_integration_active' => $this->options_helper->get( 'semrush_integration_active', true ),
233 'allow_semrush_integration' => $this->options_helper->get( 'allow_semrush_integration_active', true ),
234 'algolia_integration_active' => $this->options_helper->get( 'algolia_integration_active', false ),
235 'allow_algolia_integration' => $this->options_helper->get( 'allow_algolia_integration_active', true ),
236 'wincher_integration_active' => $this->options_helper->get( 'wincher_integration_active', true ),
237 'allow_wincher_integration' => null,
238 'elementor_integration_active' => $this->elementor_conditional->is_met(),
239 'jetpack_integration_active' => $this->jetpack_conditional->is_met(),
240 'woocommerce_seo_installed' => $woocommerce_seo_installed,
241 'woocommerce_seo_active' => $woocommerce_seo_active,
242 'woocommerce_active' => $woocommerce_active,
243 'woocommerce_seo_activate_url' => $woocommerce_seo_activate_url,
244 'acf_seo_installed' => $acf_seo_installed || $acf_seo_github_installed,
245 'acf_seo_active' => $acf_seo_active || $acf_seo_github_active,
246 'acf_active' => $acf_active,
247 'acf_seo_activate_url' => $acf_seo_activate_url,
248 'acf_seo_install_url' => $acf_seo_install_url,
249 'algolia_active' => $algolia_active || $old_algolia_active,
250 'edd_integration_active' => $edd_active,
251 'ssp_integration_active' => $ssp_active,
252 'tec_integration_active' => $tec_active,
253 'wp-recipe-maker_integration_active' => $wp_recipe_maker_active,
254 'mastodon_active' => $mastodon_active,
255 'is_multisite' => \is_multisite(),
256 'plugin_url' => \plugins_url( '', \WPSEO_FILE ),
257 'site_kit_configuration' => $this->site_kit_integration_data->to_array(),
258 'site_kit_consent_management_url' => $this->site_kit_consent_management_endpoint->get_url(),
259 'schema_framework_enabled' => $this->options_helper->get( 'enable_schema', true ) === true && ! $this->schema_configuration->is_schema_disabled_programmatically(),
260 'myyoast_connection' => $this->myyoast_connection_script_data->present(),
261 'schema_aggregation_active' => $this->options_helper->get( 'enable_schema_aggregation_endpoint', false ) === true,
262 'abilities_api_active' => $this->abilities_api_conditional->is_met(),
263 ],
264 );
265 }
266
267 /**
268 * Renders the target for the React to mount to.
269 *
270 * @return void
271 */
272 public function render_target() {
273 ?>
274 <div class="wrap yoast wpseo-admin-page page-wpseo">
275 <div class="wp-header-end" style="height: 0; width: 0;"></div>
276 <div id="wpseo-integrations"></div>
277 </div>
278 <?php
279 }
280
281 /**
282 * Checks whether the Mastodon profile field has been filled in.
283 *
284 * @return bool
285 */
286 private function is_mastodon_active() {
287 return \apply_filters( 'wpseo_mastodon_active', false );
288 }
289 }
290