Version Description
- Fix double cron launch. Timeout added
- Fix "Reduce by 0 (0 saved)" message if statistics are disabled
- Return error if attachment file not found on disk
Download this release
Release Info
Developer | resmushit |
Plugin | reSmush.it Image Optimizer |
Version | 0.3.3 |
Comparing to | |
See all releases |
Code changes from version 0.3.2 to 0.3.3
- classes/resmushit.class.php +8 -1
- readme.txt +7 -2
- resmushit.php +22 -10
- resmushit.settings.php +2 -1
classes/resmushit.class.php
CHANGED
@@ -51,7 +51,10 @@ Class reSmushit {
|
|
51 |
*/
|
52 |
public static function optimize($file_path = NULL, $is_original = TRUE) {
|
53 |
global $wp_version;
|
54 |
-
|
|
|
|
|
|
|
55 |
if(filesize($file_path) > self::MAX_FILESIZE){
|
56 |
rlog('Error! Picture ' . str_replace(ABSPATH, '/', $file_path) . ' cannot be optimized, file size is above 5MB ('. reSmushitUI::sizeFormat(filesize($file_path)) .')', 'WARNING');
|
57 |
return false;
|
@@ -430,7 +433,11 @@ Class reSmushit {
|
|
430 |
public static function wasSuccessfullyUpdated($attachment_id){
|
431 |
if( self::getDisabledState( $attachment_id ))
|
432 |
return 'disabled';
|
|
|
433 |
|
|
|
|
|
|
|
434 |
if( filesize(get_attached_file( $attachment_id )) > self::MAX_FILESIZE){
|
435 |
return 'file_too_big';
|
436 |
}
|
51 |
*/
|
52 |
public static function optimize($file_path = NULL, $is_original = TRUE) {
|
53 |
global $wp_version;
|
54 |
+
if(!file_exists($file_path) OR !is_file($file_path)) {
|
55 |
+
rlog('Error! Picture ' . str_replace(ABSPATH, '/', $file_path) . ' cannot be optimized, file is not found on disk.', 'WARNING');
|
56 |
+
return false;
|
57 |
+
}
|
58 |
if(filesize($file_path) > self::MAX_FILESIZE){
|
59 |
rlog('Error! Picture ' . str_replace(ABSPATH, '/', $file_path) . ' cannot be optimized, file size is above 5MB ('. reSmushitUI::sizeFormat(filesize($file_path)) .')', 'WARNING');
|
60 |
return false;
|
433 |
public static function wasSuccessfullyUpdated($attachment_id){
|
434 |
if( self::getDisabledState( $attachment_id ))
|
435 |
return 'disabled';
|
436 |
+
if (!file_exists(get_attached_file( $attachment_id ))) {
|
437 |
|
438 |
+
rlog("Error! File " . get_attached_file( $attachment_id ) . " not found on disk.", 'WARNING');
|
439 |
+
return 'file_not_found';
|
440 |
+
}
|
441 |
if( filesize(get_attached_file( $attachment_id )) > self::MAX_FILESIZE){
|
442 |
return 'file_too_big';
|
443 |
}
|
readme.txt
CHANGED
@@ -2,8 +2,8 @@
|
|
2 |
Contributors: resmushit
|
3 |
Tags: image, optimizer, image optimization, resmush.it, smush, jpg, png, gif, optimization, compression, Compress, Images, Pictures, Reduce Image Size, Smush, Smush.it
|
4 |
Requires at least: 4.0.0
|
5 |
-
Tested up to: 5.4.
|
6 |
-
Stable tag: 0.3.
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
@@ -70,6 +70,11 @@ Yes ! Absolutely free, the only restriction is to send images below 5MB.
|
|
70 |
|
71 |
== Changelog ==
|
72 |
|
|
|
|
|
|
|
|
|
|
|
73 |
= 0.3.2 =
|
74 |
* Fix variable check (generate notice)
|
75 |
|
2 |
Contributors: resmushit
|
3 |
Tags: image, optimizer, image optimization, resmush.it, smush, jpg, png, gif, optimization, compression, Compress, Images, Pictures, Reduce Image Size, Smush, Smush.it
|
4 |
Requires at least: 4.0.0
|
5 |
+
Tested up to: 5.4.1
|
6 |
+
Stable tag: 0.3.3
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
70 |
|
71 |
== Changelog ==
|
72 |
|
73 |
+
= 0.3.3 =
|
74 |
+
* Fix double cron launch. Timeout added
|
75 |
+
* Fix "Reduce by 0 (0 saved)" message if statistics are disabled
|
76 |
+
* Return error if attachment file not found on disk
|
77 |
+
|
78 |
= 0.3.2 =
|
79 |
* Fix variable check (generate notice)
|
80 |
|
resmushit.php
CHANGED
@@ -10,8 +10,8 @@
|
|
10 |
* Plugin Name: reSmush.it Image Optimizer
|
11 |
* Plugin URI: https://wordpress.org/plugins/resmushit-image-optimizer/
|
12 |
* Description: Image Optimization API. Provides image size optimization
|
13 |
-
* Version: 0.3.
|
14 |
-
* Timestamp: 2020.
|
15 |
* Author: reSmush.it
|
16 |
* Author URI: https://resmush.it
|
17 |
* Author: Charles Bourgeaux
|
@@ -59,6 +59,8 @@ function resmushit_activate() {
|
|
59 |
update_option( 'resmushit_total_optimized', '0' );
|
60 |
if(get_option('resmushit_cron') === null)
|
61 |
update_option( 'resmushit_cron', 0 );
|
|
|
|
|
62 |
if(get_option('resmushit_cron_lastrun') === null)
|
63 |
update_option( 'resmushit_cron_lastrun', 0 );
|
64 |
if(get_option('resmushit_cron_firstactivation') === null)
|
@@ -101,6 +103,11 @@ function resmushit_process_images($attachments, $force_keep_original = TRUE) {
|
|
101 |
if(reSmushit::getDisabledState($attachment_id))
|
102 |
return $attachments;
|
103 |
|
|
|
|
|
|
|
|
|
|
|
104 |
$fileInfo = pathinfo(get_attached_file( $attachment_id ));
|
105 |
$basepath = $fileInfo['dirname'] . '/';
|
106 |
$extension = isset($fileInfo['extension']) ? $fileInfo['extension'] : NULL;
|
@@ -128,12 +135,9 @@ function resmushit_process_images($attachments, $force_keep_original = TRUE) {
|
|
128 |
if(!$error) {
|
129 |
$optimizations_successful_count = get_option('resmushit_total_optimized');
|
130 |
update_option( 'resmushit_total_optimized', $optimizations_successful_count + $count );
|
131 |
-
|
132 |
-
update_post_meta($attachment_id,'
|
133 |
-
|
134 |
-
update_post_meta($attachment_id,'resmushed_cumulated_original_sizes', $cumulated_original_sizes);
|
135 |
-
update_post_meta($attachment_id,'resmushed_cumulated_optimized_sizes', $cumulated_optimized_sizes);
|
136 |
-
}
|
137 |
}
|
138 |
return $attachments;
|
139 |
}
|
@@ -333,21 +337,29 @@ if(!get_option('resmushit_cron') || get_option('resmushit_cron') === 0) {
|
|
333 |
function resmushit_cron_process() {
|
334 |
global $is_cron;
|
335 |
$is_cron = TRUE;
|
336 |
-
update_option( 'resmushit_cron_lastrun', time() );
|
337 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
338 |
// required if launch through wp-cron.php
|
339 |
include_once( ABSPATH . 'wp-admin/includes/image.php' );
|
340 |
|
341 |
-
add_filter('wp_generate_attachment_metadata', 'resmushit_process_images');
|
342 |
rlog('Gathering unoptimized pictures from CRON');
|
343 |
$unoptimized_pictures = json_decode(reSmushit::getNonOptimizedPictures(TRUE));
|
344 |
rlog('Found ' . count($unoptimized_pictures->nonoptimized) . ' attachments');
|
|
|
345 |
foreach($unoptimized_pictures->nonoptimized as $el) {
|
346 |
if (wp_next_scheduled ( 'resmushit_optimize' )) {
|
347 |
//avoid to collapse two crons
|
348 |
wp_unschedule_event(wp_next_scheduled('resmushit_optimize'), 'resmushit_optimize');
|
349 |
}
|
350 |
rlog('CRON Processing attachments #' . $el->ID);
|
|
|
351 |
reSmushit::revert($el->ID);
|
352 |
}
|
353 |
}
|
10 |
* Plugin Name: reSmush.it Image Optimizer
|
11 |
* Plugin URI: https://wordpress.org/plugins/resmushit-image-optimizer/
|
12 |
* Description: Image Optimization API. Provides image size optimization
|
13 |
+
* Version: 0.3.4
|
14 |
+
* Timestamp: 2020.05.01
|
15 |
* Author: reSmush.it
|
16 |
* Author URI: https://resmush.it
|
17 |
* Author: Charles Bourgeaux
|
59 |
update_option( 'resmushit_total_optimized', '0' );
|
60 |
if(get_option('resmushit_cron') === null)
|
61 |
update_option( 'resmushit_cron', 0 );
|
62 |
+
if(get_option('resmushit_cron_lastaction') === null)
|
63 |
+
update_option( 'resmushit_cron_lastaction', 0 );
|
64 |
if(get_option('resmushit_cron_lastrun') === null)
|
65 |
update_option( 'resmushit_cron_lastrun', 0 );
|
66 |
if(get_option('resmushit_cron_firstactivation') === null)
|
103 |
if(reSmushit::getDisabledState($attachment_id))
|
104 |
return $attachments;
|
105 |
|
106 |
+
if(empty($attachments)) {
|
107 |
+
rlog("Error! Attachment #$attachment_id has no corresponding file on disk.", 'WARNING');
|
108 |
+
return $attachments;
|
109 |
+
}
|
110 |
+
|
111 |
$fileInfo = pathinfo(get_attached_file( $attachment_id ));
|
112 |
$basepath = $fileInfo['dirname'] . '/';
|
113 |
$extension = isset($fileInfo['extension']) ? $fileInfo['extension'] : NULL;
|
135 |
if(!$error) {
|
136 |
$optimizations_successful_count = get_option('resmushit_total_optimized');
|
137 |
update_option( 'resmushit_total_optimized', $optimizations_successful_count + $count );
|
138 |
+
update_post_meta($attachment_id,'resmushed_quality', resmushit::getPictureQualitySetting());
|
139 |
+
update_post_meta($attachment_id,'resmushed_cumulated_original_sizes', $cumulated_original_sizes);
|
140 |
+
update_post_meta($attachment_id,'resmushed_cumulated_optimized_sizes', $cumulated_optimized_sizes);
|
|
|
|
|
|
|
141 |
}
|
142 |
return $attachments;
|
143 |
}
|
337 |
function resmushit_cron_process() {
|
338 |
global $is_cron;
|
339 |
$is_cron = TRUE;
|
|
|
340 |
|
341 |
+
if(time() - get_option('resmushit_cron_lastrun') < RESMUSHIT_CRON_TIMEOUT) {
|
342 |
+
rlog('Another CRON process is running, process aborted.', 'WARNING');
|
343 |
+
return FALSE;
|
344 |
+
}
|
345 |
+
update_option( 'resmushit_cron_lastrun', time() );
|
346 |
+
update_option( 'resmushit_cron_lastaction', time() );
|
347 |
+
|
348 |
// required if launch through wp-cron.php
|
349 |
include_once( ABSPATH . 'wp-admin/includes/image.php' );
|
350 |
|
351 |
+
add_filter('wp_generate_attachment_metadata', 'resmushit_process_images');
|
352 |
rlog('Gathering unoptimized pictures from CRON');
|
353 |
$unoptimized_pictures = json_decode(reSmushit::getNonOptimizedPictures(TRUE));
|
354 |
rlog('Found ' . count($unoptimized_pictures->nonoptimized) . ' attachments');
|
355 |
+
|
356 |
foreach($unoptimized_pictures->nonoptimized as $el) {
|
357 |
if (wp_next_scheduled ( 'resmushit_optimize' )) {
|
358 |
//avoid to collapse two crons
|
359 |
wp_unschedule_event(wp_next_scheduled('resmushit_optimize'), 'resmushit_optimize');
|
360 |
}
|
361 |
rlog('CRON Processing attachments #' . $el->ID);
|
362 |
+
update_option( 'resmushit_cron_lastaction', time() );
|
363 |
reSmushit::revert($el->ID);
|
364 |
}
|
365 |
}
|
resmushit.settings.php
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?php
|
2 |
|
3 |
define('RESMUSHIT_ENDPOINT', 'http://api.resmush.it/');
|
4 |
-
define('RESMUSHIT_VERSION', '0.3.
|
5 |
define('RESMUSHIT_DEFAULT_QLTY', '92');
|
6 |
define('RESMUSHIT_TIMEOUT', '10');
|
7 |
define('RESMUSHIT_LOGS_PATH', 'resmushit.log');
|
@@ -9,5 +9,6 @@ define('RESMUSHIT_LOGS_MAX_FILESIZE', '102400');
|
|
9 |
define('RESMUSHIT_NEWSFEED', 'https://feed.resmush.it/');
|
10 |
define('RESMUSHIT_BASE_URL', plugin_dir_url( __FILE__ ));
|
11 |
define('RESMUSHIT_CRON_FREQUENCY', 600);
|
|
|
12 |
|
13 |
global $is_cron;
|
1 |
<?php
|
2 |
|
3 |
define('RESMUSHIT_ENDPOINT', 'http://api.resmush.it/');
|
4 |
+
define('RESMUSHIT_VERSION', '0.3.3');
|
5 |
define('RESMUSHIT_DEFAULT_QLTY', '92');
|
6 |
define('RESMUSHIT_TIMEOUT', '10');
|
7 |
define('RESMUSHIT_LOGS_PATH', 'resmushit.log');
|
9 |
define('RESMUSHIT_NEWSFEED', 'https://feed.resmush.it/');
|
10 |
define('RESMUSHIT_BASE_URL', plugin_dir_url( __FILE__ ));
|
11 |
define('RESMUSHIT_CRON_FREQUENCY', 600);
|
12 |
+
define('RESMUSHIT_CRON_TIMEOUT', 60);
|
13 |
|
14 |
global $is_cron;
|