Version Description
- Added the ability to reset (or remove Kraken.io metadata) from individual images or all images at once, allowing further optimization in certain cases, for example, reoptimizing a previously losslessly optimized image as lossy.
Download this release
Release Info
Developer | karim79 |
Plugin | Kraken.io Image Optimizer |
Version | 1.0.7 |
Comparing to | |
See all releases |
Code changes from version 1.0.6 to 1.0.7
- css/admin.css +24 -0
- js/ajax.js +72 -8
- kraken.php +111 -29
- readme.txt +4 -1
css/admin.css
CHANGED
@@ -164,4 +164,28 @@ span.kraken-bulk-choose-type {
|
|
164 |
font-size: 12px;
|
165 |
display: inline-block;
|
166 |
margin: 0 0 4px 4px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
}
|
164 |
font-size: 12px;
|
165 |
display: inline-block;
|
166 |
margin: 0 0 4px 4px;
|
167 |
+
}
|
168 |
+
small.krakenReset {
|
169 |
+
text-decoration: underline;
|
170 |
+
cursor: pointer;
|
171 |
+
}
|
172 |
+
.resetSpinner {
|
173 |
+
display: inline-block;
|
174 |
+
margin-right: 3px;
|
175 |
+
margin-top: 4px;
|
176 |
+
vertical-align: baseline;
|
177 |
+
width: 10px;
|
178 |
+
height: 10px;
|
179 |
+
background: url('https://kraken-nekkraug.netdna-ssl.com/assets/images/spinner.gif') no-repeat 0 0;
|
180 |
+
background-size: 10px;
|
181 |
+
}
|
182 |
+
small.krakenWhatsThis {
|
183 |
+
font-size: 9px;
|
184 |
+
}
|
185 |
+
span.kraken-reset-all {
|
186 |
+
font-size: 11px;
|
187 |
+
}
|
188 |
+
span.kraken-reset-all.enabled {
|
189 |
+
text-decoration: underline;
|
190 |
+
cursor: pointer;
|
191 |
}
|
js/ajax.js
CHANGED
@@ -31,9 +31,9 @@ jQuery(document).ready(function($) {
|
|
31 |
}];
|
32 |
|
33 |
|
34 |
-
$('
|
35 |
fade: true,
|
36 |
-
gravity: '
|
37 |
});
|
38 |
|
39 |
var data = {
|
@@ -65,11 +65,7 @@ jQuery(document).ready(function($) {
|
|
65 |
|
66 |
$parent.fadeOut("fast", function() {
|
67 |
$cell.find(".noSavings, .krakenErrorWrap").remove();
|
68 |
-
|
69 |
-
if (typeof data.thumbs_data !== 'undefined') {
|
70 |
-
krakedData += '<br /><small>' + data.thumbs_data.length + ' thumbs optimized</small>';
|
71 |
-
}
|
72 |
-
$(this).replaceWith(krakedData);
|
73 |
$originalSizeColumn.html(originalSize);
|
74 |
$parent.remove();
|
75 |
});
|
@@ -343,7 +339,75 @@ jQuery(document).ready(function($) {
|
|
343 |
}
|
344 |
});
|
345 |
|
346 |
-
$(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
347 |
e.preventDefault();
|
348 |
var $button = $(this),
|
349 |
$parent = $(this).parent();
|
31 |
}];
|
32 |
|
33 |
|
34 |
+
$('.krakenWhatsThis').tipsy({
|
35 |
fade: true,
|
36 |
+
gravity: 'w'
|
37 |
});
|
38 |
|
39 |
var data = {
|
65 |
|
66 |
$parent.fadeOut("fast", function() {
|
67 |
$cell.find(".noSavings, .krakenErrorWrap").remove();
|
68 |
+
$(this).replaceWith(data.html);
|
|
|
|
|
|
|
|
|
69 |
$originalSizeColumn.html(originalSize);
|
70 |
$parent.remove();
|
71 |
});
|
339 |
}
|
340 |
});
|
341 |
|
342 |
+
$('body').on('click', 'small.krakenReset', function(e) {
|
343 |
+
e.preventDefault();
|
344 |
+
var $resetButton = $(this);
|
345 |
+
var resetData = {
|
346 |
+
action: 'kraken_reset'
|
347 |
+
};
|
348 |
+
resetData.id = $(this).data("id");
|
349 |
+
|
350 |
+
var $spinner = $('<span class="resetSpinner"></span>');
|
351 |
+
$resetButton.after($spinner);
|
352 |
+
|
353 |
+
var jqxhr = $.ajax({
|
354 |
+
url: ajax_object.ajax_url,
|
355 |
+
data: resetData,
|
356 |
+
type: "post",
|
357 |
+
dataType: "json",
|
358 |
+
timeout: 360000
|
359 |
+
})
|
360 |
+
.done(function(data, textStatus, jqXHR) {
|
361 |
+
if (data.success !== 'undefined') {
|
362 |
+
$resetButton
|
363 |
+
.closest('.kraked_size.column-kraked_size')
|
364 |
+
.hide()
|
365 |
+
.html(data.html)
|
366 |
+
.fadeIn()
|
367 |
+
.prev(".original_size.column-original_size")
|
368 |
+
.html(data.original_size);
|
369 |
+
}
|
370 |
+
});
|
371 |
+
});
|
372 |
+
|
373 |
+
$('body').on('click', '.kraken-reset-all', function(e) {
|
374 |
+
e.preventDefault();
|
375 |
+
|
376 |
+
var reset = confirm('This will immediately remove all Kraken metadata associated with your images. \n\nAre you sure you want to do this?');
|
377 |
+
if (!reset) {
|
378 |
+
return;
|
379 |
+
}
|
380 |
+
|
381 |
+
var $resetButton = $(this);
|
382 |
+
$resetButton
|
383 |
+
.text('Resetting images, pleaes wait...')
|
384 |
+
.attr('disabled', true);
|
385 |
+
var resetData = {
|
386 |
+
action: 'kraken_reset_all'
|
387 |
+
};
|
388 |
+
|
389 |
+
|
390 |
+
var $spinner = $('<span class="resetSpinner"></span>');
|
391 |
+
$resetButton.after($spinner);
|
392 |
+
|
393 |
+
var jqxhr = $.ajax({
|
394 |
+
url: ajax_object.ajax_url,
|
395 |
+
data: resetData,
|
396 |
+
type: "post",
|
397 |
+
dataType: "json",
|
398 |
+
timeout: 360000
|
399 |
+
})
|
400 |
+
.done(function(data, textStatus, jqXHR) {
|
401 |
+
$spinner.remove();
|
402 |
+
$resetButton
|
403 |
+
.text('Your images have been reset.')
|
404 |
+
.removeAttr('disabled')
|
405 |
+
.removeClass('enabled');
|
406 |
+
});
|
407 |
+
});
|
408 |
+
|
409 |
+
|
410 |
+
$('body').on("click", ".kraken_req", function(e) {
|
411 |
e.preventDefault();
|
412 |
var $button = $(this),
|
413 |
$parent = $(this).parent();
|
kraken.php
CHANGED
@@ -21,8 +21,8 @@
|
|
21 |
* Plugin URI: http://wordpress.org/plugins/kraken-image-optimizer/
|
22 |
* Description: This plugin allows you to optimize your WordPress images through the Kraken API, the world's most advanced image optimization solution.
|
23 |
* Author: Karim Salman
|
24 |
-
* Version: 1.0.
|
25 |
-
* Stable Tag: 1.0.
|
26 |
* Author URI: https://kraken.io
|
27 |
* License GPL2
|
28 |
*/
|
@@ -40,7 +40,7 @@ if ( !class_exists( 'Wp_Kraken' ) ) {
|
|
40 |
|
41 |
private $optimization_type = 'lossy';
|
42 |
|
43 |
-
public static $kraken_plugin_version = '1.0.
|
44 |
|
45 |
function __construct() {
|
46 |
$plugin_dir_path = dirname( __FILE__ );
|
@@ -49,7 +49,9 @@ if ( !class_exists( 'Wp_Kraken' ) ) {
|
|
49 |
$this->optimization_type = $this->kraken_settings['api_lossy'];
|
50 |
add_action( 'admin_init', array( &$this, 'admin_init' ) );
|
51 |
add_action( 'admin_enqueue_scripts', array( &$this, 'my_enqueue' ) );
|
|
|
52 |
add_action( 'wp_ajax_kraken_request', array( &$this, 'kraken_media_library_ajax_callback' ) );
|
|
|
53 |
add_action( 'manage_media_custom_column', array( &$this, 'fill_media_columns' ), 10, 2 );
|
54 |
add_filter( 'manage_media_columns', array( &$this, 'add_media_columns') );
|
55 |
|
@@ -104,6 +106,14 @@ if ( !class_exists( 'Wp_Kraken' ) ) {
|
|
104 |
'kraken_image_optimizer'
|
105 |
);
|
106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
add_settings_field(
|
108 |
'credentials_valid',
|
109 |
'API status:',
|
@@ -111,7 +121,6 @@ if ( !class_exists( 'Wp_Kraken' ) ) {
|
|
111 |
'media',
|
112 |
'kraken_image_optimizer'
|
113 |
);
|
114 |
-
|
115 |
}
|
116 |
|
117 |
function my_enqueue( $hook ) {
|
@@ -130,15 +139,6 @@ if ( !class_exists( 'Wp_Kraken' ) ) {
|
|
130 |
|
131 |
function get_api_status( $api_key, $api_secret ) {
|
132 |
|
133 |
-
/* Possible API Status Errors:
|
134 |
-
*
|
135 |
-
* 'Incoming request body does not contain a valid JSON object'
|
136 |
-
* 'Incoming request body does not contain a valid auth.api_key or auth.api_secret'
|
137 |
-
* 'Kraken has encountered an unexpected error and cannot fulfill your request'
|
138 |
-
* 'User not found'
|
139 |
-
* 'API Key and API Secret mismatch'
|
140 |
-
*/
|
141 |
-
|
142 |
if ( !empty( $api_key ) && !empty( $api_secret ) ) {
|
143 |
$kraken = new Kraken( $api_key, $api_secret );
|
144 |
$status = $kraken->status();
|
@@ -198,8 +198,9 @@ if ( !class_exists( 'Wp_Kraken' ) ) {
|
|
198 |
$kv['type'] = $result['type'];
|
199 |
$kv['success'] = true;
|
200 |
$kv['meta'] = wp_get_attachment_metadata( $image_id );
|
|
|
201 |
|
202 |
-
if ( $this->replace_image( $image_path, $kraked_url ) ) {
|
203 |
|
204 |
// get metadata for thumbnails
|
205 |
$image_data = wp_get_attachment_metadata( $image_id );
|
@@ -208,17 +209,18 @@ if ( !class_exists( 'Wp_Kraken' ) ) {
|
|
208 |
// store kraked info to DB
|
209 |
update_post_meta( $image_id, '_kraken_size', $kv );
|
210 |
|
211 |
-
// krak thumbnails, store that data too
|
212 |
$kraked_thumbs_data = get_post_meta( $image_id, '_kraked_thumbs', true );
|
213 |
if ( !empty( $kraked_thumbs_data ) ) {
|
214 |
$kv['thumbs_data'] = $kraked_thumbs_data;
|
215 |
}
|
216 |
-
|
217 |
echo json_encode( $kv );
|
218 |
} else {
|
219 |
echo json_encode( array( 'error' => 'Could not overwrite original file. Please ensure that your files are writable by plugins.' ) );
|
220 |
exit;
|
221 |
-
}
|
|
|
222 |
} else {
|
223 |
|
224 |
// error or no optimization
|
@@ -268,12 +270,14 @@ if ( !class_exists( 'Wp_Kraken' ) ) {
|
|
268 |
$kv['type'] = $result['type'];
|
269 |
$kv['success'] = true;
|
270 |
$kv['meta'] = wp_get_attachment_metadata( $image_id );
|
|
|
271 |
|
272 |
if ( $this->replace_image( $image_path, $kraked_url ) ) {
|
273 |
update_post_meta( $image_id, '_kraken_size', $kv );
|
274 |
} else {
|
275 |
// writing image failed
|
276 |
}
|
|
|
277 |
} else {
|
278 |
|
279 |
// error or no optimization
|
@@ -297,6 +301,49 @@ if ( !class_exists( 'Wp_Kraken' ) ) {
|
|
297 |
}
|
298 |
}
|
299 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
300 |
|
301 |
function show_credentials_validity() {
|
302 |
|
@@ -325,6 +372,7 @@ if ( !class_exists( 'Wp_Kraken' ) ) {
|
|
325 |
$error = '';
|
326 |
$valid['api_lossy'] = $input['api_lossy'];
|
327 |
$valid['auto_optimize'] = isset( $input['auto_optimize'] )? 1 : 0;
|
|
|
328 |
|
329 |
if ( !function_exists( 'curl_exec' ) ) {
|
330 |
$error = 'cURL not available. Kraken Image Optimizer requires cURL in order to communicate with Kraken.io servers. <br /> Please ask your system administrator or host to install PHP cURL, or contact support@kraken.io for advice';
|
@@ -399,12 +447,54 @@ if ( !class_exists( 'Wp_Kraken' ) ) {
|
|
399 |
<?php
|
400 |
}
|
401 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
402 |
function add_media_columns( $columns ) {
|
403 |
$columns['original_size'] = 'Original Size';
|
404 |
$columns['kraked_size'] = 'Kraked Size';
|
405 |
return $columns;
|
406 |
}
|
407 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
408 |
function fill_media_columns( $column_name, $id ) {
|
409 |
|
410 |
$original_size = filesize( get_attached_file( $id ) );
|
@@ -435,17 +525,7 @@ if ( !class_exists( 'Wp_Kraken' ) ) {
|
|
435 |
|
436 |
// Is it optimized? Show some stats
|
437 |
if ( isset( $meta['kraked_size'] ) && empty( $meta['no_savings'] ) ) {
|
438 |
-
$
|
439 |
-
$type = $meta['type'];
|
440 |
-
$savings_percentage = $meta['savings_percent'];
|
441 |
-
echo '<strong>' . $kraked_size .'</strong><br /><small>Type: ' . $type . '</small><br /><small>Savings: ' . $savings_percentage . '</small>';
|
442 |
-
|
443 |
-
$thumbs_data = get_post_meta( $id, '_kraked_thumbs', true );
|
444 |
-
$thumbs_count = count( $thumbs_data );
|
445 |
-
|
446 |
-
if ( !empty( $thumbs_data ) ) {
|
447 |
-
echo '<br /><small>' . $thumbs_count . ' thumbs optimized' . '</small>';
|
448 |
-
}
|
449 |
|
450 |
// Were there no savings, or was there an error?
|
451 |
} else {
|
@@ -495,7 +575,8 @@ if ( !class_exists( 'Wp_Kraken' ) ) {
|
|
495 |
|
496 |
try {
|
497 |
$data = $kraken->upload( $params );
|
498 |
-
} catch (Exception $e) {
|
|
|
499 |
|
500 |
$data['type'] = !empty( $type ) ? $type : $settings['api_lossy'];
|
501 |
|
@@ -559,6 +640,7 @@ if ( !class_exists( 'Wp_Kraken' ) ) {
|
|
559 |
return $image_data;
|
560 |
}
|
561 |
|
|
|
562 |
static function pretty_kb( $bytes ) {
|
563 |
return round( ( $bytes / 1024 ), 2 ) . ' kB';
|
564 |
}
|
21 |
* Plugin URI: http://wordpress.org/plugins/kraken-image-optimizer/
|
22 |
* Description: This plugin allows you to optimize your WordPress images through the Kraken API, the world's most advanced image optimization solution.
|
23 |
* Author: Karim Salman
|
24 |
+
* Version: 1.0.7
|
25 |
+
* Stable Tag: 1.0.7
|
26 |
* Author URI: https://kraken.io
|
27 |
* License GPL2
|
28 |
*/
|
40 |
|
41 |
private $optimization_type = 'lossy';
|
42 |
|
43 |
+
public static $kraken_plugin_version = '1.0.7';
|
44 |
|
45 |
function __construct() {
|
46 |
$plugin_dir_path = dirname( __FILE__ );
|
49 |
$this->optimization_type = $this->kraken_settings['api_lossy'];
|
50 |
add_action( 'admin_init', array( &$this, 'admin_init' ) );
|
51 |
add_action( 'admin_enqueue_scripts', array( &$this, 'my_enqueue' ) );
|
52 |
+
add_action( 'wp_ajax_kraken_reset', array( &$this, 'kraken_media_library_reset' ) );
|
53 |
add_action( 'wp_ajax_kraken_request', array( &$this, 'kraken_media_library_ajax_callback' ) );
|
54 |
+
add_action( 'wp_ajax_kraken_reset_all', array( &$this, 'kraken_media_library_reset_all' ) );
|
55 |
add_action( 'manage_media_custom_column', array( &$this, 'fill_media_columns' ), 10, 2 );
|
56 |
add_filter( 'manage_media_columns', array( &$this, 'add_media_columns') );
|
57 |
|
106 |
'kraken_image_optimizer'
|
107 |
);
|
108 |
|
109 |
+
add_settings_field(
|
110 |
+
'kraken_show_reset',
|
111 |
+
'Show Reset field: <small class="krakenWhatsThis" title="Checking this option will add a Reset button in the Kraked Size column for each optimized image. Resetting an image will remove the metadata associated with it, effectively making your blog forget that it had been optimized in the first place, allowing further optimization.">what\'s this?</small>',
|
112 |
+
array( &$this, 'show_reset_field' ),
|
113 |
+
'media',
|
114 |
+
'kraken_image_optimizer'
|
115 |
+
);
|
116 |
+
|
117 |
add_settings_field(
|
118 |
'credentials_valid',
|
119 |
'API status:',
|
121 |
'media',
|
122 |
'kraken_image_optimizer'
|
123 |
);
|
|
|
124 |
}
|
125 |
|
126 |
function my_enqueue( $hook ) {
|
139 |
|
140 |
function get_api_status( $api_key, $api_secret ) {
|
141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
if ( !empty( $api_key ) && !empty( $api_secret ) ) {
|
143 |
$kraken = new Kraken( $api_key, $api_secret );
|
144 |
$status = $kraken->status();
|
198 |
$kv['type'] = $result['type'];
|
199 |
$kv['success'] = true;
|
200 |
$kv['meta'] = wp_get_attachment_metadata( $image_id );
|
201 |
+
$saved_bytes = (int) $kv['saved_bytes'];
|
202 |
|
203 |
+
if ( $this->replace_image( $image_path, $result['kraked_url'] ) ) {
|
204 |
|
205 |
// get metadata for thumbnails
|
206 |
$image_data = wp_get_attachment_metadata( $image_id );
|
209 |
// store kraked info to DB
|
210 |
update_post_meta( $image_id, '_kraken_size', $kv );
|
211 |
|
212 |
+
// krak thumbnails, store that data too. This can be unset when there are no thumbs
|
213 |
$kraked_thumbs_data = get_post_meta( $image_id, '_kraked_thumbs', true );
|
214 |
if ( !empty( $kraked_thumbs_data ) ) {
|
215 |
$kv['thumbs_data'] = $kraked_thumbs_data;
|
216 |
}
|
217 |
+
$kv['html'] = $this->results_html( $image_id );
|
218 |
echo json_encode( $kv );
|
219 |
} else {
|
220 |
echo json_encode( array( 'error' => 'Could not overwrite original file. Please ensure that your files are writable by plugins.' ) );
|
221 |
exit;
|
222 |
+
}
|
223 |
+
|
224 |
} else {
|
225 |
|
226 |
// error or no optimization
|
270 |
$kv['type'] = $result['type'];
|
271 |
$kv['success'] = true;
|
272 |
$kv['meta'] = wp_get_attachment_metadata( $image_id );
|
273 |
+
$saved_bytes = (int) $kv['saved_bytes'];
|
274 |
|
275 |
if ( $this->replace_image( $image_path, $kraked_url ) ) {
|
276 |
update_post_meta( $image_id, '_kraken_size', $kv );
|
277 |
} else {
|
278 |
// writing image failed
|
279 |
}
|
280 |
+
|
281 |
} else {
|
282 |
|
283 |
// error or no optimization
|
301 |
}
|
302 |
}
|
303 |
|
304 |
+
function kraken_media_library_reset() {
|
305 |
+
$image_id = (int) $_POST['id'];
|
306 |
+
$image_meta = get_post_meta( $image_id, '_kraken_size', true );
|
307 |
+
$original_size = $image_meta['kraked_size'];
|
308 |
+
delete_post_meta( $image_id, '_kraken_size' );
|
309 |
+
delete_post_meta( $image_id, '_kraked_thumbs' );
|
310 |
+
echo json_encode( array( 'success' => true, 'original_size' => $original_size, 'html' => $this->optimize_button_html( $image_id ) ) );
|
311 |
+
die();
|
312 |
+
}
|
313 |
+
|
314 |
+
function kraken_media_library_reset_all() {
|
315 |
+
$result = null;
|
316 |
+
delete_post_meta_by_key( '_kraked_thumbs' );
|
317 |
+
delete_post_meta_by_key( '_kraken_size' );
|
318 |
+
$result = json_encode( array( 'success' => true ) );
|
319 |
+
echo $result;
|
320 |
+
die();
|
321 |
+
}
|
322 |
+
|
323 |
+
|
324 |
+
function optimize_button_html( $id ) {
|
325 |
+
$image_url = wp_get_attachment_url( $id );
|
326 |
+
$filename = basename( $image_url );
|
327 |
+
|
328 |
+
$html = <<<EOD
|
329 |
+
<div class="buttonWrap">
|
330 |
+
<button type="button"
|
331 |
+
data-setting="$this->optimization_type"
|
332 |
+
class="kraken_req"
|
333 |
+
data-id="$id"
|
334 |
+
id="krakenid-$id"
|
335 |
+
data-filename="$filename"
|
336 |
+
data-url="<$image_url">
|
337 |
+
Optimize This Image
|
338 |
+
</button>
|
339 |
+
<small class="krakenOptimizationType" style="display:none">$this->optimization_type</small>
|
340 |
+
<span class="krakenSpinner"></span>
|
341 |
+
</div>
|
342 |
+
EOD;
|
343 |
+
|
344 |
+
return $html;
|
345 |
+
}
|
346 |
+
|
347 |
|
348 |
function show_credentials_validity() {
|
349 |
|
372 |
$error = '';
|
373 |
$valid['api_lossy'] = $input['api_lossy'];
|
374 |
$valid['auto_optimize'] = isset( $input['auto_optimize'] )? 1 : 0;
|
375 |
+
$valid['show_reset'] = isset( $input['show_reset'] ) ? $input['show_reset'] : 0;
|
376 |
|
377 |
if ( !function_exists( 'curl_exec' ) ) {
|
378 |
$error = 'cURL not available. Kraken Image Optimizer requires cURL in order to communicate with Kraken.io servers. <br /> Please ask your system administrator or host to install PHP cURL, or contact support@kraken.io for advice';
|
447 |
<?php
|
448 |
}
|
449 |
|
450 |
+
function show_reset_field() {
|
451 |
+
$options = get_option( '_kraken_options' );
|
452 |
+
$show_reset = isset( $options['show_reset'] ) ? $options['show_reset'] : 0;
|
453 |
+
?>
|
454 |
+
<input type="checkbox" id="show_reset" name="_kraken_options[show_reset]" value="1" <?php checked( 1, $show_reset, true ); ?>/>
|
455 |
+
<span class="kraken-reset-all enabled">Reset All Images</span>
|
456 |
+
<?php
|
457 |
+
}
|
458 |
+
|
459 |
function add_media_columns( $columns ) {
|
460 |
$columns['original_size'] = 'Original Size';
|
461 |
$columns['kraked_size'] = 'Kraked Size';
|
462 |
return $columns;
|
463 |
}
|
464 |
|
465 |
+
function results_html( $id ) {
|
466 |
+
$image_meta = get_post_meta( $id, '_kraken_size', true );
|
467 |
+
$thumbs_meta = get_post_meta( $id, '_kraked_thumbs', true );
|
468 |
+
$kraked_size = $image_meta['kraked_size'];
|
469 |
+
$type = $image_meta['type'];
|
470 |
+
$thumbs_count = count( $thumbs_meta );
|
471 |
+
$savings_percentage = $image_meta['savings_percent'];
|
472 |
+
|
473 |
+
ob_start();
|
474 |
+
?>
|
475 |
+
<strong><?php echo $kraked_size; ?></strong>
|
476 |
+
<br />
|
477 |
+
<small>Type: <?php echo $type; ?></small>
|
478 |
+
<br />
|
479 |
+
<small>Savings: <?php echo $savings_percentage; ?></small>
|
480 |
+
<?php if ( !empty( $thumbs_meta ) ) { ?>
|
481 |
+
<br />
|
482 |
+
<small><?php echo $thumbs_count; ?> thumbs optimized</small>
|
483 |
+
<?php } ?>
|
484 |
+
<?php if ( !empty( $this->kraken_settings['show_reset'] ) ) { ?>
|
485 |
+
<br />
|
486 |
+
<small
|
487 |
+
class="krakenReset" data-id="<?php echo $id; ?>"
|
488 |
+
title="Removes Kraken metadata associated with this image">
|
489 |
+
Reset
|
490 |
+
</small>
|
491 |
+
<span class="krakenSpinner"></span>
|
492 |
+
<?php } ?>
|
493 |
+
<?php
|
494 |
+
$html = ob_get_clean();
|
495 |
+
return $html;
|
496 |
+
}
|
497 |
+
|
498 |
function fill_media_columns( $column_name, $id ) {
|
499 |
|
500 |
$original_size = filesize( get_attached_file( $id ) );
|
525 |
|
526 |
// Is it optimized? Show some stats
|
527 |
if ( isset( $meta['kraked_size'] ) && empty( $meta['no_savings'] ) ) {
|
528 |
+
echo $this->results_html( $id );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
529 |
|
530 |
// Were there no savings, or was there an error?
|
531 |
} else {
|
575 |
|
576 |
try {
|
577 |
$data = $kraken->upload( $params );
|
578 |
+
} catch (Exception $e) {
|
579 |
+
}
|
580 |
|
581 |
$data['type'] = !empty( $type ) ? $type : $settings['api_lossy'];
|
582 |
|
640 |
return $image_data;
|
641 |
}
|
642 |
|
643 |
+
|
644 |
static function pretty_kb( $bytes ) {
|
645 |
return round( ( $bytes / 1024 ), 2 ) . ' kB';
|
646 |
}
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Tags: Image Optimizer, Image Optimiser, Optimize, Optimise, Images, Media, Perfo
|
|
4 |
Requires at least: 3.0.1
|
5 |
Tested up to: 4.1
|
6 |
Donate link: https://kraken.io
|
7 |
-
Stable tag: 1.0.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
10 |
|
@@ -94,6 +94,9 @@ You will need to switch the Media Library from the Thumbnail view to the List vi
|
|
94 |
|
95 |
== Changelog ==
|
96 |
|
|
|
|
|
|
|
97 |
= 1.0.6 =
|
98 |
* Better error handling.
|
99 |
|
4 |
Requires at least: 3.0.1
|
5 |
Tested up to: 4.1
|
6 |
Donate link: https://kraken.io
|
7 |
+
Stable tag: 1.0.7
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
10 |
|
94 |
|
95 |
== Changelog ==
|
96 |
|
97 |
+
= 1.0.7 =
|
98 |
+
* Added the ability to reset (or remove Kraken.io metadata) from individual images or all images at once, allowing further optimization in certain cases, for example, reoptimizing a previously losslessly optimized image as lossy.
|
99 |
+
|
100 |
= 1.0.6 =
|
101 |
* Better error handling.
|
102 |
|