From c8307977a2f86ed0fc701404f9a44a9563895fbe Mon Sep 17 00:00:00 2001 From: Hai Zheng Date: Tue, 10 Sep 2024 18:14:35 -0400 Subject: [PATCH] =?UTF-8?q?v7.0-a7:=20*=20=F0=9F=8C=B1**Image=20Optimizati?= =?UTF-8?q?on**=20Added=20AVIF=20format.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- litespeed-cache.php | 4 ++-- readme.txt | 3 ++- src/media.cls.php | 19 ++++++++++++++----- tpl/img_optm/settings.media_webp.tpl.php | 2 +- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/litespeed-cache.php b/litespeed-cache.php index f7445ea13..42e7656d5 100644 --- a/litespeed-cache.php +++ b/litespeed-cache.php @@ -4,7 +4,7 @@ * Plugin Name: LiteSpeed Cache * Plugin URI: https://www.litespeedtech.com/products/cache-plugins/wordpress-acceleration * Description: High-performance page caching and site optimization from LiteSpeed - * Version: 7.0-a6 + * Version: 7.0-a7 * Author: LiteSpeed Technologies * Author URI: https://www.litespeedtech.com * License: GPLv3 @@ -34,7 +34,7 @@ return; } -!defined('LSCWP_V') && define('LSCWP_V', '7.0-a6'); +!defined('LSCWP_V') && define('LSCWP_V', '7.0-a7'); !defined('LSCWP_CONTENT_DIR') && define('LSCWP_CONTENT_DIR', WP_CONTENT_DIR); !defined('LSCWP_DIR') && define('LSCWP_DIR', __DIR__ . '/'); // Full absolute path '/var/www/html/***/wp-content/plugins/litespeed-cache/' or MU diff --git a/readme.txt b/readme.txt index af3936a1f..b5df23d42 100644 --- a/readme.txt +++ b/readme.txt @@ -49,7 +49,7 @@ LiteSpeed Cache for WordPress is compatible with ClassicPress. * Single Site and Multisite (Network) support * Import/Export settings * Attractive, easy-to-understand interface -* WebP image format support +* AVIF/WebP image format support * Heartbeat control + This service is not provided by the LSCache plugin, nor is it guaranteed to be installed by your service provider. However, the plugin is compatible with the service if it is in use on your site. @@ -256,6 +256,7 @@ You can report security bugs through the Patchstack Vulnerability Disclosure Pro == Changelog == = 7.0 - Nov 2024 = +* 🌱**Image Optimization** Added AVIF format. * **Core** Minimum required PHP version escalated to PHP v7.2.0. * **Core** Minimum required WP version escalated to WP v5.3. * **Cloud** Dropped `Domain Key`. Used sodium encryption for authentication and validation. diff --git a/src/media.cls.php b/src/media.cls.php index 29c29cfea..4a7908fc3 100644 --- a/src/media.cls.php +++ b/src/media.cls.php @@ -23,6 +23,7 @@ class Media extends Root private $content; private $_wp_upload_dir; private $_vpi_preload_list = array(); + private $_format = ''; /** * Init @@ -34,6 +35,12 @@ public function __construct() Debug2::debug2('[Media] init'); $this->_wp_upload_dir = wp_upload_dir(); + if ($this->conf(Base::O_IMG_OPTM_WEBP)) { + $this->_format = 'webp'; + if ($this->conf(Base::O_IMG_OPTM_WEBP) == 2) { + $this->_format = 'avif'; + } + } } /** @@ -49,7 +56,7 @@ public function init() } // Due to ajax call doesn't send correct accept header, have to limit webp to HTML only - if (defined('LITESPEED_GUEST_OPTM') || $this->conf(Base::O_IMG_OPTM_WEBP)) { + if (defined('LITESPEED_GUEST_OPTM') || $this->_format) { if ($this->webp_support()) { // Hook to srcset if (function_exists('wp_calculate_image_srcset')) { @@ -93,7 +100,7 @@ public function finalize_head($content) // $featured_image_url = get_the_post_thumbnail_url(); // if ($featured_image_url) { // self::debug('Append featured image to head: ' . $featured_image_url); - // if ((defined('LITESPEED_GUEST_OPTM') || $this->conf(Base::O_IMG_OPTM_WEBP)) && $this->webp_support()) { + // if ((defined('LITESPEED_GUEST_OPTM') || $this->_format) && $this->webp_support()) { // $featured_image_url = $this->replace_webp($featured_image_url) ?: $featured_image_url; // } // } @@ -437,8 +444,10 @@ public function get_image_sizes() */ public function webp_support() { - if (!empty($_SERVER['HTTP_ACCEPT']) && strpos($_SERVER['HTTP_ACCEPT'], 'image/webp') !== false) { - return true; + if (!empty($_SERVER['HTTP_ACCEPT'])) { + if (strpos($_SERVER['HTTP_ACCEPT'], 'image/' . $this->_format) !== false) { + return true; + } } if (!empty($_SERVER['HTTP_USER_AGENT'])) { @@ -506,7 +515,7 @@ private function _finalize() * Use webp for optimized images * @since 1.6.2 */ - if ((defined('LITESPEED_GUEST_OPTM') || $this->conf(Base::O_IMG_OPTM_WEBP)) && $this->webp_support()) { + if ((defined('LITESPEED_GUEST_OPTM') || $this->_format) && $this->webp_support()) { $this->content = $this->_replace_buffer_img_webp($this->content); } diff --git a/tpl/img_optm/settings.media_webp.tpl.php b/tpl/img_optm/settings.media_webp.tpl.php index 07e243a60..93b65c067 100644 --- a/tpl/img_optm/settings.media_webp.tpl.php +++ b/tpl/img_optm/settings.media_webp.tpl.php @@ -11,7 +11,7 @@ title($id); ?> - build_switch($id); ?> + build_switch($id, array(__('OFF', 'litespeed-cache'), __('WebP', 'litespeed-cache'), __('AVIF', 'litespeed-cache'))); ?>