From ad4f72344f1dc8d017557c8b2abffb94e54d274f Mon Sep 17 00:00:00 2001 From: donnchawp Date: Wed, 17 Jul 2024 16:56:36 +0000 Subject: [PATCH] Super cache: check that is_utf8_charset exists (#38383) * Check for is_utf8_charset, WP 6.6 bug * changelog Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/9978142104 Upstream-Ref: Automattic/jetpack@b4e1648cdbe3fcd4498dede1f0ebd2ffc6520948 --- CHANGELOG.md | 3 +++ wp-cache-phase2.php | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e91c8284..14bf9422 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ This is an alpha version! The changes listed here are not final. ### Removed - General: update WordPress version requirements to WordPress 6.5. +### Fixed +- WP Super Cache: fixed problem with is_utf8_charset missing in WP 6.6 + ## [1.12.3] - 2024-07-10 ### Fixed - Don't delete the log viewer when doing garbage collection [#38276] diff --git a/wp-cache-phase2.php b/wp-cache-phase2.php index 989072f0..392d25bf 100644 --- a/wp-cache-phase2.php +++ b/wp-cache-phase2.php @@ -265,7 +265,7 @@ function wp_cache_serve_cache_file() { } else { header( 'Cache-Control: max-age=3, must-revalidate' ); } - $size = function_exists( 'mb_strlen' ) ? mb_strlen( $cachefiledata, '8bit' ) : strlen( $cachefiledata ); + $size = ( function_exists( 'mb_strlen' ) && function_exists( 'is_utf8_charset' ) ) ? mb_strlen( $cachefiledata, '8bit' ) : strlen( $cachefiledata ); if ( $wp_cache_gzip_encoding ) { if ( isset( $wpsc_served_header ) && $wpsc_served_header ) { header( 'X-WP-Super-Cache: Served supercache gzip file from PHP' ); @@ -356,7 +356,7 @@ function wp_cache_serve_cache_file() { 6, FORCE_GZIP ); - $size = function_exists( 'mb_strlen' ) ? mb_strlen( $cache, '8bit' ) : strlen( $cache ); + $size = ( function_exists( 'mb_strlen' ) && function_exists( 'is_utf8_charset' ) ) ? mb_strlen( $cache, '8bit' ) : strlen( $cache ); wp_cache_debug( 'Sending Header: Content-Length: ' . $size ); header( 'Content-Length: ' . $size ); } @@ -2441,7 +2441,7 @@ function wp_cache_get_ob( &$buffer ) { wp_cache_debug( 'Gzipping dynamic buffer for display.', 5 ); wp_cache_add_to_buffer( $buffer, 'Compression = gzip' ); $gzdata = gzencode( $buffer, 6, FORCE_GZIP ); - $gzsize = function_exists( 'mb_strlen' ) ? mb_strlen( $gzdata, '8bit' ) : strlen( $gzdata ); + $gzsize = ( function_exists( 'mb_strlen' ) && function_exists( 'is_utf8_charset' ) ) ? mb_strlen( $gzdata, '8bit' ) : strlen( $gzdata ); } } else { if ( defined( 'WPSC_VARY_HEADER' ) ) { @@ -2460,7 +2460,7 @@ function wp_cache_get_ob( &$buffer ) { wp_cache_debug( 'Gzipping buffer.', 5 ); wp_cache_add_to_buffer( $buffer, 'Compression = gzip' ); $gzdata = gzencode( $buffer, 6, FORCE_GZIP ); - $gzsize = function_exists( 'mb_strlen' ) ? mb_strlen( $gzdata, '8bit' ) : strlen( $gzdata ); + $gzsize = ( function_exists( 'mb_strlen' ) && function_exists( 'is_utf8_charset' ) ) ? mb_strlen( $gzdata, '8bit' ) : strlen( $gzdata ); $wp_cache_meta['headers']['Content-Encoding'] = 'Content-Encoding: ' . $wp_cache_gzip_encoding; // Return uncompressed data & store compressed for later use