Skip to content

Commit f434d01

Browse files
feat: autoptimize conflict handling
1 parent 01e90e4 commit f434d01

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

inc/conflicts/autoptimize.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
/**
4+
* Class Optml_Autoptimize
5+
*
6+
* Handles conflicts with Autoptimize plugin.
7+
*/
8+
class Optml_Autoptimize extends Optml_Abstract_Conflict {
9+
10+
/**
11+
* Optml_Autoptimize constructor.
12+
*/
13+
public function __construct() {
14+
$this->severity = self::SEVERITY_MEDIUM;
15+
parent::__construct();
16+
}
17+
18+
/**
19+
* Set the message property
20+
*
21+
* @since 2.0.6
22+
* @access public
23+
*/
24+
public function define_message() {
25+
$this->message = sprintf(
26+
/* translators: 1 is the settings path link */
27+
__( 'Autoptimize has <strong>Lazy loading</strong> enabled. Optimole already provides its own lazy loading mechanism, which may conflict with Autoptimize\'s. To continue using Optimole\'s lazy loading feature, please disable lazy loading in %1$s.', 'optimole-wp' ),
28+
'<a href="' . admin_url( 'admin.php?page=autoptimize_imgopt' ) . '">Autoptimize → Image Optimization</a>'
29+
);
30+
}
31+
32+
/**
33+
* Determine if conflict is applicable.
34+
*
35+
* @return bool
36+
* @since 2.0.6
37+
* @access public
38+
*/
39+
public function is_conflict_valid() {
40+
if ( ! is_plugin_active( 'autoptimize/autoptimize.php' ) ) {
41+
return false;
42+
}
43+
44+
if ( ! Optml_Main::instance()->admin->settings->use_lazyload() ) {
45+
return false;
46+
}
47+
48+
$autoptimize_imgopt_settings = get_option( 'autoptimize_imgopt_settings', '' );
49+
if ( ! empty( $autoptimize_imgopt_settings ) ) {
50+
$settings = maybe_unserialize( $autoptimize_imgopt_settings );
51+
if ( is_array( $settings ) && isset( $settings['autoptimize_imgopt_checkbox_field_3'] ) ) {
52+
return (bool) $settings['autoptimize_imgopt_checkbox_field_3'];
53+
}
54+
}
55+
56+
return false;
57+
}
58+
}

inc/conflicts/conflicting_plugins.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ private function defined_plugins() {
5252
'imagerecycle' => 'imagerecycle-pdf-image-compression/wp-image-recycle.php',
5353
'imagify' => 'imagify/imagify.php',
5454
'litespeed' => 'litespeed-cache/litespeed-cache.php',
55+
'autoptimize' => 'autoptimize/autoptimize.php',
5556
// 'plugin-slug' => 'plugin-folder/plugin-file.php'
5657
];
5758

inc/main.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ public static function register_conflicts( $conflicts_to_register = [] ) {
142142
'Optml_w3_total_cache_cdn',
143143
'Optml_Smush',
144144
'Optml_Litespeed',
145+
'Optml_Autoptimize',
145146
]
146147
);
147148

0 commit comments

Comments
 (0)