Generic_Plugin_AdminCompatibility.php
4.78 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<?php
namespace W3TC;
/**
* class AdminCompatibility
*/
class Generic_Plugin_AdminCompatibility {
/**
* Config
*/
private $_config = null;
function __construct() {
$this->_config = Dispatcher::config();
}
/**
* Runs plugin
*/
function run() {
add_filter( 'pre_update_option_active_plugins', array( $this, 'pre_update_option_active_plugins' ) );
add_filter( 'pre_update_site_option_active_sitewide_plugins', array( $this, 'pre_update_option_active_plugins' ) );
if ( false === get_transient( 'w3tc.verify_plugins' ) ) {
add_action( 'admin_notices', array( $this, 'verify' ) );
add_action( 'network_admin_notices', array( $this, 'verify' ) );
}
$this->_backwards_import();
}
/**
* Active plugins pre update option filter
*
* @param string $new_value
* @return string
*/
function pre_update_option_active_plugins( $new_value ) {
delete_transient( 'w3tc.verify_plugins' );
return $new_value;
}
/**
* Check that activated plugins are not incompatible with the plugin
*/
function verify() {
if ( is_network_admin() ) {
$active_plugins = (array) get_site_option( 'active_sitewide_plugins', array() );
$active_plugins = array_keys( $active_plugins );
} else
$active_plugins = (array) get_option( 'active_plugins' );
$incomp_plugins = $this->_get_incompatible_plugins();
$message = '';
$matches = array_intersect( $active_plugins, $incomp_plugins );
if ( $matches ) {
$message = $this->_custom_message( $matches );
}
if ( $message )
Util_Ui::error_box( $message );
else
set_transient( 'w3tc.verify_plugins', true, 7*24*3600 );
}
/**
* List of incomatible plugins
*
* @return array
*/
private function _get_incompatible_plugins() {
return array(
'force-gzip/force-gzip.php'
, 'wp-http-compression/wp-http-compression.php'
, 'gzippy/gzippy.php'
, 'wordpress-gzip-compression/ezgz.php'
, 'wpcompressor/wpcompressor.php'
, 'gzip-pages/filosofo-gzip-compression.php'
, 'admin-flush-w3tc-cache/admin_flush_w3tc.php'
, 'hyper-cache/plugin.php'
, 'aio-cache/aio-cache.php'
, 'lite-cache/plugin.php'
, 'quick-cache/quick-cache.php'
, 'wp-super-cache/wp-cache.php'
, 'hyper-cache-extended/plugin.php'
, 'batcache/batcache.php'
, 'cachify/cachify.php'
, 'flexicache/wp-plugin.php'
);
}
/**
* Build incompatible plugins message
*
* @param unknown $plugins
* @return string
*/
private function _custom_message( $plugins ) {
$message = __( 'The following plugins are not compatible with W3 Total Cache and will cause unintended results:', 'w3-total-cache' );
$plugin_names = array();
foreach ( $plugins as $plugin ) {
$data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
$temp = "<li><div>{$data['Name']}</div>";
if ( is_network_admin() && current_user_can( 'manage_network_plugins' ) )
$temp .= ' <a class="button-secondary" href="' . network_admin_url( wp_nonce_url( 'plugins.php?action=deactivate&plugin=' . $plugin . '&plugin_status=all&paged=1&s=', 'deactivate-plugin_' . $plugin ) ) . '" title="' . esc_attr__( 'Deactivate this plugin', 'w3-total-cache' ) . '">' . __( 'Network Deactivate' ) . '</a>';
else
$temp .= ' <a class="button-secondary" href="' . admin_url( wp_nonce_url( 'plugins.php?action=deactivate&plugin=' . $plugin . '&plugin_status=all&paged=1&s=', 'deactivate-plugin_' . $plugin ) ) . '" title="' . esc_attr__( 'Deactivate this plugin' ) . '">' . __( 'Deactivate', 'w3-total-cache' ) . '</a>';
$temp .= "</li>";
$plugin_names[] = $temp;
}
return sprintf( "<p>$message</p><ul class=\"w3tc-incomp-plugins\">%s</ul>", implode( '', $plugin_names ) );
}
/**
* Handle importing changed configuration from older versions
*/
private function _backwards_import() {
if ( $this->_config->get_string( 'cdn.engine' ) == 'netdna' && $this->_config->get_string( 'cdn.netdna.authorization_key' ) == '' ) {
$alias = $this->_config->get_string( 'cdn.netdna.alias' );
$consumerkey = $this->_config->get_string( 'cdn.netdna.consumerkey' );
$consumersecret = $this->_config->get_string( 'cdn.netdna.consumersecret' );
if ( $alias && $consumerkey && $consumersecret ) {
$this->_config->set( 'cdn.maxcdn.authorization_key', "$alias+$consumerkey+$consumersecret" );
$this->_config->set( 'cdn.netdna.authorization_key', "$alias+$consumerkey+$consumersecret" );
$this->_config->set( 'cdn.engine', 'maxcdn' );
$this->_config->set( 'cdn.maxcdn.zone_id', $this->_config->get_integer( 'cdn.netdna.zone_id', 0 ) );
$this->_config->set( 'cdn.maxcdn.domain', $this->_config->get_array( 'cdn.netdna.domain' ) );
$this->_config->set( 'cdn.maxcdn.ssl', $this->_config->get_string( 'cdn.netdna.ssl' ) );
try{
$this->_config->save();
$this->_config->refresh_cache();
} catch ( \Exception $ex ) {}
}
}
}
}