reSmush.it Image Optimizer - Version 0.4.1

Version Description

  • Official support of WP-CLI
  • Fix cron context optimization
Download this release

Release Info

Developer resmushit
Plugin Icon 128x128 reSmush.it Image Optimizer
Version 0.4.1
Comparing to
See all releases

Code changes from version 0.4.0 to 0.4.1

classes/resmushit.class.php CHANGED
@@ -437,7 +437,6 @@ Class reSmushit {
437
  if( self::getDisabledState( $attachment_id ))
438
  return 'disabled';
439
  if (!file_exists(get_attached_file( $attachment_id ))) {
440
-
441
  rlog("Error! File " . get_attached_file( $attachment_id ) . " not found on disk.", 'WARNING');
442
  return 'file_not_found';
443
  }
437
  if( self::getDisabledState( $attachment_id ))
438
  return 'disabled';
439
  if (!file_exists(get_attached_file( $attachment_id ))) {
 
440
  rlog("Error! File " . get_attached_file( $attachment_id ) . " not found on disk.", 'WARNING');
441
  return 'file_not_found';
442
  }
classes/resmushitWPCLI.class.php ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Performs reSmushit Image Optimization through CLI
5
+ *
6
+ * ## OPTIONS
7
+ *
8
+ * <cmd>
9
+ * : can be 'optimize' to run optimization
10
+ * : can be 'set-quality <quality>' to define a new quality factor
11
+ * : can be 'help' to display global help
12
+ * : can be 'version' to retrieve plugin version
13
+ *
14
+ *
15
+ * ## EXAMPLES
16
+ *
17
+ * wp resmushit optimize
18
+ *
19
+ * @when after_wp_load
20
+ *
21
+ * @package Resmush.it
22
+ * @subpackage Controller
23
+ * @author Charles Bourgeaux <contact@resmush.it>
24
+ */
25
+
26
+ Class reSmushitWPCLI {
27
+ /**
28
+ *
29
+ * @subcommand help
30
+ *
31
+ **/
32
+ function help() {
33
+ WP_CLI::log('reSmush.it Image Optimizer Help ');
34
+ WP_CLI::log('Usage:');
35
+ WP_CLI::log('- `wp resmushit set-quality <quality_level>` : defines the quality level (1-100)');
36
+ WP_CLI::log('- `wp resmushit optimize` : optimize the whole library by batch of ' . reSmushit::MAX_ATTACHMENTS_REQ);
37
+ WP_CLI::log('- `wp resmushit optimize --attachment=<attachment_id>` : optimize a single attachment.');
38
+ }
39
+
40
+ /**
41
+ *
42
+ * @subcommand version
43
+ *
44
+ **/
45
+ function version() {
46
+ WP_CLI::success('reSmush.it Image Optimizer ' . RESMUSHIT_VERSION);
47
+ }
48
+
49
+ /**
50
+ *
51
+ * @subcommand set-quality
52
+ * @alias quality
53
+ *
54
+ **/
55
+ function set_quality( $args ) {
56
+ if(!isset($args[0])) {
57
+ WP_CLI::error( 'A Quality value is required for this command. (eg. `wp set-quality 92`). Type `wp resmushit help` for more informations.' );
58
+ return;
59
+ }
60
+ if($args[0] > 0 && $args[0] <= 100) {
61
+ update_option( 'resmushit_qlty', (int)$args[0] );
62
+ WP_CLI::success( "Quality value set to " . $args[0]);
63
+ } else {
64
+ WP_CLI::error( 'An incorrect quality value is provided (eg. `wp set-quality 92`)' );
65
+ }
66
+ }
67
+
68
+ /**
69
+ *
70
+ * @subcommand optimize
71
+ *
72
+ **/
73
+ function optimize( $args, $assoc_args ) {
74
+ if(isset($args[0])) {
75
+ WP_CLI::error('Incorrect parameter. Type `wp resmushit help` for more informations.');
76
+ return;
77
+ }
78
+
79
+ // If specific attachment has to be optimized.
80
+ if(!empty($assoc_args)) {
81
+ if(isset($assoc_args['attachment'])) {
82
+ if((int)$assoc_args['attachment'] != 0) {
83
+ if(!get_attached_file($assoc_args['attachment'])) {
84
+ WP_CLI::error('Attachment not found in database.');
85
+ return;
86
+ }
87
+ WP_CLI::log('Optimizing attachment #' . (int)$assoc_args['attachment'] . '...');
88
+ update_option( 'resmushit_cron_lastaction', time() );
89
+ switch(reSmushit::revert($assoc_args['attachment'])) {
90
+ case 'success':
91
+ WP_CLI::success('1 picture have been optimized.');
92
+ break;
93
+ case 'disabled':
94
+ WP_CLI::warning('This attachmend has optimization disabled.');
95
+ break;
96
+ case 'file_too_big':
97
+ WP_CLI::error('Attachment file is too big (below 5MB)');
98
+ break;
99
+ case 'file_not_found':
100
+ WP_CLI::error('File not found on disk.');
101
+ break;
102
+ case 'failed':
103
+ default:
104
+ WP_CLI::error('Unexpected error while running optimization.');
105
+ break;
106
+ }
107
+ return;
108
+ } else {
109
+ WP_CLI::error('Incorrect value for parameter `attachment`. Type `wp resmushit help` for more informations.');
110
+ return;
111
+ }
112
+ } else {
113
+ WP_CLI::error('Incorrect parameter. Type `wp resmushit help` for more informations.');
114
+ return;
115
+ }
116
+ }
117
+
118
+ WP_CLI::log('Gathering unoptimized pictures...');
119
+ $unoptimized_pictures = json_decode(reSmushit::getNonOptimizedPictures(TRUE));
120
+ $count_unoptimized_pictures = count($unoptimized_pictures->nonoptimized);
121
+
122
+ if($count_unoptimized_pictures > 0) {
123
+ WP_CLI::log('Found ' . $count_unoptimized_pictures . ' attachments');
124
+ $progress = \WP_CLI\Utils\make_progress_bar( 'Optimized attachments', count($unoptimized_pictures->nonoptimized) );
125
+
126
+ foreach($unoptimized_pictures->nonoptimized as $el) {
127
+ update_option( 'resmushit_cron_lastaction', time() );
128
+ reSmushit::revert($el->ID);
129
+ $progress->tick();
130
+ }
131
+ $progress->finish();
132
+ WP_CLI::success($count_unoptimized_pictures . ' pictures have been optimized.');
133
+ } else {
134
+ WP_CLI::success('All pictures have already been optimized.');
135
+ }
136
+ }
137
+ }
readme.txt CHANGED
@@ -3,7 +3,7 @@ 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.7.1
6
- Stable tag: 0.4.0
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -20,8 +20,6 @@ The plugin includes an option to exclude some pictures of the optimizer.
20
 
21
  Since Aug. 2016, reSmush.it allows to optimize pictures up to 5MB, for free !
22
 
23
- This plugin has initially been developped by [Maecia Agency](http://www.maecia.com/ "Maecia Drupal & Wordpress Agency"), Paris.
24
-
25
  [](http://coderisk.com/wp/plugin/resmushit-image-optimizer/RIPS-Af6lJWjjj5)
26
 
27
  == Installation ==
@@ -76,6 +74,10 @@ Yes ! Absolutely free, the only restriction is to send images below 5MB.
76
 
77
  == Changelog ==
78
 
 
 
 
 
79
  = 0.4.0 =
80
  * New option to restore all original pictures
81
 
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.7.1
6
+ Stable tag: 0.4.1
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
20
 
21
  Since Aug. 2016, reSmush.it allows to optimize pictures up to 5MB, for free !
22
 
 
 
23
  [](http://coderisk.com/wp/plugin/resmushit-image-optimizer/RIPS-Af6lJWjjj5)
24
 
25
  == Installation ==
74
 
75
  == Changelog ==
76
 
77
+ = 0.4.1 =
78
+ * Official support of WP-CLI
79
+ * Fix cron context optimization
80
+
81
  = 0.4.0 =
82
  * New option to restore all original pictures
83
 
resmushit.inc.php CHANGED
@@ -3,6 +3,9 @@
3
  require('resmushit.settings.php');
4
  require('classes/resmushit.class.php');
5
  require('classes/resmushitUI.class.php');
 
 
 
6
  require('resmushit.admin.php');
7
 
8
 
3
  require('resmushit.settings.php');
4
  require('classes/resmushit.class.php');
5
  require('classes/resmushitUI.class.php');
6
+ if ( defined( 'WP_CLI' ) && WP_CLI ) {
7
+ require('classes/resmushitWPCLI.class.php');
8
+ }
9
  require('resmushit.admin.php');
10
 
11
 
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.4.0
14
- * Timestamp: 2021.05.08
15
  * Author: reSmush.it
16
  * Author URI: https://resmush.it
17
  * Author: Charles Bourgeaux
@@ -142,7 +142,7 @@ function resmushit_process_images($attachments, $force_keep_original = TRUE) {
142
  return $attachments;
143
  }
144
  //Automatically optimize images if option is checked
145
- if(get_option('resmushit_on_upload') OR ( isset($_POST['action']) AND ($_POST['action'] === "resmushit_bulk_process_image" OR $_POST['action'] === "resmushit_optimize_single_attachment" )))
146
  add_filter('wp_generate_attachment_metadata', 'resmushit_process_images');
147
 
148
 
@@ -490,3 +490,14 @@ function resmushit_restore_backup_files() {
490
  die();
491
  }
492
  add_action( 'wp_ajax_resmushit_restore_backup_files', 'resmushit_restore_backup_files' );
 
 
 
 
 
 
 
 
 
 
 
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.4.1
14
+ * Timestamp: 2021.05.09
15
  * Author: reSmush.it
16
  * Author URI: https://resmush.it
17
  * Author: Charles Bourgeaux
142
  return $attachments;
143
  }
144
  //Automatically optimize images if option is checked
145
+ if(get_option('resmushit_on_upload') OR ( isset($_POST['action']) AND ($_POST['action'] === "resmushit_bulk_process_image" OR $_POST['action'] === "resmushit_optimize_single_attachment" )) OR (defined( 'WP_CLI' ) && WP_CLI ) OR ($is_cron) )
146
  add_filter('wp_generate_attachment_metadata', 'resmushit_process_images');
147
 
148
 
490
  die();
491
  }
492
  add_action( 'wp_ajax_resmushit_restore_backup_files', 'resmushit_restore_backup_files' );
493
+
494
+
495
+
496
+ /**
497
+ *
498
+ * Declares WPCLI extension if in WP_CLI context
499
+ *
500
+ */
501
+ if( defined( 'WP_CLI' ) && WP_CLI ) {
502
+ WP_CLI::add_command( 'resmushit', 'reSmushitWPCLI' );
503
+ }
resmushit.settings.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
 
3
  define('RESMUSHIT_ENDPOINT', 'http://api.resmush.it/');
4
- define('RESMUSHIT_VERSION', '0.4.0');
5
  define('RESMUSHIT_DEFAULT_QLTY', '92');
6
  define('RESMUSHIT_TIMEOUT', '10');
7
  define('RESMUSHIT_LOGS_PATH', 'resmushit.log');
1
  <?php
2
 
3
  define('RESMUSHIT_ENDPOINT', 'http://api.resmush.it/');
4
+ define('RESMUSHIT_VERSION', '0.4.1');
5
  define('RESMUSHIT_DEFAULT_QLTY', '92');
6
  define('RESMUSHIT_TIMEOUT', '10');
7
  define('RESMUSHIT_LOGS_PATH', 'resmushit.log');