Skip to content

Commit 3d7bb40

Browse files
feat: litespeed conflict
1 parent 737d709 commit 3d7bb40

File tree

5 files changed

+102
-5
lines changed

5 files changed

+102
-5
lines changed

inc/admin.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,7 @@ public function add_dashboard_page() {
11411141
* @return void
11421142
*/
11431143
public function menu_icon_style() {
1144-
$conflicts_count = $this->get_conflicts_count();
1144+
$conflicts_count = $this->get_active_notices_count();
11451145
$badge_html = '';
11461146

11471147
if ( $conflicts_count > 0 ) {
@@ -2289,13 +2289,29 @@ public function should_show_exceed_quota_warning() {
22892289
}
22902290

22912291
/**
2292-
* Get the number of active conflicts.
2292+
* Get the number of active notices (not dismissed).
22932293
*
2294-
* @return int - Number of conflicts
2294+
* @return int - Number of active notices
22952295
*/
2296-
private function get_conflicts_count() {
2296+
private function get_active_notices_count() {
22972297
$conflicting_plugins = $this->conflicting_plugins->get_conflicting_plugins();
22982298

2299+
foreach ( $conflicting_plugins as $key => $plugin ) {
2300+
$class_name = 'Optml_' . ucfirst( $key );
2301+
2302+
if ( class_exists( $class_name ) ) {
2303+
try {
2304+
$conflict_instance = new $class_name();
2305+
2306+
if ( method_exists( $conflict_instance, 'is_conflict_valid' ) && ! $conflict_instance->is_conflict_valid() ) {
2307+
unset( $conflicting_plugins[ $key ] );
2308+
}
2309+
} catch ( Exception $e ) {
2310+
unset( $conflicting_plugins[ $key ] );
2311+
}
2312+
}
2313+
}
2314+
22992315
return count( $conflicting_plugins );
23002316
}
23012317
}

inc/conflicts/conflicting_plugins.php

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

inc/conflicts/litespeed.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
/**
4+
* Class Optml_Litespeed
5+
*
6+
* Handles conflict with LiteSpeed Cache lazy loading feature.
7+
*/
8+
class Optml_Litespeed extends Optml_Abstract_Conflict {
9+
10+
/**
11+
* Optml_Litespeed_Cache 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+
__( 'LiteSpeed Cache has <strong>Lazy Loading</strong> enabled. Optimole already provides its own lazy loading mechanism, which may conflict with LiteSpeed Cache\'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=litespeed-page_optm' ) . '">LiteSpeed Cache → Page Optimization → Media Settings</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( 'litespeed-cache/litespeed-cache.php' ) ) {
41+
return false;
42+
}
43+
44+
if ( ! Optml_Main::instance()->admin->settings->use_lazyload() ) {
45+
return false;
46+
}
47+
48+
if ( ! class_exists( 'LiteSpeed\Base', false ) || ! class_exists( 'LiteSpeed\Conf', false ) ) {
49+
return false;
50+
}
51+
52+
try {
53+
$litespeed_lazy_enabled = false;
54+
55+
if ( class_exists( 'LiteSpeed\Conf', false ) && class_exists( 'LiteSpeed\Base', false ) ) {
56+
$conf_instance = \LiteSpeed\Conf::cls();
57+
$lazy_setting = $conf_instance->conf( \LiteSpeed\Base::O_MEDIA_LAZY );
58+
59+
if ( $lazy_setting ) {
60+
if ( class_exists( 'LiteSpeed\Metabox', false ) ) {
61+
$metabox = \LiteSpeed\Metabox::cls();
62+
$no_lazy_setting = $metabox->setting( 'litespeed_no_image_lazy' );
63+
64+
$litespeed_lazy_enabled = ! $no_lazy_setting;
65+
} else {
66+
$litespeed_lazy_enabled = true;
67+
}
68+
}
69+
}
70+
71+
if ( $litespeed_lazy_enabled ) {
72+
return true;
73+
}
74+
} catch ( Exception $e ) {
75+
error_log( 'Optml_Litespeed: Exception while checking LiteSpeed settings: ' . $e->getMessage() );
76+
}
77+
78+
return false;
79+
}
80+
}

inc/conflicts/smush.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ public function is_conflict_valid() {
4848
if ( class_exists( '\Smush\Core\Settings' ) ) {
4949
$smush_settings = \Smush\Core\Settings::get_instance();
5050
if ( method_exists( $smush_settings, 'get' ) ) {
51-
error_log( print_r( $smush_settings->get( 'lazy_load' ), true ) );
5251
return (bool) $smush_settings->get( 'lazy_load' );
5352
}
5453
}

inc/main.php

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

0 commit comments

Comments
 (0)