integrations-page.php
9.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<?php
namespace Yoast\WP\SEO\Integrations\Admin;
use WPSEO_Admin_Asset_Manager;
use WPSEO_Plugin_Availability;
use WPSEO_Shortlinker;
use Yoast\WP\SEO\Conditionals\Admin_Conditional;
use Yoast\WP\SEO\Conditionals\Third_Party\Jetpack_Boost_Active_Conditional;
use Yoast\WP\SEO\Conditionals\Third_Party\Jetpack_Boost_Not_Premium_Conditional;
use Yoast\WP\SEO\Conditionals\Jetpack_Conditional;
use Yoast\WP\SEO\Conditionals\Third_Party\Elementor_Activated_Conditional;
use Yoast\WP\SEO\Conditionals\WooCommerce_Conditional;
use Yoast\WP\SEO\Helpers\Options_Helper;
use Yoast\WP\SEO\Integrations\Integration_Interface;
/**
* Integrations_Page class
*/
class Integrations_Page implements Integration_Interface {
/**
* The admin asset manager.
*
* @var WPSEO_Admin_Asset_Manager
*/
private $admin_asset_manager;
/**
* The options helper.
*
* @var Options_Helper
*/
private $options_helper;
/**
* {@inheritDoc}
*/
public static function get_conditionals() {
return [ Admin_Conditional::class ];
}
/**
* Workouts_Integration constructor.
*
* @param WPSEO_Admin_Asset_Manager $admin_asset_manager The admin asset manager.
* @param Options_Helper $options_helper The options helper.
*/
public function __construct(
WPSEO_Admin_Asset_Manager $admin_asset_manager,
Options_Helper $options_helper
) {
$this->admin_asset_manager = $admin_asset_manager;
$this->options_helper = $options_helper;
}
/**
* {@inheritDoc}
*/
public function register_hooks() {
\add_filter( 'wpseo_submenu_pages', [ $this, 'add_submenu_page' ], 10 );
\add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ], 11 );
}
/**
* Adds the integrations submenu page.
*
* @param array $submenu_pages The Yoast SEO submenu pages.
*
* @return array The filtered submenu pages.
*/
public function add_submenu_page( $submenu_pages ) {
$integrations_page = [
'wpseo_dashboard',
'',
\__( 'Integrations', 'wordpress-seo' ),
'wpseo_manage_options',
'wpseo_integrations',
[ $this, 'render_target' ],
];
\array_splice( $submenu_pages, 1, 0, [ $integrations_page ] );
return $submenu_pages;
}
/**
* Enqueue the integrations app.
*/
public function enqueue_assets() {
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Date is not processed or saved.
if ( ! isset( $_GET['page'] ) || $_GET['page'] !== 'wpseo_integrations' ) {
return;
}
$this->admin_asset_manager->enqueue_style( 'admin-css' );
$this->admin_asset_manager->enqueue_style( 'tailwind' );
$this->admin_asset_manager->enqueue_style( 'monorepo' );
$this->admin_asset_manager->enqueue_script( 'integrations-page' );
$elementor_conditional = new Elementor_Activated_Conditional();
$jetpack_conditional = new Jetpack_Conditional();
$woocommerce_conditional = new WooCommerce_Conditional();
$jetpack_boost_active_conditional = new Jetpack_Boost_Active_Conditional();
$jetpack_boost_not_premium_conditional = new Jetpack_Boost_Not_Premium_Conditional();
$woocommerce_seo_file = 'wpseo-woocommerce/wpseo-woocommerce.php';
$acf_seo_file = 'acf-content-analysis-for-yoast-seo/yoast-acf-analysis.php';
$acf_seo_file_github = 'yoast-acf-analysis/yoast-acf-analysis.php';
$algolia_file = 'wp-search-with-algolia/algolia.php';
$old_algolia_file = 'search-by-algolia-instant-relevant-results/algolia.php';
$host = YoastSEO()->helpers->url->get_url_host( get_site_url() );
$wpseo_plugin_availability_checker = new WPSEO_Plugin_Availability();
$woocommerce_seo_installed = \file_exists( \WP_PLUGIN_DIR . '/' . $woocommerce_seo_file );
$woocommerce_seo_active = $wpseo_plugin_availability_checker->is_active( $woocommerce_seo_file );
$woocommerce_active = $woocommerce_conditional->is_met();
$acf_seo_installed = \file_exists( \WP_PLUGIN_DIR . '/' . $acf_seo_file );
$acf_seo_github_installed = \file_exists( \WP_PLUGIN_DIR . '/' . $acf_seo_file_github );
$acf_seo_active = $wpseo_plugin_availability_checker->is_active( $acf_seo_file );
$acf_seo_github_active = $wpseo_plugin_availability_checker->is_active( $acf_seo_file_github );
$acf_active = \class_exists( 'acf' );
$algolia_active = $wpseo_plugin_availability_checker->is_active( $algolia_file );
$edd_active = \class_exists( \Easy_Digital_Downloads::class );
$jetpack_boost_active = $jetpack_boost_active_conditional->is_met();
$jetpack_boost_premium = ( ! $jetpack_boost_not_premium_conditional->is_met() );
$old_algolia_active = $wpseo_plugin_availability_checker->is_active( $old_algolia_file );
$tec_active = \class_exists( \TEC\Events\Integrations\Plugins\WordPress_SEO\Events_Schema::class );
$ssp_active = \class_exists( \SeriouslySimplePodcasting\Integrations\Yoast\Schema\PodcastEpisode::class );
$wp_recipe_maker_active = \class_exists( \WP_Recipe_Maker::class );
$mastodon_active = $this->is_mastodon_active();
$woocommerce_seo_activate_url = \wp_nonce_url(
\self_admin_url( 'plugins.php?action=activate&plugin=' . $woocommerce_seo_file ),
'activate-plugin_' . $woocommerce_seo_file
);
if ( $acf_seo_installed ) {
$acf_seo_activate_url = \wp_nonce_url(
\self_admin_url( 'plugins.php?action=activate&plugin=' . $acf_seo_file ),
'activate-plugin_' . $acf_seo_file
);
}
else {
$acf_seo_activate_url = \wp_nonce_url(
\self_admin_url( 'plugins.php?action=activate&plugin=' . $acf_seo_file_github ),
'activate-plugin_' . $acf_seo_file_github
);
}
$acf_seo_install_url = \wp_nonce_url(
\self_admin_url( 'update.php?action=install-plugin&plugin=acf-content-analysis-for-yoast-seo' ),
'install-plugin_acf-content-analysis-for-yoast-seo'
);
$this->admin_asset_manager->localize_script(
'integrations-page',
'wpseoIntegrationsData',
[
'semrush_integration_active' => $this->options_helper->get( 'semrush_integration_active', true ),
'allow_semrush_integration' => $this->options_helper->get( 'allow_semrush_integration_active', true ),
'algolia_integration_active' => $this->options_helper->get( 'algolia_integration_active', false ),
'allow_algolia_integration' => $this->options_helper->get( 'allow_algolia_integration_active', true ),
'wincher_integration_active' => $this->options_helper->get( 'wincher_integration_active', true ),
'allow_wincher_integration' => null,
'wordproof_integration_active' => $this->options_helper->get( 'wordproof_integration_active', true ),
'allow_wordproof_integration' => null,
'elementor_integration_active' => $elementor_conditional->is_met(),
'jetpack_integration_active' => $jetpack_conditional->is_met(),
'woocommerce_seo_installed' => $woocommerce_seo_installed,
'woocommerce_seo_active' => $woocommerce_seo_active,
'woocommerce_active' => $woocommerce_active,
'woocommerce_seo_activate_url' => $woocommerce_seo_activate_url,
'acf_seo_installed' => $acf_seo_installed || $acf_seo_github_installed,
'acf_seo_active' => $acf_seo_active || $acf_seo_github_active,
'acf_active' => $acf_active,
'acf_seo_activate_url' => $acf_seo_activate_url,
'acf_seo_install_url' => $acf_seo_install_url,
'algolia_active' => $algolia_active || $old_algolia_active,
'edd_integration_active' => $edd_active,
'ssp_integration_active' => $ssp_active,
'tec_integration_active' => $tec_active,
'wp-recipe-maker_integration_active' => $wp_recipe_maker_active,
'mastodon_active' => $mastodon_active,
'is_multisite' => \is_multisite(),
'plugin_url' => \plugins_url( '', \WPSEO_FILE ),
'jetpack-boost_active' => $jetpack_boost_active,
'jetpack-boost_premium' => $jetpack_boost_premium,
'jetpack-boost_logo_link' => WPSEO_Shortlinker::get( 'https://yoa.st/integrations-logo-jetpack-boost' ),
'jetpack-boost_get_link' => WPSEO_Shortlinker::get( 'https://yoa.st/integrations-get-jetpack-boost?domain=' . $host ),
'jetpack-boost_upgrade_link' => WPSEO_Shortlinker::get( 'https://yoa.st/integrations-upgrade-jetpack-boost?domain=' . $host ),
'jetpack-boost_learn_more_link' => \admin_url( 'admin.php?page=jetpack-boost' ),
]
);
}
/**
* Renders the target for the React to mount to.
*/
public function render_target() {
?>
<div class="wrap yoast wpseo-admin-page page-wpseo">
<div class="wp-header-end" style="height: 0; width: 0;"></div>
<div id="wpseo-integrations"></div>
</div>
<?php
}
/**
* Checks whether the Mastodon profile field has been filled in.
*
* @return bool
*/
private function is_mastodon_active() {
return \apply_filters( 'wpseo_mastodon_active', false );
}
}