pluginkollektiv / cachify

Smart but efficient cache solution for WordPress. Use DB, HDD, APC or Memcached for storing your blog pages. Make WordPress faster!
https://wordpress.org/plugins/cachify/
GNU General Public License v2.0
99 stars 30 forks source link

fix: test if gzip extension is available #308

Closed stklcode closed 1 month ago

stklcode commented 1 month ago

If zlib PHP extension is not loaded and there is no substitute in place, gzencode() does not exist and generation of compressed files will fail.

Add a simple function_exists() test to prevent this.

stklcode commented 1 month ago

It might seem little far fetched, but providing the function_exists result as default filter parameter allows to implement some logic to define this function on demand, e.g.

add_filter( 'cachify_create_gzip_files', function ( $available ) {
  if ( ! $available ) {
    // Define or load anything that implements gzencode.
    function gzencode( $data, $level ) {
      return $data;
    }
  }

  return true;
} );
stklcode commented 1 month ago

In the current suggestion: Yes, you can still override the false with a filter, if gzencode is not available.

One might polyfill another compression routine on demand in the filter hook (see example above). Seems more of a theoretical possibility though.

But I'd be fine changing the logic again, so the filter is completely omitted if gzencode is not available. No hard preference for either way.

stklcode commented 1 month ago

I changed the logic, so if gzencode is not available we disable the feature and do not execute the filter.

This is trivial to change again, but >99.9% should not need such tricky configurations.

sonarcloud[bot] commented 1 month ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud