| 1 |
<?php |
| 2 |
|
| 3 |
namespace ImageOptimization\Modules\Core\Components; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; // Exit if accessed directly. |
| 7 |
} |
| 8 |
|
| 9 |
class Conflicts { |
| 10 |
private array $conflicting_plugins; |
| 11 |
|
| 12 |
private const CONFLICTING_PLUGINS = [ |
| 13 |
'imagify/imagify.php' => 'Imagify', |
| 14 |
'optimole-wp/optimole-wp.php' => 'Image optimization service by Optimole', |
| 15 |
'ewww-image-optimizer/ewww-image-optimizer.php' => 'EWWW Image Optimizer', |
| 16 |
'ewww-image-optimizer-cloud/ewww-image-optimizer-cloud.php' => 'EWWW Image Optimizer Cloud', |
| 17 |
'kraken-image-optimizer/kraken.php' => 'Kraken Image Optimizer', |
| 18 |
'shortpixel-image-optimiser/wp-shortpixel.php' => 'ShortPixel Image Optimizer', |
| 19 |
'wp-smushit/wp-smush.php' => 'Smush', |
| 20 |
'wp-smush-pro/wp-smush.php' => 'Smush PRO', |
| 21 |
'tiny-compress-images/tiny-compress-images.php' => 'TinyPNG - JPEG, PNG & WebP image compression', |
| 22 |
]; |
| 23 |
|
| 24 |
public function render_notice(): void { |
| 25 |
$conflicting_plugins_names = $this->conflicting_plugins; |
| 26 |
|
| 27 |
?> |
| 28 |
<div class="notice notice-warning image-optimizer__notice image-optimizer__notice--warning"> |
| 29 |
<p> |
| 30 |
<b> |
| 31 |
<?php esc_html_e( |
| 32 |
'Image optimizer has detected multiple active image optimization plugins.', |
| 33 |
'image-optimization' |
| 34 |
); ?> |
| 35 |
</b> |
| 36 |
|
| 37 |
<span> |
| 38 |
<?php esc_html_e( |
| 39 |
'Having more than one may result in unexpected results.', |
| 40 |
'image-optimization' |
| 41 |
); ?> |
| 42 |
</span> |
| 43 |
</p> |
| 44 |
|
| 45 |
<form action="<?php echo esc_url( admin_url( 'plugins.php' ) ); ?>" method="post" style="margin:0.5em 0;padding:2px"> |
| 46 |
<span style="margin-right: 8px;"><?php echo esc_html( join( ', ', $conflicting_plugins_names ) ); ?></span> |
| 47 |
|
| 48 |
<input type="hidden" name="action" value="deactivate-selected"> |
| 49 |
|
| 50 |
<?php foreach ( array_keys( $this->conflicting_plugins ) as $plugin ) { ?> |
| 51 |
<input type="hidden" name="checked[]" value="<?php echo esc_attr( $plugin ); ?>"> |
| 52 |
<?php } ?> |
| 53 |
|
| 54 |
<input type="hidden" name="_wpnonce" value="<?php echo esc_attr( wp_create_nonce( 'bulk-plugins' ) ); ?>"> |
| 55 |
|
| 56 |
<input type="submit" |
| 57 |
style="border:none;background-color:transparent;text-decoration:underline;cursor:pointer;font-size:13px;color:#135e96;" |
| 58 |
value="<?php esc_html_e( 'Deactivate All', 'image-optimization' ); ?>"> |
| 59 |
</form> |
| 60 |
</div> |
| 61 |
<?php |
| 62 |
} |
| 63 |
|
| 64 |
public function get_conflicting_plugins(): array { |
| 65 |
$plugins = get_option( 'active_plugins' ); |
| 66 |
$conflicting_plugins_file_names = array_keys( self::CONFLICTING_PLUGINS ); |
| 67 |
$output = []; |
| 68 |
|
| 69 |
foreach ( $plugins as $plugin_file_name ) { |
| 70 |
if ( in_array( $plugin_file_name, $conflicting_plugins_file_names, true ) ) { |
| 71 |
$output[ $plugin_file_name ] = self::CONFLICTING_PLUGINS[ $plugin_file_name ]; |
| 72 |
} |
| 73 |
} |
| 74 |
|
| 75 |
return $output; |
| 76 |
} |
| 77 |
|
| 78 |
public function __construct() { |
| 79 |
$this->conflicting_plugins = $this->get_conflicting_plugins(); |
| 80 |
|
| 81 |
if ( ! empty( $this->conflicting_plugins ) ) { |
| 82 |
add_action( 'admin_notices', [ $this, 'render_notice' ] ); |
| 83 |
} |
| 84 |
} |
| 85 |
} |
| 86 |
|