Skip to content

Commit

Permalink
v7.0-a7: * 🌱**Image Optimization** Added AVIF format.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hai Zheng committed Sep 10, 2024
1 parent e1f2aca commit 2a1e05f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
4 changes: 2 additions & 2 deletions litespeed-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

<sup>+</sup> 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.
Expand Down Expand Up @@ -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.
Expand Down
19 changes: 14 additions & 5 deletions src/media.cls.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Media extends Root
private $content;
private $_wp_upload_dir;
private $_vpi_preload_list = array();
private $_format = '';

/**
* Init
Expand All @@ -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';
}
}
}

/**
Expand All @@ -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')) {
Expand Down Expand Up @@ -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;
// }
// }
Expand Down Expand Up @@ -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'])) {
Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion tpl/img_optm/settings.media_webp.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<?php $this->title($id); ?>
</th>
<td>
<?php $this->build_switch($id); ?>
<?php $this->build_switch($id, array(__('OFF', 'litespeed-cache'), __('WebP', 'litespeed-cache'), __('AVIF', 'litespeed-cache'))); ?>
<?php Doc::maybe_on_by_gm($id); ?>
<div class="litespeed-desc">
<?php echo __('Request WebP versions of original images when doing optimization.', 'litespeed-cache'); ?>
Expand Down

0 comments on commit 2a1e05f

Please sign in to comment.