Smush Image Compression and Optimization - Version 2.0.6.5

Version Description

  • Updated: Skip webp images ( causing ajax error for few sites )
  • Fixed: Warning and Notices ( Media Library not loading )
  • Fixed: Smush full size image if no other sizes are available
  • Added: Detailed text for stats and settings
Download this release

Release Info

Developer UmeshSingla
Plugin Icon 128x128 Smush Image Compression and Optimization
Version 2.0.6.5
Comparing to
See all releases

Code changes from version 2.0.6.2 to 2.0.6.5

assets/css/wp-smushit-admin.css CHANGED
@@ -258,6 +258,7 @@ Progressbar ui
258
  overflow: hidden;
259
  position: relative;
260
  }
 
261
  #progress-ui #wp-smush-ss-progress-wrap {
262
  /*background-color: #2ea2cc;*/
263
  }
@@ -376,8 +377,26 @@ button .wp-smush-loader-wrap {
376
  padding: 5px 5px 5px 0;
377
  }
378
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
379
  .wp-smush-pro-features {
 
380
  display: inline-block;
 
 
 
381
  }
382
 
383
  input#wp-smush-save-settings {
@@ -426,6 +445,25 @@ input#wp-smush-save-settings {
426
  content: "";
427
  }
428
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
429
  /** Grid view button **/
430
  .smush-wrap {
431
  margin-left: 14%;
@@ -474,6 +512,7 @@ input#wp-smush-save-settings {
474
  #post-body-content .wp-smush-send {
475
  margin: 4px 0 0;
476
  }
 
477
  #post-body-content .smush-status {
478
  margin: 4px 0;
479
  }
@@ -535,4 +574,48 @@ input#wp-smush-save-settings {
535
 
536
  .inactive-anim {
537
  transition: opacity .3s;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
538
  }
258
  overflow: hidden;
259
  position: relative;
260
  }
261
+
262
  #progress-ui #wp-smush-ss-progress-wrap {
263
  /*background-color: #2ea2cc;*/
264
  }
377
  padding: 5px 5px 5px 0;
378
  }
379
 
380
+ /*Pro rows*/
381
+ #wp-smush-options-wrap .wp-smush-pro-features .wp-smush-setting-row {
382
+ margin: 5px 20px 5px 25px;
383
+ }
384
+
385
+ #wp-smush-options-wrap .wp-smush-pro-features .pro-note {
386
+ margin: 0 0 0 25px;
387
+ }
388
+ .wp-smush-setting-row .dashicons-info.smush-original{
389
+ top: 2px;
390
+ position: relative;
391
+ color: gray;
392
+ }
393
+
394
  .wp-smush-pro-features {
395
+ border: 1px solid lightgray;
396
  display: inline-block;
397
+ padding: 0 0 10px 0;
398
+ margin: 10px 0 0;
399
+ width: 85%;
400
  }
401
 
402
  input#wp-smush-save-settings {
445
  content: "";
446
  }
447
 
448
+ .wp-smush-pro-features legend {
449
+ margin-left: 15px;
450
+ padding: 0 10px;
451
+ }
452
+
453
+ .pro-note .dashicons-info {
454
+ color: gray;
455
+ margin: 0 5px 0 0;
456
+ }
457
+
458
+ .pro-note .find-out-link {
459
+ margin: -5px 0 0 10px;
460
+ }
461
+
462
+ .wp-smush-setting-row.disabled label, .wp-smush-setting-row.disabled input {
463
+ color: gray;
464
+ cursor: default;
465
+ }
466
+
467
  /** Grid view button **/
468
  .smush-wrap {
469
  margin-left: 14%;
512
  #post-body-content .wp-smush-send {
513
  margin: 4px 0 0;
514
  }
515
+
516
  #post-body-content .smush-status {
517
  margin: 4px 0;
518
  }
574
 
575
  .inactive-anim {
576
  transition: opacity .3s;
577
+ }
578
+
579
+ .smush-stats-wrapper {
580
+ border: 1px solid lightgray;
581
+ }
582
+ table.wp-smush-stats-holder {
583
+ border-collapse: collapse;
584
+ width: 100%;
585
+ }
586
+ table.wp-smush-stats-holder th {
587
+ background-color: #E4E4E4;
588
+ }
589
+ table.wp-smush-stats-holder td, table.wp-smush-stats-holder th {
590
+ border: 1px solid #CECECE;
591
+ }
592
+ table.wp-smush-stats-holder tr:first-child th {
593
+ border-top: 0;
594
+ }
595
+ table.wp-smush-stats-holder tr:last-child td {
596
+ border-bottom: 0;
597
+ }
598
+ table.wp-smush-stats-holder tr td:first-child,
599
+ table.wp-smush-stats-holder tr th:first-child {
600
+ border-left: 0;
601
+ }
602
+ table.wp-smush-stats-holder tr td:last-child,
603
+ table.wp-smush-stats-holder tr th:last-child {
604
+ border-right: 0;
605
+ }
606
+ table.wp-smush-stats-holder tr td:first-child {
607
+ text-align: right;
608
+ }
609
+ .smush-skipped.error {
610
+ color: #C41921;
611
+ }
612
+ .smush-skipped .dashicons-editor-help {
613
+ cursor: pointer;
614
+ }
615
+ /*Media Modal Styling*/
616
+ .compat-field-wp_smush .wp-smush-stats-holder tr {
617
+ display: table-row;
618
+ }
619
+ .compat-field-wp_smush .wp-smush-stats-holder td {
620
+ padding: 8px 10px
621
  }
assets/js/wp-smushit-admin.js CHANGED
@@ -2,40 +2,41 @@
2
  * Processes bulk smushing
3
  *
4
  * @author Saurabh Shukla <saurabh@incsub.com>
 
5
  *
6
  */
7
  var WP_Smush = WP_Smush || {};
8
  jQuery(function ($) {
9
- // url for smushing
10
- WP_Smush.errors = [];
11
- WP_Smush.timeout = 60000;
12
- /**
13
- * Checks for the specified param in URL
14
- * @param sParam
15
- * @returns {*}
16
- */
17
- WP_Smush.geturlparam = function(arg) {
18
- var $sPageURL = window.location.search.substring(1);
19
- var $sURLVariables = $sPageURL.split('&');
20
-
21
- for (var i = 0; i < $sURLVariables.length; i++) {
22
- var $sParameterName = $sURLVariables[i].split('=');
23
- if ($sParameterName[0] == arg) {
24
- return $sParameterName[1];
25
- }
26
- }
27
- };
28
-
29
- WP_Smush.ajax = function ($id, $send_url, $getnxt) {
30
- "use strict";
31
- return $.ajax({
32
- type: "GET",
33
- data: {attachment_id: $id, get_next: $getnxt},
34
- url: $send_url,
35
- timeout: WP_Smush.timeout,
36
- dataType: 'json'
37
- });
38
- };
39
 
40
  WP_Smush.Smush = function ($button, bulk) {
41
  var self = this;
@@ -171,15 +172,15 @@ jQuery(function ($) {
171
  };
172
 
173
  this.update_progress = function (stats) {
174
- if( !this.is_bulk_super_smush ) {
175
  //handle progress for normal bulk smush
176
  var progress = ( stats.data.smushed / stats.data.total) * 100;
177
- }else{
178
  //Handle progress for Super smush progress bar
179
- if( wp_smushit_data.lossless.length > 0 ) {
180
  $('#wp-smush-ss-progress-wrap .remaining-count').html(wp_smushit_data.lossless.length);
181
- }else if( wp_smushit_data.lossless.length == 0 ){
182
- $('#wp-smush-ss-progress-wrap #wp-smush-compression').html( wp_smush_msgs.all_supersmushed );
183
  }
184
 
185
  }
@@ -194,11 +195,11 @@ jQuery(function ($) {
194
 
195
  this._update_progress = function (count, width) {
196
  "use strict";
197
- if( !this.is_bulk ) {
198
  return;
199
  }
200
 
201
- if( !this.is_bulk_super_smush ) {
202
  // get the progress bar
203
  var $progress_bar = jQuery('#wp-smush-progress-wrap #wp-smush-fetched-progress div');
204
  if ($progress_bar.length < 1) {
@@ -207,9 +208,9 @@ jQuery(function ($) {
207
  $('.done-count').html(count);
208
  // increase progress
209
  $progress_bar.css('width', width + '%');
210
- }else{
211
 
212
- if( this.lossless_count > 0 ) {
213
  var remaining_lossless = this.lossless_count - wp_smushit_data.lossless.length;
214
  var progress_width = ( remaining_lossless / this.lossless_count * 100 );
215
  var $progress_bar = jQuery('#wp-smush-ss-progress-wrap #wp-smush-ss-progress div');
@@ -322,6 +323,20 @@ jQuery(function ($) {
322
  return;
323
  });
324
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
325
  //Handle smush button click
326
  $('body').on('click', '.wp-smush-send', function (e) {
327
 
@@ -329,6 +344,8 @@ jQuery(function ($) {
329
  e.preventDefault();
330
  new WP_Smush.Smush($(this), false);
331
  });
 
 
332
 
333
  });
334
  (function ($) {
2
  * Processes bulk smushing
3
  *
4
  * @author Saurabh Shukla <saurabh@incsub.com>
5
+ * @author Umesh Kumar
6
  *
7
  */
8
  var WP_Smush = WP_Smush || {};
9
  jQuery(function ($) {
10
+ // url for smushing
11
+ WP_Smush.errors = [];
12
+ WP_Smush.timeout = wp_smushit_data.timeout;
13
+ /**
14
+ * Checks for the specified param in URL
15
+ * @param sParam
16
+ * @returns {*}
17
+ */
18
+ WP_Smush.geturlparam = function (arg) {
19
+ var $sPageURL = window.location.search.substring(1);
20
+ var $sURLVariables = $sPageURL.split('&');
21
+
22
+ for (var i = 0; i < $sURLVariables.length; i++) {
23
+ var $sParameterName = $sURLVariables[i].split('=');
24
+ if ($sParameterName[0] == arg) {
25
+ return $sParameterName[1];
26
+ }
27
+ }
28
+ };
29
+
30
+ WP_Smush.ajax = function ($id, $send_url, $getnxt) {
31
+ "use strict";
32
+ return $.ajax({
33
+ type: "GET",
34
+ data: {attachment_id: $id, get_next: $getnxt},
35
+ url: $send_url,
36
+ timeout: WP_Smush.timeout,
37
+ dataType: 'json'
38
+ });
39
+ };
40
 
41
  WP_Smush.Smush = function ($button, bulk) {
42
  var self = this;
172
  };
173
 
174
  this.update_progress = function (stats) {
175
+ if (!this.is_bulk_super_smush) {
176
  //handle progress for normal bulk smush
177
  var progress = ( stats.data.smushed / stats.data.total) * 100;
178
+ } else {
179
  //Handle progress for Super smush progress bar
180
+ if (wp_smushit_data.lossless.length > 0) {
181
  $('#wp-smush-ss-progress-wrap .remaining-count').html(wp_smushit_data.lossless.length);
182
+ } else if (wp_smushit_data.lossless.length == 0) {
183
+ $('#wp-smush-ss-progress-wrap #wp-smush-compression').html(wp_smush_msgs.all_supersmushed);
184
  }
185
 
186
  }
195
 
196
  this._update_progress = function (count, width) {
197
  "use strict";
198
+ if (!this.is_bulk) {
199
  return;
200
  }
201
 
202
+ if (!this.is_bulk_super_smush) {
203
  // get the progress bar
204
  var $progress_bar = jQuery('#wp-smush-progress-wrap #wp-smush-fetched-progress div');
205
  if ($progress_bar.length < 1) {
208
  $('.done-count').html(count);
209
  // increase progress
210
  $progress_bar.css('width', width + '%');
211
+ } else {
212
 
213
+ if (this.lossless_count > 0) {
214
  var remaining_lossless = this.lossless_count - wp_smushit_data.lossless.length;
215
  var progress_width = ( remaining_lossless / this.lossless_count * 100 );
216
  var $progress_bar = jQuery('#wp-smush-ss-progress-wrap #wp-smush-ss-progress div');
323
  return;
324
  });
325
 
326
+ /**
327
+ * Handle the Smush Stats link click
328
+ */
329
+ $('body').on('click', 'a.smush-stats-details', function (e) {
330
+
331
+ // prevent the default action
332
+ e.preventDefault();
333
+ var slide_symbol = $(this).find('.stats-toggle');
334
+ $(this).parents().eq(1).find('.smush-stats-wrapper').slideToggle();
335
+ slide_symbol.text(slide_symbol.text() == '+' ? '-' : '+');
336
+
337
+ return;
338
+ });
339
+
340
  //Handle smush button click
341
  $('body').on('click', '.wp-smush-send', function (e) {
342
 
344
  e.preventDefault();
345
  new WP_Smush.Smush($(this), false);
346
  });
347
+ //Stats Button Click
348
+
349
 
350
  });
351
  (function ($) {
languages/wp-smushit.pot CHANGED
@@ -2,9 +2,9 @@
2
  # This file is distributed under the same license as the WP Smush package.
3
  msgid ""
4
  msgstr ""
5
- "Project-Id-Version: WP Smush 2.0.6.2\n"
6
- "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/wp-smushit\n"
7
- "POT-Creation-Date: 2015-09-15 07:04:21+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=UTF-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
@@ -12,357 +12,396 @@ msgstr ""
12
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
  "Language-Team: LANGUAGE <LL@li.org>\n"
14
 
15
- #. #-#-#-#-# plugin.pot (WP Smush 2.0.6.2) #-#-#-#-#
16
- #. Plugin Name of the plugin/theme
17
- #: lib/class-wp-smush-admin.php:106 lib/class-wp-smush-admin.php:299
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  msgid "WP Smush"
19
  msgstr ""
20
 
21
- #: lib/class-wp-smush-admin.php:218 lib/class-wp-smush-admin.php:989
22
- #: lib/class-wp-smush-admin.php:1005
23
  msgid "Bulk Smush Now"
24
  msgstr ""
25
 
26
- #: lib/class-wp-smush-admin.php:220 lib/class-wp-smush-admin.php:1009
27
  msgid "Bulk Smush %d Attachments"
28
  msgstr ""
29
 
30
- #: lib/class-wp-smush-admin.php:224
31
  msgid "Smushing in Progress"
32
  msgstr ""
33
 
34
- #: lib/class-wp-smush-admin.php:225 lib/class-wp-smush-admin.php:999
35
  msgid "All Done!"
36
  msgstr ""
37
 
38
- #: lib/class-wp-smush-admin.php:227
39
  msgid "Ops!... something went wrong"
40
  msgstr ""
41
 
42
- #: lib/class-wp-smush-admin.php:228 wp-smush.php:711
43
  msgid "Super-Smush"
44
  msgstr ""
45
 
46
- #: lib/class-wp-smush-admin.php:229
47
  msgid "Smush it"
48
  msgstr ""
49
 
50
- #: lib/class-wp-smush-admin.php:230
51
  msgid "Smush Now"
52
  msgstr ""
53
 
54
- #: lib/class-wp-smush-admin.php:231
55
  msgid "Sending ..."
56
  msgstr ""
57
 
58
- #: lib/class-wp-smush-admin.php:232
59
  msgid "{{errors}} image(s) were skipped due to an error."
60
  msgstr ""
61
 
62
- #: lib/class-wp-smush-admin.php:233
63
  msgid "All images are Super-Smushed."
64
  msgstr ""
65
 
66
- #: lib/class-wp-smush-admin.php:271
67
- msgid "Auto-Smush images on upload"
 
 
 
 
 
 
 
 
68
  msgstr ""
69
 
70
- #: lib/class-wp-smush-admin.php:272
71
  msgid "Super-Smush images"
72
  msgstr ""
73
 
74
- #: lib/class-wp-smush-admin.php:272
75
- msgid "lossy optimization"
76
  msgstr ""
77
 
78
- #: lib/class-wp-smush-admin.php:273
79
- msgid "Backup original images"
80
  msgstr ""
81
 
82
- #: lib/class-wp-smush-admin.php:273
83
- msgid "this will nearly double the size of your uploads directory"
84
  msgstr ""
85
 
86
- #: lib/class-wp-smush-admin.php:297
87
  msgid "WP Smush Pro"
88
  msgstr ""
89
 
90
- #: lib/class-wp-smush-admin.php:305
91
- msgid "Thanks for using WP Smush Pro! You now can:"
92
  msgstr ""
93
 
94
- #: lib/class-wp-smush-admin.php:307 lib/class-wp-smush-admin.php:318
95
- msgid ""
96
- "\"Super-Smush\" your images with our intelligent multi-pass lossy "
97
- "compression. Get 2&times; more compression than lossless with almost no "
98
- "noticeable quality loss!"
99
  msgstr ""
100
 
101
- #: lib/class-wp-smush-admin.php:308 lib/class-wp-smush-admin.php:319
102
- msgid ""
103
- "Get the best lossless compression. We try multiple methods to squeeze every "
104
- "last byte out of your images."
105
  msgstr ""
106
 
107
- #: lib/class-wp-smush-admin.php:309
108
- msgid "Smush images up to 32MB."
109
  msgstr ""
110
 
111
- #: lib/class-wp-smush-admin.php:310
112
- msgid "Bulk smush ALL your images with one click!"
 
 
 
 
 
 
113
  msgstr ""
114
 
115
- #: lib/class-wp-smush-admin.php:311 lib/class-wp-smush-admin.php:322
116
- msgid ""
117
- "Keep a backup of your original un-smushed images in case you want to restore "
118
- "later."
119
  msgstr ""
120
 
121
- #: lib/class-wp-smush-admin.php:316
122
- msgid "Upgrade to WP Smush Pro to:"
 
 
 
 
 
 
123
  msgstr ""
124
 
125
- #: lib/class-wp-smush-admin.php:320
126
- msgid "Smush images greater than 1MB."
 
 
127
  msgstr ""
128
 
129
- #: lib/class-wp-smush-admin.php:321
130
- msgid "Bulk smush ALL your images with one click! No more rate limiting."
131
  msgstr ""
132
 
133
- #: lib/class-wp-smush-admin.php:323
134
- msgid ""
135
- "Access 24/7/365 support from <a href=\"https://premium.wpmudev.org/support/?"
136
- "utm_source=wordpress.org&utm_medium=plugin&utm_campaign=WP%20Smush%20Upgrade"
137
- "\">the best WordPress support team on the planet</a>."
138
  msgstr ""
139
 
140
- #: lib/class-wp-smush-admin.php:324
141
- msgid ""
142
- "Download <a href=\"https://premium.wpmudev.org/?utm_source=wordpress."
143
- "org&utm_medium=plugin&utm_campaign=WP%20Smush%20Upgrade\">350+ other premium "
144
- "plugins and themes</a> included in your membership."
145
  msgstr ""
146
 
147
- #: lib/class-wp-smush-admin.php:327
148
- msgid "Upgrade Now &raquo;"
149
  msgstr ""
150
 
151
- #: lib/class-wp-smush-admin.php:330
152
- msgid ""
153
- "Already upgraded to a WPMU DEV membership? Install and Login to our "
154
- "Dashboard plugin to enable Smush Pro features."
155
  msgstr ""
156
 
157
- #: lib/class-wp-smush-admin.php:339
158
- msgid "Activate WPMU DEV Dashboard"
159
  msgstr ""
160
 
161
- #: lib/class-wp-smush-admin.php:342
162
- msgid "Install WPMU DEV Dashboard"
163
  msgstr ""
164
 
165
- #: lib/class-wp-smush-admin.php:353 lib/class-wp-smush-admin.php:1058
166
- msgid "Settings"
167
  msgstr ""
168
 
169
- #: lib/class-wp-smush-admin.php:439
170
- msgid "Save Changes"
171
  msgstr ""
172
 
173
- #: lib/class-wp-smush-admin.php:511
174
- msgid ""
175
- "%d image is over 1MB so will be skipped using the free version of the plugin."
176
- msgid_plural ""
177
- "%d images are over 1MB so will be skipped using the free version of the "
178
- "plugin."
179
- msgstr[0] ""
180
- msgstr[1] ""
181
 
182
- #: lib/class-wp-smush-admin.php:520
183
- msgid "Smush in Bulk"
184
  msgstr ""
185
 
186
- #: lib/class-wp-smush-admin.php:525
187
- msgid "Congratulations, all your images are currently Smushed!"
188
  msgstr ""
189
 
190
- #: lib/class-wp-smush-admin.php:534
191
- msgid "%d attachment in your media library has not been smushed."
192
- msgid_plural ""
193
- "%d image attachments in your media library have not been smushed yet."
 
 
 
194
  msgstr[0] ""
195
  msgstr[1] ""
196
 
197
- #: lib/class-wp-smush-admin.php:538
198
- msgid "Remove size limit &raquo;"
199
  msgstr ""
200
 
201
- #: lib/class-wp-smush-admin.php:543
202
- msgid ""
203
- "Please be aware, smushing a large number of images can take a while "
204
- "depending on your server and network speed.\n"
205
- "\t\t\t\t\t\t<strong>You must keep this page open while the bulk smush is "
206
- "processing</strong>, but you can leave at any time and come back to continue "
207
- "where it left off."
208
  msgstr ""
209
 
210
- #: lib/class-wp-smush-admin.php:548
211
- msgid ""
212
- "Free accounts are limited to bulk smushing %d attachments per request. You "
213
- "will need to click to start a new bulk job after each %d attachments."
214
  msgstr ""
215
 
216
- #: lib/class-wp-smush-admin.php:549
217
- msgid "Remove limits &raquo;"
218
  msgstr ""
219
 
220
- #: lib/class-wp-smush-admin.php:569
221
- msgid ""
222
- "When you <a href=\"%s\">upload some images</a> they will be available to "
223
- "smush here."
224
  msgstr ""
225
 
226
- #: lib/class-wp-smush-admin.php:575 lib/class-wp-smush-admin.php:811
227
- msgid ""
228
- "You can also smush images individually from your <a href=\"%s\">Media "
229
- "Library</a>."
230
  msgstr ""
231
 
232
- #: lib/class-wp-smush-admin.php:627
233
- msgid "Reduced by "
234
  msgstr ""
235
 
236
- #: lib/class-wp-smush-admin.php:637
237
- msgid ""
238
- "<span class=\"done-count\">%d</span> of <span class=\"total-count\">%d</"
239
- "span> total attachments have been smushed"
240
  msgstr ""
241
 
242
- #: lib/class-wp-smush-admin.php:707
243
- msgid "You don't have permission to work with uploaded files."
244
  msgstr ""
245
 
246
- #: lib/class-wp-smush-admin.php:711
247
- msgid "No attachment ID was provided."
248
  msgstr ""
249
 
250
- #: lib/class-wp-smush-admin.php:781
251
- msgid "<p>Please <a href=\"%s\">upload some images</a>.</p>"
252
  msgstr ""
253
 
254
- #: lib/class-wp-smush-admin.php:799
255
- msgid "All your images are already smushed!"
256
  msgstr ""
257
 
258
- #: lib/class-wp-smush-admin.php:899
259
- msgid "<strong>%d of %d images</strong> were sent for smushing:"
260
  msgstr ""
261
 
262
- #: lib/class-wp-smush-admin.php:1185
263
- msgid "Super-Smush Images"
264
  msgstr ""
265
 
266
- #: lib/class-wp-smush-admin.php:1186
267
- msgid ""
268
- "We found attachments that were previously smushed losslessly. If desired you "
269
- "can Super-Smush them now for more savings with almost no noticeable quality "
270
- "loss."
271
  msgstr ""
272
 
273
- #: lib/class-wp-smush-admin.php:1194
274
- msgid ""
275
- "<span class=\"remaining-count\">%d</span> attachment left to Super-Smush"
276
- msgid_plural ""
277
- "<span class=\"remaining-count\">%d</span> attachments left to Super-Smush"
278
- msgstr[0] ""
279
- msgstr[1] ""
280
-
281
- #: wp-smush.php:141
282
- msgid "File path is empty"
283
  msgstr ""
284
 
285
- #: wp-smush.php:145
286
- msgid "File URL is empty"
287
  msgstr ""
288
 
289
- #: wp-smush.php:150
290
  msgid "Could not find %s"
291
  msgstr ""
292
 
293
- #: wp-smush.php:155
294
  msgid "%s is not writable"
295
  msgstr ""
296
 
297
- #: wp-smush.php:165
298
  msgid "Skipped (%s), image not found."
299
  msgstr ""
300
 
301
- #: wp-smush.php:170
302
  msgid "Skipped (%s), size limit exceeded."
303
  msgstr ""
304
 
305
- #: wp-smush.php:185
306
  msgid "Unknown API error"
307
  msgstr ""
308
 
309
- #: wp-smush.php:329
310
  msgid "Size '%s' not processed correctly"
311
  msgstr ""
312
 
313
- #: wp-smush.php:351 wp-smush.php:359
314
  msgid "Size 'full' not processed correctly"
315
  msgstr ""
316
 
317
- #: wp-smush.php:475
318
  msgid "Error posting to API: %s"
319
  msgstr ""
320
 
321
- #: wp-smush.php:481
322
  msgid "Error posting to API: %s %s"
323
  msgstr ""
324
 
325
- #: wp-smush.php:498
326
  msgid "Smush data corrupted, try again."
327
  msgstr ""
328
 
329
- #: wp-smush.php:514
330
  msgid "Image couldn't be smushed"
331
  msgstr ""
332
 
333
- #: wp-smush.php:685
334
  msgid "Error processing request"
335
  msgstr ""
336
 
337
- #: wp-smush.php:689
338
  msgid "Already Optimized"
339
  msgstr ""
340
 
341
- #: wp-smush.php:691
342
- msgid "Reduced by %s ( %01.1f%% )"
 
 
 
 
 
 
 
 
343
  msgstr ""
344
 
345
- #: wp-smush.php:717
 
 
 
 
346
  msgid "Not processed"
347
  msgstr ""
348
 
349
- #: wp-smush.php:723
350
  msgid "Smush Now!"
351
  msgstr ""
352
 
353
- #: wp-smush.php:869
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
354
  msgid "Get Fast"
355
  msgstr ""
 
 
 
356
 
357
  #. Plugin URI of the plugin/theme
358
  msgid "http://wordpress.org/extend/plugins/wp-smushit/"
359
  msgstr ""
360
 
361
  #. Description of the plugin/theme
362
- msgid ""
363
- "Reduce image file sizes, improve performance and boost your SEO using the "
364
- "free <a href=\"https://premium.wpmudev.org/\">WPMU DEV</a> WordPress Smush "
365
- "API."
366
  msgstr ""
367
 
368
  #. Author of the plugin/theme
2
  # This file is distributed under the same license as the WP Smush package.
3
  msgid ""
4
  msgstr ""
5
+ "Project-Id-Version: WP Smush 2.0.6.5\n"
6
+ "Report-Msgid-Bugs-To: http://wordpress.org/support/plugin/wp-smush\n"
7
+ "POT-Creation-Date: 2015-10-19 19:40:37+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=UTF-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
12
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
  "Language-Team: LANGUAGE <LL@li.org>\n"
14
 
15
+ #: extras/free-dashboard/module.php:388
16
+ msgid "We're happy that you've chosen to install %s! Are you interested in how to make the most of this plugin? How would you like a quick 5 day email crash course with actionable advice on building your membership site? Only the info you want, no subscription!"
17
+ msgstr ""
18
+
19
+ #: extras/free-dashboard/module.php:403 extras/free-dashboard/module.php:438
20
+ msgid "Thanks :)"
21
+ msgstr ""
22
+
23
+ #: extras/free-dashboard/module.php:406 extras/free-dashboard/module.php:445
24
+ msgid "Saving"
25
+ msgstr ""
26
+
27
+ #: extras/free-dashboard/module.php:407 extras/free-dashboard/module.php:446
28
+ msgid "No thanks"
29
+ msgstr ""
30
+
31
+ #: extras/free-dashboard/module.php:423
32
+ msgid "Hey %s, you've been using %s for a while now, and we hope you're happy with it."
33
+ msgstr ""
34
+
35
+ #: extras/free-dashboard/module.php:423
36
+ msgid "We've spent countless hours developing this free plugin for you, and we would really appreciate it if you dropped us a quick rating!"
37
+ msgstr ""
38
+
39
+ #: extras/free-dashboard/module.php:441
40
+ msgid "Rate %s"
41
+ msgstr ""
42
+
43
+ #: lib/class-wp-smush-admin.php:105 lib/class-wp-smush-admin.php:303
44
  msgid "WP Smush"
45
  msgstr ""
46
 
47
+ #: lib/class-wp-smush-admin.php:220 lib/class-wp-smush-admin.php:952
48
+ #: lib/class-wp-smush-admin.php:968
49
  msgid "Bulk Smush Now"
50
  msgstr ""
51
 
52
+ #: lib/class-wp-smush-admin.php:222 lib/class-wp-smush-admin.php:972
53
  msgid "Bulk Smush %d Attachments"
54
  msgstr ""
55
 
56
+ #: lib/class-wp-smush-admin.php:226
57
  msgid "Smushing in Progress"
58
  msgstr ""
59
 
60
+ #: lib/class-wp-smush-admin.php:227 lib/class-wp-smush-admin.php:962
61
  msgid "All Done!"
62
  msgstr ""
63
 
64
+ #: lib/class-wp-smush-admin.php:229
65
  msgid "Ops!... something went wrong"
66
  msgstr ""
67
 
68
+ #: lib/class-wp-smush-admin.php:230 lib/class-wp-smush.php:738
69
  msgid "Super-Smush"
70
  msgstr ""
71
 
72
+ #: lib/class-wp-smush-admin.php:231
73
  msgid "Smush it"
74
  msgstr ""
75
 
76
+ #: lib/class-wp-smush-admin.php:232
77
  msgid "Smush Now"
78
  msgstr ""
79
 
80
+ #: lib/class-wp-smush-admin.php:233
81
  msgid "Sending ..."
82
  msgstr ""
83
 
84
+ #: lib/class-wp-smush-admin.php:234
85
  msgid "{{errors}} image(s) were skipped due to an error."
86
  msgstr ""
87
 
88
+ #: lib/class-wp-smush-admin.php:235
89
  msgid "All images are Super-Smushed."
90
  msgstr ""
91
 
92
+ #: lib/class-wp-smush-admin.php:274
93
+ msgid "Smush images on upload"
94
+ msgstr ""
95
+
96
+ #: lib/class-wp-smush-admin.php:275
97
+ msgid "Smush Original Image"
98
+ msgstr ""
99
+
100
+ #: lib/class-wp-smush-admin.php:275
101
+ msgid "For very large dimension images like those taken with a digital camera, the original full size image is almost never embedded (and really shouldn't be). Because of this WP Smush preserves it unaltered by default. Check this box to smush every image size."
102
  msgstr ""
103
 
104
+ #: lib/class-wp-smush-admin.php:276
105
  msgid "Super-Smush images"
106
  msgstr ""
107
 
108
+ #: lib/class-wp-smush-admin.php:276
109
+ msgid "Lossy Image Compression"
110
  msgstr ""
111
 
112
+ #: lib/class-wp-smush-admin.php:277
113
+ msgid "Backup Original Images"
114
  msgstr ""
115
 
116
+ #: lib/class-wp-smush-admin.php:277
117
+ msgid "Will nearly double the size of your Uploads Directory"
118
  msgstr ""
119
 
120
+ #: lib/class-wp-smush-admin.php:301
121
  msgid "WP Smush Pro"
122
  msgstr ""
123
 
124
+ #: lib/class-wp-smush-admin.php:311 lib/class-wp-smush-admin.php:1021
125
+ msgid "Settings"
126
  msgstr ""
127
 
128
+ #: lib/class-wp-smush-admin.php:374
129
+ msgid "PRO FEATURES"
 
 
 
130
  msgstr ""
131
 
132
+ #: lib/class-wp-smush-admin.php:379
133
+ msgid "These features are available in Pro Version of the plugin."
 
 
134
  msgstr ""
135
 
136
+ #: lib/class-wp-smush-admin.php:402
137
+ msgid "Save Changes"
138
  msgstr ""
139
 
140
+ #: lib/class-wp-smush-admin.php:474
141
+ msgid "%d image is over 1MB so will be skipped using the free version of the plugin."
142
+ msgid_plural "%d images are over 1MB so will be skipped using the free version of the plugin."
143
+ msgstr[0] ""
144
+ msgstr[1] ""
145
+
146
+ #: lib/class-wp-smush-admin.php:483
147
+ msgid "Smush in Bulk"
148
  msgstr ""
149
 
150
+ #: lib/class-wp-smush-admin.php:488
151
+ msgid "Congratulations, all your images are currently Smushed!"
 
 
152
  msgstr ""
153
 
154
+ #: lib/class-wp-smush-admin.php:497
155
+ msgid "%d attachment in your media library has not been smushed."
156
+ msgid_plural "%d image attachments in your media library have not been smushed yet."
157
+ msgstr[0] ""
158
+ msgstr[1] ""
159
+
160
+ #: lib/class-wp-smush-admin.php:501
161
+ msgid "Remove size limit &raquo;"
162
  msgstr ""
163
 
164
+ #: lib/class-wp-smush-admin.php:506
165
+ msgid ""
166
+ "Please be aware, smushing a large number of images can take a while depending on your server and network speed.\n"
167
+ "\t\t\t\t\t\t<strong>You must keep this page open while the bulk smush is processing</strong>, but you can leave at any time and come back to continue where it left off."
168
  msgstr ""
169
 
170
+ #: lib/class-wp-smush-admin.php:511
171
+ msgid "Free accounts are limited to bulk smushing %d attachments per request. You will need to click to start a new bulk job after each %d attachments."
172
  msgstr ""
173
 
174
+ #: lib/class-wp-smush-admin.php:512
175
+ msgid "Remove limits &raquo;"
 
 
 
176
  msgstr ""
177
 
178
+ #: lib/class-wp-smush-admin.php:532
179
+ msgid "When you <a href=\"%s\">upload some images</a> they will be available to smush here."
 
 
 
180
  msgstr ""
181
 
182
+ #: lib/class-wp-smush-admin.php:538 lib/class-wp-smush-admin.php:774
183
+ msgid "You can also smush images individually from your <a href=\"%s\">Media Library</a>."
184
  msgstr ""
185
 
186
+ #: lib/class-wp-smush-admin.php:590
187
+ msgid "Reduced by "
 
 
188
  msgstr ""
189
 
190
+ #: lib/class-wp-smush-admin.php:600
191
+ msgid "<span class=\"done-count\">%d</span> of <span class=\"total-count\">%d</span> total attachments have been smushed"
192
  msgstr ""
193
 
194
+ #: lib/class-wp-smush-admin.php:670
195
+ msgid "You don't have permission to work with uploaded files."
196
  msgstr ""
197
 
198
+ #: lib/class-wp-smush-admin.php:674
199
+ msgid "No attachment ID was provided."
200
  msgstr ""
201
 
202
+ #: lib/class-wp-smush-admin.php:744
203
+ msgid "<p>Please <a href=\"%s\">upload some images</a>.</p>"
204
  msgstr ""
205
 
206
+ #: lib/class-wp-smush-admin.php:762
207
+ msgid "All your images are already smushed!"
208
+ msgstr ""
 
 
 
 
 
209
 
210
+ #: lib/class-wp-smush-admin.php:862
211
+ msgid "<strong>%d of %d images</strong> were sent for smushing:"
212
  msgstr ""
213
 
214
+ #: lib/class-wp-smush-admin.php:1148
215
+ msgid "Super-Smush Images"
216
  msgstr ""
217
 
218
+ #: lib/class-wp-smush-admin.php:1149
219
+ msgid "We found attachments that were previously smushed losslessly. If desired you can Super-Smush them now for more savings with almost no noticeable quality loss."
220
+ msgstr ""
221
+
222
+ #: lib/class-wp-smush-admin.php:1157
223
+ msgid "<span class=\"remaining-count\">%d</span> attachment left to Super-Smush"
224
+ msgid_plural "<span class=\"remaining-count\">%d</span> attachments left to Super-Smush"
225
  msgstr[0] ""
226
  msgstr[1] ""
227
 
228
+ #: lib/class-wp-smush-admin.php:1177
229
+ msgid "Thanks for using WP Smush Pro! You now can:"
230
  msgstr ""
231
 
232
+ #: lib/class-wp-smush-admin.php:1179 lib/class-wp-smush-admin.php:1191
233
+ msgid "Smush the original Full image sizes that are normally skipped by default."
 
 
 
 
 
234
  msgstr ""
235
 
236
+ #: lib/class-wp-smush-admin.php:1180 lib/class-wp-smush-admin.php:1192
237
+ msgid "\"Super-Smush\" your images with our intelligent multi-pass lossy compression. Get 2&times; more compression than lossless with almost no noticeable quality loss!"
 
 
238
  msgstr ""
239
 
240
+ #: lib/class-wp-smush-admin.php:1181 lib/class-wp-smush-admin.php:1193
241
+ msgid "Get the best lossless compression. We try multiple methods to squeeze every last byte out of your images."
242
  msgstr ""
243
 
244
+ #: lib/class-wp-smush-admin.php:1182
245
+ msgid "Smush images up to 32MB."
 
 
246
  msgstr ""
247
 
248
+ #: lib/class-wp-smush-admin.php:1183
249
+ msgid "Bulk smush ALL your images with one click!"
 
 
250
  msgstr ""
251
 
252
+ #: lib/class-wp-smush-admin.php:1184 lib/class-wp-smush-admin.php:1196
253
+ msgid "Keep a backup of your original un-smushed images in case you want to restore later."
254
  msgstr ""
255
 
256
+ #: lib/class-wp-smush-admin.php:1189
257
+ msgid "Upgrade to WP Smush Pro to:"
 
 
258
  msgstr ""
259
 
260
+ #: lib/class-wp-smush-admin.php:1194
261
+ msgid "Smush images greater than 1MB."
262
  msgstr ""
263
 
264
+ #: lib/class-wp-smush-admin.php:1195
265
+ msgid "Bulk smush ALL your images with one click! No more rate limiting."
266
  msgstr ""
267
 
268
+ #: lib/class-wp-smush-admin.php:1197
269
+ msgid "Access 24/7/365 support from <a href=\"https://premium.wpmudev.org/support/?utm_source=wordpress.org&utm_medium=plugin&utm_campaign=WP%20Smush%20Upgrade\">the best WordPress support team on the planet</a>."
270
  msgstr ""
271
 
272
+ #: lib/class-wp-smush-admin.php:1198
273
+ msgid "Download <a href=\"https://premium.wpmudev.org/?utm_source=wordpress.org&utm_medium=plugin&utm_campaign=WP%20Smush%20Upgrade\">350+ other premium plugins and themes</a> included in your membership."
274
  msgstr ""
275
 
276
+ #: lib/class-wp-smush-admin.php:1201
277
+ msgid "Upgrade Now &raquo;"
278
  msgstr ""
279
 
280
+ #: lib/class-wp-smush-admin.php:1204
281
+ msgid "Already upgraded to a WPMU DEV membership? Install and Login to our Dashboard plugin to enable Smush Pro features."
282
  msgstr ""
283
 
284
+ #: lib/class-wp-smush-admin.php:1213
285
+ msgid "Activate WPMU DEV Dashboard"
 
 
 
286
  msgstr ""
287
 
288
+ #: lib/class-wp-smush-admin.php:1216
289
+ msgid "Install WPMU DEV Dashboard"
 
 
 
 
 
 
 
 
290
  msgstr ""
291
 
292
+ #: lib/class-wp-smush.php:92
293
+ msgid "File path is empty"
294
  msgstr ""
295
 
296
+ #: lib/class-wp-smush.php:97
297
  msgid "Could not find %s"
298
  msgstr ""
299
 
300
+ #: lib/class-wp-smush.php:102
301
  msgid "%s is not writable"
302
  msgstr ""
303
 
304
+ #: lib/class-wp-smush.php:112
305
  msgid "Skipped (%s), image not found."
306
  msgstr ""
307
 
308
+ #: lib/class-wp-smush.php:117
309
  msgid "Skipped (%s), size limit exceeded."
310
  msgstr ""
311
 
312
+ #: lib/class-wp-smush.php:132
313
  msgid "Unknown API error"
314
  msgstr ""
315
 
316
+ #: lib/class-wp-smush.php:310
317
  msgid "Size '%s' not processed correctly"
318
  msgstr ""
319
 
320
+ #: lib/class-wp-smush.php:334 lib/class-wp-smush.php:342
321
  msgid "Size 'full' not processed correctly"
322
  msgstr ""
323
 
324
+ #: lib/class-wp-smush.php:477
325
  msgid "Error posting to API: %s"
326
  msgstr ""
327
 
328
+ #: lib/class-wp-smush.php:483
329
  msgid "Error posting to API: %s %s"
330
  msgstr ""
331
 
332
+ #: lib/class-wp-smush.php:500
333
  msgid "Smush data corrupted, try again."
334
  msgstr ""
335
 
336
+ #: lib/class-wp-smush.php:516
337
  msgid "Image couldn't be smushed"
338
  msgstr ""
339
 
340
+ #: lib/class-wp-smush.php:702
341
  msgid "Error processing request"
342
  msgstr ""
343
 
344
+ #: lib/class-wp-smush.php:706
345
  msgid "Already Optimized"
346
  msgstr ""
347
 
348
+ #: lib/class-wp-smush.php:708
349
+ msgid "%d images reduced "
350
+ msgstr ""
351
+
352
+ #: lib/class-wp-smush.php:708
353
+ msgid "Reduced "
354
+ msgstr ""
355
+
356
+ #: lib/class-wp-smush.php:709
357
+ msgid "by %s ( %01.1f%% )"
358
  msgstr ""
359
 
360
+ #: lib/class-wp-smush.php:714
361
+ msgid "Smush stats"
362
+ msgstr ""
363
+
364
+ #: lib/class-wp-smush.php:744
365
  msgid "Not processed"
366
  msgstr ""
367
 
368
+ #: lib/class-wp-smush.php:750
369
  msgid "Smush Now!"
370
  msgstr ""
371
 
372
+ #: lib/class-wp-smush.php:1017
373
+ msgid "For very large dimension images like those taken with a digital camera, the original full size image is almost never embedded (and really shouldn't be). Because of this WP Smush preserves it unaltered by default. Pro users can change this setting."
374
+ msgstr ""
375
+
376
+ #: lib/class-wp-smush.php:1018
377
+ msgid "Image couldn't be smushed as it exceeded the 1Mb size limit, Pro users can smush images with size upto 32Mb."
378
+ msgstr ""
379
+
380
+ #: lib/class-wp-smush.php:1020
381
+ msgid " Skipped"
382
+ msgstr ""
383
+
384
+ #: lib/class-wp-smush.php:1038
385
+ msgid "Image size"
386
+ msgstr ""
387
+
388
+ #: lib/class-wp-smush.php:1039
389
+ msgid "Savings"
390
+ msgstr ""
391
+
392
+ #: wp-smush.php:82
393
  msgid "Get Fast"
394
  msgstr ""
395
+ #. Plugin Name of the plugin/theme
396
+ msgid "WP Smush"
397
+ msgstr ""
398
 
399
  #. Plugin URI of the plugin/theme
400
  msgid "http://wordpress.org/extend/plugins/wp-smushit/"
401
  msgstr ""
402
 
403
  #. Description of the plugin/theme
404
+ msgid "Reduce image file sizes, improve performance and boost your SEO using the free <a href=\"https://premium.wpmudev.org/\">WPMU DEV</a> WordPress Smush API."
 
 
 
405
  msgstr ""
406
 
407
  #. Author of the plugin/theme
lib/class-wp-smush-admin.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /**
3
- * @package WP SmushIt
4
  * @subpackage Admin
5
  * @version 1.0
6
  *
@@ -84,7 +84,6 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
84
  /// Smush Upgrade
85
  add_action( 'admin_notices', array( $this, 'smush_upgrade' ) );
86
 
87
-
88
  $this->init_settings();
89
 
90
  }
@@ -142,6 +141,9 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
142
 
143
  // Enqueue js on Post screen (Edit screen for media )
144
  add_action( 'admin_print_scripts-post.php', array( $this, 'enqueue' ) );
 
 
 
145
  }
146
 
147
  /**
@@ -166,12 +168,12 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
166
  wp_register_script( 'wp-smushit-admin-js', WP_SMUSH_URL . 'assets/js/wp-smushit-admin.js', array(
167
  'jquery',
168
  'media-views'
169
- ), WP_SMUSH_VERSON );
170
  } else {
171
  wp_register_script( 'wp-smushit-admin-js', WP_SMUSH_URL . 'assets/js/wp-smushit-admin.js', array(
172
  'jquery',
173
  'underscore'
174
- ), WP_SMUSH_VERSON );
175
  }
176
  wp_register_script( 'wp-smushit-admin-media-js', WP_SMUSH_URL . 'assets/js/wp-smushit-admin-media.js', array( 'jquery' ), $WpSmush->version );
177
 
@@ -207,7 +209,7 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
207
 
208
  function localize() {
209
  global $pagenow;
210
- if ( ! isset( $pagenow ) || ! in_array( $pagenow, array( "post.php", "upload.php" ) ) ) {
211
  return;
212
  }
213
 
@@ -256,7 +258,8 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
256
  $data = array(
257
  'smushed' => $this->get_smushed_image_ids(),
258
  'unsmushed' => $this->ids,
259
- 'lossless' => $this->lossless_ids
 
260
  );
261
 
262
  wp_localize_script( 'wp-smushit-admin-js', 'wp_smushit_data', $data );
@@ -268,9 +271,10 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
268
  */
269
  function init_settings() {
270
  $this->settings = array(
271
- 'auto' => __( 'Auto-Smush images on upload', 'wp-smushit' ),
272
- 'lossy' => __( 'Super-Smush images', 'wp-smushit' ) . ' <small>(' . __( 'lossy optimization', 'wp-smushit' ) . ')</small>',
273
- 'backup' => __( 'Backup original images', 'wp-smushit' ) . ' <small>(' . __( 'this will nearly double the size of your uploads directory', 'wp-smushit' ) . ')</small>'
 
274
  );
275
  }
276
 
@@ -298,55 +302,9 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
298
  } else {
299
  _e( 'WP Smush', 'wp-smushit' );
300
  } ?>
301
- </h2>
302
-
303
- <?php if ( $this->is_pro() ) { ?>
304
- <div class="wp-smpushit-features updated">
305
- <h3><?php _e( 'Thanks for using WP Smush Pro! You now can:', 'wp-smushit' ) ?></h3>
306
- <ol>
307
- <li><?php _e( '"Super-Smush" your images with our intelligent multi-pass lossy compression. Get 2&times; more compression than lossless with almost no noticeable quality loss!', 'wp-smushit' ); ?></li>
308
- <li><?php _e( 'Get the best lossless compression. We try multiple methods to squeeze every last byte out of your images.', 'wp-smushit' ); ?></li>
309
- <li><?php _e( 'Smush images up to 32MB.', 'wp-smushit' ); ?></li>
310
- <li><?php _e( 'Bulk smush ALL your images with one click!', 'wp-smushit' ); ?></li>
311
- <li><?php _e( 'Keep a backup of your original un-smushed images in case you want to restore later.', 'wp-smushit' ); ?></li>
312
- </ol>
313
- </div>
314
- <?php } else { ?>
315
- <div class="wp-smpushit-features error">
316
- <h3><?php _e( 'Upgrade to WP Smush Pro to:', 'wp-smushit' ) ?></h3>
317
- <ol>
318
- <li><?php _e( '"Super-Smush" your images with our intelligent multi-pass lossy compression. Get 2&times; more compression than lossless with almost no noticeable quality loss!', 'wp-smushit' ); ?></li>
319
- <li><?php _e( 'Get the best lossless compression. We try multiple methods to squeeze every last byte out of your images.', 'wp-smushit' ); ?></li>
320
- <li><?php _e( 'Smush images greater than 1MB.', 'wp-smushit' ); ?></li>
321
- <li><?php _e( 'Bulk smush ALL your images with one click! No more rate limiting.', 'wp-smushit' ); ?></li>
322
- <li><?php _e( 'Keep a backup of your original un-smushed images in case you want to restore later.', 'wp-smushit' ); ?></li>
323
- <li><?php _e( 'Access 24/7/365 support from <a href="https://premium.wpmudev.org/support/?utm_source=wordpress.org&utm_medium=plugin&utm_campaign=WP%20Smush%20Upgrade">the best WordPress support team on the planet</a>.', 'wp-smushit' ); ?></li>
324
- <li><?php _e( 'Download <a href="https://premium.wpmudev.org/?utm_source=wordpress.org&utm_medium=plugin&utm_campaign=WP%20Smush%20Upgrade">350+ other premium plugins and themes</a> included in your membership.', 'wp-smushit' ); ?></li>
325
- </ol>
326
- <p>
327
- <a class="button-primary" href="<?php echo $this->upgrade_url; ?>"><?php _e( 'Upgrade Now &raquo;', 'wp-smushit' ); ?></a>
328
- </p>
329
-
330
- <p><?php _e( 'Already upgraded to a WPMU DEV membership? Install and Login to our Dashboard plugin to enable Smush Pro features.', 'wp-smushit' ); ?></p>
331
-
332
- <p>
333
- <?php
334
- if ( ! class_exists( 'WPMUDEV_Dashboard' ) ) {
335
- if ( file_exists( WP_PLUGIN_DIR . '/wpmudev-updates/update-notifications.php' ) ) {
336
- $function = is_multisite() ? 'network_admin_url' : 'admin_url';
337
- $url = wp_nonce_url( $function( 'plugins.php?action=activate&plugin=wpmudev-updates%2Fupdate-notifications.php' ), 'activate-plugin_wpmudev-updates/update-notifications.php' );
338
- ?><a class="button-secondary"
339
- href="<?php echo $url; ?>"><?php _e( 'Activate WPMU DEV Dashboard', 'wp-smushit' ); ?></a><?php
340
- } else { //dashboard not installed at all
341
- ?><a class="button-secondary" target="_blank"
342
- href="https://premium.wpmudev.org/project/wpmu-dev-dashboard/"><?php _e( 'Install WPMU DEV Dashboard', 'wp-smushit' ); ?></a><?php
343
- }
344
- }
345
- ?>
346
- </p>
347
- </div>
348
- <?php } ?>
349
-
350
 
351
  <div class="wp-smpushit-container">
352
  <h3>
@@ -385,6 +343,11 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
385
  $opt_auto_val = 1;
386
  }
387
 
 
 
 
 
 
388
  //Smush auto key
389
  $opt_lossy = WP_SMUSH_PREFIX . 'lossy';
390
  //Auto value
@@ -396,41 +359,41 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
396
  $opt_backup_val = get_option( $opt_backup, false );
397
 
398
  //disable lossy for non-premium members
399
- $disabled = $class = '';
400
  if ( ! $this->is_pro() ) {
401
  $disabled = ' disabled';
402
  $opt_lossy_val = $opt_backup_val = 0;
403
  $class = ' inactive inactive-anim';
404
- }
405
-
406
- // return html
407
- printf(
408
- "<div class='wp-smush-setting-row'><label><input type='checkbox' name='%1\$s' id='%1\$s' value='1' %2\$s %3\$s>%4\$s</label></div>", esc_attr( $opt_auto ), checked( $opt_auto_val, 1, false ), '', $this->settings['auto']
409
- );
410
- ?>
411
- <div class="pro-only<?php echo $class; ?>"><?php
412
-
413
- //Lossy
414
- printf(
415
- "<div class='wp-smush-setting-row'><label><input type='checkbox' name='%1\$s' id='%1\$s' value='1' %2\$s %3\$s>%4\$s</label></div>", esc_attr( $opt_lossy ), checked( $opt_lossy_val, 1, false ), $disabled, $this->settings['lossy']
416
- );
417
 
418
- //Backup
419
- printf(
420
- "<div class='wp-smush-setting-row'><label><input type='checkbox' name='%1\$s' id='%1\$s' value='1' %2\$s %3\$s>%4\$s</label></div>", esc_attr( $opt_backup ), checked( $opt_backup_val, 1, false ), $disabled, $this->settings['backup']
421
- );
422
  if ( ! $this->is_pro() ) {
423
  ?>
424
  <div class="pro-note">
425
- <div style="padding:14px 0 14px;">Pro feature only.
426
- <a href="<?php echo $this->upgrade_url; ?>" target="_blank">Find out more »</a>
427
  </div>
428
  </div>
429
- <?php
 
430
  }
431
- ?>
432
- </div>
433
- <!-- End of pro-only -->
 
 
 
 
 
 
 
 
434
  </div>
435
  <!-- End of wrap --><?php
436
  // nonce
@@ -438,7 +401,7 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
438
  ?>
439
  <input type="submit" id="wp-smush-save-settings" class="button button-primary" value="<?php _e( 'Save Changes', 'wp-smushit' ); ?>">
440
  </form>
441
- <?php
442
  }
443
 
444
  /**
@@ -567,7 +530,7 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
567
  if ( ! $auto_smush && $this->remaining_count == 0 ) {
568
  ?>
569
  <p><?php printf( __( 'When you <a href="%s">upload some images</a> they will be available to smush here.', 'wp-smushit' ), admin_url( 'media-new.php' ) ); ?></p>
570
- <?php
571
  } else { ?>
572
  <p>
573
  <?php
@@ -578,7 +541,7 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
578
  }
579
  ?>
580
  </div>
581
- <?php
582
  }
583
 
584
  function print_loader() {
@@ -603,7 +566,7 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
603
  </div>
604
  </div>
605
  </div>
606
- <?php
607
  }
608
 
609
  /**
@@ -799,7 +762,7 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
799
  _e( 'All your images are already smushed!', 'wp-smushit' );
800
  ?>
801
  </p>
802
- <?php
803
  } else {
804
  $this->selected_ui( $send_ids, '' );
805
  // we have some smushing to do! :)
@@ -811,7 +774,7 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
811
  printf( __( 'You can also smush images individually from your <a href="%s">Media Library</a>.', 'wp-smushit' ), admin_url( 'upload.php' ) );
812
  ?>
813
  </p>
814
- <?php
815
  }
816
 
817
  // display the progress bar
@@ -822,7 +785,7 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
822
 
823
  ?>
824
  </div>
825
- <?php
826
  }
827
 
828
  /**
@@ -912,7 +875,7 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
912
  ?>
913
  </ul>
914
  </div>
915
- <?php
916
  }
917
 
918
  /**
@@ -927,7 +890,7 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
927
  <button class="button button-primary<?php echo ' ' . $button['class']; ?>" name="smush-all" <?php echo $disabled; ?>>
928
  <span><?php echo $button['text'] ?></span>
929
  </button>
930
- <?php
931
  }
932
 
933
  function global_stats() {
@@ -1063,7 +1026,7 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
1063
  }
1064
 
1065
  function smush_upgrade() {
1066
- if ( ! current_user_can( 'edit_others_posts' ) ) {
1067
  return;
1068
  }
1069
 
@@ -1079,7 +1042,7 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
1079
  return;
1080
  }
1081
  ?>
1082
- <div class="error">
1083
  <a href="<?php echo admin_url( 'index.php' ); ?>?dismiss_smush_upgrade=1" style="float:right;margin-top: 10px;text-decoration: none;"><span class="dashicons dashicons-dismiss" style="color:gray;"></span>Dismiss</a>
1084
 
1085
  <h3><span class="dashicons dashicons-megaphone" style="color:red"></span> Happy Smushing!</h3>
@@ -1096,7 +1059,7 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
1096
  <a href="https://premium.wpmudev.org/?coupon=SMUSH50OFF#pricing"> Click here to upgrade with a 50%
1097
  discount</a>.</p>
1098
  </div>
1099
- <?php
1100
  }
1101
 
1102
  /**
@@ -1191,16 +1154,73 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
1191
  <div id="wp-smush-ss-progress" class="wp-smush-progressbar"><div style="width:0%"></div></div>
1192
  <p id="wp-smush-compression">'
1193
  . sprintf(
1194
- _n( '<span class="remaining-count">%d</span> attachment left to Super-Smush',
1195
- '<span class="remaining-count">%d</span> attachments left to Super-Smush',
1196
- count( $this->lossless_ids ),
1197
- 'wp-smushit' ), count( $this->lossless_ids ), count( $this->lossless_ids ) )
1198
  . '</p>
1199
  </div>
1200
  </div><!-- End of progress ui -->';
1201
  echo $ss_progress_ui;
1202
  $this->setup_button( true );
1203
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1204
  }
1205
 
1206
  $wpsmushit_admin = new WpSmushitAdmin();
1
  <?php
2
  /**
3
+ * @package WP Smush
4
  * @subpackage Admin
5
  * @version 1.0
6
  *
84
  /// Smush Upgrade
85
  add_action( 'admin_notices', array( $this, 'smush_upgrade' ) );
86
 
 
87
  $this->init_settings();
88
 
89
  }
141
 
142
  // Enqueue js on Post screen (Edit screen for media )
143
  add_action( 'admin_print_scripts-post.php', array( $this, 'enqueue' ) );
144
+
145
+ // Enqueue js on Post screen (Edit screen for media )
146
+ add_action( 'admin_print_scripts-post-new.php', array( $this, 'enqueue' ) );
147
  }
148
 
149
  /**
168
  wp_register_script( 'wp-smushit-admin-js', WP_SMUSH_URL . 'assets/js/wp-smushit-admin.js', array(
169
  'jquery',
170
  'media-views'
171
+ ), WP_SMUSH_VERSION );
172
  } else {
173
  wp_register_script( 'wp-smushit-admin-js', WP_SMUSH_URL . 'assets/js/wp-smushit-admin.js', array(
174
  'jquery',
175
  'underscore'
176
+ ), WP_SMUSH_VERSION );
177
  }
178
  wp_register_script( 'wp-smushit-admin-media-js', WP_SMUSH_URL . 'assets/js/wp-smushit-admin-media.js', array( 'jquery' ), $WpSmush->version );
179
 
209
 
210
  function localize() {
211
  global $pagenow;
212
+ if ( ! isset( $pagenow ) || ! in_array( $pagenow, array( "post.php", "upload.php", "post-new.php" ) ) ) {
213
  return;
214
  }
215
 
258
  $data = array(
259
  'smushed' => $this->get_smushed_image_ids(),
260
  'unsmushed' => $this->ids,
261
+ 'lossless' => $this->lossless_ids,
262
+ 'timeout' => WP_SMUSH_TIMEOUT * 1000 //Convert it into ms
263
  );
264
 
265
  wp_localize_script( 'wp-smushit-admin-js', 'wp_smushit_data', $data );
271
  */
272
  function init_settings() {
273
  $this->settings = array(
274
+ 'auto' => __( 'Smush images on upload', 'wp-smushit' ),
275
+ 'original' => __( 'Smush Original Image', 'wp-smushit' ) . '<span class="dashicons dashicons-info smush-original" title="' . __( "For very large dimension images like those taken with a digital camera, the original full size image is almost never embedded (and really shouldn't be). Because of this WP Smush preserves it unaltered by default. Check this box to smush every image size.", 'wp-smushit' ) . '"></span>',
276
+ 'lossy' => __( 'Super-Smush images', 'wp-smushit' ) . ' <small>(' . __( 'Lossy Image Compression', 'wp-smushit' ) . ')</small>',
277
+ 'backup' => __( 'Backup Original Images', 'wp-smushit' ) . ' <small>(' . __( 'Will nearly double the size of your Uploads Directory', 'wp-smushit' ) . ')</small>'
278
  );
279
  }
280
 
302
  } else {
303
  _e( 'WP Smush', 'wp-smushit' );
304
  } ?>
305
+ </h2><?php
306
+ $this->smush_pro_features();
307
+ ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
308
 
309
  <div class="wp-smpushit-container">
310
  <h3>
343
  $opt_auto_val = 1;
344
  }
345
 
346
+ //Smush auto key
347
+ $opt_original = WP_SMUSH_PREFIX . 'original';
348
+ //Auto value
349
+ $opt_original_val = get_option( $opt_original, false );
350
+
351
  //Smush auto key
352
  $opt_lossy = WP_SMUSH_PREFIX . 'lossy';
353
  //Auto value
359
  $opt_backup_val = get_option( $opt_backup, false );
360
 
361
  //disable lossy for non-premium members
362
+ $disabled = $class = $feature_class = '';
363
  if ( ! $this->is_pro() ) {
364
  $disabled = ' disabled';
365
  $opt_lossy_val = $opt_backup_val = 0;
366
  $class = ' inactive inactive-anim';
367
+ } ?>
368
+ <div class='wp-smush-setting-row'><?php
369
+ // return html
370
+ printf( "<label><input type='checkbox' name='%1\$s' id='%1\$s' value='1' %2\$s %3\$s>%4\$s</label>", esc_attr( $opt_auto ), checked( $opt_auto_val, 1, false ), '', $this->settings['auto'] );
371
+ ?>
372
+ </div>
373
+ <fieldset class="wp-smush-pro-features">
374
+ <legend><strong><?php esc_html_e( "PRO FEATURES", "wp-smushit" ); ?></strong></legend><?php
 
 
 
 
 
375
 
 
 
 
 
376
  if ( ! $this->is_pro() ) {
377
  ?>
378
  <div class="pro-note">
379
+ <div style="padding:14px 0 14px;"><span class="dashicons dashicons-info"></span><?php esc_html_e( "These features are available in Pro Version of the plugin.", "wp-smushit" ); ?>
380
+ <a href="<?php echo $this->upgrade_url; ?>" target="_blank" class="button find-out-link">Find out more »</a>
381
  </div>
382
  </div>
383
+ <?php
384
+ $feature_class = ' disabled';
385
  }
386
+
387
+ //Smush Original
388
+ printf( "<div class='wp-smush-setting-row%5\$s'><label><input type='checkbox' name='%1\$s' id='%1\$s' value='1' %2\$s %3\$s>%4\$s</label></div>", esc_attr( $opt_original ), checked( $opt_original_val, 1, false ), $disabled, $this->settings['original'], $feature_class );
389
+
390
+ //Lossy
391
+ printf( "<div class='wp-smush-setting-row%5\$s'><label><input type='checkbox' name='%1\$s' id='%1\$s' value='1' %2\$s %3\$s>%4\$s</label></div>", esc_attr( $opt_lossy ), checked( $opt_lossy_val, 1, false ), $disabled, $this->settings['lossy'], $feature_class );
392
+
393
+ //Backup
394
+ printf( "<div class='wp-smush-setting-row%5\$s'><label><input type='checkbox' name='%1\$s' id='%1\$s' value='1' %2\$s %3\$s>%4\$s</label></div>", esc_attr( $opt_backup ), checked( $opt_backup_val, 1, false ), $disabled, $this->settings['backup'], $feature_class ); ?>
395
+ <!-- End of pro-only -->
396
+ </fieldset>
397
  </div>
398
  <!-- End of wrap --><?php
399
  // nonce
401
  ?>
402
  <input type="submit" id="wp-smush-save-settings" class="button button-primary" value="<?php _e( 'Save Changes', 'wp-smushit' ); ?>">
403
  </form>
404
+ <?php
405
  }
406
 
407
  /**
530
  if ( ! $auto_smush && $this->remaining_count == 0 ) {
531
  ?>
532
  <p><?php printf( __( 'When you <a href="%s">upload some images</a> they will be available to smush here.', 'wp-smushit' ), admin_url( 'media-new.php' ) ); ?></p>
533
+ <?php
534
  } else { ?>
535
  <p>
536
  <?php
541
  }
542
  ?>
543
  </div>
544
+ <?php
545
  }
546
 
547
  function print_loader() {
566
  </div>
567
  </div>
568
  </div>
569
+ <?php
570
  }
571
 
572
  /**
762
  _e( 'All your images are already smushed!', 'wp-smushit' );
763
  ?>
764
  </p>
765
+ <?php
766
  } else {
767
  $this->selected_ui( $send_ids, '' );
768
  // we have some smushing to do! :)
774
  printf( __( 'You can also smush images individually from your <a href="%s">Media Library</a>.', 'wp-smushit' ), admin_url( 'upload.php' ) );
775
  ?>
776
  </p>
777
+ <?php
778
  }
779
 
780
  // display the progress bar
785
 
786
  ?>
787
  </div>
788
+ <?php
789
  }
790
 
791
  /**
875
  ?>
876
  </ul>
877
  </div>
878
+ <?php
879
  }
880
 
881
  /**
890
  <button class="button button-primary<?php echo ' ' . $button['class']; ?>" name="smush-all" <?php echo $disabled; ?>>
891
  <span><?php echo $button['text'] ?></span>
892
  </button>
893
+ <?php
894
  }
895
 
896
  function global_stats() {
1026
  }
1027
 
1028
  function smush_upgrade() {
1029
+ if ( ! current_user_can( 'edit_others_posts' ) || ! is_super_admin() ) {
1030
  return;
1031
  }
1032
 
1042
  return;
1043
  }
1044
  ?>
1045
+ <div class="updated">
1046
  <a href="<?php echo admin_url( 'index.php' ); ?>?dismiss_smush_upgrade=1" style="float:right;margin-top: 10px;text-decoration: none;"><span class="dashicons dashicons-dismiss" style="color:gray;"></span>Dismiss</a>
1047
 
1048
  <h3><span class="dashicons dashicons-megaphone" style="color:red"></span> Happy Smushing!</h3>
1059
  <a href="https://premium.wpmudev.org/?coupon=SMUSH50OFF#pricing"> Click here to upgrade with a 50%
1060
  discount</a>.</p>
1061
  </div>
1062
+ <?php
1063
  }
1064
 
1065
  /**
1154
  <div id="wp-smush-ss-progress" class="wp-smush-progressbar"><div style="width:0%"></div></div>
1155
  <p id="wp-smush-compression">'
1156
  . sprintf(
1157
+ _n( '<span class="remaining-count">%d</span> attachment left to Super-Smush',
1158
+ '<span class="remaining-count">%d</span> attachments left to Super-Smush',
1159
+ count( $this->lossless_ids ),
1160
+ 'wp-smushit' ), count( $this->lossless_ids ), count( $this->lossless_ids ) )
1161
  . '</p>
1162
  </div>
1163
  </div><!-- End of progress ui -->';
1164
  echo $ss_progress_ui;
1165
  $this->setup_button( true );
1166
  }
1167
+
1168
+ /**
1169
+ * Displays the features available in Smush pro
1170
+ */
1171
+ function smush_pro_features() {
1172
+ if ( ! is_super_admin() ) {
1173
+ return;
1174
+ }
1175
+ if ( $this->is_pro() ) { ?>
1176
+ <div class="wp-smpushit-features updated">
1177
+ <h3><?php _e( 'Thanks for using WP Smush Pro! You now can:', 'wp-smushit' ) ?></h3>
1178
+ <ol>
1179
+ <li><?php _e( 'Smush the original Full image sizes that are normally skipped by default.', 'wp-smushit' ); ?></li>
1180
+ <li><?php _e( '"Super-Smush" your images with our intelligent multi-pass lossy compression. Get 2&times; more compression than lossless with almost no noticeable quality loss!', 'wp-smushit' ); ?></li>
1181
+ <li><?php _e( 'Get the best lossless compression. We try multiple methods to squeeze every last byte out of your images.', 'wp-smushit' ); ?></li>
1182
+ <li><?php _e( 'Smush images up to 32MB.', 'wp-smushit' ); ?></li>
1183
+ <li><?php _e( 'Bulk smush ALL your images with one click!', 'wp-smushit' ); ?></li>
1184
+ <li><?php _e( 'Keep a backup of your original un-smushed images in case you want to restore later.', 'wp-smushit' ); ?></li>
1185
+ </ol>
1186
+ </div>
1187
+ <?php } else { ?>
1188
+ <div class="wp-smpushit-features error">
1189
+ <h3><?php _e( 'Upgrade to WP Smush Pro to:', 'wp-smushit' ) ?></h3>
1190
+ <ol>
1191
+ <li><?php _e( 'Smush the original Full image sizes that are normally skipped by default.', 'wp-smushit' ); ?></li>
1192
+ <li><?php _e( '"Super-Smush" your images with our intelligent multi-pass lossy compression. Get 2&times; more compression than lossless with almost no noticeable quality loss!', 'wp-smushit' ); ?></li>
1193
+ <li><?php _e( 'Get the best lossless compression. We try multiple methods to squeeze every last byte out of your images.', 'wp-smushit' ); ?></li>
1194
+ <li><?php _e( 'Smush images greater than 1MB.', 'wp-smushit' ); ?></li>
1195
+ <li><?php _e( 'Bulk smush ALL your images with one click! No more rate limiting.', 'wp-smushit' ); ?></li>
1196
+ <li><?php _e( 'Keep a backup of your original un-smushed images in case you want to restore later.', 'wp-smushit' ); ?></li>
1197
+ <li><?php _e( 'Access 24/7/365 support from <a href="https://premium.wpmudev.org/support/?utm_source=wordpress.org&utm_medium=plugin&utm_campaign=WP%20Smush%20Upgrade">the best WordPress support team on the planet</a>.', 'wp-smushit' ); ?></li>
1198
+ <li><?php _e( 'Download <a href="https://premium.wpmudev.org/?utm_source=wordpress.org&utm_medium=plugin&utm_campaign=WP%20Smush%20Upgrade">350+ other premium plugins and themes</a> included in your membership.', 'wp-smushit' ); ?></li>
1199
+ </ol>
1200
+ <p>
1201
+ <a class="button-primary" href="<?php echo $this->upgrade_url; ?>"><?php _e( 'Upgrade Now &raquo;', 'wp-smushit' ); ?></a>
1202
+ </p>
1203
+
1204
+ <p><?php _e( 'Already upgraded to a WPMU DEV membership? Install and Login to our Dashboard plugin to enable Smush Pro features.', 'wp-smushit' ); ?></p>
1205
+
1206
+ <p>
1207
+ <?php
1208
+ if ( ! class_exists( 'WPMUDEV_Dashboard' ) ) {
1209
+ if ( file_exists( WP_PLUGIN_DIR . '/wpmudev-updates/update-notifications.php' ) ) {
1210
+ $function = is_multisite() ? 'network_admin_url' : 'admin_url';
1211
+ $url = wp_nonce_url( $function( 'plugins.php?action=activate&plugin=wpmudev-updates%2Fupdate-notifications.php' ), 'activate-plugin_wpmudev-updates/update-notifications.php' );
1212
+ ?><a class="button-secondary"
1213
+ href="<?php echo $url; ?>"><?php _e( 'Activate WPMU DEV Dashboard', 'wp-smushit' ); ?></a><?php
1214
+ } else { //dashboard not installed at all
1215
+ ?><a class="button-secondary" target="_blank"
1216
+ href="https://premium.wpmudev.org/project/wpmu-dev-dashboard/"><?php _e( 'Install WPMU DEV Dashboard', 'wp-smushit' ); ?></a><?php
1217
+ }
1218
+ }
1219
+ ?>
1220
+ </p>
1221
+ </div>
1222
+ <?php }
1223
+ }
1224
  }
1225
 
1226
  $wpsmushit_admin = new WpSmushitAdmin();
lib/class-wp-smush.php ADDED
@@ -0,0 +1,1098 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once WP_SMUSH_DIR . "lib/class-wp-smush-migrate.php";
3
+ if ( ! class_exists( 'WpSmush' ) ) {
4
+
5
+ class WpSmush {
6
+
7
+ var $version = WP_SMUSH_VERSION;
8
+
9
+ var $is_pro;
10
+
11
+ /**
12
+ * Meta key for api validity
13
+ *
14
+ */
15
+ const VALIDITY_KEY = "wp-smush-valid";
16
+
17
+ /**
18
+ * Api server url to check api key validity
19
+ *
20
+ */
21
+ const API_SERVER = 'https://premium.wpmudev.org/wdp-un.php?action=smushit_check';
22
+
23
+ /**
24
+ * Meta key to save smush result to db
25
+ *
26
+ *
27
+ */
28
+ const SMUSHED_META_KEY = 'wp-smpro-smush-data';
29
+
30
+ /**
31
+ * Meta key to save migrated version
32
+ *
33
+ */
34
+ const MIGRATED_VERSION = "wp-smush-migrated-version";
35
+
36
+ /**
37
+ * Constructor
38
+ */
39
+ function __construct() {
40
+ /**
41
+ * Hooks
42
+ */
43
+ //Check if auto is enabled
44
+ $auto_smush = get_option( WP_SMUSH_PREFIX . 'auto' );
45
+
46
+ //Keep the uto smush on by default
47
+ if ( $auto_smush === false ) {
48
+ $auto_smush = 1;
49
+ }
50
+
51
+ //Auto Smush the new image
52
+ if ( $auto_smush ) {
53
+ add_filter( 'wp_update_attachment_metadata', array(
54
+ $this,
55
+ 'filter_generate_attachment_metadata'
56
+ ), 12, 2 );
57
+ }
58
+
59
+ //Optimise WP Retina 2x images
60
+ add_action( 'wr2x_retina_file_added', array( $this, 'smush_retina_image' ), 20, 3 );
61
+
62
+ //Add Smush Columns
63
+ add_filter( 'manage_media_columns', array( $this, 'columns' ) );
64
+ add_action( 'manage_media_custom_column', array( $this, 'custom_column' ), 10, 2 );
65
+
66
+ //Enqueue Scripts
67
+ add_action( 'admin_init', array( $this, 'admin_init' ) );
68
+
69
+ //Old Smush stats migration
70
+ add_action( "admin_init", array( $this, "migrate" ) );
71
+
72
+ }
73
+
74
+ function admin_init() {
75
+ load_plugin_textdomain( 'wp-smushit', false, dirname( WP_SMUSH_BASENAME ) . '/languages/' );
76
+ wp_enqueue_script( 'common' );
77
+ }
78
+
79
+ /**
80
+ * Process an image with Smush.
81
+ *
82
+ * Returns an array of the $file $results.
83
+ *
84
+ * @param string $file Full absolute path to the image file
85
+ * @param string $file_url Optional full URL to the image file
86
+ *
87
+ * @returns array
88
+ */
89
+ function do_smushit( $file_path = '' ) {
90
+ $errors = new WP_Error();
91
+ if ( empty( $file_path ) ) {
92
+ $errors->add( "empty_path", __( "File path is empty", 'wp-smushit' ) );
93
+ }
94
+
95
+ // check that the file exists
96
+ if ( ! file_exists( $file_path ) || ! is_file( $file_path ) ) {
97
+ $errors->add( "file_not_found", sprintf( __( "Could not find %s", 'wp-smushit' ), $file_path ) );
98
+ }
99
+
100
+ // check that the file is writable
101
+ if ( ! is_writable( dirname( $file_path ) ) ) {
102
+ $errors->add( "not_writable", sprintf( __( "%s is not writable", 'wp-smushit' ), dirname( $file_path ) ) );
103
+ }
104
+
105
+ $file_size = filesize( $file_path );
106
+
107
+ //Check if premium user
108
+ $max_size = $this->is_pro() ? WP_SMUSH_PREMIUM_MAX_BYTES : WP_SMUSH_MAX_BYTES;
109
+
110
+ //Check if file exists
111
+ if ( $file_size == 0 ) {
112
+ $errors->add( "image_not_found", sprintf( __( 'Skipped (%s), image not found.', 'wp-smushit' ), $this->format_bytes( $file_size ) ) );
113
+ }
114
+
115
+ //Check size limit
116
+ if ( $file_size > $max_size ) {
117
+ $errors->add( "size_limit", sprintf( __( 'Skipped (%s), size limit exceeded.', 'wp-smushit' ), $this->format_bytes( $file_size ) ) );
118
+ }
119
+
120
+ if ( count( $errors->get_error_messages() ) ) {
121
+ return $errors;
122
+ }
123
+
124
+ /** Send image for smushing, and fetch the response */
125
+ $response = $this->_post( $file_path, $file_size );
126
+
127
+ if ( ! $response['success'] ) {
128
+ $errors->add( "false_response", $response['message'] );
129
+ }
130
+ //If there is no data
131
+ if ( empty( $response['data'] ) ) {
132
+ $errors->add( "no_data", __( 'Unknown API error', 'wp-smushit' ) );
133
+ }
134
+
135
+ if ( count( $errors->get_error_messages() ) ) {
136
+ return $errors;
137
+ }
138
+
139
+ //If there are no savings, or image returned is bigger in size
140
+ if ( ( ! empty( $response['data']->bytes_saved ) && intval( $response['data']->bytes_saved ) <= 0 )
141
+ || empty( $response['data']->image )
142
+ ) {
143
+ return $response;
144
+ }
145
+ $tempfile = $file_path . ".tmp";
146
+
147
+ //Add the file as tmp
148
+ file_put_contents( $tempfile, $response['data']->image );
149
+
150
+ //handle backups if enabled
151
+ $backup = get_option( WP_SMUSH_PREFIX . 'backup' );
152
+ if ( $backup && $this->is_pro() ) {
153
+ $path = pathinfo( $file_path );
154
+ $backup_name = trailingslashit( $path['dirname'] ) . $path['filename'] . ".bak." . $path['extension'];
155
+ @copy( $file_path, $backup_name );
156
+ }
157
+
158
+ //replace the file
159
+ $success = @rename( $tempfile, $file_path );
160
+
161
+ //if tempfile still exists, unlink it
162
+ if ( file_exists( $tempfile ) ) {
163
+ unlink( $tempfile );
164
+ }
165
+
166
+ //If file renaming failed
167
+ if ( ! $success ) {
168
+ copy( $tempfile, $file_path );
169
+ unlink( $tempfile );
170
+ }
171
+
172
+ //Some servers are having issue with file permission, this should fix it
173
+ chmod($file_path, 0644);
174
+
175
+ return $response;
176
+ }
177
+
178
+ /**
179
+ * Fills $placeholder array with values from $data array
180
+ *
181
+ * @param array $placeholders
182
+ * @param array $data
183
+ *
184
+ * @return array
185
+ */
186
+ private function _array_fill_placeholders( array $placeholders, array $data ) {
187
+ $placeholders['percent'] = $data['compression'];
188
+ $placeholders['bytes'] = $data['bytes_saved'];
189
+ $placeholders['size_before'] = $data['before_size'];
190
+ $placeholders['size_after'] = $data['after_size'];
191
+ $placeholders['time'] = $data['time'];
192
+
193
+ return $placeholders;
194
+ }
195
+
196
+ /**
197
+ * Returns signature for single size of the smush api message to be saved to db;
198
+ *
199
+ * @return array
200
+ */
201
+ private function _get_size_signature() {
202
+ return array(
203
+ 'percent' => - 1,
204
+ 'bytes' => - 1,
205
+ 'size_before' => - 1,
206
+ 'size_after' => - 1,
207
+ 'time' => - 1
208
+ );
209
+ }
210
+
211
+ /**
212
+ * Read the image paths from an attachment's meta data and process each image
213
+ * with wp_smushit().
214
+ *
215
+ * This method also adds a `wp_smushit` meta key for use in the media library.
216
+ * Called after `wp_generate_attachment_metadata` is completed.
217
+ *
218
+ * @param $meta
219
+ * @param null $ID
220
+ *
221
+ * @return mixed
222
+ */
223
+ function resize_from_meta_data( $meta, $ID = null ) {
224
+
225
+ //Flag to check, if original size image should be smushed or not
226
+ $original = get_option( WP_SMUSH_PREFIX . 'original' );
227
+ $smush_full = ( $this->is_pro() && $original == 1 ) ? true : false;
228
+
229
+ $errors = new WP_Error();
230
+ $stats = array(
231
+ "stats" => array_merge( $this->_get_size_signature(), array(
232
+ 'api_version' => - 1,
233
+ 'lossy' => - 1
234
+ )
235
+ ),
236
+ 'sizes' => array()
237
+ );
238
+
239
+ $size_before = $size_after = $compression = $total_time = $bytes_saved = 0;
240
+
241
+ if ( $ID && wp_attachment_is_image( $ID ) === false ) {
242
+ return $meta;
243
+ }
244
+
245
+ //File path and URL for original image
246
+ $attachment_file_path = get_attached_file( $ID );
247
+
248
+ // If images has other registered size, smush them first
249
+ if ( ! empty( $meta['sizes'] ) ) {
250
+
251
+ //if smush original is set to false, otherwise smush
252
+ //Check for large size, we will set a flag to leave the original untouched
253
+ if ( ! $smush_full ) {
254
+ if ( array_key_exists( 'large', $meta['sizes'] ) ) {
255
+ $smush_full = false;
256
+ } else {
257
+ $smush_full = true;
258
+ }
259
+ }
260
+
261
+ if( class_exists('finfo') ) {
262
+ $finfo = new finfo( FILEINFO_MIME_TYPE );
263
+ }else{
264
+ $finfo = false;
265
+ }
266
+ foreach ( $meta['sizes'] as $size_key => $size_data ) {
267
+
268
+ // We take the original image. The 'sizes' will all match the same URL and
269
+ // path. So just get the dirname and replace the filename.
270
+ $attachment_file_path_size = trailingslashit( dirname( $attachment_file_path ) ) . $size_data['file'];
271
+
272
+ if ( $finfo ) {
273
+ $ext = $finfo->file( $attachment_file_path_size );
274
+ } elseif ( function_exists( 'mime_content_type' ) ) {
275
+ $ext = mime_content_type( $attachment_file_path_size );
276
+ } else {
277
+ $ext = false;
278
+ }
279
+ if( $ext ) {
280
+ $valid_mime = array_search(
281
+ $ext,
282
+ array(
283
+ 'jpg' => 'image/jpeg',
284
+ 'png' => 'image/png',
285
+ 'gif' => 'image/gif',
286
+ ),
287
+ true
288
+ );
289
+ if ( false === $valid_mime ) {
290
+ continue;
291
+ }
292
+ }
293
+
294
+ //Store details for each size key
295
+ $response = $this->do_smushit( $attachment_file_path_size );
296
+
297
+ if ( is_wp_error( $response ) ) {
298
+ return $response;
299
+ }
300
+
301
+ if ( ! empty( $response['data'] ) ) {
302
+ $stats['sizes'][ $size_key ] = (object) $this->_array_fill_placeholders( $this->_get_size_signature(), (array) $response['data'] );
303
+ }
304
+
305
+ //Total Stats, store all data in bytes
306
+ if ( isset( $response['data'] ) ) {
307
+ list( $size_before, $size_after, $total_time, $compression, $bytes_saved )
308
+ = $this->_update_stats_data( $response['data'], $size_before, $size_after, $total_time, $bytes_saved );
309
+ } else {
310
+ $errors->add( "image_size_error" . $size_key, sprintf( __( "Size '%s' not processed correctly", 'wp-smushit' ), $size_key ) );
311
+ }
312
+
313
+ if ( empty( $stats['stats']['api_version'] ) || $stats['stats']['api_version'] == - 1 ) {
314
+ $stats['stats']['api_version'] = $response['data']->api_version;
315
+ $stats['stats']['lossy'] = $response['data']->lossy;
316
+ }
317
+ }
318
+ }else{
319
+ $smush_full = true;
320
+ }
321
+
322
+ //If original size is supposed to be smushed
323
+ if ( $smush_full ) {
324
+
325
+ $full_image_response = $this->do_smushit( $attachment_file_path );
326
+
327
+ if ( is_wp_error( $full_image_response ) ) {
328
+ return $full_image_response;
329
+ }
330
+
331
+ if ( ! empty( $full_image_response['data'] ) ) {
332
+ $stats['sizes']['full'] = (object) $this->_array_fill_placeholders( $this->_get_size_signature(), (array) $full_image_response['data'] );
333
+ } else {
334
+ $errors->add( "image_size_error", __( "Size 'full' not processed correctly", 'wp-smushit' ) );
335
+ }
336
+
337
+ //Update stats
338
+ if ( isset( $full_image_response['data'] ) ) {
339
+ list( $size_before, $size_after, $total_time, $compression, $bytes_saved )
340
+ = $this->_update_stats_data( $full_image_response['data'], $size_before, $size_after, $total_time, $bytes_saved );
341
+ } else {
342
+ $errors->add( "image_size_error", __( "Size 'full' not processed correctly", 'wp-smushit' ) );
343
+ }
344
+
345
+ //Api version and lossy, for some images, full image i skipped and for other images only full exists
346
+ //so have to add code again
347
+ if ( empty( $stats['stats']['api_version'] ) || $stats['stats']['api_version'] == - 1 ) {
348
+ $stats['stats']['api_version'] = $full_image_response['data']->api_version;
349
+ $stats['stats']['lossy'] = $full_image_response['data']->lossy;
350
+ }
351
+
352
+
353
+ }
354
+
355
+ $has_errors = (bool) count( $errors->get_error_messages() );
356
+
357
+ list( $stats['stats']['size_before'], $stats['stats']['size_after'], $stats['stats']['time'], $stats['stats']['percent'], $stats['stats']['bytes'] ) =
358
+ array( $size_before, $size_after, $total_time, $compression, $bytes_saved );
359
+
360
+ //Set smush status for all the images, store it in wp-smpro-smush-data
361
+ if ( ! $has_errors ) {
362
+
363
+ $existing_stats = get_post_meta( $ID, self::SMUSHED_META_KEY, true );
364
+
365
+ if ( ! empty( $existing_stats ) ) {
366
+ //Update total bytes saved, and compression percent
367
+ $stats['stats']['bytes'] = isset( $existing_stats['stats']['bytes'] ) ? $existing_stats['stats']['bytes'] + $stats['stats']['bytes'] : $stats['stats']['bytes'];
368
+ $stats['stats']['percent'] = isset( $existing_stats['stats']['percent'] ) ? $existing_stats['stats']['percent'] + $stats['stats']['percent'] : $stats['stats']['percent'];
369
+
370
+ //Update stats for each size
371
+ if ( isset( $existing_stats['sizes'] ) && ! empty( $stats['sizes'] ) ) {
372
+
373
+ foreach ( $existing_stats['sizes'] as $size_name => $size_stats ) {
374
+ //if stats for a particular size doesn't exists
375
+ if ( empty( $stats['sizes'][ $size_name ] ) ) {
376
+ $stats['sizes'][ $size_name ] = $existing_stats['sizes'][ $size_name ];
377
+ } else {
378
+ //Update compression percent and bytes saved for each size
379
+ $stats['sizes'][ $size_name ]->bytes = $stats['sizes'][ $size_name ]->bytes + $existing_stats['sizes'][ $size_name ]->bytes;
380
+ $stats['sizes'][ $size_name ]->percent = $stats['sizes'][ $size_name ]->percent + $existing_stats['sizes'][ $size_name ]->percent;
381
+ }
382
+ }
383
+ }
384
+ }
385
+ update_post_meta( $ID, self::SMUSHED_META_KEY, $stats );
386
+ }
387
+
388
+ return $meta;
389
+ }
390
+
391
+ /**
392
+ * Read the image paths from an attachment's meta data and process each image
393
+ * with wp_smushit()
394
+ *
395
+ * Filters wp_generate_attachment_metadata
396
+ *
397
+ * @uses WpSmush::resize_from_meta_data
398
+ *
399
+ * @param $meta
400
+ * @param null $ID
401
+ *
402
+ * @return mixed
403
+ */
404
+ function filter_generate_attachment_metadata( $meta, $ID = null ) {
405
+ //Update API url for Hostgator
406
+
407
+ //Check for use of http url, (Hostgator mostly)
408
+ $use_http = wp_cache_get( WP_SMUSH_PREFIX.'use_http', 'smush' );
409
+ if( !$use_http ) {
410
+ $use_http = get_option( WP_SMUSH_PREFIX.'use_http' );
411
+ wp_cache_add( WP_SMUSH_PREFIX.'use_http', $use_http, 'smush' );
412
+ }
413
+ $use_http ? define( 'WP_SMUSH_API_HTTP', 'http://smushpro.wpmudev.org/1.0/') : '';
414
+
415
+ $this->resize_from_meta_data( $meta, $ID );
416
+
417
+ return $meta;
418
+ }
419
+
420
+
421
+ /**
422
+ * Posts an image to Smush.
423
+ *
424
+ * @param $file_path path of file to send to Smush
425
+ * @param $file_size
426
+ *
427
+ * @return bool|array array containing success status, and stats
428
+ */
429
+ function _post( $file_path, $file_size ) {
430
+
431
+ $data = false;
432
+
433
+ $file = @fopen( $file_path, 'r' );
434
+ $file_data = fread( $file, $file_size );
435
+ $headers = array(
436
+ 'accept' => 'application/json', // The API returns JSON
437
+ 'content-type' => 'application/binary', // Set content type to binary
438
+ );
439
+
440
+ //Check if premium member, add API key
441
+ $api_key = $this->_get_api_key();
442
+ if ( ! empty( $api_key ) ) {
443
+ $headers['apikey'] = $api_key;
444
+ }
445
+
446
+ //Check if lossy compression allowed and add it to headers
447
+ $lossy = get_option( WP_SMUSH_PREFIX . 'lossy' );
448
+
449
+ if ( $lossy && $this->is_pro() ) {
450
+ $headers['lossy'] = 'true';
451
+ } else {
452
+ $headers['lossy'] = 'false';
453
+ }
454
+
455
+ $api_url = defined( 'WP_SMUSH_API_HTTP' ) ? WP_SMUSH_API_HTTP : WP_SMUSH_API;
456
+ $args = array(
457
+ 'headers' => $headers,
458
+ 'body' => $file_data,
459
+ 'timeout' => WP_SMUSH_TIMEOUT,
460
+ 'user-agent' => WP_SMUSH_UA,
461
+ );
462
+ $result = wp_remote_post( $api_url, $args );
463
+
464
+ //Close file connection
465
+ fclose( $file );
466
+ unset( $file_data );//free memory
467
+ if ( is_wp_error( $result ) ) {
468
+
469
+ $er_msg = $result->get_error_message();
470
+
471
+ //Hostgator Issue
472
+ if ( ! empty( $er_msg ) && strpos( $er_msg, 'SSL CA cert' ) !== false ) {
473
+ //Update DB for using http protocol
474
+ update_option( WP_SMUSH_PREFIX . 'use_http', 1 );
475
+ }
476
+ //Handle error
477
+ $data['message'] = sprintf( __( 'Error posting to API: %s', 'wp-smushit' ), $result->get_error_message() );
478
+ $data['success'] = false;
479
+ unset( $result ); //free memory
480
+ return $data;
481
+ } else if ( '200' != wp_remote_retrieve_response_code( $result ) ) {
482
+ //Handle error
483
+ $data['message'] = sprintf( __( 'Error posting to API: %s %s', 'wp-smushit' ), wp_remote_retrieve_response_code( $result ), wp_remote_retrieve_response_message( $result ) );
484
+ $data['success'] = false;
485
+ unset( $result ); //free memory
486
+
487
+ return $data;
488
+ }
489
+
490
+ //If there is a response and image was successfully optimised
491
+ $response = json_decode( $result['body'] );
492
+ if ( $response && $response->success == true ) {
493
+
494
+ //If there is any savings
495
+ if ( $response->data->bytes_saved > 0 ) {
496
+ $image = base64_decode( $response->data->image ); //base64_decode is necessary to send binary img over JSON, no security problems here!
497
+ $image_md5 = md5( $response->data->image );
498
+ if ( $response->data->image_md5 != $image_md5 ) {
499
+ //Handle error
500
+ $data['message'] = __( 'Smush data corrupted, try again.', 'wp-smushit' );
501
+ $data['success'] = false;
502
+ unset( $image );//free memory
503
+ } else {
504
+ $data['success'] = true;
505
+ $data['data'] = $response->data;
506
+ $data['data']->image = $image;
507
+ unset( $image );//free memory
508
+ }
509
+ } else {
510
+ //just return the data
511
+ $data['success'] = true;
512
+ $data['data'] = $response->data;
513
+ }
514
+ } else {
515
+ //Server side error, get message from response
516
+ $data['message'] = ! empty( $response->data ) ? $response->data : __( "Image couldn't be smushed", 'wp-smushit' );
517
+ $data['success'] = false;
518
+ }
519
+
520
+ unset( $result );//free memory
521
+ unset( $response );//free memory
522
+ return $data;
523
+ }
524
+
525
+
526
+ /**
527
+ * Print column header for Smush results in the media library using
528
+ * the `manage_media_columns` hook.
529
+ */
530
+ function columns( $defaults ) {
531
+ $defaults['smushit'] = 'WP Smush';
532
+
533
+ return $defaults;
534
+ }
535
+
536
+ /**
537
+ * Return the filesize in a humanly readable format.
538
+ * Taken from http://www.php.net/manual/en/function.filesize.php#91477
539
+ */
540
+ function format_bytes( $bytes, $precision = 2 ) {
541
+ $units = array( 'B', 'KB', 'MB', 'GB', 'TB' );
542
+ $bytes = max( $bytes, 0 );
543
+ $pow = floor( ( $bytes ? log( $bytes ) : 0 ) / log( 1024 ) );
544
+ $pow = min( $pow, count( $units ) - 1 );
545
+ $bytes /= pow( 1024, $pow );
546
+
547
+ return round( $bytes, $precision ) . ' ' . $units[ $pow ];
548
+ }
549
+
550
+ /**
551
+ * Print column data for Smush results in the media library using
552
+ * the `manage_media_custom_column` hook.
553
+ */
554
+ function custom_column( $column_name, $id ) {
555
+ if ( 'smushit' == $column_name ) {
556
+ $this->set_status( $id );
557
+ }
558
+ }
559
+
560
+ /**
561
+ * Check if user is premium member, check for api key
562
+ *
563
+ * @return mixed|string
564
+ */
565
+ function is_pro() {
566
+
567
+ if ( isset( $this->is_pro ) ) {
568
+ return $this->is_pro;
569
+ }
570
+
571
+ //no api key set, always false
572
+ $api_key = $this->_get_api_key();
573
+ if ( empty( $api_key ) ) {
574
+ return false;
575
+ }
576
+
577
+ $key = "wp-smush-premium-" . substr( $api_key, - 10, 10 ); //add last 10 chars of apikey to transient key in case it changes
578
+ if ( false === ( $valid = get_site_transient( $key ) ) ) {
579
+ // call api
580
+ $url = self::API_SERVER . '&key=' . urlencode( $api_key );
581
+
582
+ $request = wp_remote_get( $url, array(
583
+ "user-agent" => WP_SMUSH_UA,
584
+ "timeout" => 3
585
+ )
586
+ );
587
+
588
+ if ( ! is_wp_error( $request ) && '200' == wp_remote_retrieve_response_code( $request ) ) {
589
+ $result = json_decode( wp_remote_retrieve_body( $request ) );
590
+ if ( $result && $result->success ) {
591
+ $valid = true;
592
+ set_site_transient( $key, 1, 12 * HOUR_IN_SECONDS );
593
+ } else {
594
+ $valid = false;
595
+ set_site_transient( $key, 0, 30 * MINUTE_IN_SECONDS ); //cache failure much shorter
596
+ }
597
+
598
+ } else {
599
+ $valid = false;
600
+ set_site_transient( $key, 0, 5 * MINUTE_IN_SECONDS ); //cache network failure even shorter, we don't want a request every pageload
601
+ }
602
+
603
+ }
604
+
605
+ $this->is_pro = (bool) $valid;
606
+
607
+ return $this->is_pro;
608
+ }
609
+
610
+ /**
611
+ * Returns api key
612
+ *
613
+ * @return mixed
614
+ */
615
+ private function _get_api_key() {
616
+ //Try to fetch it from Cache
617
+ $api_key = wp_cache_get( 'wpmudev_apikey', 'smush' );
618
+
619
+ //If not available, get it from other means, and set it in cache
620
+ if ( ! $api_key ) {
621
+ if ( defined( 'WPMUDEV_APIKEY' ) ) {
622
+ $api_key = WPMUDEV_APIKEY;
623
+ } else {
624
+ $api_key = get_site_option( 'wpmudev_apikey' );
625
+ }
626
+ if ( $api_key ) {
627
+ wp_cache_add( "wpmudev_apikey", $api_key, 'smush', 6000 );
628
+ }
629
+ }
630
+
631
+ return $api_key;
632
+ }
633
+
634
+
635
+ /**
636
+ * Checks if image is already smushed
637
+ *
638
+ * @param int $id
639
+ * @param array $data
640
+ *
641
+ * @return bool|mixed
642
+ */
643
+ function is_smushed( $id, $data = null ) {
644
+
645
+ //For new images
646
+ $wp_is_smushed = get_post_meta( $id, 'wp-is-smushed', true );
647
+
648
+ //Not smushed, backward compatibility, check attachment metadata
649
+ if ( ! $wp_is_smushed && $data !== null ) {
650
+ if ( isset( $data['wp_smushit'] ) && ! empty( $data['wp_smushit'] ) ) {
651
+ $wp_is_smushed = true;
652
+ }
653
+ }
654
+
655
+ return $wp_is_smushed;
656
+ }
657
+
658
+ /**
659
+ * Returns size saved from the api call response
660
+ *
661
+ * @param string $message
662
+ *
663
+ * @return string|bool
664
+ */
665
+ function get_saved_size( $message ) {
666
+ if ( preg_match( '/\((.*)\)/', $message, $matches ) ) {
667
+ return isset( $matches[1] ) ? $matches[1] : false;
668
+ }
669
+
670
+ return false;
671
+ }
672
+
673
+ /**
674
+ * Set send button status
675
+ *
676
+ * @param $id
677
+ * @param bool $echo
678
+ * @param bool $text_only
679
+ *
680
+ * @return string|void
681
+ */
682
+ function set_status( $id, $echo = true, $text_only = false ) {
683
+ $status_txt = $button_txt = '';
684
+ $show_button = false;
685
+
686
+ //Stats are not received properly, otherwise
687
+ // wp_cache_delete( $id, 'post_meta' );
688
+
689
+ $wp_smush_data = get_post_meta( $id, self::SMUSHED_META_KEY, true );
690
+ $attachment_data = wp_get_attachment_metadata( $id );
691
+ //
692
+ // if the image is smushed
693
+ if ( ! empty( $wp_smush_data ) ) {
694
+
695
+ $image_count = count( $wp_smush_data['sizes'] );
696
+ $bytes = isset( $wp_smush_data['stats']['bytes'] ) ? $wp_smush_data['stats']['bytes'] : 0;
697
+ $bytes_readable = ! empty( $bytes ) ? $this->format_bytes( $bytes ) : '';
698
+ $percent = isset( $wp_smush_data['stats']['percent'] ) ? $wp_smush_data['stats']['percent'] : 0;
699
+ $percent = $percent < 0 ? 0 : $percent;
700
+
701
+ if ( isset( $wp_smush_data['stats']['size_before'] ) && $wp_smush_data['stats']['size_before'] == 0 && ! empty( $wp_smush_data['sizes'] ) ) {
702
+ $status_txt = __( 'Error processing request', 'wp-smushit' );
703
+ $show_button = true;
704
+ } else {
705
+ if ( $bytes == 0 || $percent == 0 ) {
706
+ $status_txt = __( 'Already Optimized', 'wp-smushit' );
707
+ } elseif ( ! empty( $percent ) && ! empty( $bytes_readable ) ) {
708
+ $status_txt = $image_count > 1 ? sprintf( __( "%d images reduced ", 'wp-smushit' ), $image_count ) : __( "Reduced ", 'wp-smushit' );
709
+ $status_txt .= sprintf( __( "by %s ( %01.1f%% )", 'wp-smushit' ), $bytes_readable, number_format_i18n( $percent, 2, '.', '' ) );
710
+
711
+ //Show detailed stats if available
712
+ if ( ! empty( $wp_smush_data['sizes'] ) ) {
713
+ //Detailed Stats Link
714
+ $status_txt .= '<br /><a href="#" class="smush-stats-details">' . esc_html__( "Smush stats", 'wp-smushit' ) . ' [<span class="stats-toggle">+</span>]</a>';
715
+
716
+ //Stats
717
+ $status_txt .= $this->get_detailed_stats( $id, $wp_smush_data, $attachment_data );
718
+ }
719
+ }
720
+ }
721
+
722
+ //IF current compression is lossy
723
+ if ( ! empty( $wp_smush_data ) && ! empty( $wp_smush_data['stats'] ) ) {
724
+ $lossy = ! empty( $wp_smush_data['stats']['lossy'] ) ? $wp_smush_data['stats']['lossy'] : '';
725
+ $is_lossy = $lossy == 1 ? true : false;
726
+ }
727
+
728
+ //Check if Lossy enabled
729
+ $opt_lossy = WP_SMUSH_PREFIX . 'lossy';
730
+ $opt_lossy_val = get_option( $opt_lossy, false );
731
+
732
+ //Check image type
733
+ $image_type = get_post_mime_type( $id );
734
+
735
+ //Check if premium user, compression was lossless, and lossy compression is enabled
736
+ if ( $this->is_pro() && ! $is_lossy && $opt_lossy_val && $image_type != 'image/gif' ) {
737
+ // the button text
738
+ $button_txt = __( 'Super-Smush', 'wp-smushit' );
739
+ $show_button = true;
740
+ }
741
+ } else {
742
+
743
+ // the status
744
+ $status_txt = __( 'Not processed', 'wp-smushit' );
745
+
746
+ // we need to show the smush button
747
+ $show_button = true;
748
+
749
+ // the button text
750
+ $button_txt = __( 'Smush Now!', 'wp-smushit' );
751
+ }
752
+ if ( $text_only ) {
753
+ return $status_txt;
754
+ }
755
+
756
+ $text = $this->column_html( $id, $status_txt, $button_txt, $show_button, $wp_smush_data, $echo );
757
+ if ( ! $echo ) {
758
+ return $text;
759
+ }
760
+ }
761
+
762
+ /**
763
+ * Print the column html
764
+ *
765
+ * @param string $id Media id
766
+ * @param string $status_txt Status text
767
+ * @param string $button_txt Button label
768
+ * @param boolean $show_button Whether to shoe the button
769
+ *
770
+ * @return null
771
+ */
772
+ function column_html( $id, $status_txt = "", $button_txt = "", $show_button = true, $smushed = false, $echo = true ) {
773
+ $allowed_images = array( 'image/jpeg', 'image/jpg', 'image/png', 'image/gif' );
774
+
775
+ // don't proceed if attachment is not image, or if image is not a jpg, png or gif
776
+ if ( ! wp_attachment_is_image( $id ) || ! in_array( get_post_mime_type( $id ), $allowed_images ) ) {
777
+ return;
778
+ }
779
+
780
+ $class = $smushed ? '' : ' hidden';
781
+ $html = '
782
+ <p class="smush-status' . $class . '">' . $status_txt . '</p>';
783
+ // if we aren't showing the button
784
+ if ( ! $show_button ) {
785
+ if ( $echo ) {
786
+ echo $html;
787
+
788
+ return;
789
+ } else {
790
+ if ( ! $smushed ) {
791
+ $class = ' currently-smushing';
792
+ } else {
793
+ $class = ' smushed';
794
+ }
795
+
796
+ return '<div class="smush-wrap' . $class . '">' . $html . '</div>';
797
+ }
798
+ }
799
+ if ( ! $echo ) {
800
+ $html .= '
801
+ <button class="button button-primary wp-smush-send" data-id="' . $id . '">
802
+ <span>' . $button_txt . '</span>
803
+ </button>';
804
+ if ( ! $smushed ) {
805
+ $class = ' unsmushed';
806
+ } else {
807
+ $class = ' smushed';
808
+ }
809
+
810
+ return '<div class="smush-wrap' . $class . '">' . $html . '</div>';
811
+ } else {
812
+ $html .= '<button class="button wp-smush-send" data-id="' . $id . '">
813
+ <span>' . $button_txt . '</span>
814
+ </button>';
815
+ echo $html;
816
+ }
817
+ }
818
+
819
+ /**
820
+ * Migrates smushit api message to the latest structure
821
+ *
822
+ *
823
+ * @return void
824
+ */
825
+ function migrate() {
826
+
827
+ if ( ! version_compare( $this->version, "1.7.1", "lte" ) ) {
828
+ return;
829
+ }
830
+
831
+ $migrated_version = get_option( self::MIGRATED_VERSION );
832
+
833
+ if ( $migrated_version === $this->version ) {
834
+ return;
835
+ }
836
+
837
+ global $wpdb;
838
+
839
+ $q = $wpdb->prepare( "SELECT * FROM `" . $wpdb->postmeta . "` WHERE `meta_key`=%s AND `meta_value` LIKE %s ", "_wp_attachment_metadata", "%wp_smushit%" );
840
+ $results = $wpdb->get_results( $q );
841
+
842
+ if ( count( $results ) < 1 ) {
843
+ return;
844
+ }
845
+
846
+ $migrator = new WpSmushMigrate();
847
+ foreach ( $results as $attachment_meta ) {
848
+ $migrated_message = $migrator->migrate_api_message( maybe_unserialize( $attachment_meta->meta_value ) );
849
+ if ( $migrated_message !== array() ) {
850
+ update_post_meta( $attachment_meta->post_id, self::SMUSHED_META_KEY, $migrated_message );
851
+ }
852
+ }
853
+
854
+ update_option( self::MIGRATED_VERSION, $this->version );
855
+
856
+ }
857
+
858
+ /**
859
+ * @param Object $response_data
860
+ * @param $size_before
861
+ * @param $size_after
862
+ * @param $total_time
863
+ * @param $bytes_saved
864
+ *
865
+ * @return array
866
+ */
867
+ private function _update_stats_data( $response_data, $size_before, $size_after, $total_time, $bytes_saved ) {
868
+ $size_before += ! empty( $response_data->before_size ) ? (int) $response_data->before_size : 0;
869
+ $size_after += ( ! empty( $response_data->after_size ) && $response_data->after_size > 0 ) ? (int) $response_data->after_size : (int) $response_data->before_size;
870
+ $total_time += ! empty( $response_data->time ) ? (float) $response_data->time : 0;
871
+ $bytes_saved += ( ! empty( $response_data->bytes_saved ) && $response_data->bytes_saved > 0 ) ? $response_data->bytes_saved : 0;
872
+ $compression = ( $bytes_saved > 0 && $size_before > 0 ) ? ( ( $bytes_saved / $size_before ) * 100 ) : 0;
873
+
874
+ return array( $size_before, $size_after, $total_time, $compression, $bytes_saved );
875
+ }
876
+
877
+ /**
878
+ * Updates the smush stats for a single image size
879
+ * @param $id
880
+ * @param $stats
881
+ * @param $image_size
882
+ */
883
+ function update_smush_stats_single( $id, $smush_stats, $image_size = '' ) {
884
+ //Return, if we don't have image id or stats for it
885
+ if ( empty( $id ) || empty( $smush_stats ) || empty( $image_size ) ) {
886
+ return false;
887
+ }
888
+ $image_size = $image_size . '@2x';
889
+ $data = $smush_stats['data'];
890
+ //Get existing Stats
891
+ $stats = get_post_meta( $id, self::SMUSHED_META_KEY, true );
892
+ //Update existing Stats
893
+ if ( ! empty( $stats ) ) {
894
+ //Update total bytes saved, and compression percent
895
+ //Update Main Stats
896
+ list( $stats['stats']['size_before'], $stats['stats']['size_after'], $stats['stats']['time'], $stats['stats']['percent'], $stats['stats']['bytes'] ) =
897
+ $this->_update_stats_data( $data, $stats['stats']['size_before'], $stats['stats']['size_after'], $stats['stats']['time'], $stats['stats']['bytes'] );
898
+
899
+
900
+ //Update stats for each size
901
+ if ( isset( $stats['sizes'] ) ) {
902
+
903
+ //if stats for a particular size doesn't exists
904
+ if ( empty( $stats['sizes'][ $image_size ] ) ) {
905
+ //Update size wise details
906
+ $stats['sizes'][ $image_size ] = (object) $this->_array_fill_placeholders( $this->_get_size_signature(), (array) $data );
907
+ } else {
908
+ //Update compression percent and bytes saved for each size
909
+ $stats['sizes'][ $image_size ]->bytes = $stats['sizes'][ $image_size ]->bytes + $data->bytes_saved;
910
+ $stats['sizes'][ $image_size ]->percent = $stats['sizes'][ $image_size ]->percent + $data->compression;
911
+ }
912
+ }
913
+ } else {
914
+ //Create new stats
915
+ $stats = array(
916
+ "stats" => array_merge( $this->_get_size_signature(), array(
917
+ 'api_version' => - 1,
918
+ 'lossy' => - 1
919
+ )
920
+ ),
921
+ 'sizes' => array()
922
+ );
923
+ $stats['stats']['api_version'] = $data->api_version;
924
+ $stats['stats']['lossy'] = $data->lossy;
925
+ //Update Main Stats
926
+ list( $stats['stats']['size_before'], $stats['stats']['size_after'], $stats['stats']['time'], $stats['stats']['percent'], $stats['stats']['bytes'] ) =
927
+ array( $data->before_size, $data->after_size, $data->time, $data->compression, $data->bytes_saved );
928
+ //Update size wise details
929
+ $stats['sizes'][ $image_size ] = (object) $this->_array_fill_placeholders( $this->_get_size_signature(), (array) $data );
930
+ }
931
+ //Calculate Percent
932
+ update_post_meta( $id, self::SMUSHED_META_KEY, $stats );
933
+
934
+ }
935
+
936
+ function smush_retina_image( $id, $retina_file, $image_size ) {
937
+
938
+ $stats = $this->do_smushit( $retina_file );
939
+ //If we squeezed out something, Update stats
940
+ if ( ! empty( $stats['data'] ) && isset( $stats['data'] ) && $stats['data']->bytes_saved > 0 ) {
941
+ $this->update_smush_stats_single( $id, $stats, $image_size );
942
+ }
943
+ }
944
+
945
+ /**
946
+ * Return a list of images not smushed and reason
947
+ * @param $image_id
948
+ * @param $size_stats
949
+ * @param $attachment_metadata
950
+ *
951
+ * @return array
952
+ */
953
+ function get_skipped_images( $image_id, $size_stats, $attachment_metadata ) {
954
+ $skipped = array();
955
+
956
+ //Get a list of all the sizes, Show skipped images
957
+ $media_size = get_intermediate_image_sizes();
958
+
959
+ //Full size
960
+ $full_image = get_attached_file( $image_id );
961
+
962
+ //If full image was not smushed, reason 1. Large Size logic, 2. Free and greater than 1Mb
963
+ if ( ! array_key_exists( 'full', $size_stats ) ) {
964
+ //For free version, Check the image size
965
+ if ( ! $this->is_pro() ) {
966
+ //For free version, check if full size is greater than 1 Mb, show the skipped status
967
+ $file_size = filesize( $full_image );
968
+ if ( ( $file_size / WP_SMUSH_MAX_BYTES ) > 1 ) {
969
+ $skipped[] = array(
970
+ 'size' => 'full',
971
+ 'reason' => 'size_limit'
972
+ );
973
+ }else{
974
+ $skipped[] = array(
975
+ 'size' => 'full',
976
+ 'reason' => 'large_size'
977
+ );
978
+ }
979
+ } else {
980
+ //Paid version, Check if we have large size
981
+ if ( array_key_exists( 'large', $size_stats ) ) {
982
+ $skipped[] = array(
983
+ 'size' => 'full',
984
+ 'reason' => 'large_size'
985
+ );
986
+ }
987
+
988
+ }
989
+ }
990
+ //For other sizes, check if the image was generated and not available in stats
991
+ if ( is_array( $media_size ) ) {
992
+ foreach ( $media_size as $size ) {
993
+ if ( array_key_exists( $size, $attachment_metadata['sizes'] ) && ! array_key_exists( $size, $size_stats ) ) {
994
+ //Image Path
995
+ $img_path = trailingslashit( dirname( $full_image ) ) . $size['file'];
996
+ $image_size = filesize( $img_path );
997
+ if ( ( $image_size / WP_SMUSH_MAX_BYTES ) > 1 ) {
998
+ $skipped[] = array(
999
+ 'size' => 'full',
1000
+ 'reason' => 'size_limit'
1001
+ );
1002
+ }
1003
+ }
1004
+ }
1005
+ }
1006
+ return $skipped;
1007
+ }
1008
+
1009
+ /**
1010
+ * Skip messages respective to their ids
1011
+ * @param $msg_id
1012
+ *
1013
+ * @return bool
1014
+ */
1015
+ function skip_reason( $msg_id ) {
1016
+ $skip_msg = array(
1017
+ 'large_size' => esc_html__( "For very large dimension images like those taken with a digital camera, the original full size image is almost never embedded (and really shouldn't be). Because of this WP Smush preserves it unaltered by default. Pro users can change this setting.", 'wp-smushit' ),
1018
+ 'size_limit' => esc_html__( "Image couldn't be smushed as it exceeded the 1Mb size limit, Pro users can smush images with size upto 32Mb.", "wp-smushit" )
1019
+ );
1020
+ $skip_rsn = !empty( $skip_msg[$msg_id ] ) ? esc_html__(" Skipped", 'wp-smushit', 'wp-smushit'): '';
1021
+ $skip_rsn = ! empty( $skip_rsn ) ? $skip_rsn . '<span class="dashicons dashicons-editor-help" title="' . $skip_msg[ $msg_id ] . '"></span>' : '';
1022
+ return $skip_rsn;
1023
+ }
1024
+
1025
+ /**
1026
+ * Shows the image size and the compression for each of them
1027
+ * @param $image_id
1028
+ * @param $wp_smush_data
1029
+ *
1030
+ * @return string
1031
+ */
1032
+ function get_detailed_stats( $image_id, $wp_smush_data, $attachment_metadata ) {
1033
+
1034
+ $stats = '<div id="smush-stats-' . $image_id . '" class="smush-stats-wrapper hidden">
1035
+ <table class="wp-smush-stats-holder">
1036
+ <thead>
1037
+ <tr>
1038
+ <th><strong>' . esc_html__( 'Image size', 'wp-smushit' ) . '</strong></th>
1039
+ <th><strong>' . esc_html__( 'Savings', 'wp-smushit' ) . '</strong></th>
1040
+ </tr>
1041
+ </thead>
1042
+ <tbody>';
1043
+ $size_stats = $wp_smush_data['sizes'];
1044
+
1045
+ //Reorder Sizes as per the maximum savings
1046
+ uasort( $size_stats, array( $this, "cmp" ) );
1047
+
1048
+ if ( ! empty( $attachment_metadata['sizes'] ) ) {
1049
+ //Get skipped images
1050
+ $skipped = $this->get_skipped_images( $image_id, $size_stats, $attachment_metadata );
1051
+
1052
+ if ( ! empty( $skipped ) ) {
1053
+ foreach ( $skipped as $img_data ) {
1054
+ $skip_class = $img_data['reason'] == 'size_limit' ? ' error' : '';
1055
+ $stats .= '<tr>
1056
+ <td>' . strtoupper( $img_data['size'] ) . '</td>
1057
+ <td class="smush-skipped' . $skip_class . '">' . $this->skip_reason( $img_data['reason'] ) . '</td>
1058
+ </tr>';
1059
+ }
1060
+
1061
+ }
1062
+ }
1063
+ //Show Sizes and their compression
1064
+ foreach ( $size_stats as $size_key => $size_stats ) {
1065
+ if ( $size_stats->bytes > 0 ) {
1066
+ $stats .= '<tr>
1067
+ <td>' . strtoupper( $size_key ) . '</td>
1068
+ <td>' . $this->format_bytes( $size_stats->bytes ) . ' ( ' . $size_stats->percent . '% )</td>
1069
+ </tr>';
1070
+ }
1071
+ }
1072
+ $stats .= '</tbody>
1073
+ </table>
1074
+ </div>';
1075
+
1076
+ return $stats;
1077
+ }
1078
+
1079
+ /**
1080
+ * Compare Values
1081
+ * @param $a
1082
+ * @param $b
1083
+ *
1084
+ * @return int
1085
+ */
1086
+ function cmp($a, $b) {
1087
+ return $a->bytes < $b->bytes;
1088
+ }
1089
+ }
1090
+
1091
+ global $WpSmush;
1092
+ $WpSmush = new WpSmush();
1093
+
1094
+ }
1095
+
1096
+ //Include Admin classes
1097
+ require_once( WP_SMUSH_DIR . 'lib/class-wp-smush-bulk.php' );
1098
+ require_once( WP_SMUSH_DIR . 'lib/class-wp-smush-admin.php' );
readme.txt CHANGED
@@ -1,13 +1,13 @@
1
  === WP Smush ===
2
  Plugin Name: WP Smush
3
- Version: 2.0.6.2
4
  Author: WPMU DEV
5
  Author URI: http://premium.wpmudev.org/
6
  Contributors: WPMUDEV, alexdunae
7
  Tags: Attachment,Attachments,Compress,Compress Image File,Compress Image Size,Compress JPG,Compressed JPG, Compression Image,Image,Images,JPG,Optimise,Optimize,Photo,Photos,Pictures,PNG,Reduce Image Size,Smush,Smush.it,Upload,WordPress Compression,WordPress Image Tool,Yahoo, Yahoo Smush.it
8
  Requires at least: 3.5
9
- Tested up to: 4.3
10
- Stable tag: 2.0.6.2
11
  License: GPL v2 - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
12
 
13
  Reduce image file sizes, improve performance and boost your SEO using the free <a href="https://premium.wpmudev.org/">WPMU DEV</a> WordPress Smush API.
@@ -81,6 +81,25 @@ Yahoo's Smush.it API is gone forever. So WPMU DEV built our own free API that is
81
 
82
  == Changelog ==
83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  = 2.0.6.2 =
85
 
86
  * Use string for text domain instead of PHP Constant ( WordPress Guideline )
1
  === WP Smush ===
2
  Plugin Name: WP Smush
3
+ Version: 2.0.6.5
4
  Author: WPMU DEV
5
  Author URI: http://premium.wpmudev.org/
6
  Contributors: WPMUDEV, alexdunae
7
  Tags: Attachment,Attachments,Compress,Compress Image File,Compress Image Size,Compress JPG,Compressed JPG, Compression Image,Image,Images,JPG,Optimise,Optimize,Photo,Photos,Pictures,PNG,Reduce Image Size,Smush,Smush.it,Upload,WordPress Compression,WordPress Image Tool,Yahoo, Yahoo Smush.it
8
  Requires at least: 3.5
9
+ Tested up to: 4.3.1
10
+ Stable tag: 2.0.6.5
11
  License: GPL v2 - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
12
 
13
  Reduce image file sizes, improve performance and boost your SEO using the free <a href="https://premium.wpmudev.org/">WPMU DEV</a> WordPress Smush API.
81
 
82
  == Changelog ==
83
 
84
+ = 2.0.6.5 =
85
+
86
+ * Updated: Skip webp images ( causing ajax error for few sites )
87
+ * Fixed: Warning and Notices ( Media Library not loading )
88
+ * Fixed: Smush full size image if no other sizes are available
89
+ * Added: Detailed text for stats and settings
90
+
91
+ = 2.0.6.3 =
92
+
93
+ * Fixed: Change File permission after replacing image
94
+ * Fixed: Directory path for files
95
+ * Fixed: Workaround for Auto Smush issue on Hostgator
96
+ * Fixed: Smush button doesn't works in media library dialog on post screen, when add media is clicked
97
+ (https://wordpress.org/support/topic/like-wp-smush-a-lot)
98
+ * New: Show number of images smushed in stats column
99
+ * Added: Support for WP Retina 2x Plugin
100
+ * Added: Filter `WP_SMUSH_API_TIMEOUT` to change the default time out value from 60s
101
+ * Added: Smush original image option (Pro Only)
102
+
103
  = 2.0.6.2 =
104
 
105
  * Use string for text domain instead of PHP Constant ( WordPress Guideline )
wp-smush.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: WP Smush
4
  Plugin URI: http://wordpress.org/extend/plugins/wp-smushit/
5
  Description: Reduce image file sizes, improve performance and boost your SEO using the free <a href="https://premium.wpmudev.org/">WPMU DEV</a> WordPress Smush API.
6
  Author: WPMU DEV
7
- Version: 2.0.6.2
8
  Author URI: http://premium.wpmudev.org/
9
  Textdomain: wp-smushit
10
  */
@@ -36,9 +36,15 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
36
  * Constants
37
  */
38
  $prefix = 'WP_SMUSH_';
39
- $version = '2.0.6.1';
40
- $smush_constatns = array(
41
- 'VERSON' => $version,
 
 
 
 
 
 
42
  'BASENAME' => plugin_basename( __FILE__ ),
43
  'API' => 'https://smushpro.wpmudev.org/1.0/',
44
  'UA' => 'WP Smush/' . $version . '; ' . network_home_url(),
@@ -47,870 +53,94 @@ $smush_constatns = array(
47
  'MAX_BYTES' => 1000000,
48
  'PREMIUM_MAX_BYTES' => 32000000,
49
  'PREFIX' => 'wp-smush-',
50
- 'TIMEOUT' => 30
51
-
52
  );
53
 
54
- foreach ( $smush_constatns as $const_name => $constant_val ) {
55
  if ( ! defined( $prefix . $const_name ) ) {
56
  define( $prefix . $const_name, $constant_val );
57
  }
58
  }
 
 
59
 
60
- require_once WP_SMUSH_DIR . "lib/class-wp-smush-migrate.php";
61
-
62
- if ( ! class_exists( 'WpSmush' ) ) {
63
-
64
- class WpSmush {
65
-
66
- var $version = WP_SMUSH_VERSON;
67
-
68
- var $is_pro;
69
-
70
- /**
71
- * Meta key for api validity
72
- *
73
- */
74
- const VALIDITY_KEY = "wp-smush-valid";
75
-
76
- /**
77
- * Api server url to check api key validity
78
- *
79
- */
80
- const API_SERVER = 'https://premium.wpmudev.org/wdp-un.php?action=smushit_check';
81
-
82
- /**
83
- * Meta key to save smush result to db
84
- *
85
- *
86
- */
87
- const SMUSHED_META_KEY = 'wp-smpro-smush-data';
88
-
89
- /**
90
- * Meta key to save migrated version
91
- *
92
- */
93
- const MIGRATED_VERSION = "wp-smush-migrated-version";
94
-
95
- /**
96
- * Constructor
97
- */
98
- function __construct() {
99
- /**
100
- * Hooks
101
- */
102
- //Check if auto is enabled
103
- $auto_smush = get_option( WP_SMUSH_PREFIX . 'auto' );
104
-
105
- //Keep the uto smush on by default
106
- if ( $auto_smush === false ) {
107
- $auto_smush = 1;
108
- }
109
-
110
- if ( $auto_smush ) {
111
- add_filter( 'wp_generate_attachment_metadata', array(
112
- $this,
113
- 'filter_generate_attachment_metadata'
114
- ), 10, 2 );
115
- }
116
- add_filter( 'manage_media_columns', array( $this, 'columns' ) );
117
- add_action( 'manage_media_custom_column', array( $this, 'custom_column' ), 10, 2 );
118
- add_action( 'admin_init', array( $this, 'admin_init' ) );
119
- add_action( "admin_init", array( $this, "migrate" ) );
120
-
121
- }
122
-
123
- function admin_init() {
124
- load_plugin_textdomain( 'wp-smushit', false, dirname( WP_SMUSH_BASENAME ) . '/languages/' );
125
- wp_enqueue_script( 'common' );
126
- }
127
-
128
- /**
129
- * Process an image with Smush.
130
- *
131
- * Returns an array of the $file $results.
132
- *
133
- * @param string $file Full absolute path to the image file
134
- * @param string $file_url Optional full URL to the image file
135
- *
136
- * @returns array
137
- */
138
- function do_smushit( $file_path = '', $file_url = '' ) {
139
- $errors = new WP_Error();
140
- if ( empty( $file_path ) ) {
141
- $errors->add( "empty_path", __( "File path is empty", 'wp-smushit' ) );
142
- }
143
-
144
- if ( empty( $file_url ) ) {
145
- $errors->add( "empty_url", __( "File URL is empty", 'wp-smushit' ) );
146
- }
147
-
148
- // check that the file exists
149
- if ( ! file_exists( $file_path ) || ! is_file( $file_path ) ) {
150
- $errors->add( "file_not_found", sprintf( __( "Could not find %s", 'wp-smushit' ), $file_path ) );
151
- }
152
-
153
- // check that the file is writable
154
- if ( ! is_writable( dirname( $file_path ) ) ) {
155
- $errors->add( "not_writable", sprintf( __( "%s is not writable", 'wp-smushit' ), dirname( $file_path ) ) );
156
- }
157
-
158
- $file_size = file_exists( $file_path ) ? filesize( $file_path ) : 0;
159
-
160
- //Check if premium user
161
- $max_size = $this->is_pro() ? WP_SMUSH_PREMIUM_MAX_BYTES : WP_SMUSH_MAX_BYTES;
162
-
163
- //Check if file exists
164
- if ( $file_size == 0 ) {
165
- $errors->add( "image_not_found", sprintf( __( 'Skipped (%s), image not found.', 'wp-smushit' ), $this->format_bytes( $file_size ) ) );
166
- }
167
-
168
- //Check size limit
169
- if ( $file_size > $max_size ) {
170
- $errors->add( "size_limit", sprintf( __( 'Skipped (%s), size limit exceeded.', 'wp-smushit' ), $this->format_bytes( $file_size ) ) );
171
- }
172
-
173
- if ( count( $errors->get_error_messages() ) ) {
174
- return $errors;
175
- }
176
-
177
- /** Send image for smushing, and fetch the response */
178
- $response = $this->_post( $file_path, $file_size );
179
-
180
- if ( ! $response['success'] ) {
181
- $errors->add( "false_response", $response['message'] );
182
- }
183
- //If there is no data
184
- if ( empty( $response['data'] ) ) {
185
- $errors->add( "no_data", __( 'Unknown API error', 'wp-smushit' ) );
186
- }
187
-
188
- if ( count( $errors->get_error_messages() ) ) {
189
- return $errors;
190
- }
191
-
192
- //If there are no savings, or image returned is bigger in size
193
- if ( ( ! empty( $response['data']->bytes_saved ) && intval( $response['data']->bytes_saved ) <= 0 )
194
- || empty( $response['data']->image )
195
- ) {
196
- return $response;
197
- }
198
- $tempfile = $file_path . ".tmp";
199
-
200
- //Add the file as tmp
201
- file_put_contents( $tempfile, $response['data']->image );
202
-
203
- //handle backups if enabled
204
- $backup = get_option( WP_SMUSH_PREFIX . 'backup' );
205
- if ( $backup && $this->is_pro() ) {
206
- $path = pathinfo( $file_path );
207
- $backup_name = trailingslashit( $path['dirname'] ) . $path['filename'] . ".bak." . $path['extension'];
208
- @copy( $file_path, $backup_name );
209
- }
210
-
211
- //replace the file
212
- $success = @rename( $tempfile, $file_path );
213
-
214
- //if tempfile still exists, unlink it
215
- if ( file_exists( $tempfile ) ) {
216
- unlink( $tempfile );
217
- }
218
-
219
- //If file renaming was successful
220
- if ( ! $success ) {
221
- copy( $tempfile, $file_path );
222
- unlink( $tempfile );
223
- }
224
-
225
- return $response;
226
- }
227
-
228
- /**
229
- * Fills $placeholder array with values from $data array
230
- *
231
- * @param array $placeholders
232
- * @param array $data
233
- *
234
- * @return array
235
- */
236
- private function _array_fill_placeholders( array $placeholders, array $data ) {
237
- $placeholders['percent'] = $data['compression'];
238
- $placeholders['bytes'] = $data['bytes_saved'];
239
- $placeholders['size_before'] = $data['before_size'];
240
- $placeholders['size_after'] = $data['after_size'];
241
- $placeholders['time'] = $data['time'];
242
-
243
- return $placeholders;
244
- }
245
-
246
- /**
247
- * Returns signature for single size of the smush api message to be saved to db;
248
- *
249
- * @return array
250
- */
251
- private function _get_size_signature() {
252
- return array(
253
- 'percent' => - 1,
254
- 'bytes' => - 1,
255
- 'size_before' => - 1,
256
- 'size_after' => - 1,
257
- 'time' => - 1
258
- );
259
- }
260
-
261
- /**
262
- * Read the image paths from an attachment's meta data and process each image
263
- * with wp_smushit().
264
- *
265
- * This method also adds a `wp_smushit` meta key for use in the media library.
266
- * Called after `wp_generate_attachment_metadata` is completed.
267
- *
268
- * @param $meta
269
- * @param null $ID
270
- *
271
- * @return mixed
272
- */
273
- function resize_from_meta_data( $meta, $ID = null ) {
274
-
275
- //Flag to check, if original size image needs to be smushed or not
276
- $smush_full = true;
277
- $errors = new WP_Error();
278
- $stats = array(
279
- "stats" => array_merge( $this->_get_size_signature(), array(
280
- 'api_version' => - 1,
281
- 'lossy' => - 1
282
- )
283
- ),
284
- 'sizes' => array()
285
- );
286
-
287
- $size_before = $size_after = $compression = $total_time = $bytes_saved = 0;
288
-
289
- if ( $ID && wp_attachment_is_image( $ID ) === false ) {
290
- return $meta;
291
- }
292
-
293
- //File path and URL for original image
294
- $attachment_file_path = get_attached_file( $ID );
295
- $attachment_file_url = wp_get_attachment_url( $ID );
296
-
297
- // If images has other registered size, smush them first
298
- if ( ! empty( $meta['sizes'] ) ) {
299
-
300
- foreach ( $meta['sizes'] as $size_key => $size_data ) {
301
-
302
- //if there is a large size, then we will set a flag to leave the original untouched
303
- if ( $size_key == 'large' ) {
304
- $smush_full = false;
305
- }
306
-
307
- // We take the original image. The 'sizes' will all match the same URL and
308
- // path. So just get the dirname and replace the filename.
309
-
310
- $attachment_file_path_size = trailingslashit( dirname( $attachment_file_path ) ) . $size_data['file'];
311
- $attachment_file_url_size = trailingslashit( dirname( $attachment_file_url ) ) . $size_data['file'];
312
-
313
- //Store details for each size key
314
- $response = $this->do_smushit( $attachment_file_path_size, $attachment_file_url_size );
315
-
316
- if ( is_wp_error( $response ) ) {
317
- return $response;
318
- }
319
-
320
- if ( ! empty( $response['data'] ) ) {
321
- $stats['sizes'][ $size_key ] = (object) $this->_array_fill_placeholders( $this->_get_size_signature(), (array) $response['data'] );
322
- }
323
-
324
- //Total Stats, store all data in bytes
325
- if ( isset( $response['data'] ) ) {
326
- list( $size_before, $size_after, $total_time, $compression, $bytes_saved )
327
- = $this->_update_stats_data( $response['data'], $size_before, $size_after, $total_time, $bytes_saved );
328
- } else {
329
- $errors->add( "image_size_error" . $size_key, sprintf( __( "Size '%s' not processed correctly", 'wp-smushit' ), $size_key ) );
330
- }
331
-
332
- if ( empty( $stats['stats']['api_version'] ) || $stats['stats']['api_version'] == - 1 ) {
333
- $stats['stats']['api_version'] = $response['data']->api_version;
334
- $stats['stats']['lossy'] = $response['data']->lossy;
335
- }
336
- }
337
- }
338
-
339
- //If original size is supposed to be smushed
340
- if ( $smush_full ) {
341
-
342
- $full_image_response = $this->do_smushit( $attachment_file_path, $attachment_file_url );
343
-
344
- if ( is_wp_error( $full_image_response ) ) {
345
- return $full_image_response;
346
- }
347
-
348
- if ( ! empty( $full_image_response['data'] ) ) {
349
- $stats['sizes']['full'] = (object) $this->_array_fill_placeholders( $this->_get_size_signature(), (array) $full_image_response['data'] );
350
- } else {
351
- $errors->add( "image_size_error", __( "Size 'full' not processed correctly", 'wp-smushit' ) );
352
- }
353
-
354
- //Update stats
355
- if ( isset( $full_image_response['data'] ) ) {
356
- list( $size_before, $size_after, $total_time, $compression, $bytes_saved )
357
- = $this->_update_stats_data( $full_image_response['data'], $size_before, $size_after, $total_time, $bytes_saved );
358
- } else {
359
- $errors->add( "image_size_error", __( "Size 'full' not processed correctly", 'wp-smushit' ) );
360
- }
361
-
362
- //Api version and lossy, for some images, full image i skipped and for other images only full exists
363
- //so have to add code again
364
- if ( empty( $stats['stats']['api_version'] ) || $stats['stats']['api_version'] == - 1 ) {
365
- $stats['stats']['api_version'] = $full_image_response['data']->api_version;
366
- $stats['stats']['lossy'] = $full_image_response['data']->lossy;
367
- }
368
-
369
-
370
- }
371
-
372
- $has_errors = (bool) count( $errors->get_error_messages() );
373
-
374
- list( $stats['stats']['size_before'], $stats['stats']['size_after'], $stats['stats']['time'], $stats['stats']['percent'], $stats['stats']['bytes'] ) =
375
- array( $size_before, $size_after, $total_time, $compression, $bytes_saved );
376
-
377
- //Set smush status for all the images, store it in wp-smpro-smush-data
378
- if ( ! $has_errors ) {
379
-
380
- $existing_stats = get_post_meta( $ID, self::SMUSHED_META_KEY, true );
381
-
382
- if ( ! empty( $existing_stats ) ) {
383
- //Update total bytes saved, and compression percent
384
- $stats['stats']['bytes'] = isset( $existing_stats['stats']['bytes'] ) ? $existing_stats['stats']['bytes'] + $stats['stats']['bytes'] : $stats['stats']['bytes'];
385
- $stats['stats']['percent'] = isset( $existing_stats['stats']['percent'] ) ? $existing_stats['stats']['percent'] + $stats['stats']['percent'] : $stats['stats']['percent'];
386
-
387
- //Update stats for each size
388
- if ( ! empty( $existing_stats['sizes'] ) && ! empty( $stats['sizes'] ) ) {
389
-
390
- foreach ( $existing_stats['sizes'] as $size_name => $size_stats ) {
391
- //if stats for a particular size doesn't exists
392
- if ( empty( $stats['sizes'][$size_name] ) ) {
393
- $stats['sizes'][$size_name] = $existing_stats['sizes'][$size_name];
394
- } else {
395
- //Update compression percent and bytes saved for each size
396
- $stats['sizes'][$size_name]->bytes = $stats['sizes'][$size_name]->bytes + $existing_stats['sizes'][$size_name]->bytes;
397
- $stats['sizes'][$size_name]->percent = $stats['sizes'][$size_name]->percent + $existing_stats['sizes'][$size_name]->percent;
398
- }
399
- }
400
- }
401
- }
402
- update_post_meta( $ID, self::SMUSHED_META_KEY, $stats );
403
- }
404
-
405
- return $meta;
406
- }
407
-
408
- /**
409
- * Read the image paths from an attachment's meta data and process each image
410
- * with wp_smushit()
411
- *
412
- * Filters wp_generate_attachment_metadata
413
- *
414
- * @uses WpSmush::resize_from_meta_data
415
- *
416
- * @param $meta
417
- * @param null $ID
418
- *
419
- * @return mixed
420
- */
421
- function filter_generate_attachment_metadata( $meta, $ID = null ) {
422
- $this->resize_from_meta_data( $meta, $ID );
423
-
424
- return $meta;
425
- }
426
-
427
-
428
- /**
429
- * Posts an image to Smush.
430
- *
431
- * @param $file_path path of file to send to Smush
432
- * @param $file_size
433
- *
434
- * @return bool|array array containing success status, and stats
435
- */
436
- function _post( $file_path, $file_size ) {
437
-
438
- $data = false;
439
-
440
- $file = @fopen( $file_path, 'r' );
441
- $file_data = fread( $file, $file_size );
442
- $headers = array(
443
- 'accept' => 'application/json', // The API returns JSON
444
- 'content-type' => 'application/binary', // Set content type to binary
445
- );
446
-
447
- //Check if premium member, add API key
448
- $api_key = $this->_get_api_key();
449
- if ( ! empty( $api_key ) ) {
450
- $headers['apikey'] = $api_key;
451
- }
452
-
453
- //Check if lossy compression allowed and add it to headers
454
- $lossy = get_option( WP_SMUSH_PREFIX . 'lossy' );
455
-
456
- if ( $lossy && $this->is_pro() ) {
457
- $headers['lossy'] = 'true';
458
- } else {
459
- $headers['lossy'] = 'false';
460
- }
461
-
462
- $args = array(
463
- 'headers' => $headers,
464
- 'body' => $file_data,
465
- 'timeout' => WP_SMUSH_TIMEOUT,
466
- 'user-agent' => WP_SMUSH_UA
467
- );
468
- $result = wp_remote_post( WP_SMUSH_API, $args );
469
-
470
- //Close file connection
471
- fclose( $file );
472
- unset( $file_data );//free memory
473
- if ( is_wp_error( $result ) ) {
474
- //Handle error
475
- $data['message'] = sprintf( __( 'Error posting to API: %s', 'wp-smushit' ), $result->get_error_message() );
476
- $data['success'] = false;
477
- unset( $result ); //free memory
478
- return $data;
479
- } else if ( '200' != wp_remote_retrieve_response_code( $result ) ) {
480
- //Handle error
481
- $data['message'] = sprintf( __( 'Error posting to API: %s %s', 'wp-smushit' ), wp_remote_retrieve_response_code( $result ), wp_remote_retrieve_response_message( $result ) );
482
- $data['success'] = false;
483
- unset( $result ); //free memory
484
-
485
- return $data;
486
- }
487
-
488
- //If there is a response and image was successfully optimised
489
- $response = json_decode( $result['body'] );
490
- if ( $response && $response->success == true ) {
491
-
492
- //If there is any savings
493
- if ( $response->data->bytes_saved > 0 ) {
494
- $image = base64_decode( $response->data->image ); //base64_decode is necessary to send binary img over JSON, no security problems here!
495
- $image_md5 = md5( $response->data->image );
496
- if ( $response->data->image_md5 != $image_md5 ) {
497
- //Handle error
498
- $data['message'] = __( 'Smush data corrupted, try again.', 'wp-smushit' );
499
- $data['success'] = false;
500
- unset( $image );//free memory
501
- } else {
502
- $data['success'] = true;
503
- $data['data'] = $response->data;
504
- $data['data']->image = $image;
505
- unset( $image );//free memory
506
- }
507
- } else {
508
- //just return the data
509
- $data['success'] = true;
510
- $data['data'] = $response->data;
511
- }
512
- } else {
513
- //Server side error, get message from response
514
- $data['message'] = ! empty( $response->data ) ? $response->data : __( "Image couldn't be smushed", 'wp-smushit' );
515
- $data['success'] = false;
516
- }
517
-
518
- unset( $result );//free memory
519
- unset( $response );//free memory
520
- return $data;
521
- }
522
-
523
-
524
- /**
525
- * Print column header for Smush results in the media library using
526
- * the `manage_media_columns` hook.
527
- */
528
- function columns( $defaults ) {
529
- $defaults['smushit'] = 'WP Smush';
530
-
531
- return $defaults;
532
- }
533
-
534
- /**
535
- * Return the filesize in a humanly readable format.
536
- * Taken from http://www.php.net/manual/en/function.filesize.php#91477
537
- */
538
- function format_bytes( $bytes, $precision = 2 ) {
539
- $units = array( 'B', 'KB', 'MB', 'GB', 'TB' );
540
- $bytes = max( $bytes, 0 );
541
- $pow = floor( ( $bytes ? log( $bytes ) : 0 ) / log( 1024 ) );
542
- $pow = min( $pow, count( $units ) - 1 );
543
- $bytes /= pow( 1024, $pow );
544
-
545
- return round( $bytes, $precision ) . ' ' . $units[ $pow ];
546
- }
547
-
548
- /**
549
- * Print column data for Smush results in the media library using
550
- * the `manage_media_custom_column` hook.
551
- */
552
- function custom_column( $column_name, $id ) {
553
- if ( 'smushit' == $column_name ) {
554
- $this->set_status( $id );
555
- }
556
- }
557
-
558
- /**
559
- * Check if user is premium member, check for api key
560
- *
561
- * @return mixed|string
562
- */
563
- function is_pro() {
564
-
565
- if ( isset( $this->is_pro ) ) return $this->is_pro;
566
-
567
- //no api key set, always false
568
- $api_key = $this->_get_api_key();
569
- if ( empty( $api_key ) ) {
570
- return false;
571
- }
572
-
573
- $key = "wp-smush-premium-" . substr( $api_key, -10, 10); //add last 10 chars of apikey to transient key in case it changes
574
- if ( false === ( $valid = get_site_transient( $key ) ) ) {
575
- // call api
576
- $url = self::API_SERVER . '&key=' . urlencode( $api_key );
577
-
578
- $request = wp_remote_get( $url, array(
579
- "user-agent" => WP_SMUSH_UA,
580
- "timeout" => 3
581
- )
582
- );
583
-
584
- if ( ! is_wp_error( $request ) && '200' == wp_remote_retrieve_response_code( $request ) ) {
585
- $result = json_decode( wp_remote_retrieve_body( $request ) );
586
- if ( $result && $result->success ) {
587
- $valid = true;
588
- set_site_transient( $key, 1, 12 * HOUR_IN_SECONDS );
589
- } else {
590
- $valid = false;
591
- set_site_transient( $key, 0, 30 * MINUTE_IN_SECONDS ); //cache failure much shorter
592
- }
593
-
594
- } else {
595
- $valid = false;
596
- set_site_transient( $key, 0, 5 * MINUTE_IN_SECONDS ); //cache network failure even shorter, we don't want a request every pageload
597
- }
598
-
599
- }
600
-
601
- $this->is_pro = (bool) $valid;
602
- return $this->is_pro;
603
- }
604
-
605
- /**
606
- * Returns api key
607
- *
608
- * @return mixed
609
- */
610
- private function _get_api_key() {
611
- if ( defined( 'WPMUDEV_APIKEY' ) ) {
612
- $api_key = WPMUDEV_APIKEY;
613
- } else {
614
- $api_key = get_site_option( 'wpmudev_apikey' );
615
- }
616
-
617
- return $api_key;
618
- }
619
-
620
-
621
- /**
622
- * Checks if image is already smushed
623
- *
624
- * @param int $id
625
- * @param array $data
626
- *
627
- * @return bool|mixed
628
- */
629
- function is_smushed( $id, $data = null ) {
630
-
631
- //For new images
632
- $wp_is_smushed = get_post_meta( $id, 'wp-is-smushed', true );
633
-
634
- //Not smushed, backward compatibility, check attachment metadata
635
- if ( ! $wp_is_smushed && $data !== null ) {
636
- if ( isset( $data['wp_smushit'] ) && ! empty( $data['wp_smushit'] ) ) {
637
- $wp_is_smushed = true;
638
- }
639
- }
640
-
641
- return $wp_is_smushed;
642
- }
643
-
644
- /**
645
- * Returns size saved from the api call response
646
- *
647
- * @param string $message
648
- *
649
- * @return string|bool
650
- */
651
- function get_saved_size( $message ) {
652
- if ( preg_match( '/\((.*)\)/', $message, $matches ) ) {
653
- return isset( $matches[1] ) ? $matches[1] : false;
654
- }
655
-
656
- return false;
657
- }
658
-
659
- /**
660
- * Set send button status
661
- *
662
- * @param $id
663
- * @param bool $echo
664
- * @param bool $text_only
665
- *
666
- * @return string|void
667
- */
668
- function set_status( $id, $echo = true, $text_only = false ) {
669
- $status_txt = $button_txt = '';
670
- $show_button = false;
671
-
672
- //Stats are not received properly, otherwise
673
- wp_cache_delete( $id, 'post_meta' );
674
-
675
- $wp_smush_data = get_post_meta( $id, self::SMUSHED_META_KEY, true );
676
- // if the image is smushed
677
- if ( ! empty( $wp_smush_data ) ) {
678
-
679
- $bytes = isset( $wp_smush_data['stats']['bytes'] ) ? $wp_smush_data['stats']['bytes'] : 0;
680
- $bytes_readable = ! empty( $bytes ) ? $this->format_bytes( $bytes ) : '';
681
- $percent = isset( $wp_smush_data['stats']['percent'] ) ? $wp_smush_data['stats']['percent'] : 0;
682
- $percent = $percent < 0 ? 0 : $percent;
683
-
684
- if ( isset( $wp_smush_data['stats']['size_before'] ) && $wp_smush_data['stats']['size_before'] == 0 ) {
685
- $status_txt = __( 'Error processing request', 'wp-smushit' );
686
- $show_button = true;
687
- } else {
688
- if ( $bytes == 0 || $percent == 0 ) {
689
- $status_txt = __( 'Already Optimized', 'wp-smushit' );
690
- } elseif ( ! empty( $percent ) && ! empty( $bytes_readable ) ) {
691
- $status_txt = sprintf( __( "Reduced by %s ( %01.1f%% )", 'wp-smushit' ), $bytes_readable, number_format_i18n( $percent, 2, '.', '' ) );
692
- }
693
- }
694
-
695
- //IF current compression is lossy
696
- if ( ! empty( $wp_smush_data ) && ! empty( $wp_smush_data['stats'] ) ) {
697
- $lossy = !empty( $wp_smush_data['stats']['lossy'] ) ? $wp_smush_data['stats']['lossy'] : '';
698
- $is_lossy = $lossy == 1 ? true : false;
699
- }
700
-
701
- //Check if Lossy enabled
702
- $opt_lossy = WP_SMUSH_PREFIX . 'lossy';
703
- $opt_lossy_val = get_option( $opt_lossy, false );
704
-
705
- //Check image type
706
- $image_type = get_post_mime_type( $id );
707
-
708
- //Check if premium user, compression was lossless, and lossy compression is enabled
709
- if ( $this->is_pro() && ! $is_lossy && $opt_lossy_val && $image_type != 'image/gif' ) {
710
- // the button text
711
- $button_txt = __( 'Super-Smush', 'wp-smushit' );
712
- $show_button = true;
713
- }
714
- } else {
715
-
716
- // the status
717
- $status_txt = __( 'Not processed', 'wp-smushit' );
718
-
719
- // we need to show the smush button
720
- $show_button = true;
721
-
722
- // the button text
723
- $button_txt = __( 'Smush Now!', 'wp-smushit' );
724
- }
725
- if ( $text_only ) {
726
- return $status_txt;
727
- }
728
-
729
- $text = $this->column_html( $id, $status_txt, $button_txt, $show_button, $wp_smush_data, $echo );
730
- if ( ! $echo ) {
731
- return $text;
732
- }
733
- }
734
-
735
- /**
736
- * Print the column html
737
- *
738
- * @param string $id Media id
739
- * @param string $status_txt Status text
740
- * @param string $button_txt Button label
741
- * @param boolean $show_button Whether to shoe the button
742
- *
743
- * @return null
744
- */
745
- function column_html( $id, $status_txt = "", $button_txt = "", $show_button = true, $smushed = false, $echo = true ) {
746
- $allowed_images = array( 'image/jpeg', 'image/jpg', 'image/png', 'image/gif' );
747
-
748
- // don't proceed if attachment is not image, or if image is not a jpg, png or gif
749
- if ( ! wp_attachment_is_image( $id ) || ! in_array( get_post_mime_type( $id ), $allowed_images ) ) {
750
- return;
751
- }
752
-
753
- $class = $smushed ? '' : ' hidden';
754
- $html = '
755
- <p class="smush-status' . $class . '">' . $status_txt . '</p>';
756
- // if we aren't showing the button
757
- if ( ! $show_button ) {
758
- if ( $echo ) {
759
- echo $html;
760
-
761
- return;
762
- } else {
763
- if ( ! $smushed ) {
764
- $class = ' currently-smushing';
765
- } else {
766
- $class = ' smushed';
767
- }
768
-
769
- return '<div class="smush-wrap' . $class . '">' . $html . '</div>';
770
- }
771
- }
772
- if ( ! $echo ) {
773
- $html .= '
774
- <button class="button button-primary wp-smush-send" data-id="' . $id . '">
775
- <span>' . $button_txt . '</span>
776
- </button>';
777
- if ( ! $smushed ) {
778
- $class = ' unsmushed';
779
- } else {
780
- $class = ' smushed';
781
- }
782
-
783
- return '<div class="smush-wrap' . $class . '">' . $html . '</div>';
784
- } else {
785
- $html .= '<button class="button wp-smush-send" data-id="' . $id . '">
786
- <span>' . $button_txt . '</span>
787
- </button>';
788
- echo $html;
789
- }
790
- }
791
-
792
- /**
793
- * Migrates smushit api message to the latest structure
794
- *
795
- *
796
- * @return void
797
- */
798
- function migrate() {
799
-
800
- if ( ! version_compare( $this->version, "1.7.1", "lte" ) ) {
801
- return;
802
- }
803
-
804
- $migrated_version = get_option( self::MIGRATED_VERSION );
805
-
806
- if ( $migrated_version === $this->version ) {
807
- return;
808
- }
809
-
810
- global $wpdb;
811
-
812
- $q = $wpdb->prepare( "SELECT * FROM `" . $wpdb->postmeta . "` WHERE `meta_key`=%s AND `meta_value` LIKE %s ", "_wp_attachment_metadata", "%wp_smushit%" );
813
- $results = $wpdb->get_results( $q );
814
-
815
- if ( count( $results ) < 1 ) {
816
- return;
817
- }
818
-
819
- $migrator = new WpSmushMigrate();
820
- foreach ( $results as $attachment_meta ) {
821
- $migrated_message = $migrator->migrate_api_message( maybe_unserialize( $attachment_meta->meta_value ) );
822
- if ( $migrated_message !== array() ) {
823
- update_post_meta( $attachment_meta->post_id, self::SMUSHED_META_KEY, $migrated_message );
824
- }
825
- }
826
-
827
- update_option( self::MIGRATED_VERSION, $this->version );
828
-
829
- }
830
-
831
- /**
832
- * @param Object $response_data
833
- * @param $size_before
834
- * @param $size_after
835
- * @param $total_time
836
- * @param $bytes_saved
837
- *
838
- * @return array
839
- */
840
- private function _update_stats_data( $response_data, $size_before, $size_after, $total_time, $bytes_saved ) {
841
- $size_before += ! empty( $response_data->before_size ) ? (int) $response_data->before_size : 0;
842
- $size_after += ( ! empty( $response_data->after_size ) && $response_data->after_size > 0 ) ? (int) $response_data->after_size : (int) $response_data->before_size;
843
- $total_time += ! empty( $response_data->time ) ? (float) $response_data->time : 0;
844
- $bytes_saved += ( ! empty( $response_data->bytes_saved ) && $response_data->bytes_saved > 0 ) ? $response_data->bytes_saved : 0;
845
- $compression = ( $bytes_saved > 0 && $size_before > 0 ) ? ( ( $bytes_saved / $size_before ) * 100 ) : 0;
846
-
847
- return array( $size_before, $size_after, $total_time, $compression, $bytes_saved );
848
- }
849
- }
850
-
851
- global $WpSmush;
852
- $WpSmush = new WpSmush();
853
-
854
- }
855
-
856
- //Include Admin classes
857
- require_once( WP_SMUSH_DIR . '/lib/class-wp-smush-bulk.php' );
858
- require_once( WP_SMUSH_DIR . '/lib/class-wp-smush-admin.php' );
859
-
860
- //require_once( WP_SMUSH_DIR . '/extras/dash-notice/wpmudev-dash-notification.php' );
861
- require_once( WP_SMUSH_DIR . '/extras/free-dashboard/module.php' );
862
 
863
  // Register the current plugin.
864
- do_action(
865
- 'wdev-register-plugin',
866
- /* 1 Plugin ID */ plugin_basename( __FILE__ ), /* Plugin ID */
867
- /* 2 Plugin Title */ 'WP Smush',
868
- /* 3 https://wordpress.org */ '/plugins/wp-smushit/',
869
- /* 4 Email Button CTA */ __( 'Get Fast', 'wp-smushit' ),
870
- /* 5 getdrip Plugin param */ 'Smush'
871
- );
 
 
 
 
 
872
 
873
  // The rating message contains 2 variables: user-name, plugin-name
874
- add_filter(
875
- 'wdev-rating-message-' . plugin_basename( __FILE__ ),
876
- 'wp_smush_rating_message'
877
- );
878
-
879
- /**
880
- * Filters the rating message, include stats if greater than 1Mb
881
- * @param $message
882
- *
883
- * @return string
884
- */
885
- function wp_smush_rating_message( $message ) {
886
- global $wpsmushit_admin;
887
- $savings = $wpsmushit_admin->global_stats();
888
- $image_count = $wpsmushit_admin->total_count();
889
- $show_stats = false;
890
-
891
- //If there is any saving, greater than 1Mb, show stats
892
- if( !empty( $savings ) && !empty( $savings['bytes'] ) && $savings['bytes'] > 1048576 ) {
893
- $show_stats = true;
894
- }
895
-
896
- $message = "Hey %s, you've been using %s for a while now, and we hope you're happy with it.";
897
-
898
- //Conditionally Show stats in rating message
899
- if( $show_stats ) {
900
- $message .= sprintf( " You've smushed <strong>%s</strong> from %d images already, improving the speed and SEO ranking of this site!", $savings['human'], $image_count );
 
 
 
 
 
901
  }
902
- $message .= " We've spent countless hours developing this free plugin for you, and we would really appreciate it if you dropped us a quick rating!";
903
-
904
- return $message;
905
- }
906
 
907
  // The email message contains 1 variable: plugin-name
908
- add_filter(
909
- 'wdev-email-message-' . plugin_basename( __FILE__ ),
910
- 'wp_smush_email_message'
911
- );
912
- function wp_smush_email_message( $message ) {
913
- $message = "You're awesome for installing %s! Site speed isn't all image optimization though, so we've collected all the best speed resources we know in a single email - just for users of WP Smush!";
914
- return $message;
915
- }
916
- // All done!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  Plugin URI: http://wordpress.org/extend/plugins/wp-smushit/
5
  Description: Reduce image file sizes, improve performance and boost your SEO using the free <a href="https://premium.wpmudev.org/">WPMU DEV</a> WordPress Smush API.
6
  Author: WPMU DEV
7
+ Version: 2.0.6.5
8
  Author URI: http://premium.wpmudev.org/
9
  Textdomain: wp-smushit
10
  */
36
  * Constants
37
  */
38
  $prefix = 'WP_SMUSH_';
39
+ $version = '2.0.6.5';
40
+
41
+ /**
42
+ * Set the default timeout for API request and AJAX timeout
43
+ */
44
+ $timeout = apply_filters( 'WP_SMUSH_API_TIMEOUT', 90 );
45
+
46
+ $smush_constants = array(
47
+ 'VERSION' => $version,
48
  'BASENAME' => plugin_basename( __FILE__ ),
49
  'API' => 'https://smushpro.wpmudev.org/1.0/',
50
  'UA' => 'WP Smush/' . $version . '; ' . network_home_url(),
53
  'MAX_BYTES' => 1000000,
54
  'PREMIUM_MAX_BYTES' => 32000000,
55
  'PREFIX' => 'wp-smush-',
56
+ 'TIMEOUT' => $timeout
 
57
  );
58
 
59
+ foreach ( $smush_constants as $const_name => $constant_val ) {
60
  if ( ! defined( $prefix . $const_name ) ) {
61
  define( $prefix . $const_name, $constant_val );
62
  }
63
  }
64
+ //Include main class
65
+ require_once WP_SMUSH_DIR . 'lib/class-wp-smush.php';
66
 
67
+ //Only for wordpress.org members
68
+ $plugin = basename( plugin_dir_path( __FILE__ ) );
69
+ if ( $plugin == 'wp-smushit' ) {
70
+ require_once( WP_SMUSH_DIR . 'extras/free-dashboard/module.php' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
 
72
  // Register the current plugin.
73
+ do_action(
74
+ 'wdev-register-plugin',
75
+ /* 1 Plugin ID */
76
+ plugin_basename( __FILE__ ), /* Plugin ID */
77
+ /* 2 Plugin Title */
78
+ 'WP Smush',
79
+ /* 3 https://wordpress.org */
80
+ '/plugins/wp-smushit/',
81
+ /* 4 Email Button CTA */
82
+ __( 'Get Fast', 'wp-smushit' ),
83
+ /* 5 getdrip Plugin param */
84
+ 'Smush'
85
+ );
86
 
87
  // The rating message contains 2 variables: user-name, plugin-name
88
+ add_filter(
89
+ 'wdev-rating-message-' . plugin_basename( __FILE__ ),
90
+ 'wp_smush_rating_message'
91
+ );
92
+
93
+ /**
94
+ * Filters the rating message, include stats if greater than 1Mb
95
+ *
96
+ * @param $message
97
+ *
98
+ * @return string
99
+ */
100
+ function wp_smush_rating_message( $message ) {
101
+ global $wpsmushit_admin;
102
+ $savings = $wpsmushit_admin->global_stats();
103
+ $image_count = $wpsmushit_admin->total_count();
104
+ $show_stats = false;
105
+
106
+ //If there is any saving, greater than 1Mb, show stats
107
+ if ( ! empty( $savings ) && ! empty( $savings['bytes'] ) && $savings['bytes'] > 1048576 ) {
108
+ $show_stats = true;
109
+ }
110
+
111
+ $message = "Hey %s, you've been using %s for a while now, and we hope you're happy with it.";
112
+
113
+ //Conditionally Show stats in rating message
114
+ if ( $show_stats ) {
115
+ $message .= sprintf( " You've smushed <strong>%s</strong> from %d images already, improving the speed and SEO ranking of this site!", $savings['human'], $image_count );
116
+ }
117
+ $message .= " We've spent countless hours developing this free plugin for you, and we would really appreciate it if you dropped us a quick rating!";
118
+
119
+ return $message;
120
  }
 
 
 
 
121
 
122
  // The email message contains 1 variable: plugin-name
123
+ add_filter(
124
+ 'wdev-email-message-' . plugin_basename( __FILE__ ),
125
+ 'wp_smush_email_message'
126
+ );
127
+ function wp_smush_email_message( $message ) {
128
+ $message = "You're awesome for installing %s! Site speed isn't all image optimization though, so we've collected all the best speed resources we know in a single email - just for users of WP Smush!";
129
+
130
+ return $message;
131
+ }
132
+ } elseif ( $plugin == 'wp-smush-pro' ) {
133
+
134
+ //Only for WPMU DEV Members
135
+ require_once( WP_SMUSH_DIR . 'extras/dash-notice/wpmudev-dash-notification.php' );
136
+ //register items for the dashboard plugin
137
+ global $wpmudev_notices;
138
+ $wpmudev_notices[] = array(
139
+ 'id' => 912164,
140
+ 'name' => 'WP Smush Pro',
141
+ 'screens' => array(
142
+ 'media_page_wp-smush-bulk',
143
+ 'upload'
144
+ )
145
+ );
146
+ }