diff --git a/inc/class-cachify-hdd.php b/inc/class-cachify-hdd.php index 103234e..a82c90e 100644 --- a/inc/class-cachify-hdd.php +++ b/inc/class-cachify-hdd.php @@ -33,6 +33,11 @@ public static function is_available() { * @since 2.4.0 */ public static function is_gzip_enabled() { + if ( ! function_exists( 'gzencode' ) ) { + // GZip is not available on the system. + return false; + } + /** * Filter that allows to enable/disable gzip file creation * diff --git a/tests/test-cachify-hdd.php b/tests/test-cachify-hdd.php index e5b7ab2..b573020 100644 --- a/tests/test-cachify-hdd.php +++ b/tests/test-cachify-hdd.php @@ -33,7 +33,16 @@ public function test_stringify_method() { * Test GZip availability. */ public function test_is_gzip_enabled() { - self::assertTrue( Cachify_HDD::is_gzip_enabled(), 'GZip should be enabled by default' ); + if ( ! function_exists( 'gzencode' ) ) { + self::assertFalse( Cachify_HDD::is_gzip_enabled(), 'GZip should be disabled, if not available' ); + + // Define gzencode function for testing the hook. + function gzencode( $data, $level = -1 ) { + return $data; + } + } + + self::assertTrue( Cachify_HDD::is_gzip_enabled(), 'GZip should be enabled if available' ); $capture = null; add_filter(