PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 27.9
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v27.9
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 19.0 All 129 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 27.9, at src/integrations/admin/integrations-page.php

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