Skip to content

Commit 4f031a3

Browse files
feat: litespeed conflict
1 parent ecd212f commit 4f031a3

5 files changed

Lines changed: 102 additions & 5 deletions

File tree

inc/admin.php

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

11511151
if ( $conflicts_count > 0 ) {
@@ -2303,13 +2303,29 @@ public function should_show_exceed_quota_warning() {
23032303
}
23042304

23052305
/**
2306-
* Get the number of active conflicts.
2306+
* Get the number of active notices (not dismissed).
23072307
*
2308-
* @return int - Number of conflicts
2308+
* @return int - Number of active notices
23092309
*/
2310-
private function get_conflicts_count() {
2310+
private function get_active_notices_count() {
23112311
$conflicting_plugins = $this->conflicting_plugins->get_conflicting_plugins();
23122312

2313+
foreach ( $conflicting_plugins as $key => $plugin ) {
2314+
$class_name = 'Optml_' . ucfirst( $key );
2315+
2316+
if ( class_exists( $class_name ) ) {
2317+
try {
2318+
$conflict_instance = new $class_name();
2319+
2320+
if ( method_exists( $conflict_instance, 'is_conflict_valid' ) && ! $conflict_instance->is_conflict_valid() ) {
2321+
unset( $conflicting_plugins[ $key ] );
2322+
}
2323+
} catch ( Exception $e ) {
2324+
unset( $conflicting_plugins[ $key ] );
2325+
}
2326+
}
2327+
}
2328+
23132329
return count( $conflicting_plugins );
23142330
}
23152331
}

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)