ConflictingPlugins.php
2.82 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
<?php
namespace AIOSEO\Plugin\Common\Admin;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use AIOSEO\Plugin\Common\Models;
/**
* Checks for conflicting plugins.
*
* @since 4.0.0
*/
class ConflictingPlugins {
/**
* Class Constructor.
*
* @since 4.0.0
*/
public function __construct() {
// We don't want to trigger our notices when not in the admin.
if ( ! is_admin() ) {
return;
}
add_action( 'init', [ $this, 'init' ] );
}
/**
* Initialize the conflicting plugins check.
*
* @since 4.0.0
*
* @return void
*/
public function init() {
// Only do this for users who can install/deactivate plugins.
if ( ! current_user_can( 'install_plugins' ) ) {
return;
}
$conflictingPlugins = $this->getAllConflictingPlugins();
$notification = Models\Notification::getNotificationByName( 'conflicting-plugins' );
if ( empty( $conflictingPlugins ) ) {
if ( ! $notification->exists() ) {
return;
}
Models\Notification::deleteNotificationByName( 'conflicting-plugins' );
return;
}
aioseo()->notices->conflictingPlugins( $conflictingPlugins );
}
/**
* Get a list of all conflicting plugins.
*
* @since 4.0.0
*
* @return array An array of conflicting plugins.
*/
protected function getAllConflictingPlugins() {
$conflictingSeoPlugins = $this->getConflictingPlugins( 'seo' );
$conflictingSitemapPlugins = [];
if (
aioseo()->options->sitemap->general->enable ||
aioseo()->options->sitemap->rss->enable
) {
$conflictingSitemapPlugins = $this->getConflictingPlugins( 'sitemap' );
}
return array_merge( $conflictingSeoPlugins, $conflictingSitemapPlugins );
}
/**
* Get a list of conflicting plugins for AIOSEO.
*
* @since 4.0.0
*
* @param string $type A type to look for.
* @return array An array of conflicting plugins.
*/
public function getConflictingPlugins( $type ) {
$activePlugins = get_option( 'active_plugins' );
$conflictingPlugins = [];
switch ( $type ) {
case 'seo':
$conflictingPlugins = [
'Yoast SEO' => 'wordpress-seo/wp-seo.php',
'Yoast SEO Premium' => 'wordpress-seo-premium/wp-seo-premium.php',
'Rank Math SEO' => 'seo-by-rank-math/rank-math.php',
'SEOPress' => 'wp-seopress/seopress.php',
'The SEO Framework' => 'autodescription/autodescription.php',
];
break;
case 'sitemap':
$conflictingPlugins = [
'Google XML Sitemaps' => 'google-sitemap-generator/sitemap.php',
'XML Sitemap & Google News' => 'xml-sitemap-feed/xml-sitemap.php',
'Google XML Sitemap Generator' => 'www-xml-sitemap-generator-org/www-xml-sitemap-generator-org.php',
'Sitemap by BestWebSoft' => 'google-sitemap-plugin/google-sitemap-plugin.php',
];
break;
}
return array_intersect( $conflictingPlugins, $activePlugins );
}
}