diff --git a/inc/compatibilities/jetpack_photon_compatibility.php b/inc/compatibilities/jetpack_photon_compatibility.php new file mode 100644 index 00000000..1dfefff3 --- /dev/null +++ b/inc/compatibilities/jetpack_photon_compatibility.php @@ -0,0 +1,57 @@ + $plugins Conflicting plugin definitions. + * @return array + */ + public function add_conflicting_plugin( $plugins ) { + $plugins[ self::CONFLICT_KEY ] = self::PLUGIN_FILE; + + return $plugins; + } + + /** + * Register before the generic conflict notice is evaluated. + * + * @return bool + */ + public function should_load_early() { + return true; + } +} diff --git a/inc/conflicts/conflicting_plugins.php b/inc/conflicts/conflicting_plugins.php index 721a3a13..4b13a755 100644 --- a/inc/conflicts/conflicting_plugins.php +++ b/inc/conflicts/conflicting_plugins.php @@ -1,4 +1,5 @@ 'litespeed-cache/litespeed-cache.php', 'autoptimize' => 'autoptimize/autoptimize.php', 'perfmatters' => 'perfmatters/perfmatters.php', - 'jetpack_Photon' => 'jetpack/jetpack.php', // 'plugin-slug' => 'plugin-folder/plugin-file.php' ]; @@ -73,6 +73,7 @@ private function get_active_plugins() { $conflicting_plugins = $this->defined_plugins(); $conflicting_plugins = array_filter( $conflicting_plugins, 'is_plugin_active' ); + return apply_filters( 'optml_conflicting_active_plugins', $conflicting_plugins ); } diff --git a/inc/conflicts/jetpack_photon.php b/inc/conflicts/jetpack_photon.php index 533b81e2..b545c986 100644 --- a/inc/conflicts/jetpack_photon.php +++ b/inc/conflicts/jetpack_photon.php @@ -34,14 +34,8 @@ public function define_message() { * @access public */ public function is_conflict_valid() { + $compatibility = new Optml_jetpack_photon_compatibility(); - if ( ! is_plugin_active( 'jetpack/jetpack.php' ) ) { - return false; - } - if ( ! class_exists( 'Jetpack', false ) ) { - return false; - } - - return Jetpack::is_module_active( 'photon' ); + return $compatibility->should_load(); } } diff --git a/inc/manager.php b/inc/manager.php index ffb713c7..07020fde 100644 --- a/inc/manager.php +++ b/inc/manager.php @@ -104,6 +104,7 @@ final class Optml_Manager { 'wpsp', 'jetengine', 'jetpack', + 'jetpack_photon_compatibility', 'wp_rocket', 'wp_super_cache', 'breeze', diff --git a/tests/test-jetpack-conflicts.php b/tests/test-jetpack-conflicts.php new file mode 100644 index 00000000..fb0bbecf --- /dev/null +++ b/tests/test-jetpack-conflicts.php @@ -0,0 +1,101 @@ +active_plugins = get_option( 'active_plugins', [] ); + $this->compatibility = new Optml_jetpack_photon_compatibility(); + update_option( + 'active_plugins', + array_merge( $this->active_plugins, [ 'jetpack/jetpack.php' ] ) + ); + } + + /** + * Restore active plugins after each test. + */ + public function tear_down() { + remove_filter( 'optml_conflicting_defined_plugins', [ $this->compatibility, 'add_conflicting_plugin' ] ); + Jetpack::$photon_active = false; + update_option( 'active_plugins', $this->active_plugins ); + + parent::tear_down(); + } + + /** + * Jetpack without Photon should not be a generic conflict. + */ + public function test_jetpack_without_photon_is_not_a_generic_conflict() { + $conflicts = new Optml_Conflicting_Plugins(); + $conflict = new Optml_Jetpack_Photon(); + + $this->assertFalse( $this->compatibility->should_load() ); + $this->assertFalse( $conflict->is_conflict_valid() ); + $this->assertNotContains( 'jetpack/jetpack.php', $conflicts->get_conflicting_plugins( true ) ); + } + + /** + * Jetpack with Photon should remain a generic conflict. + */ + public function test_jetpack_with_photon_is_a_generic_conflict() { + Jetpack::$photon_active = true; + $this->compatibility->register(); + $conflicts = new Optml_Conflicting_Plugins(); + $conflict = new Optml_Jetpack_Photon(); + + $this->assertTrue( $this->compatibility->should_load() ); + $this->assertTrue( $conflict->is_conflict_valid() ); + $this->assertContains( 'jetpack/jetpack.php', $conflicts->get_conflicting_plugins( true ) ); + } +} + +if ( ! class_exists( 'Jetpack', false ) ) { + /** + * Minimal Jetpack test double. + */ + class Jetpack { + /** + * Whether Photon is active. + * + * @var bool + */ + public static $photon_active = false; + + /** + * Check whether a module is active. + * + * @param string $module Module slug. + * @return bool + */ + public static function is_module_active( $module ) { + return 'photon' === $module && self::$photon_active; + } + } +}