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