Skip to content

Commit 8bfc444

Browse files
authored
Merge pull request #964 from Codeinwp/feat/compability_notices
feat: added compatibility notices for lazy loading
2 parents 387be28 + eafe7c7 commit 8bfc444

File tree

11 files changed

+347
-74
lines changed

11 files changed

+347
-74
lines changed

assets/src/dashboard/parts/connected/conflicts/ConflictItem.js

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,36 @@ const ConflictItem = ({ conflict }) => {
3131
);
3232
};
3333

34+
const getBorderColor = () => {
35+
if ( 'high' === conflict.severity ) {
36+
return '#E77777';
37+
} else if ( 'medium' === conflict.severity ) {
38+
return '#577BF9';
39+
}
40+
return '#5F9D61';
41+
};
42+
43+
const noticeStyles = {
44+
border: '1px solid #c3c4c7',
45+
borderLeftWidth: '4px',
46+
borderLeftColor: getBorderColor(),
47+
margin: '5px 0 15px',
48+
padding: '12px',
49+
paddingRight: '38px',
50+
position: 'relative'
51+
};
52+
53+
const messageStyles = {
54+
margin: '0',
55+
padding: '2px',
56+
lineHeight: '1.5',
57+
fontSize: '15px'
58+
};
59+
3460
return (
35-
<div
36-
className={ classnames(
37-
'flex gap-2 text-white rounded relative px-6 py-5 mb-5',
38-
{
39-
'bg-danger': 'high' === conflict.severity,
40-
'bg-info': 'medium' === conflict.severity,
41-
'bg-success': 'high' !== conflict.severity && 'medium' !== conflict.severity
42-
}
43-
) }
44-
>
61+
<div style={ noticeStyles }>
4562
<p
46-
className="m-0 text-white"
63+
style={ messageStyles }
4764
dangerouslySetInnerHTML={ { __html: conflict.message } }
4865
/>
4966

@@ -52,12 +69,17 @@ const ConflictItem = ({ conflict }) => {
5269
label={ optimoleDashboardApp.strings.conflicts.conflict_close }
5370
disabled={ isLoading }
5471
className={ classnames(
55-
'text-white hover:text-white',
72+
'text-black hover:text-black',
5673
{
5774
'animate-spin': isLoading
5875
}
5976
) }
6077
onClick={ dismiss }
78+
style={{
79+
position: 'absolute',
80+
top: '8px',
81+
right: '8px'
82+
}}
6183
/>
6284
</div>
6385
);

inc/admin.php

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,29 @@ public function add_dashboard_page() {
11411141
* @return void
11421142
*/
11431143
public function menu_icon_style() {
1144-
echo '<style>#toplevel_page_optimole img{ max-width:22px;padding-top:6px!important;opacity:.9!important;} #toplevel_page_optimole li.wp-first-item{ display:none }</style>';
1144+
$conflicts_count = $this->get_active_notices_count();
1145+
$badge_html = '';
1146+
1147+
if ( $conflicts_count > 0 ) {
1148+
$badge_html = sprintf(
1149+
'<style>
1150+
#toplevel_page_optimole .wp-menu-name::after {
1151+
content: "%d";
1152+
background: #d63638;
1153+
border-radius: 10px;
1154+
padding: 1.5px 1px;
1155+
font-size: 11px;
1156+
margin-left: 5px;
1157+
min-width: 18px;
1158+
display: inline-block;
1159+
text-align: center;
1160+
}
1161+
</style>',
1162+
$conflicts_count
1163+
);
1164+
}
1165+
1166+
echo '<style>#toplevel_page_optimole img{ max-width:22px;padding-top:6px!important;opacity:.9!important;} #toplevel_page_optimole li.wp-first-item{ display:none }</style>' . $badge_html;
11451167
}
11461168

11471169
/**
@@ -2265,4 +2287,36 @@ public function should_show_exceed_quota_warning() {
22652287

22662288
return true;
22672289
}
2290+
2291+
/**
2292+
* Get the number of active notices (not dismissed).
2293+
*
2294+
* @return int - Number of active notices
2295+
*/
2296+
private function get_active_notices_count() {
2297+
$conflicting_plugins = $this->conflicting_plugins->get_conflicting_plugins();
2298+
$conflicts_count = 0;
2299+
2300+
foreach ( $conflicting_plugins as $key => $plugin ) {
2301+
$key = str_replace( 'wp-', '', $key );
2302+
$class_name = 'Optml_' . ucfirst( $key );
2303+
2304+
if ( ! class_exists( $class_name ) ) {
2305+
continue;
2306+
}
2307+
$conflict_instance = new $class_name();
2308+
2309+
if ( ! is_a( $conflict_instance, 'Optml_Abstract_Conflict' ) ) {
2310+
continue;
2311+
}
2312+
2313+
if ( $conflict_instance->is_conflict_valid() ) {
2314+
++$conflicts_count;
2315+
}
2316+
}
2317+
2318+
$dismissed_notices = get_option( 'optml_dismissed_conflicts', [] );
2319+
2320+
return $conflicts_count - count( $dismissed_notices );
2321+
}
22682322
}

inc/conflicts/autoptimize.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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 4.1.0
22+
* @access public
23+
* @return void
24+
*/
25+
public function define_message() {
26+
$this->message = sprintf(
27+
/* translators: 1 is the settings path link */
28+
__( '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' ),
29+
'<a href="' . admin_url( 'admin.php?page=autoptimize_imgopt' ) . '">Autoptimize → Image Optimization</a>'
30+
);
31+
}
32+
33+
/**
34+
* Determine if conflict is applicable.
35+
*
36+
* @return bool
37+
* @since 2.0.6
38+
* @access public
39+
*/
40+
public function is_conflict_valid() {
41+
if ( ! is_plugin_active( 'autoptimize/autoptimize.php' ) ) {
42+
return false;
43+
}
44+
45+
if ( ! Optml_Main::instance()->admin->settings->use_lazyload() ) {
46+
return false;
47+
}
48+
49+
$autoptimize_imgopt_settings = get_option( 'autoptimize_imgopt_settings', '' );
50+
if ( ! empty( $autoptimize_imgopt_settings ) ) {
51+
$settings = maybe_unserialize( $autoptimize_imgopt_settings );
52+
if ( is_array( $settings ) && isset( $settings['autoptimize_imgopt_checkbox_field_3'] ) ) {
53+
return (bool) $settings['autoptimize_imgopt_checkbox_field_3'];
54+
}
55+
}
56+
57+
return false;
58+
}
59+
}

inc/conflicts/conflicting_plugins.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ 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',
55+
'autoptimize' => 'autoptimize/autoptimize.php',
56+
'perfmatters' => 'perfmatters/perfmatters.php',
57+
'jetpack_Photon' => 'jetpack/jetpack.php',
5458
// 'plugin-slug' => 'plugin-folder/plugin-file.php'
5559
];
5660

inc/conflicts/jetpack_lazyload.php

Lines changed: 0 additions & 53 deletions
This file was deleted.

inc/conflicts/litespeed.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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 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 4.1.0
22+
* @access public
23+
* @return void
24+
*/
25+
public function define_message() {
26+
$this->message = sprintf(
27+
/* translators: 1 is the settings path link */
28+
__( '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' ),
29+
'<a href="' . admin_url( 'admin.php?page=litespeed-page_optm#settings_media' ) . '">LiteSpeed Cache → Page Optimization → Media Settings</a>'
30+
);
31+
}
32+
33+
/**
34+
* Determine if conflict is applicable.
35+
*
36+
* @return bool
37+
* @since 2.0.6
38+
* @access public
39+
*/
40+
public function is_conflict_valid() {
41+
if ( ! is_plugin_active( 'litespeed-cache/litespeed-cache.php' ) ) {
42+
return false;
43+
}
44+
45+
if ( ! Optml_Main::instance()->admin->settings->use_lazyload() ) {
46+
return false;
47+
}
48+
49+
if ( ! class_exists( 'LiteSpeed\Conf', false ) || ! class_exists( 'LiteSpeed\Base', false ) ) {
50+
return false;
51+
}
52+
53+
$conf_instance = \LiteSpeed\Conf::cls();
54+
$lazy_setting = $conf_instance->conf( \LiteSpeed\Base::O_MEDIA_LAZY );
55+
56+
if ( ! $lazy_setting ) {
57+
return false;
58+
}
59+
60+
if ( class_exists( 'LiteSpeed\Metabox', false ) ) {
61+
$metabox = \LiteSpeed\Metabox::cls();
62+
$no_lazy_setting = $metabox->setting( 'litespeed_no_image_lazy' );
63+
64+
return ! $no_lazy_setting;
65+
}
66+
67+
return false;
68+
}
69+
}

inc/conflicts/perfmatters.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
/**
4+
* Class Optml_Perfmatters
5+
*
6+
* Handles conflicts with Perfmatters plugin.
7+
*/
8+
class Optml_Perfmatters extends Optml_Abstract_Conflict {
9+
10+
/**
11+
* Optml_Perfmatters 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 4.1.0
22+
* @access public
23+
* @return void
24+
*/
25+
public function define_message() {
26+
$this->message = sprintf(
27+
/* translators: 1 is the settings path link */
28+
__( 'Perfmatters has <strong>Lazy loading</strong> enabled. Optimole already provides its own lazy loading mechanism, which may conflict with Perfmatters\'. To continue using Optimole\'s lazy loading feature, please disable lazy loading in %1$s.', 'optimole-wp' ),
29+
'<a href="' . admin_url( 'admin.php?page=perfmatters&tab=lazyload#lazyload' ) . '">Perfmatters → Lazy Load</a>'
30+
);
31+
}
32+
33+
/**
34+
* Determine if conflict is applicable.
35+
*
36+
* @return bool
37+
* @since 2.0.6
38+
* @access public
39+
*/
40+
public function is_conflict_valid() {
41+
if ( ! is_plugin_active( 'perfmatters/perfmatters.php' ) ) {
42+
return false;
43+
}
44+
45+
if ( ! Optml_Main::instance()->admin->settings->use_lazyload() ) {
46+
return false;
47+
}
48+
49+
$perfmatters_options = get_option( 'perfmatters_options', [] );
50+
if ( ! empty( $perfmatters_options ) && isset( $perfmatters_options['lazyload'] ) ) {
51+
$lazyload_settings = $perfmatters_options['lazyload'];
52+
if ( is_array( $lazyload_settings ) && isset( $lazyload_settings['lazy_loading'] ) ) {
53+
return (bool) $lazyload_settings['lazy_loading'];
54+
}
55+
}
56+
57+
return false;
58+
}
59+
}

0 commit comments

Comments
 (0)