| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Class Optml_jetpack_photon_compatibility. |
| 5 |
* |
| 6 |
* @reason Register Jetpack as a conflicting plugin when its image Site Accelerator is active. |
| 7 |
*/ |
| 8 |
class Optml_jetpack_photon_compatibility extends Optml_compatibility { |
| 9 |
/** |
| 10 |
* Jetpack conflict key. |
| 11 |
*/ |
| 12 |
const CONFLICT_KEY = 'jetpack_Photon'; |
| 13 |
|
| 14 |
/** |
| 15 |
* Jetpack plugin file. |
| 16 |
*/ |
| 17 |
const PLUGIN_FILE = 'jetpack/jetpack.php'; |
| 18 |
|
| 19 |
/** |
| 20 |
* Check whether Jetpack's image Site Accelerator is active. |
| 21 |
* |
| 22 |
* @return bool Whether to load the compatibility. |
| 23 |
*/ |
| 24 |
public function should_load() { |
| 25 |
return class_exists( '\Jetpack', false ) && \Jetpack::is_module_active( 'photon' ); |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Register the Jetpack conflict integration. |
| 30 |
* |
| 31 |
* @return void |
| 32 |
*/ |
| 33 |
public function register() { |
| 34 |
add_filter( 'optml_conflicting_defined_plugins', [ $this, 'add_conflicting_plugin' ] ); |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Add Jetpack to the conflicting plugin definitions. |
| 39 |
* |
| 40 |
* @param array<string, string> $plugins Conflicting plugin definitions. |
| 41 |
* @return array<string, string> |
| 42 |
*/ |
| 43 |
public function add_conflicting_plugin( $plugins ) { |
| 44 |
$plugins[ self::CONFLICT_KEY ] = self::PLUGIN_FILE; |
| 45 |
|
| 46 |
return $plugins; |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Register before the generic conflict notice is evaluated. |
| 51 |
* |
| 52 |
* @return bool |
| 53 |
*/ |
| 54 |
public function should_load_early() { |
| 55 |
return true; |
| 56 |
} |
| 57 |
} |
| 58 |
|