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

Yoast / wordpress-seo / dd6e866a9e6d253114633104d9e3858d807178ba

19 Jun 2024 10:03AM UTC coverage: 48.628% (-4.3%) from 52.936%
dd6e866a9e6d253114633104d9e3858d807178ba

push

github

web-flow
Merge pull request #21431 from Yoast/21429-update-copy-in-the-introduction-and-consent-modals

Updates the copy for the introduction and consent modals

7441 of 13454 branches covered (55.31%)

Branch coverage included in aggregate %.

0 of 3 new or added lines in 2 files covered. (0.0%)

3718 existing lines in 107 files now uncovered.

25100 of 53464 relevant lines covered (46.95%)

62392.47 hits per line

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

0.0
/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() {
×
29
                $this->register_yoast_plugins();
×
30
                $this->register_yoast_plugins_status();
×
31
        }
32

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

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

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

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

84
                        'yoast-woocommerce-seo' => [
85
                                'url'           => WPSEO_Shortlinker::get( 'https://yoa.st/1o0' ),
×
86
                                'title'         => 'Yoast WooCommerce SEO',
×
87
                                'description'   => sprintf(
×
88
                                        /* translators: %1$s expands to Yoast SEO */
89
                                        __( 'Seamlessly integrate WooCommerce with %1$s and get extra features!', 'wordpress-seo' ),
×
90
                                        'Yoast SEO'
×
91
                                ),
92
                                '_dependencies' => [
93
                                        'WooCommerce' => [
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(),
×
96
                                        ],
97
                                ],
98
                                'installed'     => false,
99
                                'slug'          => 'wpseo-woocommerce/wpseo-woocommerce.php',
×
100
                                'version_sync'  => true,
101
                                'premium'       => true,
102
                        ],
103
                ];
104
        }
105

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

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

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

118
                        if ( file_exists( $plugin_path ) ) {
×
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
        }
126

127
        /**
128
         * Checks whether or not a plugin is known within the Yoast SEO collection.
129
         *
130
         * @param string $plugin The plugin to search for.
131
         *
132
         * @return bool Whether or not the plugin is exists.
133
         */
134
        protected function plugin_exists( $plugin ) {
×
135
                return isset( $this->plugins[ $plugin ] );
×
136
        }
137

138
        /**
139
         * Gets all the possibly available plugins.
140
         *
141
         * @return array Array containing the information about the plugins.
142
         */
143
        public function get_plugins() {
×
144
                return $this->plugins;
×
145
        }
146

147
        /**
148
         * Gets a specific plugin. Returns an empty array if it cannot be found.
149
         *
150
         * @param string $plugin The plugin to search for.
151
         *
152
         * @return array The plugin properties.
153
         */
UNCOV
154
        public function get_plugin( $plugin ) {
×
UNCOV
155
                if ( ! $this->plugin_exists( $plugin ) ) {
×
UNCOV
156
                        return [];
×
157
                }
158

UNCOV
159
                return $this->plugins[ $plugin ];
×
160
        }
161

162
        /**
163
         * Gets the version of the plugin.
164
         *
165
         * @param array $plugin The information available about the plugin.
166
         *
167
         * @return string The version associated with the plugin.
168
         */
UNCOV
169
        public function get_version( $plugin ) {
×
UNCOV
170
                if ( ! isset( $plugin['version'] ) ) {
×
UNCOV
171
                        return '';
×
172
                }
173

UNCOV
174
                return $plugin['version'];
×
175
        }
176

177
        /**
178
         * Checks if there are dependencies available for the plugin.
179
         *
180
         * @param array $plugin The information available about the plugin.
181
         *
182
         * @return bool Whether or not there is a dependency present.
183
         */
184
        public function has_dependencies( $plugin ) {
×
185
                return ( isset( $plugin['_dependencies'] ) && ! empty( $plugin['_dependencies'] ) );
×
186
        }
187

188
        /**
189
         * Gets the dependencies for the plugin.
190
         *
191
         * @param array $plugin The information available about the plugin.
192
         *
193
         * @return array Array containing all the dependencies associated with the plugin.
194
         */
195
        public function get_dependencies( $plugin ) {
×
196
                if ( ! $this->has_dependencies( $plugin ) ) {
×
197
                        return [];
×
198
                }
199

200
                return $plugin['_dependencies'];
×
201
        }
202

203
        /**
204
         * Checks if all dependencies are satisfied.
205
         *
206
         * @param array $plugin The information available about the plugin.
207
         *
208
         * @return bool Whether or not the dependencies are satisfied.
209
         */
210
        public function dependencies_are_satisfied( $plugin ) {
×
211
                if ( ! $this->has_dependencies( $plugin ) ) {
×
212
                        return true;
×
213
                }
214

215
                $dependencies        = $this->get_dependencies( $plugin );
×
216
                $active_dependencies = array_filter( $dependencies, [ $this, 'is_dependency_active' ] );
×
217

218
                return count( $active_dependencies ) === count( $dependencies );
×
219
        }
220

221
        /**
222
         * Checks whether or not one of the plugins is properly installed and usable.
223
         *
224
         * @param array $plugin The information available about the plugin.
225
         *
226
         * @return bool Whether or not the plugin is properly installed.
227
         */
UNCOV
228
        public function is_installed( $plugin ) {
×
UNCOV
229
                if ( empty( $plugin ) ) {
×
230
                        return false;
×
231
                }
232

UNCOV
233
                return $this->is_available( $plugin );
×
234
        }
235

236
        /**
237
         * Gets all installed plugins.
238
         *
239
         * @return array The installed plugins.
240
         */
241
        public function get_installed_plugins() {
×
242
                $installed = [];
×
243

244
                foreach ( $this->plugins as $plugin_key => $plugin ) {
×
245
                        if ( $this->is_installed( $plugin ) ) {
×
246
                                $installed[ $plugin_key ] = $plugin;
×
247
                        }
248
                }
249

250
                return $installed;
×
251
        }
252

253
        /**
254
         * Checks for the availability of the plugin.
255
         *
256
         * @param array $plugin The information available about the plugin.
257
         *
258
         * @return bool Whether or not the plugin is available.
259
         */
UNCOV
260
        public function is_available( $plugin ) {
×
UNCOV
261
                return isset( $plugin['installed'] ) && $plugin['installed'] === true;
×
262
        }
263

264
        /**
265
         * Checks whether a dependency is active.
266
         *
267
         * @param array<string, Conditional> $dependency The information about the dependency to look for.
268
         *
269
         * @return bool Whether or not the dependency is active.
270
         */
271
        public function is_dependency_active( $dependency ) {
×
272
                return $dependency['conditional']->is_met();
×
273
        }
274

275
        /**
276
         * Checks whether a dependency is available.
277
         *
278
         * @deprecated 22.4
279
         * @codeCoverageIgnore
280
         *
281
         * @param array $dependency The information about the dependency to look for.
282
         *
283
         * @return bool Whether or not the dependency is available.
284
         */
285
        public function is_dependency_available( $dependency ) {
286
                _deprecated_function( __METHOD__, 'Yoast SEO 22.4' );
287

288
                return isset( get_plugins()[ $dependency['slug'] ] );
289
        }
290

291
        /**
292
         * Gets the names of the dependencies.
293
         *
294
         * @param array $plugin The plugin to get the dependency names from.
295
         *
296
         * @return array Array containing the names of the associated dependencies.
297
         */
298
        public function get_dependency_names( $plugin ) {
×
299
                if ( ! $this->has_dependencies( $plugin ) ) {
×
300
                        return [];
×
301
                }
302

303
                return array_keys( $plugin['_dependencies'] );
×
304
        }
305

306
        /**
307
         * Gets an array of plugins that have defined dependencies.
308
         *
309
         * @return array Array of the plugins that have dependencies.
310
         */
311
        public function get_plugins_with_dependencies() {
×
312
                return array_filter( $this->plugins, [ $this, 'has_dependencies' ] );
×
313
        }
314

315
        /**
316
         * Determines whether or not a plugin is active.
317
         *
318
         * @param string $plugin The plugin slug to check.
319
         *
320
         * @return bool Whether or not the plugin is active.
321
         */
322
        public function is_active( $plugin ) {
×
323
                return is_plugin_active( $plugin );
×
324
        }
325

326
        /**
327
         * Determines whether or not a plugin is a Premium product.
328
         *
329
         * @param array $plugin The plugin to check.
330
         *
331
         * @return bool Whether or not the plugin is a Premium product.
332
         */
UNCOV
333
        public function is_premium( $plugin ) {
×
UNCOV
334
                return isset( $plugin['premium'] ) && $plugin['premium'] === true;
×
335
        }
336
}
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

© 2025 Coveralls, Inc