PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.5
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.5
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
← All changes | admin/class-plugin-availability.php +136 -89 18.128.5 View file →
@@ -4,8 +4,11 @@
4 4 *
5 5 * @package WPSEO\Plugin_Availability
6 6 */
7 7
8 +use Yoast\WP\SEO\Conditionals\Conditional;
9 +use Yoast\WP\SEO\Conditionals\WooCommerce_Conditional;
10 +
8 11 /**
9 12 * Class WPSEO_Plugin_Availability
10 13 */
11 14 class WPSEO_Plugin_Availability {
@@ -18,8 +21,10 @@
18 21 protected $plugins = [];
19 22
20 23 /**
21 24 * Registers the plugins so we can access them.
25 + *
26 + * @return void
22 27 */
23 28 public function register() {
24 29 $this->register_yoast_plugins();
25 30 $this->register_yoast_plugins_status();
@@ -26,8 +31,10 @@
26 31 }
27 32
28 33 /**
29 34 * Registers all the available Yoast SEO plugins.
35 + *
36 + * @return void
30 37 */
31 38 protected function register_yoast_plugins() {
32 39 $this->plugins = [
33 40 'yoast-seo-premium' => [
@@ -35,9 +42,9 @@
35 42 'title' => 'Yoast SEO Premium',
36 43 'description' => sprintf(
37 44 /* translators: %1$s expands to Yoast SEO */
38 45 __( 'The premium version of %1$s with more features & support.', 'wordpress-seo' ),
39 - 'Yoast SEO'
46 + 'Yoast SEO',
40 47 ),
41 48 'installed' => false,
42 49 'slug' => 'wordpress-seo-premium/wp-seo-premium.php',
43 50 'version_sync' => true,
@@ -79,13 +86,14 @@
79 86 'title' => 'Yoast WooCommerce SEO',
80 87 'description' => sprintf(
81 88 /* translators: %1$s expands to Yoast SEO */
82 89 __( 'Seamlessly integrate WooCommerce with %1$s and get extra features!', 'wordpress-seo' ),
83 - 'Yoast SEO'
90 + 'Yoast SEO',
84 91 ),
85 92 '_dependencies' => [
86 93 'WooCommerce' => [
87 - 'slug' => 'woocommerce/woocommerce.php',
94 + 'slug' => 'woocommerce/woocommerce.php', // Kept for backwards compatibility, in case external code uses get_dependencies(). Deprecated in 22.4.
95 + 'conditional' => new WooCommerce_Conditional(),
88 96 ],
89 97 ],
90 98 'installed' => false,
91 99 'slug' => 'wpseo-woocommerce/wpseo-woocommerce.php',
@@ -96,8 +104,10 @@
96 104 }
97 105
98 106 /**
99 107 * Sets certain plugin properties based on WordPress' status.
108 + *
109 + * @return void
100 110 */
101 111 protected function register_yoast_plugins_status() {
102 112
103 113 foreach ( $this->plugins as $name => $plugin ) {
@@ -114,152 +124,178 @@
114 124 }
115 125 }
116 126
117 127 /**
118 - * Checks whether or not a plugin is known within the Yoast SEO collection.
128 + * Checks if there are dependencies available for the plugin.
119 129 *
120 - * @param string $plugin The plugin to search for.
130 + * @param array $plugin The information available about the plugin.
121 131 *
122 - * @return bool Whether or not the plugin is exists.
132 + * @return bool Whether there is a dependency present.
123 133 */
124 - protected function plugin_exists( $plugin ) {
125 - return isset( $this->plugins[ $plugin ] );
134 + public function has_dependencies( $plugin ) {
135 + return ( isset( $plugin['_dependencies'] ) && ! empty( $plugin['_dependencies'] ) );
126 136 }
127 137
128 138 /**
129 - * Gets all the possibly available plugins.
139 + * Gets the dependencies for the plugin.
130 140 *
131 - * @return array Array containing the information about the plugins.
141 + * @param array $plugin The information available about the plugin.
142 + *
143 + * @return array Array containing all the dependencies associated with the plugin.
132 144 */
133 - public function get_plugins() {
134 - return $this->plugins;
145 + public function get_dependencies( $plugin ) {
146 + if ( ! $this->has_dependencies( $plugin ) ) {
147 + return [];
148 + }
149 +
150 + return $plugin['_dependencies'];
135 151 }
136 152
137 153 /**
138 - * Gets a specific plugin. Returns an empty array if it cannot be found.
154 + * Checks if all dependencies are satisfied.
139 155 *
140 - * @param string $plugin The plugin to search for.
156 + * @param array $plugin The information available about the plugin.
141 157 *
142 - * @return array The plugin properties.
158 + * @return bool Whether or not the dependencies are satisfied.
143 159 */
144 - public function get_plugin( $plugin ) {
145 - if ( ! $this->plugin_exists( $plugin ) ) {
146 - return [];
160 + public function dependencies_are_satisfied( $plugin ) {
161 + if ( ! $this->has_dependencies( $plugin ) ) {
162 + return true;
147 163 }
148 164
149 - return $this->plugins[ $plugin ];
165 + $dependencies = $this->get_dependencies( $plugin );
166 + $active_dependencies = array_filter( $dependencies, [ $this, 'is_dependency_active' ] );
167 +
168 + return count( $active_dependencies ) === count( $dependencies );
150 169 }
151 170
152 171 /**
153 - * Gets the version of the plugin.
172 + * Checks whether or not one of the plugins is properly installed and usable.
154 173 *
155 174 * @param array $plugin The information available about the plugin.
156 175 *
157 - * @return string The version associated with the plugin.
176 + * @return bool Whether or not the plugin is properly installed.
158 177 */
159 - public function get_version( $plugin ) {
160 - if ( ! isset( $plugin['version'] ) ) {
161 - return '';
178 + public function is_installed( $plugin ) {
179 + if ( empty( $plugin ) ) {
180 + return false;
162 181 }
163 182
164 - return $plugin['version'];
183 + return $this->is_available( $plugin );
165 184 }
166 185
167 186 /**
168 - * Checks if there are dependencies available for the plugin.
187 + * Checks for the availability of the plugin.
169 188 *
170 189 * @param array $plugin The information available about the plugin.
171 190 *
172 - * @return bool Whether or not there is a dependency present.
191 + * @return bool Whether or not the plugin is available.
173 192 */
174 - public function has_dependencies( $plugin ) {
175 - return ( isset( $plugin['_dependencies'] ) && ! empty( $plugin['_dependencies'] ) );
193 + public function is_available( $plugin ) {
194 + return isset( $plugin['installed'] ) && $plugin['installed'] === true;
176 195 }
177 196
178 197 /**
179 - * Gets the dependencies for the plugin.
198 + * Checks whether a dependency is active.
180 199 *
181 - * @param array $plugin The information available about the plugin.
200 + * @param array<string, Conditional> $dependency The information about the dependency to look for.
182 201 *
183 - * @return array Array containing all the dependencies associated with the plugin.
202 + * @return bool Whether or not the dependency is active.
184 203 */
185 - public function get_dependencies( $plugin ) {
186 - if ( ! $this->has_dependencies( $plugin ) ) {
187 - return [];
188 - }
204 + public function is_dependency_active( $dependency ) {
205 + return $dependency['conditional']->is_met();
206 + }
189 207
190 - return $plugin['_dependencies'];
208 + /**
209 + * Gets an array of plugins that have defined dependencies.
210 + *
211 + * @return array Array of the plugins that have dependencies.
212 + */
213 + public function get_plugins_with_dependencies() {
214 + return array_filter( $this->plugins, [ $this, 'has_dependencies' ] );
191 215 }
192 216
193 217 /**
194 - * Checks if all dependencies are satisfied.
218 + * Determines whether or not a plugin is active.
195 219 *
196 - * @param array $plugin The information available about the plugin.
220 + * @deprecated 23.4
221 + * @codeCoverageIgnore
197 222 *
198 - * @return bool Whether or not the dependencies are satisfied.
223 + * @param string $plugin The plugin slug to check.
224 + *
225 + * @return bool Whether or not the plugin is active.
199 226 */
200 - public function dependencies_are_satisfied( $plugin ) {
201 - if ( ! $this->has_dependencies( $plugin ) ) {
202 - return true;
203 - }
227 + public function is_active( $plugin ) {
228 + _deprecated_function( __METHOD__, 'Yoast SEO 23.4', 'is_plugin_active' );
204 229
205 - $dependencies = $this->get_dependencies( $plugin );
206 - $installed_dependencies = array_filter( $dependencies, [ $this, 'is_dependency_available' ] );
207 -
208 - return count( $installed_dependencies ) === count( $dependencies );
230 + return is_plugin_active( $plugin );
209 231 }
210 232
211 233 /**
212 - * Checks whether or not one of the plugins is properly installed and usable.
234 + * Gets all the possibly available plugins.
213 235 *
214 - * @param array $plugin The information available about the plugin.
236 + * @deprecated 23.4
237 + * @codeCoverageIgnore
215 238 *
216 - * @return bool Whether or not the plugin is properly installed.
239 + * @return array Array containing the information about the plugins.
217 240 */
218 - public function is_installed( $plugin ) {
219 - if ( empty( $plugin ) ) {
220 - return false;
221 - }
241 + public function get_plugins() {
242 + _deprecated_function( __METHOD__, 'Yoast SEO 23.4', 'WPSEO_Addon_Manager::get_addon_filenames' );
222 243
223 - return $this->is_available( $plugin );
244 + return $this->plugins;
224 245 }
225 246
226 247 /**
227 - * Gets all installed plugins.
248 + * Gets a specific plugin. Returns an empty array if it cannot be found.
228 249 *
229 - * @return array The installed plugins.
250 + * @deprecated 23.4
251 + * @codeCoverageIgnore
252 + *
253 + * @param string $plugin The plugin to search for.
254 + *
255 + * @return array The plugin properties.
230 256 */
231 - public function get_installed_plugins() {
232 - $installed = [];
233 -
234 - foreach ( $this->plugins as $plugin_key => $plugin ) {
235 - if ( $this->is_installed( $plugin ) ) {
236 - $installed[ $plugin_key ] = $plugin;
237 - }
257 + public function get_plugin( $plugin ) { // @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- needed for BC reasons
258 + _deprecated_function( __METHOD__, 'Yoast SEO 23.4', 'WPSEO_Addon_Manager::get_plugin_file' );
259 + if ( ! isset( $this->plugins[ $plugin ] ) ) {
260 + return [];
238 261 }
239 262
240 - return $installed;
263 + return $this->plugins[ $plugin ];
241 264 }
242 265
243 266 /**
244 - * Checks for the availability of the plugin.
267 + * Gets the version of the plugin.
245 268 *
269 + * @deprecated 23.4
270 + * @codeCoverageIgnore
271 + *
246 272 * @param array $plugin The information available about the plugin.
247 273 *
248 - * @return bool Whether or not the plugin is available.
274 + * @return string The version associated with the plugin.
249 275 */
250 - public function is_available( $plugin ) {
251 - return isset( $plugin['installed'] ) && $plugin['installed'] === true;
276 + public function get_version( $plugin ) { // @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- needed for BC reasons
277 + _deprecated_function( __METHOD__, 'Yoast SEO 23.4', 'WPSEO_Addon_Manager::get_installed_addons_versions' );
278 + if ( ! isset( $plugin['version'] ) ) {
279 + return '';
280 + }
281 +
282 + return $plugin['version'];
252 283 }
253 284
254 285 /**
255 286 * Checks whether a dependency is available.
256 287 *
288 + * @deprecated 22.4
289 + * @codeCoverageIgnore
290 + *
257 291 * @param array $dependency The information about the dependency to look for.
258 292 *
259 293 * @return bool Whether or not the dependency is available.
260 294 */
261 295 public function is_dependency_available( $dependency ) {
296 + _deprecated_function( __METHOD__, 'Yoast SEO 22.4' );
297 +
262 298 return isset( get_plugins()[ $dependency['slug'] ] );
263 299 }
264 300
265 301 /**
@@ -264,13 +300,17 @@
264 300
265 301 /**
266 302 * Gets the names of the dependencies.
267 303 *
304 + * @deprecated 23.4
305 + * @codeCoverageIgnore
306 + *
268 307 * @param array $plugin The plugin to get the dependency names from.
269 308 *
270 309 * @return array Array containing the names of the associated dependencies.
271 310 */
272 - public function get_dependency_names( $plugin ) {
311 + public function get_dependency_names( $plugin ) { // @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- needed for BC reasons
312 + _deprecated_function( __METHOD__, 'Yoast SEO 23.4' );
273 313 if ( ! $this->has_dependencies( $plugin ) ) {
274 314 return [];
275 315 }
276 316
@@ -277,34 +317,41 @@
277 317 return array_keys( $plugin['_dependencies'] );
278 318 }
279 319
280 320 /**
281 - * Gets an array of plugins that have defined dependencies.
321 + * Determines whether or not a plugin is a Premium product.
282 322 *
283 - * @return array Array of the plugins that have dependencies.
284 - */
285 - public function get_plugins_with_dependencies() {
286 - return array_filter( $this->plugins, [ $this, 'has_dependencies' ] );
287 - }
288 -
289 - /**
290 - * Determines whether or not a plugin is active.
323 + * @deprecated 23.4
324 + * @codeCoverageIgnore
291 325 *
292 - * @param string $plugin The plugin slug to check.
326 + * @param array $plugin The plugin to check.
293 327 *
294 - * @return bool Whether or not the plugin is active.
328 + * @return bool Whether or not the plugin is a Premium product.
295 329 */
296 - public function is_active( $plugin ) {
297 - return is_plugin_active( $plugin );
330 + public function is_premium( $plugin ) {
331 + _deprecated_function( __METHOD__, 'Yoast SEO 23.4' );
332 +
333 + return isset( $plugin['premium'] ) && $plugin['premium'] === true;
298 334 }
299 335
300 336 /**
301 - * Determines whether or not a plugin is a Premium product.
337 + * Gets all installed plugins.
302 338 *
303 - * @param array $plugin The plugin to check.
339 + * @deprecated 23.4
340 + * @codeCoverageIgnore
304 341 *
305 - * @return bool Whether or not the plugin is a Premium product.
342 + * @return array The installed plugins.
306 343 */
307 - public function is_premium( $plugin ) {
308 - return isset( $plugin['premium'] ) && $plugin['premium'] === true;
344 + public function get_installed_plugins() {
345 +
346 + _deprecated_function( __METHOD__, 'Yoast SEO 23.4', 'WPSEO_Addon_Manager::get_installed_addons_versions' );
347 + $installed = [];
348 +
349 + foreach ( $this->plugins as $plugin_key => $plugin ) {
350 + if ( $this->is_installed( $plugin ) ) {
351 + $installed[ $plugin_key ] = $plugin;
352 + }
353 + }
354 +
355 + return $installed;
309 356 }
310 357 }