Version Description
- New: Allow Super-smush for existing smushed images (Pro Only)
- Fixed: IMPORTANT - broken transient caching for is_pro
- Fixed: Fixed conflict with wp gallery link plugin in grid view
- Fixed: Other small fixes
Download this release
Release Info
Developer | UmeshSingla |
Plugin | Smush Image Compression and Optimization |
Version | 2.0.5 |
Comparing to | |
See all releases |
Code changes from version 2.0.4 to 2.0.5
- assets/css/wp-smushit-admin.css +37 -8
- assets/js/wp-smushit-admin.js +314 -280
- languages/wp-smush.pot +118 -84
- lib/class-wp-smush-admin.php +227 -66
- lib/class-wp-smush-bulk.php +2 -7
- readme.txt +11 -4
- wp-smush.php +98 -130
assets/css/wp-smushit-admin.css
CHANGED
@@ -251,26 +251,29 @@ Progressbar ui
|
|
251 |
margin-bottom: 20px;
|
252 |
}
|
253 |
|
254 |
-
#progress-ui #wp-smush-progress-wrap {
|
255 |
height: 20px;
|
256 |
border: 1px solid #0074a2;
|
257 |
border-radius: 10px;
|
258 |
overflow: hidden;
|
259 |
position: relative;
|
260 |
}
|
|
|
|
|
|
|
261 |
|
262 |
-
#progress-ui #wp-smush-progress-wrap .wp-smush-progressbar {
|
263 |
height: 20px;
|
264 |
position: absolute;
|
265 |
width: 100%;
|
266 |
}
|
267 |
|
268 |
-
#progress-ui #wp-smush-progress-wrap .wp-smush-progressbar div {
|
269 |
height: 20px;
|
270 |
border-radius: 10px;
|
271 |
}
|
272 |
|
273 |
-
#progress-ui #wp-smush-progress-wrap #wp-smush-fetched-progress div {
|
274 |
background-color: #7ad03a;
|
275 |
}
|
276 |
|
@@ -429,10 +432,6 @@ input#wp-smush-save-settings {
|
|
429 |
max-width: 60%;
|
430 |
}
|
431 |
|
432 |
-
.smush-wrap.unsmushed .smush-status {
|
433 |
-
display: block;
|
434 |
-
}
|
435 |
-
|
436 |
.currently-smushing .smush-status {
|
437 |
color: #0074a2;
|
438 |
}
|
@@ -458,6 +457,36 @@ input#wp-smush-save-settings {
|
|
458 |
color: red;
|
459 |
}
|
460 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
461 |
/*===================================*\
|
462 |
=======================================
|
463 |
== ==
|
251 |
margin-bottom: 20px;
|
252 |
}
|
253 |
|
254 |
+
#progress-ui #wp-smush-progress-wrap, #progress-ui #wp-smush-ss-progress-wrap {
|
255 |
height: 20px;
|
256 |
border: 1px solid #0074a2;
|
257 |
border-radius: 10px;
|
258 |
overflow: hidden;
|
259 |
position: relative;
|
260 |
}
|
261 |
+
#progress-ui #wp-smush-ss-progress-wrap {
|
262 |
+
/*background-color: #2ea2cc;*/
|
263 |
+
}
|
264 |
|
265 |
+
#progress-ui #wp-smush-progress-wrap .wp-smush-progressbar, #progress-ui #wp-smush-ss-progress-wrap .wp-smush-progressbar {
|
266 |
height: 20px;
|
267 |
position: absolute;
|
268 |
width: 100%;
|
269 |
}
|
270 |
|
271 |
+
#progress-ui #wp-smush-progress-wrap .wp-smush-progressbar div, #progress-ui #wp-smush-ss-progress-wrap .wp-smush-progressbar div {
|
272 |
height: 20px;
|
273 |
border-radius: 10px;
|
274 |
}
|
275 |
|
276 |
+
#progress-ui #wp-smush-progress-wrap #wp-smush-fetched-progress div, #progress-ui #wp-smush-ss-progress-wrap #wp-smush-ss-progress div {
|
277 |
background-color: #7ad03a;
|
278 |
}
|
279 |
|
432 |
max-width: 60%;
|
433 |
}
|
434 |
|
|
|
|
|
|
|
|
|
435 |
.currently-smushing .smush-status {
|
436 |
color: #0074a2;
|
437 |
}
|
457 |
color: red;
|
458 |
}
|
459 |
|
460 |
+
.smush_attachment_detail_loader {
|
461 |
+
float: left;
|
462 |
+
}
|
463 |
+
|
464 |
+
.compat-field-wp_smush {
|
465 |
+
margin-top: 10px;
|
466 |
+
}
|
467 |
+
|
468 |
+
.attachment-info .smush-status {
|
469 |
+
margin: 1px 0 0;
|
470 |
+
padding: 0;
|
471 |
+
line-height: 29px;
|
472 |
+
}
|
473 |
+
|
474 |
+
#post-body-content .wp-smush-send {
|
475 |
+
margin: 4px 0 0;
|
476 |
+
}
|
477 |
+
#post-body-content .smush-status {
|
478 |
+
margin: 4px 0;
|
479 |
+
}
|
480 |
+
|
481 |
+
.compat-field-wp_smush button {
|
482 |
+
float: left;
|
483 |
+
}
|
484 |
+
|
485 |
+
.compat-field-wp_smush .smush-wrap {
|
486 |
+
margin: 0;
|
487 |
+
max-width: 100%;
|
488 |
+
}
|
489 |
+
|
490 |
/*===================================*\
|
491 |
=======================================
|
492 |
== ==
|
assets/js/wp-smushit-admin.js
CHANGED
@@ -37,292 +37,326 @@ jQuery(function ($) {
|
|
37 |
});
|
38 |
};
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
|
80 |
-
|
81 |
-
|
82 |
-
this.single_start = function(){
|
83 |
-
if( this.is_bulk ) return;
|
84 |
-
this.$button_span.text(wp_smush_msgs.sending);
|
85 |
-
this.$status.removeClass("error");
|
86 |
-
};
|
87 |
-
|
88 |
-
this.enable_button = function(){
|
89 |
-
this.$button.prop("disabled", false);
|
90 |
-
};
|
91 |
-
|
92 |
-
|
93 |
-
this.disable_button = function(){
|
94 |
-
this.$button.prop("disabled", true);
|
95 |
-
};
|
96 |
-
|
97 |
-
this.show_loader = function(){
|
98 |
-
this.$loader.removeClass("hidden");
|
99 |
-
this.$loader.show();
|
100 |
-
};
|
101 |
-
|
102 |
-
this.hide_loader = function(){
|
103 |
-
this.$loader.hide();
|
104 |
-
};
|
105 |
-
|
106 |
-
this.single_done = function(){
|
107 |
-
if( this.is_bulk ) return;
|
108 |
-
|
109 |
-
this.hide_loader();
|
110 |
-
this.request.done(function(response){
|
111 |
-
if (typeof response.data != 'undefined') {
|
112 |
-
//Append the smush stats or error
|
113 |
-
self.$status.html(response.data);
|
114 |
-
if (response.success && response.data !== "Not processed") {
|
115 |
-
self.$button.remove();
|
116 |
-
} else {
|
117 |
-
self.$status.addClass("error");
|
118 |
-
}
|
119 |
-
self.$status.html(response.data);
|
120 |
-
}
|
121 |
-
self.$button_span.text( self.button_text );
|
122 |
-
self.enable_button();
|
123 |
-
}).error(function (response) {
|
124 |
-
self.$status.html(response.data);
|
125 |
-
self.$status.addClass("error");
|
126 |
-
self.enable_button();
|
127 |
-
self.$button_span.text( self.button_text );
|
128 |
-
});
|
129 |
-
|
130 |
-
};
|
131 |
-
|
132 |
-
this.bulk_done = function(){
|
133 |
-
if( !this.is_bulk ) return;
|
134 |
-
|
135 |
-
this.hide_loader();
|
136 |
-
|
137 |
-
// Add finished class
|
138 |
-
this.$button.addClass('wp-smush-finished');
|
139 |
-
|
140 |
-
// Remove started class
|
141 |
-
this.$button.removeClass('wp-smush-started');
|
142 |
-
|
143 |
-
//Enable the button
|
144 |
-
this.disable_button();
|
145 |
-
|
146 |
-
// Update button text
|
147 |
-
self.$button_span.text( wp_smush_msgs.done );
|
148 |
-
};
|
149 |
-
|
150 |
-
this.is_resolved = function(){
|
151 |
-
"use strict";
|
152 |
-
return this.deferred.state() === "resolved";
|
153 |
-
};
|
154 |
-
|
155 |
-
this.free_exceeded = function(){
|
156 |
-
this.hide_loader();
|
157 |
-
|
158 |
-
// Add new class for css adjustment
|
159 |
-
this.$button.removeClass('wp-smush-started');
|
160 |
-
|
161 |
-
//Enable button
|
162 |
-
this.$button.prop("disabled", false);
|
163 |
-
|
164 |
-
// Update text
|
165 |
-
this.$button.find('span').html(wp_smush_msgs.bulk_now);
|
166 |
-
};
|
167 |
-
|
168 |
-
this.update_progress = function(stats){
|
169 |
-
var progress = ( stats.data.smushed / stats.data.total) * 100;
|
170 |
-
|
171 |
-
//Update stats
|
172 |
-
$('#wp-smush-compression #human').html(stats.data.human);
|
173 |
-
$('#wp-smush-compression #percent').html(stats.data.percent);
|
174 |
-
|
175 |
-
// increase the progress bar
|
176 |
-
this._update_progress(stats.data.smushed, progress);
|
177 |
-
};
|
178 |
-
|
179 |
-
this._update_progress = function( count, width ){
|
180 |
-
"use strict";
|
181 |
-
// get the progress bar
|
182 |
-
var $progress_bar = jQuery('#wp-smush-progress-wrap #wp-smush-fetched-progress div');
|
183 |
-
if ($progress_bar.length < 1) {
|
184 |
-
return;
|
185 |
-
}
|
186 |
-
$('.done-count').html(count);
|
187 |
-
// increase progress
|
188 |
-
$progress_bar.css('width', width + '%');
|
189 |
-
|
190 |
-
};
|
191 |
-
|
192 |
-
this.continue = function(){
|
193 |
-
return this.ids.length > 0 && this.is_bulk;
|
194 |
-
};
|
195 |
-
|
196 |
-
this.increment_errors = function(){
|
197 |
-
WP_Smush.errors.push(this.current_id);
|
198 |
-
};
|
199 |
-
|
200 |
-
this.call_ajax = function(){
|
201 |
-
|
202 |
-
this.current_id = this.is_bulk ? this.ids.shift() : this.$button.data("id"); //remove from array while processing so we can continue where left off
|
203 |
-
|
204 |
-
this.request = WP_Smush.ajax(this.current_id, this.url , 0)
|
205 |
-
.complete(function(){
|
206 |
-
if( !self.continue() || !self.is_bulk ){
|
207 |
-
self.deferred.resolve();
|
208 |
-
}
|
209 |
-
})
|
210 |
-
.error(function () {
|
211 |
-
self.increment_errors();
|
212 |
-
}).done(function (res) {
|
213 |
-
self.update_progress(res);
|
214 |
-
|
215 |
-
if (typeof res.success === "undefined" || ( typeof res.success !== "undefined" && res.success === false && res.data.error !== 'bulk_request_image_limit_exceeded' )) {
|
216 |
-
self.increment_errors();
|
217 |
-
}
|
218 |
-
|
219 |
-
if (typeof res.data !== "undefined" && res.data.error == 'bulk_request_image_limit_exceeded' && !self.is_resolved() ) {
|
220 |
-
self.free_exceeded();
|
221 |
-
}else{
|
222 |
-
if( self.continue() ){
|
223 |
-
self.call_ajax();
|
224 |
-
}
|
225 |
-
}
|
226 |
-
self.single_done();
|
227 |
-
});
|
228 |
-
|
229 |
-
self.deferred.errors = WP_Smush.errors;
|
230 |
-
return self.deferred;
|
231 |
-
};
|
232 |
-
|
233 |
-
this.init( arguments );
|
234 |
-
this.run = function(){
|
235 |
-
|
236 |
-
// if we have a definite number of ids
|
237 |
-
if ( this.is_bulk && this.ids.length > 0) {
|
238 |
-
this.call_ajax();
|
239 |
-
}
|
240 |
|
241 |
-
|
242 |
-
|
243 |
|
244 |
-
|
|
|
245 |
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
var error_message = wp_smush_msgs.error_in_bulk.replace("{{errors}}", WP_Smush.errors.length);
|
251 |
-
self.$log.append(error_message);
|
252 |
-
}
|
253 |
-
self.bulk_done();
|
254 |
-
});
|
255 |
-
|
256 |
-
};
|
257 |
-
|
258 |
-
this.start();
|
259 |
-
this.run();
|
260 |
-
this.bind_deferred_events();
|
261 |
-
return this.deferred;
|
262 |
-
};
|
263 |
-
/**
|
264 |
-
* Handle the start button click
|
265 |
-
*/
|
266 |
-
$('button[name="smush-all"]').on('click', function (e) {
|
267 |
-
// prevent the default action
|
268 |
-
e.preventDefault();
|
269 |
-
|
270 |
-
$(".smush-remaining-images-notice").remove();
|
271 |
-
//Enable Cancel button
|
272 |
-
$('#wp-smush-cancel').prop('disabled', false);
|
273 |
-
|
274 |
-
new WP_Smush.Smush( $(this), true );
|
275 |
-
|
276 |
-
//buttonProgress(jQuery(this), wp_smush_msgs.progress, wp_smushit_bulk_smush());
|
277 |
-
});
|
278 |
-
|
279 |
-
//Handle smush button click
|
280 |
-
$('body').on('click', '.wp-smush-send', function (e) {
|
281 |
-
|
282 |
-
// prevent the default action
|
283 |
-
e.preventDefault();
|
284 |
-
new WP_Smush.Smush( $(this), false );
|
285 |
-
});
|
286 |
|
287 |
});
|
288 |
(function ($) {
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
303 |
|
304 |
-
// Return early if this element already has a plugin instance
|
305 |
-
if (element.data('wpsmush'))
|
306 |
-
return;
|
307 |
-
|
308 |
-
// pass options to plugin constructor and create a new instance
|
309 |
-
var wpsmush = new Smush(this, options);
|
310 |
-
|
311 |
-
// Store plugin object in this element's data
|
312 |
-
element.data('wpsmush', wpsmush);
|
313 |
-
});
|
314 |
-
};
|
315 |
-
if (typeof wp !== 'undefined') {
|
316 |
-
_.extend(wp.media.view.AttachmentCompat.prototype, {
|
317 |
-
render: function () {
|
318 |
-
$view = this;
|
319 |
-
//Dirty hack, as there is no way around to get updated status of attachment
|
320 |
-
$html = jQuery.get(ajaxurl + '?action=attachment_status', {'id': this.model.get('id')}, function (res) {
|
321 |
-
$view.$el.html(res.data);
|
322 |
-
$view.views.render();
|
323 |
-
return $view;
|
324 |
-
});
|
325 |
-
}
|
326 |
-
});
|
327 |
-
}
|
328 |
})(jQuery);
|
37 |
});
|
38 |
};
|
39 |
|
40 |
+
WP_Smush.Smush = function ($button, bulk) {
|
41 |
+
var self = this;
|
42 |
+
|
43 |
+
this.init = function (arguments) {
|
44 |
+
this.$button = $($button[0]);
|
45 |
+
this.is_bulk = typeof bulk ? bulk : false;
|
46 |
+
this.url = ajaxurl;
|
47 |
+
this.url += this.is_bulk ? '?action=wp_smushit_bulk' : '?action=wp_smushit_manual';
|
48 |
+
this.button_text = this.is_bulk ? wp_smush_msgs.bulk_now : wp_smush_msgs.smush_now;
|
49 |
+
this.$log = $(".smush-final-log");
|
50 |
+
this.$button_span = this.$button.find("span");
|
51 |
+
this.$loader = $(".wp-smush-loader-wrap").eq(0).clone();
|
52 |
+
this.deferred = jQuery.Deferred();
|
53 |
+
this.deferred.errors = [];
|
54 |
+
this.ids = wp_smushit_data.unsmushed.length > 0 ? wp_smushit_data.unsmushed : wp_smushit_data.lossless;
|
55 |
+
this.is_bulk_super_smush = wp_smushit_data.unsmushed.length > 0 ? false : true;
|
56 |
+
this.lossless_count = wp_smushit_data.lossless.length;
|
57 |
+
this.$status = this.$button.parent().find('.smush-status');
|
58 |
+
};
|
59 |
+
|
60 |
+
//Show loader in button for single and bulk smush
|
61 |
+
this.start = function () {
|
62 |
+
|
63 |
+
this.$button.attr('disabled', 'disabled');
|
64 |
+
this.$button.addClass('wp-smush-started');
|
65 |
+
if (!this.$button.find(".wp-smush-loader-wrap").length) {
|
66 |
+
this.$button.prepend(this.$loader);
|
67 |
+
} else {
|
68 |
+
this.$loader = this.$button.find(".wp-smush-loader-wrap");
|
69 |
+
}
|
70 |
+
|
71 |
+
|
72 |
+
this.show_loader();
|
73 |
+
this.bulk_start();
|
74 |
+
this.single_start();
|
75 |
+
};
|
76 |
+
|
77 |
+
this.bulk_start = function () {
|
78 |
+
if (!this.is_bulk) return;
|
79 |
+
$('#progress-ui').show();
|
80 |
+
this.$button_span.text(wp_smush_msgs.progress);
|
81 |
+
this.show_loader();
|
82 |
+
|
83 |
+
};
|
84 |
+
|
85 |
+
this.single_start = function () {
|
86 |
+
if (this.is_bulk) return;
|
87 |
+
this.$button_span.text(wp_smush_msgs.sending);
|
88 |
+
this.$status.removeClass("error");
|
89 |
+
};
|
90 |
+
|
91 |
+
this.enable_button = function () {
|
92 |
+
this.$button.prop("disabled", false);
|
93 |
+
};
|
94 |
+
|
95 |
+
|
96 |
+
this.disable_button = function () {
|
97 |
+
this.$button.prop("disabled", true);
|
98 |
+
};
|
99 |
+
|
100 |
+
this.show_loader = function () {
|
101 |
+
this.$loader.removeClass("hidden");
|
102 |
+
this.$loader.show();
|
103 |
+
};
|
104 |
+
|
105 |
+
this.hide_loader = function () {
|
106 |
+
this.$loader.hide();
|
107 |
+
};
|
108 |
+
|
109 |
+
this.single_done = function () {
|
110 |
+
if (this.is_bulk) return;
|
111 |
+
|
112 |
+
this.hide_loader();
|
113 |
+
this.request.done(function (response) {
|
114 |
+
if (typeof response.data != 'undefined') {
|
115 |
+
//Append the smush stats or error
|
116 |
+
self.$status.html(response.data);
|
117 |
+
if (response.success && response.data !== "Not processed") {
|
118 |
+
self.$status.removeClass('hidden');
|
119 |
+
self.$button.parent().removeClass('unsmushed').addClass('smushed');
|
120 |
+
self.$button.remove();
|
121 |
+
} else {
|
122 |
+
self.$status.addClass("error");
|
123 |
+
}
|
124 |
+
self.$status.html(response.data);
|
125 |
+
}
|
126 |
+
self.$button_span.text(self.button_text);
|
127 |
+
self.enable_button();
|
128 |
+
}).error(function (response) {
|
129 |
+
self.$status.html(response.data);
|
130 |
+
self.$status.addClass("error");
|
131 |
+
self.enable_button();
|
132 |
+
self.$button_span.text(self.button_text);
|
133 |
+
});
|
134 |
+
|
135 |
+
};
|
136 |
+
|
137 |
+
this.bulk_done = function () {
|
138 |
+
if (!this.is_bulk) return;
|
139 |
+
|
140 |
+
this.hide_loader();
|
141 |
+
|
142 |
+
// Add finished class
|
143 |
+
this.$button.addClass('wp-smush-finished');
|
144 |
+
|
145 |
+
// Remove started class
|
146 |
+
this.$button.removeClass('wp-smush-started');
|
147 |
+
|
148 |
+
//Enable the button
|
149 |
+
this.disable_button();
|
150 |
+
|
151 |
+
// Update button text
|
152 |
+
self.$button_span.text(wp_smush_msgs.done);
|
153 |
+
};
|
154 |
+
|
155 |
+
this.is_resolved = function () {
|
156 |
+
"use strict";
|
157 |
+
return this.deferred.state() === "resolved";
|
158 |
+
};
|
159 |
+
|
160 |
+
this.free_exceeded = function () {
|
161 |
+
this.hide_loader();
|
162 |
+
|
163 |
+
// Add new class for css adjustment
|
164 |
+
this.$button.removeClass('wp-smush-started');
|
165 |
+
|
166 |
+
//Enable button
|
167 |
+
this.$button.prop("disabled", false);
|
168 |
+
|
169 |
+
// Update text
|
170 |
+
this.$button.find('span').html(wp_smush_msgs.bulk_now);
|
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 |
+
}
|
186 |
+
|
187 |
+
//Update stats
|
188 |
+
$('#wp-smush-compression #human').html(stats.data.human);
|
189 |
+
$('#wp-smush-compression #percent').html(stats.data.percent);
|
190 |
+
|
191 |
+
// increase the progress bar
|
192 |
+
this._update_progress(stats.data.smushed, progress);
|
193 |
+
};
|
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) {
|
205 |
+
return;
|
206 |
+
}
|
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');
|
216 |
+
if ($progress_bar.length < 1) {
|
217 |
+
return;
|
218 |
+
}
|
219 |
+
// increase progress
|
220 |
+
$progress_bar.css('width', progress_width + '%');
|
221 |
+
}
|
222 |
+
}
|
223 |
+
|
224 |
+
};
|
225 |
+
|
226 |
+
this.continue = function () {
|
227 |
+
return this.ids.length > 0 && this.is_bulk;
|
228 |
+
};
|
229 |
+
|
230 |
+
this.increment_errors = function () {
|
231 |
+
WP_Smush.errors.push(this.current_id);
|
232 |
+
};
|
233 |
+
|
234 |
+
//Send ajax request for smushing single and bulk, call update_progress on ajax response
|
235 |
+
this.call_ajax = function () {
|
236 |
+
|
237 |
+
this.current_id = this.is_bulk ? this.ids.shift() : this.$button.data("id"); //remove from array while processing so we can continue where left off
|
238 |
+
|
239 |
+
this.request = WP_Smush.ajax(this.current_id, this.url, 0)
|
240 |
+
.complete(function () {
|
241 |
+
if (!self.continue() || !self.is_bulk) {
|
242 |
+
self.deferred.resolve();
|
243 |
+
}
|
244 |
+
})
|
245 |
+
.error(function () {
|
246 |
+
self.increment_errors();
|
247 |
+
}).done(function (res) {
|
248 |
+
self.update_progress(res);
|
249 |
+
|
250 |
+
if (typeof res.success === "undefined" || ( typeof res.success !== "undefined" && res.success === false && res.data.error !== 'bulk_request_image_limit_exceeded' )) {
|
251 |
+
self.increment_errors();
|
252 |
+
}
|
253 |
+
|
254 |
+
if (typeof res.data !== "undefined" && res.data.error == 'bulk_request_image_limit_exceeded' && !self.is_resolved()) {
|
255 |
+
self.free_exceeded();
|
256 |
+
} else {
|
257 |
+
if (self.continue()) {
|
258 |
+
self.call_ajax();
|
259 |
+
}
|
260 |
+
}
|
261 |
+
self.single_done();
|
262 |
+
});
|
263 |
+
|
264 |
+
self.deferred.errors = WP_Smush.errors;
|
265 |
+
return self.deferred;
|
266 |
+
};
|
267 |
+
|
268 |
+
this.init(arguments);
|
269 |
+
|
270 |
+
//Send ajax request for single and bulk smushing
|
271 |
+
this.run = function () {
|
272 |
+
|
273 |
+
// if we have a definite number of ids
|
274 |
+
if (this.is_bulk && this.ids.length > 0) {
|
275 |
+
this.call_ajax();
|
276 |
+
}
|
277 |
+
|
278 |
+
if (!this.is_bulk)
|
279 |
+
this.call_ajax();
|
280 |
+
|
281 |
+
};
|
282 |
+
|
283 |
+
//Show bulk smush errors, and disable bulk smush button on completion
|
284 |
+
this.bind_deferred_events = function () {
|
285 |
+
|
286 |
+
this.deferred.done(function () {
|
287 |
+
if (WP_Smush.errors.length) {
|
288 |
+
var error_message = wp_smush_msgs.error_in_bulk.replace("{{errors}}", WP_Smush.errors.length);
|
289 |
+
self.$log.append(error_message);
|
290 |
+
}
|
291 |
+
self.bulk_done();
|
292 |
+
});
|
293 |
+
|
294 |
+
};
|
295 |
+
|
296 |
+
this.start();
|
297 |
+
this.run();
|
298 |
+
this.bind_deferred_events();
|
299 |
+
return this.deferred;
|
300 |
+
};
|
301 |
+
/**
|
302 |
+
* Handle the start button click
|
303 |
+
*/
|
304 |
+
$('button[name="smush-all"]').on('click', function (e) {
|
305 |
+
|
306 |
+
// prevent the default action
|
307 |
+
e.preventDefault();
|
308 |
+
|
309 |
+
//Check for ids, if there is none (Unsmushed or lossless), don't call smush function
|
310 |
+
if (typeof wp_smushit_data == 'undefined' ||
|
311 |
+
( wp_smushit_data.unsmushed.length == 0 && wp_smushit_data.lossless.length == 0 )
|
312 |
+
) {
|
313 |
+
|
314 |
+
return false;
|
315 |
+
|
316 |
+
}
|
317 |
+
|
318 |
+
$(".smush-remaining-images-notice").remove();
|
319 |
|
320 |
+
new WP_Smush.Smush($(this), true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
321 |
|
322 |
+
return;
|
323 |
+
});
|
324 |
|
325 |
+
//Handle smush button click
|
326 |
+
$('body').on('click', '.wp-smush-send', function (e) {
|
327 |
|
328 |
+
// prevent the default action
|
329 |
+
e.preventDefault();
|
330 |
+
new WP_Smush.Smush($(this), false);
|
331 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
332 |
|
333 |
});
|
334 |
(function ($) {
|
335 |
+
var Smush = function (element, options) {
|
336 |
+
var elem = $(element);
|
337 |
+
|
338 |
+
var defaults = {
|
339 |
+
isSingle: false,
|
340 |
+
ajaxurl: '',
|
341 |
+
msgs: {},
|
342 |
+
msgClass: 'wp-smush-msg',
|
343 |
+
ids: []
|
344 |
+
};
|
345 |
+
};
|
346 |
+
$.fn.wpsmush = function (options) {
|
347 |
+
return this.each(function () {
|
348 |
+
var element = $(this);
|
349 |
+
|
350 |
+
// Return early if this element already has a plugin instance
|
351 |
+
if (element.data('wpsmush'))
|
352 |
+
return;
|
353 |
+
|
354 |
+
// pass options to plugin constructor and create a new instance
|
355 |
+
var wpsmush = new Smush(this, options);
|
356 |
+
|
357 |
+
// Store plugin object in this element's data
|
358 |
+
element.data('wpsmush', wpsmush);
|
359 |
+
});
|
360 |
+
};
|
361 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
362 |
})(jQuery);
|
languages/wp-smush.pot
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
-
# Copyright (C) 2015
|
2 |
-
# This file is distributed under the same license as the
|
3 |
msgid ""
|
4 |
msgstr ""
|
5 |
-
"Project-Id-Version:
|
6 |
-
"Report-Msgid-Bugs-To: http://
|
7 |
-
"POT-Creation-Date: 2015-04-
|
8 |
"MIME-Version: 1.0\n"
|
9 |
"Content-Type: text/plain; charset=UTF-8\n"
|
10 |
"Content-Transfer-Encoding: 8bit\n"
|
@@ -12,288 +12,322 @@ msgstr ""
|
|
12 |
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
13 |
"Language-Team: LANGUAGE <LL@li.org>\n"
|
14 |
|
15 |
-
#: lib/class-wp-smush-admin.php:
|
|
|
|
|
|
|
|
|
|
|
16 |
msgid "Bulk Smush Now"
|
17 |
msgstr ""
|
18 |
|
19 |
-
#: lib/class-wp-smush-admin.php:
|
20 |
msgid "Bulk Smush %d Attachments"
|
21 |
msgstr ""
|
22 |
|
23 |
-
#: lib/class-wp-smush-admin.php:
|
24 |
msgid "Smushing in Progress"
|
25 |
msgstr ""
|
26 |
|
27 |
-
#: lib/class-wp-smush-admin.php:
|
28 |
msgid "All Done!"
|
29 |
msgstr ""
|
30 |
|
31 |
-
#: lib/class-wp-smush-admin.php:
|
32 |
msgid "Ops!... something went wrong"
|
33 |
msgstr ""
|
34 |
|
35 |
-
#: lib/class-wp-smush-admin.php:
|
36 |
-
msgid "
|
37 |
msgstr ""
|
38 |
|
39 |
-
#: lib/class-wp-smush-admin.php:
|
40 |
msgid "Smush it"
|
41 |
msgstr ""
|
42 |
|
43 |
-
#: lib/class-wp-smush-admin.php:
|
44 |
msgid "Smush Now"
|
45 |
msgstr ""
|
46 |
|
47 |
-
#: lib/class-wp-smush-admin.php:
|
48 |
msgid "Sending ..."
|
49 |
msgstr ""
|
50 |
|
51 |
-
#: lib/class-wp-smush-admin.php:
|
52 |
msgid "{{errors}} image(s) were skipped due to an error."
|
53 |
msgstr ""
|
54 |
|
55 |
-
#: lib/class-wp-smush-admin.php:
|
|
|
|
|
|
|
|
|
56 |
msgid "Auto-Smush images on upload"
|
57 |
msgstr ""
|
58 |
|
59 |
-
#: lib/class-wp-smush-admin.php:
|
60 |
msgid "Super-Smush images"
|
61 |
msgstr ""
|
62 |
|
63 |
-
#: lib/class-wp-smush-admin.php:
|
64 |
msgid "lossy optimization"
|
65 |
msgstr ""
|
66 |
|
67 |
-
#: lib/class-wp-smush-admin.php:
|
68 |
msgid "Backup original images"
|
69 |
msgstr ""
|
70 |
|
71 |
-
#: lib/class-wp-smush-admin.php:
|
72 |
msgid "this will nearly double the size of your uploads directory"
|
73 |
msgstr ""
|
74 |
|
75 |
-
#: lib/class-wp-smush-admin.php:
|
76 |
msgid "WP Smush Pro"
|
77 |
msgstr ""
|
78 |
|
79 |
-
#: lib/class-wp-smush-admin.php:
|
80 |
-
msgid "WP Smush"
|
81 |
-
msgstr ""
|
82 |
-
|
83 |
-
#: lib/class-wp-smush-admin.php:230
|
84 |
msgid "Thanks for using WP Smush Pro! You now can:"
|
85 |
msgstr ""
|
86 |
|
87 |
-
#: lib/class-wp-smush-admin.php:
|
88 |
-
msgid "\"Super-Smush\" your images with our intelligent multi-pass lossy compression. Get &
|
89 |
msgstr ""
|
90 |
|
91 |
-
#: lib/class-wp-smush-admin.php:
|
92 |
msgid "Get the best lossless compression. We try multiple methods to squeeze every last byte out of your images."
|
93 |
msgstr ""
|
94 |
|
95 |
-
#: lib/class-wp-smush-admin.php:
|
96 |
msgid "Smush images up to 8MB."
|
97 |
msgstr ""
|
98 |
|
99 |
-
#: lib/class-wp-smush-admin.php:
|
100 |
msgid "Bulk smush ALL your images with one click!"
|
101 |
msgstr ""
|
102 |
|
103 |
-
#: lib/class-wp-smush-admin.php:
|
104 |
msgid "Keep a backup of your original un-smushed images in case you want to restore later."
|
105 |
msgstr ""
|
106 |
|
107 |
-
#: lib/class-wp-smush-admin.php:
|
108 |
msgid "Upgrade to WP Smush Pro to:"
|
109 |
msgstr ""
|
110 |
|
111 |
-
#: lib/class-wp-smush-admin.php:
|
112 |
msgid "Smush images greater than 1MB."
|
113 |
msgstr ""
|
114 |
|
115 |
-
#: lib/class-wp-smush-admin.php:
|
116 |
msgid "Bulk smush ALL your images with one click! No more rate limiting."
|
117 |
msgstr ""
|
118 |
|
119 |
-
#: lib/class-wp-smush-admin.php:
|
120 |
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>."
|
121 |
msgstr ""
|
122 |
|
123 |
-
#: lib/class-wp-smush-admin.php:
|
124 |
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."
|
125 |
msgstr ""
|
126 |
|
127 |
-
#: lib/class-wp-smush-admin.php:
|
128 |
msgid "Upgrade Now »"
|
129 |
msgstr ""
|
130 |
|
131 |
-
#: lib/class-wp-smush-admin.php:
|
132 |
msgid "Already upgraded to a WPMU DEV membership? Install and Login to our Dashboard plugin to enable Smush Pro features."
|
133 |
msgstr ""
|
134 |
|
135 |
-
#: lib/class-wp-smush-admin.php:
|
136 |
msgid "Activate WPMU DEV Dashboard"
|
137 |
msgstr ""
|
138 |
|
139 |
-
#: lib/class-wp-smush-admin.php:
|
140 |
msgid "Install WPMU DEV Dashboard"
|
141 |
msgstr ""
|
142 |
|
143 |
-
#: lib/class-wp-smush-admin.php:
|
144 |
msgid "Settings"
|
145 |
msgstr ""
|
146 |
|
147 |
-
#: lib/class-wp-smush-admin.php:
|
148 |
msgid "Save Changes"
|
149 |
msgstr ""
|
150 |
|
151 |
-
#: lib/class-wp-smush-admin.php:
|
152 |
msgid "%d image is over 1MB so will be skipped using the free version of the plugin."
|
153 |
msgid_plural "%d images are over 1MB so will be skipped using the free version of the plugin."
|
154 |
msgstr[0] ""
|
155 |
msgstr[1] ""
|
156 |
|
157 |
-
#: lib/class-wp-smush-admin.php:
|
158 |
msgid "Smush in Bulk"
|
159 |
msgstr ""
|
160 |
|
161 |
-
#: lib/class-wp-smush-admin.php:
|
162 |
msgid "Congratulations, all your images are currently Smushed!"
|
163 |
msgstr ""
|
164 |
|
165 |
-
#: lib/class-wp-smush-admin.php:
|
166 |
msgid "%d attachment in your media library has not been smushed."
|
167 |
msgid_plural "%d image attachments in your media library have not been smushed yet."
|
168 |
msgstr[0] ""
|
169 |
msgstr[1] ""
|
170 |
|
171 |
-
#: lib/class-wp-smush-admin.php:
|
172 |
msgid "Remove size limit »"
|
173 |
msgstr ""
|
174 |
|
175 |
-
#: lib/class-wp-smush-admin.php:
|
176 |
msgid ""
|
177 |
"Please be aware, smushing a large number of images can take a while depending on your server and network speed.\n"
|
178 |
"\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."
|
179 |
msgstr ""
|
180 |
|
181 |
-
#: lib/class-wp-smush-admin.php:
|
182 |
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."
|
183 |
msgstr ""
|
184 |
|
185 |
-
#: lib/class-wp-smush-admin.php:
|
186 |
msgid "Remove limits »"
|
187 |
msgstr ""
|
188 |
|
189 |
-
#: lib/class-wp-smush-admin.php:
|
190 |
msgid "When you <a href=\"%s\">upload some images</a> they will be available to smush here."
|
191 |
msgstr ""
|
192 |
|
193 |
-
#: lib/class-wp-smush-admin.php:
|
194 |
msgid "You can also smush images individually from your <a href=\"%s\">Media Library</a>."
|
195 |
msgstr ""
|
196 |
|
197 |
-
#: lib/class-wp-smush-admin.php:
|
198 |
msgid "Reduced by "
|
199 |
msgstr ""
|
200 |
|
201 |
-
#: lib/class-wp-smush-admin.php:
|
202 |
msgid "<span class=\"done-count\">%d</span> of <span class=\"total-count\">%d</span> total attachments have been smushed"
|
203 |
msgstr ""
|
204 |
|
205 |
-
#: lib/class-wp-smush-admin.php:
|
206 |
-
msgid "Smushing <span id=\"smushed-count\">1</span> of <span id=\"smushing-total\">%d</span>"
|
207 |
-
msgstr ""
|
208 |
-
|
209 |
-
#: lib/class-wp-smush-admin.php:589
|
210 |
msgid "You don't have permission to work with uploaded files."
|
211 |
msgstr ""
|
212 |
|
213 |
-
#: lib/class-wp-smush-admin.php:
|
214 |
msgid "No attachment ID was provided."
|
215 |
msgstr ""
|
216 |
|
217 |
-
#: lib/class-wp-smush-admin.php:
|
218 |
msgid "<p>Please <a href=\"%s\">upload some images</a>.</p>"
|
219 |
msgstr ""
|
220 |
|
221 |
-
#: lib/class-wp-smush-admin.php:
|
222 |
msgid "All your images are already smushed!"
|
223 |
msgstr ""
|
224 |
|
225 |
-
#: lib/class-wp-smush-admin.php:
|
226 |
msgid "<strong>%d of %d images</strong> were sent for smushing:"
|
227 |
msgstr ""
|
228 |
|
229 |
-
#: wp-smush.php:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
230 |
msgid "File path is empty"
|
231 |
msgstr ""
|
232 |
|
233 |
-
#: wp-smush.php:
|
234 |
msgid "File URL is empty"
|
235 |
msgstr ""
|
236 |
|
237 |
-
#: wp-smush.php:
|
238 |
msgid "Could not find %s"
|
239 |
msgstr ""
|
240 |
|
241 |
-
#: wp-smush.php:
|
242 |
msgid "%s is not writable"
|
243 |
msgstr ""
|
244 |
|
245 |
-
#: wp-smush.php:
|
246 |
msgid "Skipped (%s), image not found."
|
247 |
msgstr ""
|
248 |
|
249 |
-
#: wp-smush.php:
|
250 |
msgid "Skipped (%s), size limit exceeded."
|
251 |
msgstr ""
|
252 |
|
253 |
-
#: wp-smush.php:
|
254 |
msgid "Unknown API error"
|
255 |
msgstr ""
|
256 |
|
257 |
-
#: wp-smush.php:
|
258 |
msgid "Size '%s' not processed correctly"
|
259 |
msgstr ""
|
260 |
|
261 |
-
#: wp-smush.php:
|
262 |
msgid "Size 'full' not processed correctly"
|
263 |
msgstr ""
|
264 |
|
265 |
-
#: wp-smush.php:
|
266 |
msgid "Error posting to API: %s"
|
267 |
msgstr ""
|
268 |
|
269 |
-
#: wp-smush.php:
|
270 |
msgid "Error posting to API: %s %s"
|
271 |
msgstr ""
|
272 |
|
273 |
-
#: wp-smush.php:
|
274 |
msgid "Smush data corrupted, try again."
|
275 |
msgstr ""
|
276 |
|
277 |
-
#: wp-smush.php:
|
278 |
msgid "Image couldn't be smushed"
|
279 |
msgstr ""
|
280 |
|
281 |
-
#: wp-smush.php:
|
282 |
msgid "Error processing request"
|
283 |
msgstr ""
|
284 |
|
285 |
-
#: wp-smush.php:
|
286 |
msgid "Already Optimized"
|
287 |
msgstr ""
|
288 |
|
289 |
-
#: wp-smush.php:
|
290 |
msgid "Reduced by %s ( %01.1f%% )"
|
291 |
msgstr ""
|
292 |
|
293 |
-
#: wp-smush.php:
|
294 |
msgid "Not processed"
|
295 |
msgstr ""
|
296 |
|
297 |
-
#: wp-smush.php:
|
298 |
msgid "Smush Now!"
|
299 |
-
msgstr ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright (C) 2015 WP Smush
|
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.5\n"
|
6 |
+
"Report-Msgid-Bugs-To: http://wordpress.org/support/plugin/wp-smush\n"
|
7 |
+
"POT-Creation-Date: 2015-04-16 19:27:10+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 |
+
#: lib/class-wp-smush-admin.php:106 lib/class-wp-smush-admin.php:290
|
16 |
+
msgid "WP Smush"
|
17 |
+
msgstr ""
|
18 |
+
|
19 |
+
#: lib/class-wp-smush-admin.php:209 lib/class-wp-smush-admin.php:980
|
20 |
+
#: lib/class-wp-smush-admin.php:996
|
21 |
msgid "Bulk Smush Now"
|
22 |
msgstr ""
|
23 |
|
24 |
+
#: lib/class-wp-smush-admin.php:211 lib/class-wp-smush-admin.php:1000
|
25 |
msgid "Bulk Smush %d Attachments"
|
26 |
msgstr ""
|
27 |
|
28 |
+
#: lib/class-wp-smush-admin.php:215
|
29 |
msgid "Smushing in Progress"
|
30 |
msgstr ""
|
31 |
|
32 |
+
#: lib/class-wp-smush-admin.php:216 lib/class-wp-smush-admin.php:990
|
33 |
msgid "All Done!"
|
34 |
msgstr ""
|
35 |
|
36 |
+
#: lib/class-wp-smush-admin.php:218
|
37 |
msgid "Ops!... something went wrong"
|
38 |
msgstr ""
|
39 |
|
40 |
+
#: lib/class-wp-smush-admin.php:219 wp-smush.php:712
|
41 |
+
msgid "Super-Smush"
|
42 |
msgstr ""
|
43 |
|
44 |
+
#: lib/class-wp-smush-admin.php:220
|
45 |
msgid "Smush it"
|
46 |
msgstr ""
|
47 |
|
48 |
+
#: lib/class-wp-smush-admin.php:221
|
49 |
msgid "Smush Now"
|
50 |
msgstr ""
|
51 |
|
52 |
+
#: lib/class-wp-smush-admin.php:222
|
53 |
msgid "Sending ..."
|
54 |
msgstr ""
|
55 |
|
56 |
+
#: lib/class-wp-smush-admin.php:223
|
57 |
msgid "{{errors}} image(s) were skipped due to an error."
|
58 |
msgstr ""
|
59 |
|
60 |
+
#: lib/class-wp-smush-admin.php:224
|
61 |
+
msgid "All images are Super-Smushed."
|
62 |
+
msgstr ""
|
63 |
+
|
64 |
+
#: lib/class-wp-smush-admin.php:262
|
65 |
msgid "Auto-Smush images on upload"
|
66 |
msgstr ""
|
67 |
|
68 |
+
#: lib/class-wp-smush-admin.php:263
|
69 |
msgid "Super-Smush images"
|
70 |
msgstr ""
|
71 |
|
72 |
+
#: lib/class-wp-smush-admin.php:263
|
73 |
msgid "lossy optimization"
|
74 |
msgstr ""
|
75 |
|
76 |
+
#: lib/class-wp-smush-admin.php:264
|
77 |
msgid "Backup original images"
|
78 |
msgstr ""
|
79 |
|
80 |
+
#: lib/class-wp-smush-admin.php:264
|
81 |
msgid "this will nearly double the size of your uploads directory"
|
82 |
msgstr ""
|
83 |
|
84 |
+
#: lib/class-wp-smush-admin.php:288
|
85 |
msgid "WP Smush Pro"
|
86 |
msgstr ""
|
87 |
|
88 |
+
#: lib/class-wp-smush-admin.php:296
|
|
|
|
|
|
|
|
|
89 |
msgid "Thanks for using WP Smush Pro! You now can:"
|
90 |
msgstr ""
|
91 |
|
92 |
+
#: lib/class-wp-smush-admin.php:298 lib/class-wp-smush-admin.php:309
|
93 |
+
msgid "\"Super-Smush\" your images with our intelligent multi-pass lossy compression. Get 2× more compression than lossless with almost no noticeable quality loss!"
|
94 |
msgstr ""
|
95 |
|
96 |
+
#: lib/class-wp-smush-admin.php:299 lib/class-wp-smush-admin.php:310
|
97 |
msgid "Get the best lossless compression. We try multiple methods to squeeze every last byte out of your images."
|
98 |
msgstr ""
|
99 |
|
100 |
+
#: lib/class-wp-smush-admin.php:300
|
101 |
msgid "Smush images up to 8MB."
|
102 |
msgstr ""
|
103 |
|
104 |
+
#: lib/class-wp-smush-admin.php:301
|
105 |
msgid "Bulk smush ALL your images with one click!"
|
106 |
msgstr ""
|
107 |
|
108 |
+
#: lib/class-wp-smush-admin.php:302 lib/class-wp-smush-admin.php:313
|
109 |
msgid "Keep a backup of your original un-smushed images in case you want to restore later."
|
110 |
msgstr ""
|
111 |
|
112 |
+
#: lib/class-wp-smush-admin.php:307
|
113 |
msgid "Upgrade to WP Smush Pro to:"
|
114 |
msgstr ""
|
115 |
|
116 |
+
#: lib/class-wp-smush-admin.php:311
|
117 |
msgid "Smush images greater than 1MB."
|
118 |
msgstr ""
|
119 |
|
120 |
+
#: lib/class-wp-smush-admin.php:312
|
121 |
msgid "Bulk smush ALL your images with one click! No more rate limiting."
|
122 |
msgstr ""
|
123 |
|
124 |
+
#: lib/class-wp-smush-admin.php:314
|
125 |
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>."
|
126 |
msgstr ""
|
127 |
|
128 |
+
#: lib/class-wp-smush-admin.php:315
|
129 |
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."
|
130 |
msgstr ""
|
131 |
|
132 |
+
#: lib/class-wp-smush-admin.php:318
|
133 |
msgid "Upgrade Now »"
|
134 |
msgstr ""
|
135 |
|
136 |
+
#: lib/class-wp-smush-admin.php:321
|
137 |
msgid "Already upgraded to a WPMU DEV membership? Install and Login to our Dashboard plugin to enable Smush Pro features."
|
138 |
msgstr ""
|
139 |
|
140 |
+
#: lib/class-wp-smush-admin.php:330
|
141 |
msgid "Activate WPMU DEV Dashboard"
|
142 |
msgstr ""
|
143 |
|
144 |
+
#: lib/class-wp-smush-admin.php:333
|
145 |
msgid "Install WPMU DEV Dashboard"
|
146 |
msgstr ""
|
147 |
|
148 |
+
#: lib/class-wp-smush-admin.php:344 lib/class-wp-smush-admin.php:1049
|
149 |
msgid "Settings"
|
150 |
msgstr ""
|
151 |
|
152 |
+
#: lib/class-wp-smush-admin.php:430
|
153 |
msgid "Save Changes"
|
154 |
msgstr ""
|
155 |
|
156 |
+
#: lib/class-wp-smush-admin.php:502
|
157 |
msgid "%d image is over 1MB so will be skipped using the free version of the plugin."
|
158 |
msgid_plural "%d images are over 1MB so will be skipped using the free version of the plugin."
|
159 |
msgstr[0] ""
|
160 |
msgstr[1] ""
|
161 |
|
162 |
+
#: lib/class-wp-smush-admin.php:511
|
163 |
msgid "Smush in Bulk"
|
164 |
msgstr ""
|
165 |
|
166 |
+
#: lib/class-wp-smush-admin.php:516
|
167 |
msgid "Congratulations, all your images are currently Smushed!"
|
168 |
msgstr ""
|
169 |
|
170 |
+
#: lib/class-wp-smush-admin.php:525
|
171 |
msgid "%d attachment in your media library has not been smushed."
|
172 |
msgid_plural "%d image attachments in your media library have not been smushed yet."
|
173 |
msgstr[0] ""
|
174 |
msgstr[1] ""
|
175 |
|
176 |
+
#: lib/class-wp-smush-admin.php:529
|
177 |
msgid "Remove size limit »"
|
178 |
msgstr ""
|
179 |
|
180 |
+
#: lib/class-wp-smush-admin.php:534
|
181 |
msgid ""
|
182 |
"Please be aware, smushing a large number of images can take a while depending on your server and network speed.\n"
|
183 |
"\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."
|
184 |
msgstr ""
|
185 |
|
186 |
+
#: lib/class-wp-smush-admin.php:539
|
187 |
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."
|
188 |
msgstr ""
|
189 |
|
190 |
+
#: lib/class-wp-smush-admin.php:540
|
191 |
msgid "Remove limits »"
|
192 |
msgstr ""
|
193 |
|
194 |
+
#: lib/class-wp-smush-admin.php:560
|
195 |
msgid "When you <a href=\"%s\">upload some images</a> they will be available to smush here."
|
196 |
msgstr ""
|
197 |
|
198 |
+
#: lib/class-wp-smush-admin.php:566 lib/class-wp-smush-admin.php:802
|
199 |
msgid "You can also smush images individually from your <a href=\"%s\">Media Library</a>."
|
200 |
msgstr ""
|
201 |
|
202 |
+
#: lib/class-wp-smush-admin.php:618
|
203 |
msgid "Reduced by "
|
204 |
msgstr ""
|
205 |
|
206 |
+
#: lib/class-wp-smush-admin.php:628
|
207 |
msgid "<span class=\"done-count\">%d</span> of <span class=\"total-count\">%d</span> total attachments have been smushed"
|
208 |
msgstr ""
|
209 |
|
210 |
+
#: lib/class-wp-smush-admin.php:698
|
|
|
|
|
|
|
|
|
211 |
msgid "You don't have permission to work with uploaded files."
|
212 |
msgstr ""
|
213 |
|
214 |
+
#: lib/class-wp-smush-admin.php:702
|
215 |
msgid "No attachment ID was provided."
|
216 |
msgstr ""
|
217 |
|
218 |
+
#: lib/class-wp-smush-admin.php:772
|
219 |
msgid "<p>Please <a href=\"%s\">upload some images</a>.</p>"
|
220 |
msgstr ""
|
221 |
|
222 |
+
#: lib/class-wp-smush-admin.php:790
|
223 |
msgid "All your images are already smushed!"
|
224 |
msgstr ""
|
225 |
|
226 |
+
#: lib/class-wp-smush-admin.php:890
|
227 |
msgid "<strong>%d of %d images</strong> were sent for smushing:"
|
228 |
msgstr ""
|
229 |
|
230 |
+
#: lib/class-wp-smush-admin.php:1176
|
231 |
+
msgid "Super-Smush Images"
|
232 |
+
msgstr ""
|
233 |
+
|
234 |
+
#: lib/class-wp-smush-admin.php:1177
|
235 |
+
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."
|
236 |
+
msgstr ""
|
237 |
+
|
238 |
+
#: lib/class-wp-smush-admin.php:1185
|
239 |
+
msgid "<span class=\"remaining-count\">%d</span> attachment left to Super-Smush"
|
240 |
+
msgid_plural "<span class=\"remaining-count\">%d</span> attachments left to Super-Smush"
|
241 |
+
msgstr[0] ""
|
242 |
+
msgstr[1] ""
|
243 |
+
|
244 |
+
#: wp-smush.php:142
|
245 |
msgid "File path is empty"
|
246 |
msgstr ""
|
247 |
|
248 |
+
#: wp-smush.php:146
|
249 |
msgid "File URL is empty"
|
250 |
msgstr ""
|
251 |
|
252 |
+
#: wp-smush.php:151
|
253 |
msgid "Could not find %s"
|
254 |
msgstr ""
|
255 |
|
256 |
+
#: wp-smush.php:156
|
257 |
msgid "%s is not writable"
|
258 |
msgstr ""
|
259 |
|
260 |
+
#: wp-smush.php:166
|
261 |
msgid "Skipped (%s), image not found."
|
262 |
msgstr ""
|
263 |
|
264 |
+
#: wp-smush.php:171
|
265 |
msgid "Skipped (%s), size limit exceeded."
|
266 |
msgstr ""
|
267 |
|
268 |
+
#: wp-smush.php:186
|
269 |
msgid "Unknown API error"
|
270 |
msgstr ""
|
271 |
|
272 |
+
#: wp-smush.php:330
|
273 |
msgid "Size '%s' not processed correctly"
|
274 |
msgstr ""
|
275 |
|
276 |
+
#: wp-smush.php:352 wp-smush.php:360
|
277 |
msgid "Size 'full' not processed correctly"
|
278 |
msgstr ""
|
279 |
|
280 |
+
#: wp-smush.php:476
|
281 |
msgid "Error posting to API: %s"
|
282 |
msgstr ""
|
283 |
|
284 |
+
#: wp-smush.php:482
|
285 |
msgid "Error posting to API: %s %s"
|
286 |
msgstr ""
|
287 |
|
288 |
+
#: wp-smush.php:499
|
289 |
msgid "Smush data corrupted, try again."
|
290 |
msgstr ""
|
291 |
|
292 |
+
#: wp-smush.php:515
|
293 |
msgid "Image couldn't be smushed"
|
294 |
msgstr ""
|
295 |
|
296 |
+
#: wp-smush.php:686
|
297 |
msgid "Error processing request"
|
298 |
msgstr ""
|
299 |
|
300 |
+
#: wp-smush.php:690
|
301 |
msgid "Already Optimized"
|
302 |
msgstr ""
|
303 |
|
304 |
+
#: wp-smush.php:692
|
305 |
msgid "Reduced by %s ( %01.1f%% )"
|
306 |
msgstr ""
|
307 |
|
308 |
+
#: wp-smush.php:718
|
309 |
msgid "Not processed"
|
310 |
msgstr ""
|
311 |
|
312 |
+
#: wp-smush.php:724
|
313 |
msgid "Smush Now!"
|
314 |
+
msgstr ""
|
315 |
+
#. Plugin Name of the plugin/theme
|
316 |
+
msgid "WP Smush"
|
317 |
+
msgstr ""
|
318 |
+
|
319 |
+
#. Plugin URI of the plugin/theme
|
320 |
+
msgid "http://wordpress.org/extend/plugins/wp-smushit/"
|
321 |
+
msgstr ""
|
322 |
+
|
323 |
+
#. Description of the plugin/theme
|
324 |
+
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."
|
325 |
+
msgstr ""
|
326 |
+
|
327 |
+
#. Author of the plugin/theme
|
328 |
+
msgid "WPMU DEV"
|
329 |
+
msgstr ""
|
330 |
+
|
331 |
+
#. Author URI of the plugin/theme
|
332 |
+
msgid "http://premium.wpmudev.org/"
|
333 |
+
msgstr ""
|
lib/class-wp-smush-admin.php
CHANGED
@@ -43,6 +43,12 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
43 |
|
44 |
public $upgrade_url = 'https://premium.wpmudev.org/project/wp-smush-pro/?utm_source=wordpress.org&utm_medium=plugin&utm_campaign=WP%20Smush%20Upgrade';
|
45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
/**
|
47 |
* Constructor
|
48 |
*/
|
@@ -61,8 +67,6 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
61 |
//Handle Smush Single Ajax
|
62 |
add_action( 'wp_ajax_wp_smushit_manual', array( $this, 'smush_single' ) );
|
63 |
|
64 |
-
add_action( "admin_enqueue_scripts", array( $this, "admin_enqueue_scripts" ) );
|
65 |
-
|
66 |
add_filter( 'plugin_action_links_' . WP_SMUSH_BASENAME, array(
|
67 |
$this,
|
68 |
'settings_link'
|
@@ -72,7 +76,7 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
72 |
'settings_link'
|
73 |
) );
|
74 |
//Attachment status, Grid view
|
75 |
-
|
76 |
|
77 |
// hook into admin footer to load a hidden html/css spinner
|
78 |
add_action( 'admin_footer-upload.php', array( $this, 'print_loader' ) );
|
@@ -81,11 +85,34 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
81 |
add_action( 'admin_notices', array( $this, 'smush_upgrade' ) );
|
82 |
|
83 |
|
84 |
-
|
85 |
$this->init_settings();
|
86 |
|
87 |
}
|
88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
function __get( $prop ) {
|
90 |
|
91 |
if ( method_exists( "WpSmushitAdmin", $prop ) ) {
|
@@ -112,13 +139,21 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
112 |
|
113 |
// Enqueue js on media screen
|
114 |
add_action( 'admin_print_scripts-upload.php', array( $this, 'enqueue' ) );
|
|
|
|
|
|
|
115 |
}
|
116 |
|
117 |
/**
|
118 |
* Register js and css
|
119 |
*/
|
120 |
function register() {
|
|
|
121 |
global $WpSmush;
|
|
|
|
|
|
|
|
|
122 |
// Register js for smush utton in grid view
|
123 |
$current_blog_id = get_current_blog_id();
|
124 |
$meta_key = $current_blog_id == 1 ? 'wp_media_library_mode' : 'wp_' . $current_blog_id . '_media_library_mode';
|
@@ -138,16 +173,12 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
138 |
'underscore'
|
139 |
), WP_SMUSH_VERSON );
|
140 |
}
|
|
|
141 |
|
142 |
|
143 |
/* Register Style. */
|
144 |
wp_register_style( 'wp-smushit-admin-css', WP_SMUSH_URL . 'assets/css/wp-smushit-admin.css', array(), $WpSmush->version );
|
145 |
|
146 |
-
// localize translatable strings for js
|
147 |
-
$this->localize();
|
148 |
-
|
149 |
-
wp_enqueue_script( 'wp-smushit-admin-media-js', WP_SMUSH_URL . 'assets/js/wp-smushit-admin-media.js', array( 'jquery' ), $WpSmush->version );
|
150 |
-
|
151 |
}
|
152 |
|
153 |
/**
|
@@ -155,15 +186,26 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
155 |
*/
|
156 |
function enqueue() {
|
157 |
wp_enqueue_script( 'wp-smushit-admin-js' );
|
|
|
|
|
|
|
158 |
wp_enqueue_style( 'wp-smushit-admin-css' );
|
|
|
|
|
|
|
159 |
}
|
160 |
|
161 |
|
162 |
function localize() {
|
|
|
|
|
|
|
|
|
|
|
163 |
$bulk = new WpSmushitBulk();
|
164 |
$handle = 'wp-smushit-admin-js';
|
165 |
|
166 |
-
if ( $this->
|
167 |
$bulk_now = __( 'Bulk Smush Now', WP_SMUSH_DOMAIN );
|
168 |
} else {
|
169 |
$bulk_now = sprintf( __( 'Bulk Smush %d Attachments', WP_SMUSH_DOMAIN ), $this->max_free_bulk );
|
@@ -174,31 +216,44 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
174 |
'done' => __( 'All Done!', WP_SMUSH_DOMAIN ),
|
175 |
'bulk_now' => $bulk_now,
|
176 |
'something_went_wrong' => __( 'Ops!... something went wrong', WP_SMUSH_DOMAIN ),
|
177 |
-
'resmush' => __( '
|
178 |
'smush_it' => __( 'Smush it', WP_SMUSH_DOMAIN ),
|
179 |
'smush_now' => __( 'Smush Now', WP_SMUSH_DOMAIN ),
|
180 |
'sending' => __( 'Sending ...', WP_SMUSH_DOMAIN ),
|
181 |
-
"error_in_bulk" => __( '{{errors}} image(s) were skipped due to an error.', WP_SMUSH_DOMAIN )
|
|
|
182 |
);
|
183 |
|
184 |
wp_localize_script( $handle, 'wp_smush_msgs', $wp_smush_msgs );
|
185 |
|
186 |
//Localize smushit_ids variable, if there are fix number of ids
|
187 |
-
$ids = ! empty( $_REQUEST['ids'] ) ? explode( ',', $_REQUEST['ids'] ) : $bulk->get_attachments();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
188 |
|
|
|
189 |
$data = array(
|
190 |
'smushed' => $this->get_smushed_image_ids(),
|
191 |
-
'unsmushed' => $ids
|
|
|
192 |
);
|
193 |
|
194 |
wp_localize_script( 'wp-smushit-admin-js', 'wp_smushit_data', $data );
|
195 |
|
196 |
}
|
197 |
|
198 |
-
function admin_enqueue_scripts() {
|
199 |
-
wp_enqueue_script( 'wp-smushit-admin-media-js' );
|
200 |
-
}
|
201 |
-
|
202 |
/**
|
203 |
* Translation ready settings
|
204 |
*/
|
@@ -229,18 +284,18 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
229 |
|
230 |
<h2>
|
231 |
<?php
|
232 |
-
if ( $this->
|
233 |
_e( 'WP Smush Pro', WP_SMUSH_DOMAIN );
|
234 |
} else {
|
235 |
_e( 'WP Smush', WP_SMUSH_DOMAIN );
|
236 |
} ?>
|
237 |
</h2>
|
238 |
|
239 |
-
<?php if ( $this->
|
240 |
<div class="wp-smpushit-features updated">
|
241 |
<h3><?php _e( 'Thanks for using WP Smush Pro! You now can:', WP_SMUSH_DOMAIN ) ?></h3>
|
242 |
<ol>
|
243 |
-
<li><?php _e( '"Super-Smush" your images with our intelligent multi-pass lossy compression. Get &
|
244 |
<li><?php _e( 'Get the best lossless compression. We try multiple methods to squeeze every last byte out of your images.', WP_SMUSH_DOMAIN ); ?></li>
|
245 |
<li><?php _e( 'Smush images up to 8MB.', WP_SMUSH_DOMAIN ); ?></li>
|
246 |
<li><?php _e( 'Bulk smush ALL your images with one click!', WP_SMUSH_DOMAIN ); ?></li>
|
@@ -251,7 +306,7 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
251 |
<div class="wp-smpushit-features error">
|
252 |
<h3><?php _e( 'Upgrade to WP Smush Pro to:', WP_SMUSH_DOMAIN ) ?></h3>
|
253 |
<ol>
|
254 |
-
<li><?php _e( '"Super-Smush" your images with our intelligent multi-pass lossy compression. Get &
|
255 |
<li><?php _e( 'Get the best lossless compression. We try multiple methods to squeeze every last byte out of your images.', WP_SMUSH_DOMAIN ); ?></li>
|
256 |
<li><?php _e( 'Smush images greater than 1MB.', WP_SMUSH_DOMAIN ); ?></li>
|
257 |
<li><?php _e( 'Bulk smush ALL your images with one click! No more rate limiting.', WP_SMUSH_DOMAIN ); ?></li>
|
@@ -305,10 +360,6 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
305 |
* Process and display the options form
|
306 |
*/
|
307 |
function options_ui() {
|
308 |
-
|
309 |
-
// Save settings, if needed
|
310 |
-
$this->process_options();
|
311 |
-
|
312 |
?>
|
313 |
<form action="" method="post">
|
314 |
|
@@ -337,7 +388,7 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
337 |
|
338 |
//disable lossy for non-premium members
|
339 |
$disabled = $class = '';
|
340 |
-
if ( ! $this->
|
341 |
$disabled = ' disabled';
|
342 |
$opt_lossy_val = $opt_backup_val = 0;
|
343 |
$class = ' inactive inactive-anim';
|
@@ -359,16 +410,20 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
359 |
printf(
|
360 |
"<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']
|
361 |
);
|
362 |
-
if ( ! $this->
|
363 |
?>
|
364 |
<div class="pro-note">
|
365 |
-
<div style="padding:14px 0 14px;">Pro feature only.
|
|
|
|
|
366 |
</div>
|
367 |
<?php
|
368 |
}
|
369 |
?>
|
370 |
-
</div
|
371 |
-
|
|
|
|
|
372 |
// nonce
|
373 |
wp_nonce_field( 'save_wp_smush_options', 'wp_smush_options_nonce' );
|
374 |
?>
|
@@ -440,7 +495,7 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
440 |
function bulk_preview() {
|
441 |
|
442 |
$exceed_mb = '';
|
443 |
-
if ( ! $this->
|
444 |
|
445 |
if ( $this->exceeding_items_count ) {
|
446 |
$exceed_mb = sprintf(
|
@@ -461,6 +516,9 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
461 |
<p><?php _e( "Congratulations, all your images are currently Smushed!", WP_SMUSH_DOMAIN ); ?></p>
|
462 |
<?php
|
463 |
$this->progress_ui();
|
|
|
|
|
|
|
464 |
} else {
|
465 |
?>
|
466 |
<div class="smush-instructions">
|
@@ -476,7 +534,7 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
476 |
<p><?php _e( "Please be aware, smushing a large number of images can take a while depending on your server and network speed.
|
477 |
<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.", WP_SMUSH_DOMAIN ); ?></p>
|
478 |
|
479 |
-
<?php if ( ! $this->
|
480 |
<p class="error">
|
481 |
<?php printf( __( "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.", WP_SMUSH_DOMAIN ), $this->max_free_bulk, $this->max_free_bulk ); ?>
|
482 |
<a href="<?php echo $this->upgrade_url; ?>"><?php _e( 'Remove limits »', WP_SMUSH_DOMAIN ); ?></a>
|
@@ -544,9 +602,8 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
544 |
*/
|
545 |
function progress_ui() {
|
546 |
|
547 |
-
// calculate %ages
|
548 |
-
if ( $this->total_count > 0 )
|
549 |
-
{
|
550 |
$smushed_pc = $this->smushed_count / $this->total_count * 100;
|
551 |
} else {
|
552 |
$smushed_pc = 0;
|
@@ -587,16 +644,16 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
587 |
global $WpSmush;
|
588 |
|
589 |
$should_continue = true;
|
590 |
-
$
|
591 |
|
592 |
if ( empty( $_REQUEST['attachment_id'] ) ) {
|
593 |
wp_send_json_error( 'missing id' );
|
594 |
}
|
595 |
|
596 |
//if not premium
|
597 |
-
$
|
598 |
|
599 |
-
if ( ! $
|
600 |
//Free version bulk smush, check the transient counter value
|
601 |
$should_continue = $this->check_bulk_limit();
|
602 |
}
|
@@ -615,7 +672,7 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
615 |
|
616 |
$original_meta = wp_get_attachment_metadata( $attachment_id, true );
|
617 |
|
618 |
-
$smush = $WpSmush->resize_from_meta_data( $original_meta, $attachment_id
|
619 |
|
620 |
$this->setup_global_stats();
|
621 |
|
@@ -854,8 +911,8 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
854 |
*
|
855 |
* @todo Add the API status here, next to the button
|
856 |
*/
|
857 |
-
function setup_button() {
|
858 |
-
$button = $this->button_state();
|
859 |
$disabled = ! empty( $button['disabled'] ) ? ' disabled="disabled"' : '';
|
860 |
?>
|
861 |
<button class="button button-primary<?php echo ' ' . $button['class']; ?>" name="smush-all" <?php echo $disabled; ?>>
|
@@ -913,28 +970,37 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
913 |
* @return array
|
914 |
*/
|
915 |
|
916 |
-
private function button_state() {
|
917 |
$button = array(
|
918 |
'cancel' => false,
|
919 |
);
|
|
|
|
|
920 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
921 |
|
922 |
-
|
923 |
-
|
924 |
-
|
925 |
-
|
926 |
-
|
927 |
-
$button['disabled'] = 'disabled';
|
928 |
|
929 |
-
|
930 |
|
931 |
-
|
932 |
-
|
933 |
|
934 |
-
|
935 |
-
|
936 |
-
|
937 |
|
|
|
938 |
}
|
939 |
|
940 |
return $button;
|
@@ -969,15 +1035,6 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
969 |
return $response;
|
970 |
}
|
971 |
|
972 |
-
/**
|
973 |
-
* Returns the image smush status, called by grid view ajax
|
974 |
-
*/
|
975 |
-
function attachment_status() {
|
976 |
-
$id = $_REQUEST['id'];
|
977 |
-
$status_text = $this->smush_status( $id );
|
978 |
-
wp_send_json_success( $status_text );
|
979 |
-
die();
|
980 |
-
}
|
981 |
|
982 |
/**
|
983 |
* Adds a smushit pro settings link on plugin page
|
@@ -1009,7 +1066,7 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
1009 |
update_option( 'dismiss_smush_upgrade', 1 );
|
1010 |
}
|
1011 |
|
1012 |
-
if ( get_option( 'dismiss_smush_upgrade' ) || $this->
|
1013 |
return;
|
1014 |
}
|
1015 |
?>
|
@@ -1024,13 +1081,117 @@ if ( ! class_exists( 'WpSmushitAdmin' ) ) {
|
|
1024 |
and reliability... enjoy!</p>
|
1025 |
|
1026 |
<p>And now, if you'd like to upgrade to the WP Smush Pro plugin you can smush images up to 8MB in size,
|
1027 |
-
get 'Super Smushing' of, on average,
|
|
|
1028 |
unlimited number of images at once.
|
1029 |
<a href="https://premium.wpmudev.org/?coupon=SMUSH50OFF#pricing"> Click here to upgrade with a 50%
|
1030 |
discount</a>.</p>
|
1031 |
</div>
|
1032 |
<?php
|
1033 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1034 |
}
|
1035 |
|
1036 |
$wpsmushit_admin = new WpSmushitAdmin();
|
43 |
|
44 |
public $upgrade_url = 'https://premium.wpmudev.org/project/wp-smush-pro/?utm_source=wordpress.org&utm_medium=plugin&utm_campaign=WP%20Smush%20Upgrade';
|
45 |
|
46 |
+
//Stores unsmushed ids
|
47 |
+
private $ids = '';
|
48 |
+
|
49 |
+
//Stores all lossless smushed ids
|
50 |
+
private $lossless_ids = '';
|
51 |
+
|
52 |
/**
|
53 |
* Constructor
|
54 |
*/
|
67 |
//Handle Smush Single Ajax
|
68 |
add_action( 'wp_ajax_wp_smushit_manual', array( $this, 'smush_single' ) );
|
69 |
|
|
|
|
|
70 |
add_filter( 'plugin_action_links_' . WP_SMUSH_BASENAME, array(
|
71 |
$this,
|
72 |
'settings_link'
|
76 |
'settings_link'
|
77 |
) );
|
78 |
//Attachment status, Grid view
|
79 |
+
add_filter( 'attachment_fields_to_edit', array( $this, 'filter_attachment_fields_to_edit' ), 10, 2 );
|
80 |
|
81 |
// hook into admin footer to load a hidden html/css spinner
|
82 |
add_action( 'admin_footer-upload.php', array( $this, 'print_loader' ) );
|
85 |
add_action( 'admin_notices', array( $this, 'smush_upgrade' ) );
|
86 |
|
87 |
|
|
|
88 |
$this->init_settings();
|
89 |
|
90 |
}
|
91 |
|
92 |
+
/**
|
93 |
+
* Adds smush button and status to attachment modal and edit page if it's an image
|
94 |
+
*
|
95 |
+
*
|
96 |
+
* @param array $form_fields
|
97 |
+
* @param WP_Post $post
|
98 |
+
*
|
99 |
+
* @return array $form_fields
|
100 |
+
*/
|
101 |
+
function filter_attachment_fields_to_edit( $form_fields, $post ) {
|
102 |
+
if ( ! wp_attachment_is_image( $post->ID ) ) {
|
103 |
+
return $form_fields;
|
104 |
+
}
|
105 |
+
$form_fields['wp_smush'] = array(
|
106 |
+
'label' => __( 'WP Smush', WP_SMUSH_DOMAIN ),
|
107 |
+
'input' => 'html',
|
108 |
+
'html' => $this->smush_status( $post->ID ),
|
109 |
+
'show_in_edit' => true,
|
110 |
+
'show_in_modal' => true,
|
111 |
+
);
|
112 |
+
|
113 |
+
return $form_fields;
|
114 |
+
}
|
115 |
+
|
116 |
function __get( $prop ) {
|
117 |
|
118 |
if ( method_exists( "WpSmushitAdmin", $prop ) ) {
|
139 |
|
140 |
// Enqueue js on media screen
|
141 |
add_action( 'admin_print_scripts-upload.php', array( $this, 'enqueue' ) );
|
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 |
/**
|
148 |
* Register js and css
|
149 |
*/
|
150 |
function register() {
|
151 |
+
|
152 |
global $WpSmush;
|
153 |
+
|
154 |
+
// Save settings, if needed
|
155 |
+
$this->process_options();
|
156 |
+
|
157 |
// Register js for smush utton in grid view
|
158 |
$current_blog_id = get_current_blog_id();
|
159 |
$meta_key = $current_blog_id == 1 ? 'wp_media_library_mode' : 'wp_' . $current_blog_id . '_media_library_mode';
|
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 |
|
178 |
|
179 |
/* Register Style. */
|
180 |
wp_register_style( 'wp-smushit-admin-css', WP_SMUSH_URL . 'assets/css/wp-smushit-admin.css', array(), $WpSmush->version );
|
181 |
|
|
|
|
|
|
|
|
|
|
|
182 |
}
|
183 |
|
184 |
/**
|
186 |
*/
|
187 |
function enqueue() {
|
188 |
wp_enqueue_script( 'wp-smushit-admin-js' );
|
189 |
+
wp_enqueue_script( 'wp-smushit-admin-media-js' );
|
190 |
+
|
191 |
+
//Style
|
192 |
wp_enqueue_style( 'wp-smushit-admin-css' );
|
193 |
+
|
194 |
+
// localize translatable strings for js
|
195 |
+
$this->localize();
|
196 |
}
|
197 |
|
198 |
|
199 |
function localize() {
|
200 |
+
global $pagenow;
|
201 |
+
if ( ! isset( $pagenow ) || ! in_array( $pagenow, array( "post.php", "upload.php" ) ) ) {
|
202 |
+
return;
|
203 |
+
}
|
204 |
+
|
205 |
$bulk = new WpSmushitBulk();
|
206 |
$handle = 'wp-smushit-admin-js';
|
207 |
|
208 |
+
if ( $this->is_pro() || $this->remaining_count <= $this->max_free_bulk ) {
|
209 |
$bulk_now = __( 'Bulk Smush Now', WP_SMUSH_DOMAIN );
|
210 |
} else {
|
211 |
$bulk_now = sprintf( __( 'Bulk Smush %d Attachments', WP_SMUSH_DOMAIN ), $this->max_free_bulk );
|
216 |
'done' => __( 'All Done!', WP_SMUSH_DOMAIN ),
|
217 |
'bulk_now' => $bulk_now,
|
218 |
'something_went_wrong' => __( 'Ops!... something went wrong', WP_SMUSH_DOMAIN ),
|
219 |
+
'resmush' => __( 'Super-Smush', WP_SMUSH_DOMAIN ),
|
220 |
'smush_it' => __( 'Smush it', WP_SMUSH_DOMAIN ),
|
221 |
'smush_now' => __( 'Smush Now', WP_SMUSH_DOMAIN ),
|
222 |
'sending' => __( 'Sending ...', WP_SMUSH_DOMAIN ),
|
223 |
+
"error_in_bulk" => __( '{{errors}} image(s) were skipped due to an error.', WP_SMUSH_DOMAIN ),
|
224 |
+
"all_supersmushed" => __( 'All images are Super-Smushed.', WP_SMUSH_DOMAIN )
|
225 |
);
|
226 |
|
227 |
wp_localize_script( $handle, 'wp_smush_msgs', $wp_smush_msgs );
|
228 |
|
229 |
//Localize smushit_ids variable, if there are fix number of ids
|
230 |
+
$this->ids = ! empty( $_REQUEST['ids'] ) ? explode( ',', $_REQUEST['ids'] ) : $bulk->get_attachments();
|
231 |
+
|
232 |
+
//If premium, Super smush allowed, all images are smushed, localize lossless smushed ids for bulk compression
|
233 |
+
if ( $this->is_pro() &&
|
234 |
+
( $this->total_count == $this->smushed_count && empty( $this->ids ) )
|
235 |
+
) {
|
236 |
+
|
237 |
+
//Check if Super smush enabled
|
238 |
+
$super_smush = get_option( WP_SMUSH_PREFIX . 'lossy', false );
|
239 |
+
|
240 |
+
if ( $super_smush ) {
|
241 |
+
//get the attachments, and get lossless count
|
242 |
+
$this->lossless_ids = $this->get_lossless_attachments();
|
243 |
+
}
|
244 |
+
}
|
245 |
|
246 |
+
//Array of all smushed, unsmushed and lossless ids
|
247 |
$data = array(
|
248 |
'smushed' => $this->get_smushed_image_ids(),
|
249 |
+
'unsmushed' => $this->ids,
|
250 |
+
'lossless' => $this->lossless_ids
|
251 |
);
|
252 |
|
253 |
wp_localize_script( 'wp-smushit-admin-js', 'wp_smushit_data', $data );
|
254 |
|
255 |
}
|
256 |
|
|
|
|
|
|
|
|
|
257 |
/**
|
258 |
* Translation ready settings
|
259 |
*/
|
284 |
|
285 |
<h2>
|
286 |
<?php
|
287 |
+
if ( $this->is_pro() ) {
|
288 |
_e( 'WP Smush Pro', WP_SMUSH_DOMAIN );
|
289 |
} else {
|
290 |
_e( 'WP Smush', WP_SMUSH_DOMAIN );
|
291 |
} ?>
|
292 |
</h2>
|
293 |
|
294 |
+
<?php if ( $this->is_pro() ) { ?>
|
295 |
<div class="wp-smpushit-features updated">
|
296 |
<h3><?php _e( 'Thanks for using WP Smush Pro! You now can:', WP_SMUSH_DOMAIN ) ?></h3>
|
297 |
<ol>
|
298 |
+
<li><?php _e( '"Super-Smush" your images with our intelligent multi-pass lossy compression. Get 2× more compression than lossless with almost no noticeable quality loss!', WP_SMUSH_DOMAIN ); ?></li>
|
299 |
<li><?php _e( 'Get the best lossless compression. We try multiple methods to squeeze every last byte out of your images.', WP_SMUSH_DOMAIN ); ?></li>
|
300 |
<li><?php _e( 'Smush images up to 8MB.', WP_SMUSH_DOMAIN ); ?></li>
|
301 |
<li><?php _e( 'Bulk smush ALL your images with one click!', WP_SMUSH_DOMAIN ); ?></li>
|
306 |
<div class="wp-smpushit-features error">
|
307 |
<h3><?php _e( 'Upgrade to WP Smush Pro to:', WP_SMUSH_DOMAIN ) ?></h3>
|
308 |
<ol>
|
309 |
+
<li><?php _e( '"Super-Smush" your images with our intelligent multi-pass lossy compression. Get 2× more compression than lossless with almost no noticeable quality loss!', WP_SMUSH_DOMAIN ); ?></li>
|
310 |
<li><?php _e( 'Get the best lossless compression. We try multiple methods to squeeze every last byte out of your images.', WP_SMUSH_DOMAIN ); ?></li>
|
311 |
<li><?php _e( 'Smush images greater than 1MB.', WP_SMUSH_DOMAIN ); ?></li>
|
312 |
<li><?php _e( 'Bulk smush ALL your images with one click! No more rate limiting.', WP_SMUSH_DOMAIN ); ?></li>
|
360 |
* Process and display the options form
|
361 |
*/
|
362 |
function options_ui() {
|
|
|
|
|
|
|
|
|
363 |
?>
|
364 |
<form action="" method="post">
|
365 |
|
388 |
|
389 |
//disable lossy for non-premium members
|
390 |
$disabled = $class = '';
|
391 |
+
if ( ! $this->is_pro() ) {
|
392 |
$disabled = ' disabled';
|
393 |
$opt_lossy_val = $opt_backup_val = 0;
|
394 |
$class = ' inactive inactive-anim';
|
410 |
printf(
|
411 |
"<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']
|
412 |
);
|
413 |
+
if ( ! $this->is_pro() ) {
|
414 |
?>
|
415 |
<div class="pro-note">
|
416 |
+
<div style="padding:14px 0 14px;">Pro feature only.
|
417 |
+
<a href="<?php echo $this->upgrade_url; ?>" target="_blank">Find out more »</a>
|
418 |
+
</div>
|
419 |
</div>
|
420 |
<?php
|
421 |
}
|
422 |
?>
|
423 |
+
</div>
|
424 |
+
<!-- End of pro-only -->
|
425 |
+
</div>
|
426 |
+
<!-- End of wrap --><?php
|
427 |
// nonce
|
428 |
wp_nonce_field( 'save_wp_smush_options', 'wp_smush_options_nonce' );
|
429 |
?>
|
495 |
function bulk_preview() {
|
496 |
|
497 |
$exceed_mb = '';
|
498 |
+
if ( ! $this->is_pro() ) {
|
499 |
|
500 |
if ( $this->exceeding_items_count ) {
|
501 |
$exceed_mb = sprintf(
|
516 |
<p><?php _e( "Congratulations, all your images are currently Smushed!", WP_SMUSH_DOMAIN ); ?></p>
|
517 |
<?php
|
518 |
$this->progress_ui();
|
519 |
+
|
520 |
+
//Display Super smush bulk progress bar
|
521 |
+
$this->super_smush_bulk_ui();
|
522 |
} else {
|
523 |
?>
|
524 |
<div class="smush-instructions">
|
534 |
<p><?php _e( "Please be aware, smushing a large number of images can take a while depending on your server and network speed.
|
535 |
<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.", WP_SMUSH_DOMAIN ); ?></p>
|
536 |
|
537 |
+
<?php if ( ! $this->is_pro() ) { ?>
|
538 |
<p class="error">
|
539 |
<?php printf( __( "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.", WP_SMUSH_DOMAIN ), $this->max_free_bulk, $this->max_free_bulk ); ?>
|
540 |
<a href="<?php echo $this->upgrade_url; ?>"><?php _e( 'Remove limits »', WP_SMUSH_DOMAIN ); ?></a>
|
602 |
*/
|
603 |
function progress_ui() {
|
604 |
|
605 |
+
// calculate %ages, avoid divide by zero error with no attachments
|
606 |
+
if ( $this->total_count > 0 ) {
|
|
|
607 |
$smushed_pc = $this->smushed_count / $this->total_count * 100;
|
608 |
} else {
|
609 |
$smushed_pc = 0;
|
644 |
global $WpSmush;
|
645 |
|
646 |
$should_continue = true;
|
647 |
+
$is_pro = false;
|
648 |
|
649 |
if ( empty( $_REQUEST['attachment_id'] ) ) {
|
650 |
wp_send_json_error( 'missing id' );
|
651 |
}
|
652 |
|
653 |
//if not premium
|
654 |
+
$is_pro = $WpSmush->is_pro();
|
655 |
|
656 |
+
if ( ! $is_pro ) {
|
657 |
//Free version bulk smush, check the transient counter value
|
658 |
$should_continue = $this->check_bulk_limit();
|
659 |
}
|
672 |
|
673 |
$original_meta = wp_get_attachment_metadata( $attachment_id, true );
|
674 |
|
675 |
+
$smush = $WpSmush->resize_from_meta_data( $original_meta, $attachment_id );
|
676 |
|
677 |
$this->setup_global_stats();
|
678 |
|
911 |
*
|
912 |
* @todo Add the API status here, next to the button
|
913 |
*/
|
914 |
+
function setup_button( $super_smush = false ) {
|
915 |
+
$button = $this->button_state( $super_smush );
|
916 |
$disabled = ! empty( $button['disabled'] ) ? ' disabled="disabled"' : '';
|
917 |
?>
|
918 |
<button class="button button-primary<?php echo ' ' . $button['class']; ?>" name="smush-all" <?php echo $disabled; ?>>
|
970 |
* @return array
|
971 |
*/
|
972 |
|
973 |
+
private function button_state( $super_smush ) {
|
974 |
$button = array(
|
975 |
'cancel' => false,
|
976 |
);
|
977 |
+
if ( $super_smush ) {
|
978 |
+
if ( $this->is_pro() || $this->remaining_count <= $this->max_free_bulk ) { //if premium or under limit
|
979 |
|
980 |
+
$button['text'] = __( 'Bulk Smush Now', WP_SMUSH_DOMAIN );
|
981 |
+
$button['class'] = 'wp-smush-button wp-smush-send';
|
982 |
+
} else {
|
983 |
+
return array();
|
984 |
+
}
|
985 |
+
|
986 |
+
} else {
|
987 |
|
988 |
+
// if we have nothing left to smush, disable the buttons
|
989 |
+
if ( $this->smushed_count === $this->total_count ) {
|
990 |
+
$button['text'] = __( 'All Done!', WP_SMUSH_DOMAIN );
|
991 |
+
$button['class'] = 'wp-smush-finished disabled wp-smush-finished';
|
992 |
+
$button['disabled'] = 'disabled';
|
|
|
993 |
|
994 |
+
} else if ( $this->is_pro() || $this->remaining_count <= $this->max_free_bulk ) { //if premium or under limit
|
995 |
|
996 |
+
$button['text'] = __( 'Bulk Smush Now', WP_SMUSH_DOMAIN );
|
997 |
+
$button['class'] = 'wp-smush-button wp-smush-send';
|
998 |
|
999 |
+
} else { //if not premium and over limit
|
1000 |
+
$button['text'] = sprintf( __( 'Bulk Smush %d Attachments', WP_SMUSH_DOMAIN ), $this->max_free_bulk );
|
1001 |
+
$button['class'] = 'wp-smush-button wp-smush-send';
|
1002 |
|
1003 |
+
}
|
1004 |
}
|
1005 |
|
1006 |
return $button;
|
1035 |
return $response;
|
1036 |
}
|
1037 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1038 |
|
1039 |
/**
|
1040 |
* Adds a smushit pro settings link on plugin page
|
1066 |
update_option( 'dismiss_smush_upgrade', 1 );
|
1067 |
}
|
1068 |
|
1069 |
+
if ( get_option( 'dismiss_smush_upgrade' ) || $this->is_pro() ) {
|
1070 |
return;
|
1071 |
}
|
1072 |
?>
|
1081 |
and reliability... enjoy!</p>
|
1082 |
|
1083 |
<p>And now, if you'd like to upgrade to the WP Smush Pro plugin you can smush images up to 8MB in size,
|
1084 |
+
get 'Super Smushing' of, on average, 2× more reduction than lossless, backup all non smushed
|
1085 |
+
images and bulk smush an
|
1086 |
unlimited number of images at once.
|
1087 |
<a href="https://premium.wpmudev.org/?coupon=SMUSH50OFF#pricing"> Click here to upgrade with a 50%
|
1088 |
discount</a>.</p>
|
1089 |
</div>
|
1090 |
<?php
|
1091 |
}
|
1092 |
+
|
1093 |
+
/**
|
1094 |
+
* Get the smushed attachments from the database, except gif
|
1095 |
+
*
|
1096 |
+
* @global object $wpdb
|
1097 |
+
*
|
1098 |
+
* @param int|bool|array $attachment_id
|
1099 |
+
*
|
1100 |
+
* @return object query results
|
1101 |
+
*/
|
1102 |
+
function get_attachments() {
|
1103 |
+
|
1104 |
+
global $wpdb;
|
1105 |
+
|
1106 |
+
$allowed_images = "( 'image/jpeg', 'image/jpg', 'image/png' )";
|
1107 |
+
|
1108 |
+
// get the attachment id, smush data
|
1109 |
+
$sql = "SELECT p.ID as attachment_id, p.post_mime_type as type, ms.meta_value as smush_data"
|
1110 |
+
. " FROM $wpdb->posts as p"
|
1111 |
+
. " LEFT JOIN $wpdb->postmeta as ms"
|
1112 |
+
. " ON (p.ID= ms.post_id AND ms.meta_key='wp-smpro-smush-data')"
|
1113 |
+
. " WHERE"
|
1114 |
+
. " p.post_type='attachment'"
|
1115 |
+
. " AND p.post_mime_type IN " . $allowed_images
|
1116 |
+
. " ORDER BY p . ID DESC"
|
1117 |
+
// add a limit
|
1118 |
+
. " LIMIT " . $this->total_count();
|
1119 |
+
$results = $wpdb->get_results( $sql );
|
1120 |
+
unset( $sql );
|
1121 |
+
|
1122 |
+
return $results;
|
1123 |
+
}
|
1124 |
+
|
1125 |
+
/**
|
1126 |
+
* Returns the ids and meta which are losslessly compressed
|
1127 |
+
*
|
1128 |
+
* @return array
|
1129 |
+
*/
|
1130 |
+
function get_lossless_attachments() {
|
1131 |
+
|
1132 |
+
$lossless_attachments = array();
|
1133 |
+
|
1134 |
+
//Fetch all the smushed attachment ids
|
1135 |
+
$attachments = $this->get_attachments();
|
1136 |
+
|
1137 |
+
//Check if image is lossless or lossy
|
1138 |
+
foreach ( $attachments as $attachment ) {
|
1139 |
+
|
1140 |
+
//Check meta for lossy value
|
1141 |
+
$smush_data = ! empty( $attachment->smush_data ) ? maybe_unserialize( $attachment->smush_data ) : '';
|
1142 |
+
|
1143 |
+
//Return if not smushed
|
1144 |
+
if ( empty( $smush_data ) ) {
|
1145 |
+
continue;
|
1146 |
+
}
|
1147 |
+
|
1148 |
+
//if stats not set or lossy is not set for attachment, return
|
1149 |
+
if ( empty( $smush_data['stats'] ) || ! isset( $smush_data['stats']['lossy'] ) ) {
|
1150 |
+
continue;
|
1151 |
+
}
|
1152 |
+
//Add to array if lossy is not 1
|
1153 |
+
if ( $smush_data['stats']['lossy'] != 1 ) {
|
1154 |
+
$lossless_attachments[] = $attachment->attachment_id;
|
1155 |
+
}
|
1156 |
+
|
1157 |
+
}
|
1158 |
+
unset( $attachments );
|
1159 |
+
|
1160 |
+
return $lossless_attachments;
|
1161 |
+
}
|
1162 |
+
|
1163 |
+
/**
|
1164 |
+
* Adds progress bar for Super Smush bulk, if there are any lossless smushed images
|
1165 |
+
*/
|
1166 |
+
function super_smush_bulk_ui() {
|
1167 |
+
|
1168 |
+
//Check if Super smush enabled
|
1169 |
+
$super_smush = get_option( WP_SMUSH_PREFIX . 'lossy', false );
|
1170 |
+
|
1171 |
+
//Need to check, if there are any lossless ids
|
1172 |
+
if ( ! $super_smush || empty( $this->lossless_ids ) || count( $this->lossless_ids ) <= 0 ) {
|
1173 |
+
return;
|
1174 |
+
}
|
1175 |
+
|
1176 |
+
$ss_progress_ui = '<h4>' . __( 'Super-Smush Images', WP_SMUSH_DOMAIN ) . '</h4>';
|
1177 |
+
$ss_progress_ui .= '<p>' . __( '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.', WP_SMUSH_DOMAIN ) . '</p>';
|
1178 |
+
$ss_progress_ui .= '<div id="progress-ui" class="super-smush">';
|
1179 |
+
|
1180 |
+
// display the progress bars
|
1181 |
+
$ss_progress_ui .= '<div id="wp-smush-ss-progress-wrap">
|
1182 |
+
<div id="wp-smush-ss-progress" class="wp-smush-progressbar"><div style="width:0%"></div></div>
|
1183 |
+
<p id="wp-smush-compression">'
|
1184 |
+
. sprintf(
|
1185 |
+
_n( '<span class="remaining-count">%d</span> attachment left to Super-Smush',
|
1186 |
+
'<span class="remaining-count">%d</span> attachments left to Super-Smush',
|
1187 |
+
count( $this->lossless_ids ),
|
1188 |
+
WP_SMUSH_DOMAIN ), count( $this->lossless_ids ), count( $this->lossless_ids ) )
|
1189 |
+
. '</p>
|
1190 |
+
</div>
|
1191 |
+
</div><!-- End of progress ui -->';
|
1192 |
+
echo $ss_progress_ui;
|
1193 |
+
$this->setup_button( true );
|
1194 |
+
}
|
1195 |
}
|
1196 |
|
1197 |
$wpsmushit_admin = new WpSmushitAdmin();
|
lib/class-wp-smush-bulk.php
CHANGED
@@ -28,19 +28,14 @@ if ( ! class_exists( 'WpSmushitBulk' ) ) {
|
|
28 |
'post_type' => 'attachment',
|
29 |
'post_status' => 'any',
|
30 |
'post_mime_type' => array( 'image/jpeg', 'image/gif', 'image/png' ),
|
31 |
-
'order' => '
|
32 |
'posts_per_page' => - 1,
|
33 |
'meta_query' => array(
|
34 |
-
'relation' => 'AND',
|
35 |
array(
|
36 |
'key' => 'wp-smpro-smush-data',
|
37 |
'compare' => 'NOT EXISTS'
|
38 |
-
),
|
39 |
-
array(
|
40 |
-
'key' => 'wp-smush-data',
|
41 |
-
'compare' => 'NOT EXISTS'
|
42 |
)
|
43 |
-
)
|
44 |
);
|
45 |
$query = new WP_Query( $args );
|
46 |
$unsmushed_posts = $query->posts;
|
28 |
'post_type' => 'attachment',
|
29 |
'post_status' => 'any',
|
30 |
'post_mime_type' => array( 'image/jpeg', 'image/gif', 'image/png' ),
|
31 |
+
'order' => 'DESC',
|
32 |
'posts_per_page' => - 1,
|
33 |
'meta_query' => array(
|
|
|
34 |
array(
|
35 |
'key' => 'wp-smpro-smush-data',
|
36 |
'compare' => 'NOT EXISTS'
|
|
|
|
|
|
|
|
|
37 |
)
|
38 |
+
)
|
39 |
);
|
40 |
$query = new WP_Query( $args );
|
41 |
$unsmushed_posts = $query->posts;
|
readme.txt
CHANGED
@@ -1,13 +1,13 @@
|
|
1 |
=== WP Smush ===
|
2 |
Plugin Name: WP Smush
|
3 |
-
Version: 2.0.
|
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.2
|
10 |
-
Stable tag: 2.0.
|
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.
|
@@ -37,7 +37,7 @@ Install WP Smush and find out why it's the most popular image optimization plugi
|
|
37 |
<br>
|
38 |
<a href="https://premium.wpmudev.org/project/wp-smush-pro/?utm_source=wordpress.org&utm_medium=readme">WP Smush Pro</a> gives you everything you'll find in WP Smush and more:
|
39 |
<ul>
|
40 |
-
|
41 |
<li>Get even better lossless compression. We try multiple methods to squeeze every last byte out of your images.</li>
|
42 |
<li>Smush images up to 8MB (WP Smush is limited to 1MB)</li>
|
43 |
<li>Bulk smush ALL your images with one click! No more rate limiting.</li>
|
@@ -81,6 +81,13 @@ 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.4 =
|
85 |
* Fix: Fatal error conflict with some plugins on fronted of site
|
86 |
|
@@ -96,7 +103,7 @@ Yahoo's Smush.it API is gone forever. So WPMU DEV built our own free API that is
|
|
96 |
= 2.0 =
|
97 |
* Complete rewrite to use WPMU DEV's new fast and reliable API service.
|
98 |
* New: One-click bulk smushing of all your images.
|
99 |
-
* New: "Super-Smush" your images with our intelligent multi-pass lossy compression. Get
|
100 |
* New: Keep a backup of your original un-smushed images in case you want to restore later. (Pro)
|
101 |
* UX/UI updated with overall stats, progress bar.
|
102 |
|
1 |
=== WP Smush ===
|
2 |
Plugin Name: WP Smush
|
3 |
+
Version: 2.0.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.2
|
10 |
+
Stable tag: 2.0.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.
|
37 |
<br>
|
38 |
<a href="https://premium.wpmudev.org/project/wp-smush-pro/?utm_source=wordpress.org&utm_medium=readme">WP Smush Pro</a> gives you everything you'll find in WP Smush and more:
|
39 |
<ul>
|
40 |
+
<li>"Super-Smush" your images with our intelligent multi-pass lossy compression. Get over 2x more compression than lossless with almost no noticeable quality loss!</li>
|
41 |
<li>Get even better lossless compression. We try multiple methods to squeeze every last byte out of your images.</li>
|
42 |
<li>Smush images up to 8MB (WP Smush is limited to 1MB)</li>
|
43 |
<li>Bulk smush ALL your images with one click! No more rate limiting.</li>
|
81 |
|
82 |
== Changelog ==
|
83 |
|
84 |
+
= 2.0.5 =
|
85 |
+
|
86 |
+
* New: Allow Super-smush for existing smushed images (Pro Only)
|
87 |
+
* Fixed: IMPORTANT - broken transient caching for is_pro
|
88 |
+
* Fixed: Fixed conflict with wp gallery link plugin in grid view
|
89 |
+
* Fixed: Other small fixes
|
90 |
+
|
91 |
= 2.0.4 =
|
92 |
* Fix: Fatal error conflict with some plugins on fronted of site
|
93 |
|
103 |
= 2.0 =
|
104 |
* Complete rewrite to use WPMU DEV's new fast and reliable API service.
|
105 |
* New: One-click bulk smushing of all your images.
|
106 |
+
* New: "Super-Smush" your images with our intelligent multi-pass lossy compression. Get over 2x more compression with almost no noticeable quality loss! (Pro)
|
107 |
* New: Keep a backup of your original un-smushed images in case you want to restore later. (Pro)
|
108 |
* UX/UI updated with overall stats, progress bar.
|
109 |
|
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.
|
8 |
Author URI: http://premium.wpmudev.org/
|
9 |
Textdomain: wp_smush
|
10 |
*/
|
@@ -36,7 +36,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
36 |
* Constants
|
37 |
*/
|
38 |
$prefix = 'WP_SMUSH_';
|
39 |
-
$version = '2.0.
|
40 |
$smush_constatns = array(
|
41 |
'VERSON' => $version,
|
42 |
'BASENAME' => plugin_basename( __FILE__ ),
|
@@ -66,6 +66,8 @@ if ( ! class_exists( 'WpSmush' ) ) {
|
|
66 |
|
67 |
var $version = WP_SMUSH_VERSON;
|
68 |
|
|
|
|
|
69 |
/**
|
70 |
* Meta key for api validity
|
71 |
*
|
@@ -134,7 +136,7 @@ if ( ! class_exists( 'WpSmush' ) ) {
|
|
134 |
*
|
135 |
* @returns array
|
136 |
*/
|
137 |
-
function do_smushit( $
|
138 |
$errors = new WP_Error();
|
139 |
if ( empty( $file_path ) ) {
|
140 |
$errors->add( "empty_path", __( "File path is empty", WP_SMUSH_DOMAIN ) );
|
@@ -154,10 +156,10 @@ if ( ! class_exists( 'WpSmush' ) ) {
|
|
154 |
$errors->add( "not_writable", sprintf( __( "%s is not writable", WP_SMUSH_DOMAIN ), dirname( $file_path ) ) );
|
155 |
}
|
156 |
|
157 |
-
$file_size = filesize( $file_path );
|
158 |
|
159 |
//Check if premium user
|
160 |
-
$max_size = $this->
|
161 |
|
162 |
//Check if file exists
|
163 |
if ( $file_size == 0 ) {
|
@@ -201,7 +203,7 @@ if ( ! class_exists( 'WpSmush' ) ) {
|
|
201 |
|
202 |
//handle backups if enabled
|
203 |
$backup = get_option( WP_SMUSH_PREFIX . 'backup' );
|
204 |
-
if ( $backup && $this->
|
205 |
$path = pathinfo( $file_path );
|
206 |
$backup_name = trailingslashit( $path['dirname'] ) . $path['filename'] . ".bak." . $path['extension'];
|
207 |
@copy( $file_path, $backup_name );
|
@@ -225,7 +227,7 @@ if ( ! class_exists( 'WpSmush' ) ) {
|
|
225 |
}
|
226 |
|
227 |
/**
|
228 |
-
* Fills $placeholder array with values from $data array
|
229 |
*
|
230 |
* @param array $placeholders
|
231 |
* @param array $data
|
@@ -233,7 +235,13 @@ if ( ! class_exists( 'WpSmush' ) ) {
|
|
233 |
* @return array
|
234 |
*/
|
235 |
private function _array_fill_placeholders( array $placeholders, array $data ) {
|
236 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
237 |
}
|
238 |
|
239 |
/**
|
@@ -260,11 +268,10 @@ if ( ! class_exists( 'WpSmush' ) ) {
|
|
260 |
*
|
261 |
* @param $meta
|
262 |
* @param null $ID
|
263 |
-
* @param bool $force_resmush
|
264 |
*
|
265 |
* @return mixed
|
266 |
*/
|
267 |
-
function resize_from_meta_data( $meta, $ID = null
|
268 |
|
269 |
//Flag to check, if original size image needs to be smushed or not
|
270 |
$smush_full = true;
|
@@ -305,7 +312,7 @@ if ( ! class_exists( 'WpSmush' ) ) {
|
|
305 |
$attachment_file_url_size = trailingslashit( dirname( $attachment_file_url ) ) . $size_data['file'];
|
306 |
|
307 |
//Store details for each size key
|
308 |
-
$response = $this->do_smushit( $
|
309 |
|
310 |
if ( is_wp_error( $response ) ) {
|
311 |
return $response;
|
@@ -323,7 +330,7 @@ if ( ! class_exists( 'WpSmush' ) ) {
|
|
323 |
$errors->add( "image_size_error" . $size_key, sprintf( __( "Size '%s' not processed correctly", WP_SMUSH_DOMAIN ), $size_key ) );
|
324 |
}
|
325 |
|
326 |
-
if ( empty( $stats['stats']['api_version'] ) ) {
|
327 |
$stats['stats']['api_version'] = $response['data']->api_version;
|
328 |
$stats['stats']['lossy'] = $response['data']->lossy;
|
329 |
}
|
@@ -333,7 +340,7 @@ if ( ! class_exists( 'WpSmush' ) ) {
|
|
333 |
//If original size is supposed to be smushed
|
334 |
if ( $smush_full ) {
|
335 |
|
336 |
-
$full_image_response = $this->do_smushit( $
|
337 |
|
338 |
if ( is_wp_error( $full_image_response ) ) {
|
339 |
return $full_image_response;
|
@@ -353,6 +360,14 @@ if ( ! class_exists( 'WpSmush' ) ) {
|
|
353 |
$errors->add( "image_size_error", __( "Size 'full' not processed correctly", WP_SMUSH_DOMAIN ) );
|
354 |
}
|
355 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
356 |
}
|
357 |
|
358 |
$has_errors = (bool) count( $errors->get_error_messages() );
|
@@ -362,6 +377,29 @@ if ( ! class_exists( 'WpSmush' ) ) {
|
|
362 |
|
363 |
//Set smush status for all the images, store it in wp-smpro-smush-data
|
364 |
if ( ! $has_errors ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
365 |
update_post_meta( $ID, self::SMUSHED_META_KEY, $stats );
|
366 |
}
|
367 |
|
@@ -374,126 +412,29 @@ if ( ! class_exists( 'WpSmush' ) ) {
|
|
374 |
*
|
375 |
* Filters wp_generate_attachment_metadata
|
376 |
*
|
|
|
|
|
377 |
* @param $meta
|
378 |
* @param null $ID
|
379 |
*
|
380 |
* @return mixed
|
381 |
*/
|
382 |
function filter_generate_attachment_metadata( $meta, $ID = null ) {
|
383 |
-
|
384 |
-
$smush_full = true;
|
385 |
-
$errors = new WP_Error();
|
386 |
-
$stats = array(
|
387 |
-
"stats" => array_merge( $this->_get_size_signature(), array(
|
388 |
-
'api_version' => - 1,
|
389 |
-
'lossy' => - 1
|
390 |
-
)
|
391 |
-
),
|
392 |
-
'sizes' => array()
|
393 |
-
);
|
394 |
-
|
395 |
-
$size_before = $size_after = $compression = $total_time = $bytes_saved = 0;
|
396 |
-
|
397 |
-
if ( $ID && wp_attachment_is_image( $ID ) === false ) {
|
398 |
-
return $meta;
|
399 |
-
}
|
400 |
-
|
401 |
-
//File path and URL for original image
|
402 |
-
$attachment_file_path = get_attached_file( $ID );
|
403 |
-
$attachment_file_url = wp_get_attachment_url( $ID );
|
404 |
-
|
405 |
-
// If images has other registered size, smush them first
|
406 |
-
if ( ! empty( $meta['sizes'] ) ) {
|
407 |
-
|
408 |
-
foreach ( $meta['sizes'] as $size_key => $size_data ) {
|
409 |
-
|
410 |
-
//if there is a large size, then we will set a flag to leave the original untouched
|
411 |
-
if ( $size_key == 'large' ) {
|
412 |
-
$smush_full = false;
|
413 |
-
}
|
414 |
-
|
415 |
-
// We take the original image. The 'sizes' will all match the same URL and
|
416 |
-
// path. So just get the dirname and replace the filename.
|
417 |
-
|
418 |
-
$attachment_file_path_size = trailingslashit( dirname( $attachment_file_path ) ) . $size_data['file'];
|
419 |
-
$attachment_file_url_size = trailingslashit( dirname( $attachment_file_url ) ) . $size_data['file'];
|
420 |
-
|
421 |
-
//Store details for each size key
|
422 |
-
$response = $this->do_smushit( $ID, $attachment_file_path_size, $attachment_file_url_size );
|
423 |
-
|
424 |
-
if ( is_wp_error( $response ) ) {
|
425 |
-
return $meta;
|
426 |
-
}
|
427 |
-
|
428 |
-
if ( ! empty( $response['data'] ) ) {
|
429 |
-
$stats['sizes'][ $size_key ] = (object) $this->_array_fill_placeholders( $this->_get_size_signature(), (array) $response['data'] );
|
430 |
-
}
|
431 |
-
|
432 |
-
//Total Stats, store all data in bytes
|
433 |
-
if ( isset( $response['data'] ) ) {
|
434 |
-
list( $size_before, $size_after, $total_time, $compression, $bytes_saved )
|
435 |
-
= $this->_update_stats_data( $response['data'], $size_before, $size_after, $total_time, $bytes_saved );
|
436 |
-
} else {
|
437 |
-
$errors->add( "image_size_error" . $size_key, sprintf( __( "Size '%s' not processed correctly", WP_SMUSH_DOMAIN ), $size_key ) );
|
438 |
-
}
|
439 |
-
|
440 |
-
if ( empty( $stats['stats']['api_version'] ) ) {
|
441 |
-
$stats['stats']['api_version'] = $response['data']->api_version;
|
442 |
-
$stats['stats']['lossy'] = $response['data']->lossy;
|
443 |
-
}
|
444 |
-
}
|
445 |
-
}
|
446 |
-
|
447 |
-
//If original size is supposed to be smushed
|
448 |
-
if ( $smush_full ) {
|
449 |
-
|
450 |
-
$full_image_response = $this->do_smushit( $ID, $attachment_file_path, $attachment_file_url );
|
451 |
-
|
452 |
-
if ( is_wp_error( $full_image_response ) ) {
|
453 |
-
return $meta;
|
454 |
-
}
|
455 |
-
|
456 |
-
if ( ! empty( $full_image_response['data'] ) ) {
|
457 |
-
$stats['sizes']['full'] = (object) $this->_array_fill_placeholders( $this->_get_size_signature(), (array) $full_image_response['data'] );
|
458 |
-
} else {
|
459 |
-
$errors->add( "image_size_error", __( "Size 'full' not processed correctly", WP_SMUSH_DOMAIN ) );
|
460 |
-
}
|
461 |
-
|
462 |
-
//Update stats
|
463 |
-
if ( isset( $full_image_response['data'] ) ) {
|
464 |
-
list( $size_before, $size_after, $total_time, $compression, $bytes_saved )
|
465 |
-
= $this->_update_stats_data( $full_image_response['data'], $size_before, $size_after, $total_time, $bytes_saved );
|
466 |
-
} else {
|
467 |
-
$errors->add( "image_size_error", __( "Size 'full' not processed correctly", WP_SMUSH_DOMAIN ) );
|
468 |
-
}
|
469 |
-
|
470 |
-
}
|
471 |
-
|
472 |
-
$has_errors = (bool) count( $errors->get_error_messages() );
|
473 |
-
|
474 |
-
//Store stats
|
475 |
-
|
476 |
-
list( $stats['stats']['size_before'], $stats['stats']['size_after'], $stats['stats']['time'], $stats['stats']['percent'], $stats['stats']['bytes'] ) =
|
477 |
-
array( $size_before, $size_after, $total_time, $compression, $bytes_saved );
|
478 |
-
|
479 |
-
|
480 |
-
//Set smush status for all the images, store it in wp-smpro-smush-data
|
481 |
-
if ( ! $has_errors ) {
|
482 |
-
update_post_meta( $ID, self::SMUSHED_META_KEY, $stats );
|
483 |
-
}
|
484 |
|
485 |
return $meta;
|
486 |
}
|
487 |
|
|
|
488 |
/**
|
489 |
-
*
|
490 |
*
|
491 |
-
* @param
|
|
|
492 |
*
|
493 |
-
* @return
|
494 |
*/
|
495 |
function _post( $file_path, $file_size ) {
|
496 |
-
global $log;
|
497 |
|
498 |
$data = false;
|
499 |
|
@@ -513,7 +454,7 @@ if ( ! class_exists( 'WpSmush' ) ) {
|
|
513 |
//Check if lossy compression allowed and add it to headers
|
514 |
$lossy = get_option( WP_SMUSH_PREFIX . 'lossy' );
|
515 |
|
516 |
-
if ( $lossy && $this->
|
517 |
$headers['lossy'] = 'true';
|
518 |
} else {
|
519 |
$headers['lossy'] = 'false';
|
@@ -538,7 +479,7 @@ if ( ! class_exists( 'WpSmush' ) ) {
|
|
538 |
return $data;
|
539 |
} else if ( '200' != wp_remote_retrieve_response_code( $result ) ) {
|
540 |
//Handle error
|
541 |
-
$data['message'] = sprintf( __( 'Error posting to API: %s %s',
|
542 |
$data['success'] = false;
|
543 |
unset( $result ); //free memory
|
544 |
|
@@ -620,7 +561,9 @@ if ( ! class_exists( 'WpSmush' ) ) {
|
|
620 |
*
|
621 |
* @return mixed|string
|
622 |
*/
|
623 |
-
function
|
|
|
|
|
624 |
|
625 |
//no api key set, always false
|
626 |
$api_key = $this->_get_api_key();
|
@@ -628,13 +571,13 @@ if ( ! class_exists( 'WpSmush' ) ) {
|
|
628 |
return false;
|
629 |
}
|
630 |
|
631 |
-
$key = "wp-smush-
|
632 |
-
|
633 |
if ( false === ( $valid = get_site_transient( $key ) ) ) {
|
634 |
// call api
|
635 |
$url = self::API_SERVER . '&key=' . urlencode( $api_key );
|
636 |
|
637 |
$request = wp_remote_get( $url, array(
|
|
|
638 |
"timeout" => 3
|
639 |
)
|
640 |
);
|
@@ -656,7 +599,8 @@ if ( ! class_exists( 'WpSmush' ) ) {
|
|
656 |
|
657 |
}
|
658 |
|
659 |
-
|
|
|
660 |
}
|
661 |
|
662 |
/**
|
@@ -723,8 +667,12 @@ if ( ! class_exists( 'WpSmush' ) ) {
|
|
723 |
* @return string|void
|
724 |
*/
|
725 |
function set_status( $id, $echo = true, $text_only = false ) {
|
726 |
-
$status_txt
|
727 |
-
$show_button
|
|
|
|
|
|
|
|
|
728 |
$wp_smush_data = get_post_meta( $id, self::SMUSHED_META_KEY, true );
|
729 |
// if the image is smushed
|
730 |
if ( ! empty( $wp_smush_data ) ) {
|
@@ -745,8 +693,25 @@ if ( ! class_exists( 'WpSmush' ) ) {
|
|
745 |
}
|
746 |
}
|
747 |
|
748 |
-
//
|
749 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
750 |
} else {
|
751 |
|
752 |
// the status
|
@@ -780,12 +745,15 @@ if ( ! class_exists( 'WpSmush' ) ) {
|
|
780 |
*/
|
781 |
function column_html( $id, $status_txt = "", $button_txt = "", $show_button = true, $smushed = false, $echo = true ) {
|
782 |
$allowed_images = array( 'image/jpeg', 'image/jpg', 'image/png', 'image/gif' );
|
|
|
783 |
// don't proceed if attachment is not image, or if image is not a jpg, png or gif
|
784 |
if ( ! wp_attachment_is_image( $id ) || ! in_array( get_post_mime_type( $id ), $allowed_images ) ) {
|
785 |
return;
|
786 |
}
|
787 |
-
|
788 |
-
|
|
|
|
|
789 |
// if we aren't showing the button
|
790 |
if ( ! $show_button ) {
|
791 |
if ( $echo ) {
|
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.5
|
8 |
Author URI: http://premium.wpmudev.org/
|
9 |
Textdomain: wp_smush
|
10 |
*/
|
36 |
* Constants
|
37 |
*/
|
38 |
$prefix = 'WP_SMUSH_';
|
39 |
+
$version = '2.0.5';
|
40 |
$smush_constatns = array(
|
41 |
'VERSON' => $version,
|
42 |
'BASENAME' => plugin_basename( __FILE__ ),
|
66 |
|
67 |
var $version = WP_SMUSH_VERSON;
|
68 |
|
69 |
+
var $is_pro;
|
70 |
+
|
71 |
/**
|
72 |
* Meta key for api validity
|
73 |
*
|
136 |
*
|
137 |
* @returns array
|
138 |
*/
|
139 |
+
function do_smushit( $file_path = '', $file_url = '' ) {
|
140 |
$errors = new WP_Error();
|
141 |
if ( empty( $file_path ) ) {
|
142 |
$errors->add( "empty_path", __( "File path is empty", WP_SMUSH_DOMAIN ) );
|
156 |
$errors->add( "not_writable", sprintf( __( "%s is not writable", WP_SMUSH_DOMAIN ), dirname( $file_path ) ) );
|
157 |
}
|
158 |
|
159 |
+
$file_size = file_exists( $file_path ) ? filesize( $file_path ) : 0;
|
160 |
|
161 |
//Check if premium user
|
162 |
+
$max_size = $this->is_pro() ? WP_SMUSH_PREMIUM_MAX_BYTES : WP_SMUSH_MAX_BYTES;
|
163 |
|
164 |
//Check if file exists
|
165 |
if ( $file_size == 0 ) {
|
203 |
|
204 |
//handle backups if enabled
|
205 |
$backup = get_option( WP_SMUSH_PREFIX . 'backup' );
|
206 |
+
if ( $backup && $this->is_pro() ) {
|
207 |
$path = pathinfo( $file_path );
|
208 |
$backup_name = trailingslashit( $path['dirname'] ) . $path['filename'] . ".bak." . $path['extension'];
|
209 |
@copy( $file_path, $backup_name );
|
227 |
}
|
228 |
|
229 |
/**
|
230 |
+
* Fills $placeholder array with values from $data array
|
231 |
*
|
232 |
* @param array $placeholders
|
233 |
* @param array $data
|
235 |
* @return array
|
236 |
*/
|
237 |
private function _array_fill_placeholders( array $placeholders, array $data ) {
|
238 |
+
$placeholders['percent'] = $data['compression'];
|
239 |
+
$placeholders['bytes'] = $data['bytes_saved'];
|
240 |
+
$placeholders['size_before'] = $data['before_size'];
|
241 |
+
$placeholders['size_after'] = $data['after_size'];
|
242 |
+
$placeholders['time'] = $data['time'];
|
243 |
+
|
244 |
+
return $placeholders;
|
245 |
}
|
246 |
|
247 |
/**
|
268 |
*
|
269 |
* @param $meta
|
270 |
* @param null $ID
|
|
|
271 |
*
|
272 |
* @return mixed
|
273 |
*/
|
274 |
+
function resize_from_meta_data( $meta, $ID = null ) {
|
275 |
|
276 |
//Flag to check, if original size image needs to be smushed or not
|
277 |
$smush_full = true;
|
312 |
$attachment_file_url_size = trailingslashit( dirname( $attachment_file_url ) ) . $size_data['file'];
|
313 |
|
314 |
//Store details for each size key
|
315 |
+
$response = $this->do_smushit( $attachment_file_path_size, $attachment_file_url_size );
|
316 |
|
317 |
if ( is_wp_error( $response ) ) {
|
318 |
return $response;
|
330 |
$errors->add( "image_size_error" . $size_key, sprintf( __( "Size '%s' not processed correctly", WP_SMUSH_DOMAIN ), $size_key ) );
|
331 |
}
|
332 |
|
333 |
+
if ( empty( $stats['stats']['api_version'] ) || $stats['stats']['api_version'] == - 1 ) {
|
334 |
$stats['stats']['api_version'] = $response['data']->api_version;
|
335 |
$stats['stats']['lossy'] = $response['data']->lossy;
|
336 |
}
|
340 |
//If original size is supposed to be smushed
|
341 |
if ( $smush_full ) {
|
342 |
|
343 |
+
$full_image_response = $this->do_smushit( $attachment_file_path, $attachment_file_url );
|
344 |
|
345 |
if ( is_wp_error( $full_image_response ) ) {
|
346 |
return $full_image_response;
|
360 |
$errors->add( "image_size_error", __( "Size 'full' not processed correctly", WP_SMUSH_DOMAIN ) );
|
361 |
}
|
362 |
|
363 |
+
//Api version and lossy, for some images, full image i skipped and for other images only full exists
|
364 |
+
//so have to add code again
|
365 |
+
if ( empty( $stats['stats']['api_version'] ) || $stats['stats']['api_version'] == - 1 ) {
|
366 |
+
$stats['stats']['api_version'] = $full_image_response['data']->api_version;
|
367 |
+
$stats['stats']['lossy'] = $full_image_response['data']->lossy;
|
368 |
+
}
|
369 |
+
|
370 |
+
|
371 |
}
|
372 |
|
373 |
$has_errors = (bool) count( $errors->get_error_messages() );
|
377 |
|
378 |
//Set smush status for all the images, store it in wp-smpro-smush-data
|
379 |
if ( ! $has_errors ) {
|
380 |
+
|
381 |
+
$existing_stats = get_post_meta( $ID, self::SMUSHED_META_KEY, true );
|
382 |
+
|
383 |
+
if ( ! empty( $existing_stats ) ) {
|
384 |
+
//Update total bytes saved, and compression percent
|
385 |
+
$stats['stats']['bytes'] = isset( $existing_stats['stats']['bytes'] ) ? $existing_stats['stats']['bytes'] + $stats['stats']['bytes'] : $stats['stats']['bytes'];
|
386 |
+
$stats['stats']['percent'] = isset( $existing_stats['stats']['percent'] ) ? $existing_stats['stats']['percent'] + $stats['stats']['percent'] : $stats['stats']['percent'];
|
387 |
+
|
388 |
+
//Update stats for each size
|
389 |
+
if ( ! empty( $existing_stats['sizes'] ) && ! empty( $stats['sizes'] ) ) {
|
390 |
+
|
391 |
+
foreach ( $existing_stats['sizes'] as $size_name => $size_stats ) {
|
392 |
+
//if stats for a particular size doesn't exists
|
393 |
+
if ( empty( $stats['sizes'][$size_name] ) ) {
|
394 |
+
$stats['sizes'][$size_name] = $existing_stats['sizes'][$size_name];
|
395 |
+
} else {
|
396 |
+
//Update compression percent and bytes saved for each size
|
397 |
+
$stats['sizes'][$size_name]->bytes = $stats['sizes'][$size_name]->bytes + $existing_stats['sizes'][$size_name]->bytes;
|
398 |
+
$stats['sizes'][$size_name]->percent = $stats['sizes'][$size_name]->percent + $existing_stats['sizes'][$size_name]->percent;
|
399 |
+
}
|
400 |
+
}
|
401 |
+
}
|
402 |
+
}
|
403 |
update_post_meta( $ID, self::SMUSHED_META_KEY, $stats );
|
404 |
}
|
405 |
|
412 |
*
|
413 |
* Filters wp_generate_attachment_metadata
|
414 |
*
|
415 |
+
* @uses WpSmush::resize_from_meta_data
|
416 |
+
*
|
417 |
* @param $meta
|
418 |
* @param null $ID
|
419 |
*
|
420 |
* @return mixed
|
421 |
*/
|
422 |
function filter_generate_attachment_metadata( $meta, $ID = null ) {
|
423 |
+
$this->resize_from_meta_data( $meta, $ID );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
424 |
|
425 |
return $meta;
|
426 |
}
|
427 |
|
428 |
+
|
429 |
/**
|
430 |
+
* Posts an image to Smush.
|
431 |
*
|
432 |
+
* @param $file_path path of file to send to Smush
|
433 |
+
* @param $file_size
|
434 |
*
|
435 |
+
* @return bool|array array containing success status, and stats
|
436 |
*/
|
437 |
function _post( $file_path, $file_size ) {
|
|
|
438 |
|
439 |
$data = false;
|
440 |
|
454 |
//Check if lossy compression allowed and add it to headers
|
455 |
$lossy = get_option( WP_SMUSH_PREFIX . 'lossy' );
|
456 |
|
457 |
+
if ( $lossy && $this->is_pro() ) {
|
458 |
$headers['lossy'] = 'true';
|
459 |
} else {
|
460 |
$headers['lossy'] = 'false';
|
479 |
return $data;
|
480 |
} else if ( '200' != wp_remote_retrieve_response_code( $result ) ) {
|
481 |
//Handle error
|
482 |
+
$data['message'] = sprintf( __( 'Error posting to API: %s %s', WP_SMUSH_DOMAIN ), wp_remote_retrieve_response_code( $result ), wp_remote_retrieve_response_message( $result ) );
|
483 |
$data['success'] = false;
|
484 |
unset( $result ); //free memory
|
485 |
|
561 |
*
|
562 |
* @return mixed|string
|
563 |
*/
|
564 |
+
function is_pro() {
|
565 |
+
|
566 |
+
if ( isset( $this->is_pro ) ) return $this->is_pro;
|
567 |
|
568 |
//no api key set, always false
|
569 |
$api_key = $this->_get_api_key();
|
571 |
return false;
|
572 |
}
|
573 |
|
574 |
+
$key = "wp-smush-premium-" . substr( $api_key, -10, 10); //add last 10 chars of apikey to transient key in case it changes
|
|
|
575 |
if ( false === ( $valid = get_site_transient( $key ) ) ) {
|
576 |
// call api
|
577 |
$url = self::API_SERVER . '&key=' . urlencode( $api_key );
|
578 |
|
579 |
$request = wp_remote_get( $url, array(
|
580 |
+
"user-agent" => WP_SMUSH_UA,
|
581 |
"timeout" => 3
|
582 |
)
|
583 |
);
|
599 |
|
600 |
}
|
601 |
|
602 |
+
$this->is_pro = (bool) $valid;
|
603 |
+
return $this->is_pro;
|
604 |
}
|
605 |
|
606 |
/**
|
667 |
* @return string|void
|
668 |
*/
|
669 |
function set_status( $id, $echo = true, $text_only = false ) {
|
670 |
+
$status_txt = $button_txt = '';
|
671 |
+
$show_button = false;
|
672 |
+
|
673 |
+
//Stats are not received properly, otherwise
|
674 |
+
wp_cache_delete( $id, 'post_meta' );
|
675 |
+
|
676 |
$wp_smush_data = get_post_meta( $id, self::SMUSHED_META_KEY, true );
|
677 |
// if the image is smushed
|
678 |
if ( ! empty( $wp_smush_data ) ) {
|
693 |
}
|
694 |
}
|
695 |
|
696 |
+
//IF current compression is lossy
|
697 |
+
if ( ! empty( $wp_smush_data ) && ! empty( $wp_smush_data['stats'] ) ) {
|
698 |
+
$lossy = $wp_smush_data['stats']['lossy'];
|
699 |
+
$is_lossy = $lossy == 1 ? true : false;
|
700 |
+
}
|
701 |
+
|
702 |
+
//Check if Lossy enabled
|
703 |
+
$opt_lossy = WP_SMUSH_PREFIX . 'lossy';
|
704 |
+
$opt_lossy_val = get_option( $opt_lossy, false );
|
705 |
+
|
706 |
+
//Check image type
|
707 |
+
$image_type = get_post_mime_type( $id );
|
708 |
+
|
709 |
+
//Check if premium user, compression was lossless, and lossy compression is enabled
|
710 |
+
if ( $this->is_pro() && ! $is_lossy && $opt_lossy_val && $image_type != 'image/gif' ) {
|
711 |
+
// the button text
|
712 |
+
$button_txt = __( 'Super-Smush', WP_SMUSH_DOMAIN );
|
713 |
+
$show_button = true;
|
714 |
+
}
|
715 |
} else {
|
716 |
|
717 |
// the status
|
745 |
*/
|
746 |
function column_html( $id, $status_txt = "", $button_txt = "", $show_button = true, $smushed = false, $echo = true ) {
|
747 |
$allowed_images = array( 'image/jpeg', 'image/jpg', 'image/png', 'image/gif' );
|
748 |
+
|
749 |
// don't proceed if attachment is not image, or if image is not a jpg, png or gif
|
750 |
if ( ! wp_attachment_is_image( $id ) || ! in_array( get_post_mime_type( $id ), $allowed_images ) ) {
|
751 |
return;
|
752 |
}
|
753 |
+
|
754 |
+
$class = $smushed ? '' : ' hidden';
|
755 |
+
$html = '
|
756 |
+
<p class="smush-status' . $class . '">' . $status_txt . '</p>';
|
757 |
// if we aren't showing the button
|
758 |
if ( ! $show_button ) {
|
759 |
if ( $echo ) {
|