Skip to content

Commit 390a9f6

Browse files
feat:perfmatters conflict handling
1 parent f434d01 commit 390a9f6

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

inc/conflicts/conflicting_plugins.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ private function defined_plugins() {
5353
'imagify' => 'imagify/imagify.php',
5454
'litespeed' => 'litespeed-cache/litespeed-cache.php',
5555
'autoptimize' => 'autoptimize/autoptimize.php',
56+
'perfmatters' => 'perfmatters/perfmatters.php',
5657
// 'plugin-slug' => 'plugin-folder/plugin-file.php'
5758
];
5859

inc/conflicts/perfmatters.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_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 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+
__( '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' ),
28+
'<a href="' . admin_url( 'admin.php?page=perfmatters&tab=lazyload#lazyload' ) . '">Perfmatters → Lazy Load</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( 'perfmatters/perfmatters.php' ) ) {
41+
return false;
42+
}
43+
44+
if ( ! Optml_Main::instance()->admin->settings->use_lazyload() ) {
45+
return false;
46+
}
47+
48+
$perfmatters_options = get_option( 'perfmatters_options', [] );
49+
if ( ! empty( $perfmatters_options ) && isset( $perfmatters_options['lazyload'] ) ) {
50+
$lazyload_settings = $perfmatters_options['lazyload'];
51+
if ( is_array( $lazyload_settings ) && isset( $lazyload_settings['lazy_loading'] ) ) {
52+
return (bool) $lazyload_settings['lazy_loading'];
53+
}
54+
}
55+
56+
return false;
57+
}
58+
}

inc/main.php

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

0 commit comments

Comments
 (0)