• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Yoast / wordpress-seo / b78c91bd80d89b034df841d284a428c954224385

03 Sep 2024 07:50AM UTC coverage: 54.503% (+0.4%) from 54.072%
b78c91bd80d89b034df841d284a428c954224385

push

github

YoastBot
Bump version to 23.4 on free

7504 of 13559 branches covered (55.34%)

Branch coverage included in aggregate %.

29831 of 54942 relevant lines covered (54.3%)

41571.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.78
/admin/class-plugin-availability.php
1
<?php
2
/**
3
 * WPSEO plugin file.
4
 *
5
 * @package WPSEO\Plugin_Availability
6
 */
7

8
use Yoast\WP\SEO\Conditionals\Conditional;
9
use Yoast\WP\SEO\Conditionals\WooCommerce_Conditional;
10

11
/**
12
 * Class WPSEO_Plugin_Availability
13
 */
14
class WPSEO_Plugin_Availability {
15

16
        /**
17
         * Holds the plugins.
18
         *
19
         * @var array
20
         */
21
        protected $plugins = [];
22

23
        /**
24
         * Registers the plugins so we can access them.
25
         *
26
         * @return void
27
         */
28
        public function register() {
6✔
29
                $this->register_yoast_plugins();
6✔
30
                $this->register_yoast_plugins_status();
6✔
31
        }
3✔
32

33
        /**
34
         * Registers all the available Yoast SEO plugins.
35
         *
36
         * @return void
37
         */
38
        protected function register_yoast_plugins() {
6✔
39
                $this->plugins = [
6✔
40
                        'yoast-seo-premium' => [
6✔
41
                                'url'          => WPSEO_Shortlinker::get( 'https://yoa.st/1y7' ),
6✔
42
                                'title'        => 'Yoast SEO Premium',
6✔
43
                                'description'  => sprintf(
6✔
44
                                        /* translators: %1$s expands to Yoast SEO */
45
                                        __( 'The premium version of %1$s with more features & support.', 'wordpress-seo' ),
6✔
46
                                        'Yoast SEO'
6✔
47
                                ),
3✔
48
                                'installed'    => false,
3✔
49
                                'slug'         => 'wordpress-seo-premium/wp-seo-premium.php',
6✔
50
                                'version_sync' => true,
3✔
51
                                'premium'      => true,
3✔
52
                        ],
3✔
53

54
                        'video-seo-for-wordpress-seo-by-yoast' => [
3✔
55
                                'url'          => WPSEO_Shortlinker::get( 'https://yoa.st/1y8' ),
6✔
56
                                'title'        => 'Video SEO',
6✔
57
                                'description'  => __( 'Optimize your videos to show them off in search results and get more clicks!', 'wordpress-seo' ),
6✔
58
                                'installed'    => false,
3✔
59
                                'slug'         => 'wpseo-video/video-seo.php',
6✔
60
                                'version_sync' => true,
3✔
61
                                'premium'      => true,
3✔
62
                        ],
3✔
63

64
                        'yoast-news-seo' => [
3✔
65
                                'url'          => WPSEO_Shortlinker::get( 'https://yoa.st/1y9' ),
6✔
66
                                'title'        => 'News SEO',
6✔
67
                                'description'  => __( 'Are you in Google News? Increase your traffic from Google News by optimizing for it!', 'wordpress-seo' ),
6✔
68
                                'installed'    => false,
3✔
69
                                'slug'         => 'wpseo-news/wpseo-news.php',
6✔
70
                                'version_sync' => true,
3✔
71
                                'premium'      => true,
3✔
72
                        ],
3✔
73

74
                        'local-seo-for-yoast-seo' => [
3✔
75
                                'url'          => WPSEO_Shortlinker::get( 'https://yoa.st/1ya' ),
6✔
76
                                'title'        => 'Local SEO',
6✔
77
                                'description'  => __( 'Rank better locally and in Google Maps, without breaking a sweat!', 'wordpress-seo' ),
6✔
78
                                'installed'    => false,
3✔
79
                                'slug'         => 'wordpress-seo-local/local-seo.php',
6✔
80
                                'version_sync' => true,
3✔
81
                                'premium'      => true,
3✔
82
                        ],
3✔
83

84
                        'yoast-woocommerce-seo' => [
3✔
85
                                'url'           => WPSEO_Shortlinker::get( 'https://yoa.st/1o0' ),
6✔
86
                                'title'         => 'Yoast WooCommerce SEO',
6✔
87
                                'description'   => sprintf(
6✔
88
                                        /* translators: %1$s expands to Yoast SEO */
89
                                        __( 'Seamlessly integrate WooCommerce with %1$s and get extra features!', 'wordpress-seo' ),
6✔
90
                                        'Yoast SEO'
6✔
91
                                ),
3✔
92
                                '_dependencies' => [
3✔
93
                                        'WooCommerce' => [
3✔
94
                                                'slug'        => 'woocommerce/woocommerce.php', // Kept for backwards compatibility, in case external code uses get_dependencies(). Deprecated in 22.4.
6✔
95
                                                'conditional' => new WooCommerce_Conditional(),
6✔
96
                                        ],
3✔
97
                                ],
3✔
98
                                'installed'     => false,
3✔
99
                                'slug'          => 'wpseo-woocommerce/wpseo-woocommerce.php',
6✔
100
                                'version_sync'  => true,
3✔
101
                                'premium'       => true,
3✔
102
                        ],
3✔
103
                ];
3✔
104
        }
3✔
105

106
        /**
107
         * Sets certain plugin properties based on WordPress' status.
108
         *
109
         * @return void
110
         */
111
        protected function register_yoast_plugins_status() {
6✔
112

113
                foreach ( $this->plugins as $name => $plugin ) {
6✔
114

115
                        $plugin_slug = $plugin['slug'];
6✔
116
                        $plugin_path = WP_PLUGIN_DIR . '/' . $plugin_slug;
6✔
117

118
                        if ( file_exists( $plugin_path ) ) {
6✔
119
                                $plugin_data                         = get_plugin_data( $plugin_path, false, false );
×
120
                                $this->plugins[ $name ]['installed'] = true;
×
121
                                $this->plugins[ $name ]['version']   = $plugin_data['Version'];
×
122
                                $this->plugins[ $name ]['active']    = is_plugin_active( $plugin_slug );
×
123
                        }
124
                }
125
        }
3✔
126

127
        /**
128
         * Checks if there are dependencies available for the plugin.
129
         *
130
         * @param array $plugin The information available about the plugin.
131
         *
132
         * @return bool Whether there is a dependency present.
133
         */
134
        public function has_dependencies( $plugin ) {
6✔
135
                return ( isset( $plugin['_dependencies'] ) && ! empty( $plugin['_dependencies'] ) );
6✔
136
        }
137

138
        /**
139
         * Gets the dependencies for the plugin.
140
         *
141
         * @param array $plugin The information available about the plugin.
142
         *
143
         * @return array Array containing all the dependencies associated with the plugin.
144
         */
145
        public function get_dependencies( $plugin ) {
4✔
146
                if ( ! $this->has_dependencies( $plugin ) ) {
4✔
147
                        return [];
×
148
                }
149

150
                return $plugin['_dependencies'];
4✔
151
        }
152

153
        /**
154
         * Checks if all dependencies are satisfied.
155
         *
156
         * @param array $plugin The information available about the plugin.
157
         *
158
         * @return bool Whether or not the dependencies are satisfied.
159
         */
160
        public function dependencies_are_satisfied( $plugin ) {
2✔
161
                if ( ! $this->has_dependencies( $plugin ) ) {
2✔
162
                        return true;
×
163
                }
164

165
                $dependencies        = $this->get_dependencies( $plugin );
2✔
166
                $active_dependencies = array_filter( $dependencies, [ $this, 'is_dependency_active' ] );
2✔
167

168
                return count( $active_dependencies ) === count( $dependencies );
2✔
169
        }
170

171
        /**
172
         * Checks whether or not one of the plugins is properly installed and usable.
173
         *
174
         * @param array $plugin The information available about the plugin.
175
         *
176
         * @return bool Whether or not the plugin is properly installed.
177
         */
178
        public function is_installed( $plugin ) {
4✔
179
                if ( empty( $plugin ) ) {
4✔
180
                        return false;
×
181
                }
182

183
                return $this->is_available( $plugin );
4✔
184
        }
185

186
        /**
187
         * Checks for the availability of the plugin.
188
         *
189
         * @param array $plugin The information available about the plugin.
190
         *
191
         * @return bool Whether or not the plugin is available.
192
         */
193
        public function is_available( $plugin ) {
4✔
194
                return isset( $plugin['installed'] ) && $plugin['installed'] === true;
4✔
195
        }
196

197
        /**
198
         * Checks whether a dependency is active.
199
         *
200
         * @param array<string, Conditional> $dependency The information about the dependency to look for.
201
         *
202
         * @return bool Whether or not the dependency is active.
203
         */
204
        public function is_dependency_active( $dependency ) {
2✔
205
                return $dependency['conditional']->is_met();
2✔
206
        }
207

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() {
2✔
214
                return array_filter( $this->plugins, [ $this, 'has_dependencies' ] );
2✔
215
        }
216

217
        /**
218
         * Determines whether or not a plugin is active.
219
         *
220
         * @param string $plugin The plugin slug to check.
221
         *
222
         * @return bool Whether or not the plugin is active.
223
         *
224
         * @deprecated 23.4
225
         * @codeCoverageIgnore
226
         */
227
        public function is_active( $plugin ) {
228
                _deprecated_function( __METHOD__, 'Yoast SEO 23.4', 'is_plugin_active' );
229

230
                return is_plugin_active( $plugin );
231
        }
232

233
        /**
234
         * Gets all the possibly available plugins.
235
         *
236
         * @return array Array containing the information about the plugins.
237
         *
238
         * @deprecated 23.4
239
         * @codeCoverageIgnore
240
         */
241
        public function get_plugins() {
242
                _deprecated_function( __METHOD__, 'Yoast SEO 23.4', 'WPSEO_Addon_Manager::get_addon_filenames' );
243

244
                return $this->plugins;
245
        }
246

247
        /**
248
         * Gets a specific plugin. Returns an empty array if it cannot be found.
249
         *
250
         * @param string $plugin The plugin to search for.
251
         *
252
         * @return array The plugin properties.
253
         *
254
         * @deprecated 23.4
255
         * @codeCoverageIgnore
256
         */
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 [];
261
                }
262

263
                return $this->plugins[ $plugin ];
264
        }
265

266
        /**
267
         * Gets the version of the plugin.
268
         *
269
         * @param array $plugin The information available about the plugin.
270
         *
271
         * @return string The version associated with the plugin.
272
         *
273
         * @deprecated 23.4
274
         * @codeCoverageIgnore
275
         */
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'];
283
        }
284

285
        /**
286
         * Checks whether a dependency is available.
287
         *
288
         * @param array $dependency The information about the dependency to look for.
289
         *
290
         * @return bool Whether or not the dependency is available.
291
         * @deprecated 22.4
292
         * @codeCoverageIgnore
293
         */
294
        public function is_dependency_available( $dependency ) {
295
                _deprecated_function( __METHOD__, 'Yoast SEO 22.4' );
296

297
                return isset( get_plugins()[ $dependency['slug'] ] );
298
        }
299

300
        /**
301
         * Gets the names of the dependencies.
302
         *
303
         * @param array $plugin The plugin to get the dependency names from.
304
         *
305
         * @return array Array containing the names of the associated dependencies.
306
         * @deprecated 23.4
307
         * @codeCoverageIgnore
308
         */
309
        public function get_dependency_names( $plugin ) { // @phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found, VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable -- needed for BC reasons
310
                _deprecated_function( __METHOD__, 'Yoast SEO 23.4' );
311
                if ( ! $this->has_dependencies( $plugin ) ) {
312
                        return [];
313
                }
314

315
                return array_keys( $plugin['_dependencies'] );
316
        }
317

318
        /**
319
         * Determines whether or not a plugin is a Premium product.
320
         *
321
         * @param array $plugin The plugin to check.
322
         *
323
         * @return bool Whether or not the plugin is a Premium product.
324
         *
325
         * @deprecated 23.4
326
         * @codeCoverageIgnore
327
         */
328
        public function is_premium( $plugin ) {
329
                _deprecated_function( __METHOD__, 'Yoast SEO 23.4' );
330

331
                return isset( $plugin['premium'] ) && $plugin['premium'] === true;
332
        }
333

334
        /**
335
         * Gets all installed plugins.
336
         *
337
         * @return array The installed plugins.
338
         *
339
         * @deprecated 23.4
340
         * @codeCoverageIgnore
341
         */
342
        public function get_installed_plugins() {
343

344
                _deprecated_function( __METHOD__, 'Yoast SEO 23.4', 'WPSEO_Addon_Manager::get_installed_addons_versions' );
345
                $installed = [];
346

347
                foreach ( $this->plugins as $plugin_key => $plugin ) {
348
                        if ( $this->is_installed( $plugin ) ) {
349
                                $installed[ $plugin_key ] = $plugin;
350
                        }
351
                }
352

353
                return $installed;
354
        }
355
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc