Skip to content

Commit ec6d47c

Browse files
author
Hai Zheng
committed
-
1 parent 2b4e335 commit ec6d47c

5 files changed

Lines changed: 14 additions & 13 deletions

File tree

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ You can report security bugs through the Patchstack Vulnerability Disclosure Pro
258258
== Changelog ==
259259

260260
= 7.4 - Aug 26 2025 =
261+
* 🌱**Media** Auto Rescale Original Image.
261262
* 🌱**Toolbox** Disable All for 24 Hours. (PR#886)
262263
* 🐞**Object Cache** Fixed a bug that failed to detect the Redis connection status.
263264
* **Cache** Better match iPhone browsers for mobile cache detection.

src/base.cls.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ class Base extends Root {
218218
const O_MEDIA_VPI = 'media-vpi';
219219
const O_MEDIA_VPI_CRON = 'media-vpi_cron';
220220
const O_IMG_OPTM_JPG_QUALITY = 'img_optm-jpg_quality';
221-
const O_MEDIA_REP_W_SCALED = 'media-replace_w_scaled';
221+
const O_MEDIA_AUTO_RESCALE_ORI = 'media-auto_rescale_ori';
222222

223223
// -------------------------------------------------- ##
224224
// -------------- Image Optm ----------------- ##
@@ -280,7 +280,7 @@ class Base extends Root {
280280
const O_QC_CNAME = 'qc-cname';
281281

282282
const NETWORK_O_USE_PRIMARY = 'use_primary_settings';
283-
283+
284284
const DEBUG_TMP_DISABLE = 'debug-disable_tmp';
285285

286286
/*** Other consts ***/
@@ -503,7 +503,7 @@ class Base extends Root {
503503
self::O_MEDIA_LQIP_EXC => array(),
504504
self::O_MEDIA_VPI => false,
505505
self::O_MEDIA_VPI_CRON => false,
506-
self::O_MEDIA_REP_W_SCALED => false,
506+
self::O_MEDIA_AUTO_RESCALE_ORI => false,
507507

508508
// Image Optm
509509
self::O_IMG_OPTM_AUTO => false,

src/lang.cls.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public static function title( $id ) {
202202
self::O_MEDIA_ADD_MISSING_SIZES => __('Add Missing Sizes', 'litespeed-cache'),
203203
self::O_MEDIA_VPI => __('Viewport Images', 'litespeed-cache'),
204204
self::O_MEDIA_VPI_CRON => __('Viewport Images Cron', 'litespeed-cache'),
205-
self::O_MEDIA_REP_W_SCALED => __('Replace Original with Scaled', 'litespeed-cache'),
205+
self::O_MEDIA_AUTO_RESCALE_ORI => __('Auto Rescale Original Images', 'litespeed-cache'),
206206

207207
self::O_IMG_OPTM_AUTO => __('Auto Request Cron', 'litespeed-cache'),
208208
self::O_IMG_OPTM_ORI => __('Optimize Original Images', 'litespeed-cache'),

src/media.cls.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ public function after_user_init() {
6060
add_action('delete_attachment', array( $this, 'delete_attachment' ), 11, 2);
6161

6262
// For big images, allow to replace original with scaled image.
63-
if( $this->conf(Base::O_MEDIA_REP_W_SCALED) ){
63+
if( $this->conf(Base::O_MEDIA_AUTO_RESCALE_ORI) ){
6464
// Added priority 9 to happen before other functions added.
65-
add_filter('wp_update_attachment_metadata', array( $this, 'replace_original_with_scaled' ), 9, 2);
65+
add_filter('wp_update_attachment_metadata', array( $this, 'rescale_ori' ), 9, 2);
6666
}
6767
}
6868

@@ -107,19 +107,19 @@ public function init() {
107107

108108
/**
109109
* Handle attachment create
110-
*
110+
*
111111
* @param array $metadata Current meta array.
112112
* @param int $attachment_id Attachment ID.
113113
* @return array $metadata
114114
* @since 7.4
115115
*/
116-
public function replace_original_with_scaled( $metadata, $attachment_id ) {
116+
public function rescale_ori( $metadata, $attachment_id ) {
117117
// Test if create and image was resized.
118118
if( $metadata && isset($metadata['original_image']) && isset($metadata['file']) && false !== strstr($metadata['file'], '-scaled')){
119119
// Get rescaled file name.
120120
$path_exploded = explode( '/', strrev($metadata['file']), 2 );
121121
$rescaled_file_name = strrev($path_exploded[0]);
122-
122+
123123
// Create paths for images: resized and original.
124124
$base_path = $this->_wp_upload_dir['basedir'] . $this->_wp_upload_dir['subdir'] . '/';
125125
$rescaled_path = $base_path . $rescaled_file_name;

tpl/page_optm/settings_media.tpl.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,20 +280,20 @@
280280

281281
<tr>
282282
<th>
283-
<?php $option_id = Base::O_MEDIA_REP_W_SCALED; ?>
283+
<?php $option_id = Base::O_MEDIA_AUTO_RESCALE_ORI; ?>
284284
<?php $this->title( $option_id ); ?>
285285
</th>
286286
<td>
287287
<?php $this->build_switch( $option_id ); ?>
288288
<div class="litespeed-desc">
289289
<?php esc_html_e( 'Automatically replace large images with scaled versions.', 'litespeed-cache' ); ?>
290-
<br />
291-
<?php echo wp_kses_post( sprintf( __( 'Scaled size and threshold is: %s', 'litespeed-cache' ), '<code>' . $scaled_size . '</code>' ) ); ?>
290+
<?php esc_html_e( 'Scaled size threshold', 'litespeed-cache' ); ?>: <code><?php echo wp_kses_post( $scaled_size ); ?></code>
292291
<br />
293292
<span class="litespeed-success">
293+
API:
294294
<?php
295295
printf(
296-
esc_html__( 'API: Filter %s available to change threshold.', 'litespeed-cache' ),
296+
esc_html__( 'Filter %s available to change threshold.', 'litespeed-cache' ),
297297
'<code>big_image_size_threshold</code>'
298298
);
299299
?>

0 commit comments

Comments
 (0)