PluginProbe
Image Optimization – Compress Images and Convert to WebP or AVIF / 1.1.0
Image Optimization – Compress Images and Convert to WebP or AVIF v1.1.0
1.7.6 1.7.5 1.7.4 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 All 32 releases
image-optimization / modules / core / components / conflicts.php

conflicts.php in Image Optimization – Compress Images and Convert to WebP or AVIF 1.1.0, at modules/core/components/conflicts.php

86 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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