Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
96.00% |
24 / 25 |
|
100.00% |
2 / 2 |
CRAP | n/a |
0 / 0 |
|
| jetpack_seo_detect_conflicting_plugin | |
100.00% |
20 / 20 |
|
100.00% |
1 / 1 |
5 | |||
| jetpack_seo_has_conflicting_plugin | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Conflicting SEO plugin detection, also loaded while the SEO Tools module is off (see module-extras.php). |
| 4 | * |
| 5 | * @package automattic/jetpack |
| 6 | */ |
| 7 | |
| 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | exit( 0 ); |
| 10 | } |
| 11 | |
| 12 | // Name the SEO plugin that owns the site's SEO output, for SEO Tools, Canonical URLs and the SEO dashboard. |
| 13 | add_filter( 'jetpack_seo_conflicting_plugin', 'jetpack_seo_detect_conflicting_plugin' ); |
| 14 | |
| 15 | /** |
| 16 | * Return the display name of the first active SEO plugin Jetpack steps aside for. |
| 17 | * |
| 18 | * @since $$next-version$$ |
| 19 | * |
| 20 | * @param string|null $plugin A name reported by an earlier callback, or null. |
| 21 | * @return string|null The plugin's display name, or null when none is active. |
| 22 | */ |
| 23 | function jetpack_seo_detect_conflicting_plugin( $plugin ) { |
| 24 | // WordPress.com Simple's stub Jetpack class lacks this method, and Simple runs no plugins. |
| 25 | if ( $plugin || ! method_exists( 'Jetpack', 'get_active_plugins' ) ) { |
| 26 | return $plugin; |
| 27 | } |
| 28 | |
| 29 | // Read the list once: this runs on every SEO Tools check, front end included. |
| 30 | $active_plugins = Jetpack::get_active_plugins(); |
| 31 | |
| 32 | // Paid editions come before the free plugins they run alongside, so the first match names the right one. |
| 33 | $conflicting_plugins = array( |
| 34 | 'wordpress-seo-premium/wp-seo-premium.php' => 'Yoast SEO Premium', |
| 35 | 'wordpress-seo/wp-seo.php' => 'Yoast SEO', |
| 36 | 'all-in-one-seo-pack-pro/all_in_one_seo_pack.php' => 'All in One SEO Pro', |
| 37 | 'all-in-one-seo-pack/all_in_one_seo_pack.php' => 'All in One SEO', |
| 38 | 'seo-by-rank-math/rank-math.php' => 'Rank Math SEO', |
| 39 | 'autodescription/autodescription.php' => 'The SEO Framework', |
| 40 | 'slim-seo/slim-seo.php' => 'Slim SEO', |
| 41 | 'wp-seopress-pro/seopress-pro.php' => 'SEOPress PRO', |
| 42 | 'wp-seopress/seopress.php' => 'SEOPress', |
| 43 | 'seo-key-pro/seo-key.php' => 'SEOKEY Pro', |
| 44 | 'seo-key/seo-key.php' => 'SEOKEY', |
| 45 | ); |
| 46 | |
| 47 | foreach ( $conflicting_plugins as $file => $name ) { |
| 48 | if ( in_array( $file, $active_plugins, true ) ) { |
| 49 | return $name; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | return $plugin; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Whether `jetpack_seo_conflicting_plugin` names a plugin, by the same rule the SEO dashboard uses. |
| 58 | * |
| 59 | * @since $$next-version$$ |
| 60 | * |
| 61 | * @return bool |
| 62 | */ |
| 63 | function jetpack_seo_has_conflicting_plugin() { |
| 64 | /** This filter is documented in projects/packages/seo/src/class-seo-tools.php */ |
| 65 | $plugin = apply_filters( 'jetpack_seo_conflicting_plugin', null ); |
| 66 | |
| 67 | return is_string( $plugin ) && '' !== trim( $plugin ); |
| 68 | } |