Version Description
- Thumbnails are now optimized when triggering an image optimization from within the media library.
- Number of Kraked thumbnails is now shown in media library in "Kraked Size" column.
- "Failed! Hover here" error notification does not persist where an image was not optimized. It goes away after page refresh.
- Optimize Image button no longer shown for incompatible media types.
- Information about thumbnail optimization is persisted for future fun-stats page/widget.
- Minor CSS tweaks.
Download this release
Release Info
Developer | karim79 |
Plugin | Kraken.io Image Optimizer |
Version | 1.0.2 |
Comparing to | |
See all releases |
Code changes from version 1.0.1 to 1.0.2
- css/admin.css +1 -0
- js/ajax.js +8 -2
- kraken.php +60 -32
- readme.txt +20 -3
css/admin.css
CHANGED
@@ -54,6 +54,7 @@
|
|
54 |
}
|
55 |
.buttonWrap {
|
56 |
position: relative;
|
|
|
57 |
}
|
58 |
.apiValid {
|
59 |
left: 0;
|
54 |
}
|
55 |
.buttonWrap {
|
56 |
position: relative;
|
57 |
+
margin-bottom: 5px;
|
58 |
}
|
59 |
.apiValid {
|
60 |
left: 0;
|
js/ajax.js
CHANGED
@@ -70,11 +70,16 @@ jQuery(document).ready(function ($) {
|
|
70 |
, krakedSize = data.kraked_size
|
71 |
, originalSize = data.original_size
|
72 |
, savingsPercent = data.savings_percent
|
73 |
-
, $originalSizeColumn = $(this).parent().prev("td.original_size")
|
|
|
74 |
|
75 |
$parent.fadeOut("fast", function () {
|
76 |
$cell.find(".noSavings, .krakenErrorWrap").remove();
|
77 |
-
|
|
|
|
|
|
|
|
|
78 |
$originalSizeColumn.html(originalSize);
|
79 |
$parent.remove();
|
80 |
});
|
@@ -142,6 +147,7 @@ jQuery(document).ready(function ($) {
|
|
142 |
data: data,
|
143 |
type: "post",
|
144 |
dataType: "json",
|
|
|
145 |
context: $button
|
146 |
})
|
147 |
|
70 |
, krakedSize = data.kraked_size
|
71 |
, originalSize = data.original_size
|
72 |
, savingsPercent = data.savings_percent
|
73 |
+
, $originalSizeColumn = $(this).parent().prev("td.original_size")
|
74 |
+
, krakedData = '';
|
75 |
|
76 |
$parent.fadeOut("fast", function () {
|
77 |
$cell.find(".noSavings, .krakenErrorWrap").remove();
|
78 |
+
krakedData = '<strong>' + krakedSize + '</strong><br /><small>Type: ' + type + '</small><br /><small>Savings: ' + savingsPercent + '</small>';
|
79 |
+
if (typeof data.thumbs_data !== 'undefined') {
|
80 |
+
krakedData += '<br /><small>' + data.thumbs_data.length + ' thumbs optimized</small>';
|
81 |
+
}
|
82 |
+
$(this).replaceWith(krakedData);
|
83 |
$originalSizeColumn.html(originalSize);
|
84 |
$parent.remove();
|
85 |
});
|
147 |
data: data,
|
148 |
type: "post",
|
149 |
dataType: "json",
|
150 |
+
timeout: 60000,
|
151 |
context: $button
|
152 |
})
|
153 |
|
kraken.php
CHANGED
@@ -21,8 +21,8 @@
|
|
21 |
* Plugin URI: http://wordpress.org/plugins/kraken-image-optimizer/
|
22 |
* Description: Optimize Wordpress image uploads through Kraken.io's Image Optimization API
|
23 |
* Author: Karim Salman
|
24 |
-
* Version: 1.0.
|
25 |
-
* Stable Tag: 1.0.
|
26 |
* Author URI: https://kraken.io
|
27 |
* License GPL2
|
28 |
*/
|
@@ -36,6 +36,8 @@ if ( !class_exists( 'Wp_Kraken' ) ) {
|
|
36 |
|
37 |
private $kraken_settings = array();
|
38 |
|
|
|
|
|
39 |
function __construct() {
|
40 |
$plugin_dir_path = dirname( __FILE__ );
|
41 |
require_once( $plugin_dir_path . '/lib/Kraken.php' );
|
@@ -130,30 +132,26 @@ if ( !class_exists( 'Wp_Kraken' ) ) {
|
|
130 |
function kraken_media_library_ajax_callback() {
|
131 |
|
132 |
$image_id = (int) $_POST['id'];
|
|
|
133 |
|
134 |
if ( wp_attachment_is_image( $image_id ) ) {
|
135 |
|
136 |
$imageUrl = wp_get_attachment_url( $image_id );
|
137 |
$image_path = get_attached_file( $image_id );
|
138 |
-
|
139 |
$settings = $this->kraken_settings;
|
140 |
-
|
141 |
$api_key = isset( $settings['api_key'] ) ? $settings['api_key'] : '';
|
142 |
$api_secret = isset( $settings['api_secret'] ) ? $settings['api_secret'] : '';
|
143 |
|
144 |
$status = $this->get_api_status( $api_key, $api_secret );
|
145 |
-
|
146 |
|
147 |
if ( $status === false ) {
|
148 |
-
|
149 |
-
// TODO: Update older error messages stored in WP Post Meta
|
150 |
$kv['error'] = 'There is a problem with your credentials. Please check them in the Kraken.io settings section of Media Settings, and try again.';
|
151 |
update_post_meta( $image_id, '_kraken_size', $kv );
|
152 |
echo json_encode( array( 'error' => $kv['error'] ) );
|
153 |
exit;
|
154 |
}
|
155 |
|
156 |
-
if ( isset($status['active']) && $status['active'] === true ) {
|
157 |
|
158 |
} else {
|
159 |
echo json_encode( array( 'error' => 'Your API is inactive. Please visit your account settings' ) );
|
@@ -176,7 +174,20 @@ if ( !class_exists( 'Wp_Kraken' ) ) {
|
|
176 |
$kv['meta'] = wp_get_attachment_metadata( $image_id );
|
177 |
|
178 |
if ( $this->replace_image( $image_path, $kraked_url ) ) {
|
179 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
180 |
echo json_encode( $kv );
|
181 |
}
|
182 |
} else {
|
@@ -348,23 +359,34 @@ if ( !class_exists( 'Wp_Kraken' ) ) {
|
|
348 |
echo $html;
|
349 |
}
|
350 |
|
|
|
|
|
|
|
|
|
|
|
|
|
351 |
function fill_media_columns( $column_name, $id ) {
|
352 |
-
|
353 |
$original_size = filesize( get_attached_file( $id ) );
|
354 |
$original_size = self::pretty_kb( $original_size );
|
355 |
-
|
356 |
-
|
357 |
-
|
|
|
|
|
358 |
|
359 |
if ( isset( $meta['original_size'] ) ) {
|
360 |
echo $meta['original_size'];
|
361 |
} else {
|
362 |
echo $original_size;
|
363 |
}
|
|
|
|
|
|
|
|
|
364 |
|
365 |
-
|
366 |
|
367 |
-
case 'kraken_size' :
|
368 |
$meta = get_post_meta($id, '_kraken_size', true);
|
369 |
|
370 |
// Is it optimized? Show some stats
|
@@ -373,30 +395,30 @@ if ( !class_exists( 'Wp_Kraken' ) ) {
|
|
373 |
$type = $meta['type'];
|
374 |
$savings_percentage = $meta['savings_percent'];
|
375 |
echo '<strong>' . $kraked_size .'</strong><br /><small>Type: ' . $type . '</small><br /><small>Savings: ' . $savings_percentage . '</small>';
|
376 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
377 |
// Were there no savings, or was there an error?
|
378 |
} else {
|
379 |
echo '<div class="buttonWrap"><button type="button" class="kraken_req" data-id="' . $id . '" id="krakenid-' . $id .'">Optimize This Image</button><span class="krakenSpinner"></span></div>';
|
380 |
|
381 |
-
if ( isset( $meta['error'] ) ) {
|
382 |
-
$error = $meta['error'];
|
383 |
-
echo '<div class="krakenErrorWrap"><a class="krakenError" title="' . $error . '">Failed! Hover here</a></div>';
|
384 |
-
}
|
385 |
-
|
386 |
if ( !empty( $meta['no_savings'] ) ) {
|
387 |
echo '<div class="noSavings"><strong>No savings found</strong><br /><small>Type: ' . $meta['type'] . '</small></div>';
|
|
|
|
|
|
|
388 |
}
|
389 |
-
|
390 |
}
|
391 |
-
|
|
|
|
|
392 |
}
|
393 |
}
|
394 |
-
|
395 |
-
function add_media_columns( $columns ) {
|
396 |
-
$columns['original_size'] = 'Original Size';
|
397 |
-
$columns['kraken_size'] = 'Kraked Size';
|
398 |
-
return $columns;
|
399 |
-
}
|
400 |
|
401 |
function replace_image($image_path, $kraked_url) {
|
402 |
|
@@ -439,7 +461,8 @@ if ( !class_exists( 'Wp_Kraken' ) ) {
|
|
439 |
$upload_dir = wp_upload_dir();
|
440 |
$upload_path = $upload_dir['path'];
|
441 |
$upload_url = $upload_dir['url'];
|
442 |
-
|
|
|
443 |
if ( isset( $image_data['sizes'] ) ) {
|
444 |
$sizes = $image_data['sizes'];
|
445 |
}
|
@@ -449,7 +472,10 @@ if ( !class_exists( 'Wp_Kraken' ) ) {
|
|
449 |
$thumb_url = '';
|
450 |
$thumb_path = '';
|
451 |
|
452 |
-
|
|
|
|
|
|
|
453 |
|
454 |
$thumb_path = $upload_path . '/' . $size['file'];
|
455 |
$thumb_url = $upload_url . '/' . $size['file'];
|
@@ -460,12 +486,14 @@ if ( !class_exists( 'Wp_Kraken' ) ) {
|
|
460 |
if ( !empty($result) && isset($result['success']) && isset( $result['kraked_url'] ) ) {
|
461 |
$kraked_url = $result["kraked_url"];
|
462 |
if ( $this->replace_image( $thumb_path, $kraked_url ) ) {
|
463 |
-
|
|
|
464 |
}
|
465 |
}
|
466 |
}
|
467 |
}
|
468 |
}
|
|
|
469 |
return $image_data;
|
470 |
}
|
471 |
|
21 |
* Plugin URI: http://wordpress.org/plugins/kraken-image-optimizer/
|
22 |
* Description: Optimize Wordpress image uploads through Kraken.io's Image Optimization API
|
23 |
* Author: Karim Salman
|
24 |
+
* Version: 1.0.2
|
25 |
+
* Stable Tag: 1.0.2
|
26 |
* Author URI: https://kraken.io
|
27 |
* License GPL2
|
28 |
*/
|
36 |
|
37 |
private $kraken_settings = array();
|
38 |
|
39 |
+
private $thumbs_data = array();
|
40 |
+
|
41 |
function __construct() {
|
42 |
$plugin_dir_path = dirname( __FILE__ );
|
43 |
require_once( $plugin_dir_path . '/lib/Kraken.php' );
|
132 |
function kraken_media_library_ajax_callback() {
|
133 |
|
134 |
$image_id = (int) $_POST['id'];
|
135 |
+
$this->id = $image_id;
|
136 |
|
137 |
if ( wp_attachment_is_image( $image_id ) ) {
|
138 |
|
139 |
$imageUrl = wp_get_attachment_url( $image_id );
|
140 |
$image_path = get_attached_file( $image_id );
|
|
|
141 |
$settings = $this->kraken_settings;
|
|
|
142 |
$api_key = isset( $settings['api_key'] ) ? $settings['api_key'] : '';
|
143 |
$api_secret = isset( $settings['api_secret'] ) ? $settings['api_secret'] : '';
|
144 |
|
145 |
$status = $this->get_api_status( $api_key, $api_secret );
|
|
|
146 |
|
147 |
if ( $status === false ) {
|
|
|
|
|
148 |
$kv['error'] = 'There is a problem with your credentials. Please check them in the Kraken.io settings section of Media Settings, and try again.';
|
149 |
update_post_meta( $image_id, '_kraken_size', $kv );
|
150 |
echo json_encode( array( 'error' => $kv['error'] ) );
|
151 |
exit;
|
152 |
}
|
153 |
|
154 |
+
if ( isset( $status['active'] ) && $status['active'] === true ) {
|
155 |
|
156 |
} else {
|
157 |
echo json_encode( array( 'error' => 'Your API is inactive. Please visit your account settings' ) );
|
174 |
$kv['meta'] = wp_get_attachment_metadata( $image_id );
|
175 |
|
176 |
if ( $this->replace_image( $image_path, $kraked_url ) ) {
|
177 |
+
|
178 |
+
// get metadata for thumbnails
|
179 |
+
$image_data = wp_get_attachment_metadata( $image_id );
|
180 |
+
$this->optimize_thumbnails( $image_data );
|
181 |
+
|
182 |
+
// store kraked info to DB
|
183 |
+
update_post_meta( $image_id, '_kraken_size', $kv );
|
184 |
+
|
185 |
+
// krak thumbnails, store that data too
|
186 |
+
$kraked_thumbs_data = get_post_meta( $image_id, '_kraked_thumbs', true );
|
187 |
+
if ( !empty( $kraked_thumbs_data ) ) {
|
188 |
+
$kv['thumbs_data'] = $kraked_thumbs_data;
|
189 |
+
}
|
190 |
+
|
191 |
echo json_encode( $kv );
|
192 |
}
|
193 |
} else {
|
359 |
echo $html;
|
360 |
}
|
361 |
|
362 |
+
function add_media_columns( $columns ) {
|
363 |
+
$columns['original_size'] = 'Original Size';
|
364 |
+
$columns['kraken_size'] = 'Kraked Size';
|
365 |
+
return $columns;
|
366 |
+
}
|
367 |
+
|
368 |
function fill_media_columns( $column_name, $id ) {
|
369 |
+
|
370 |
$original_size = filesize( get_attached_file( $id ) );
|
371 |
$original_size = self::pretty_kb( $original_size );
|
372 |
+
|
373 |
+
if ( strcmp( $column_name, 'original_size' ) === 0 ) {
|
374 |
+
if ( wp_attachment_is_image( $id ) ) {
|
375 |
+
|
376 |
+
$meta = get_post_meta( $id, '_kraken_size', true );
|
377 |
|
378 |
if ( isset( $meta['original_size'] ) ) {
|
379 |
echo $meta['original_size'];
|
380 |
} else {
|
381 |
echo $original_size;
|
382 |
}
|
383 |
+
} else {
|
384 |
+
echo $original_size;
|
385 |
+
}
|
386 |
+
} else {
|
387 |
|
388 |
+
if ( wp_attachment_is_image( $id ) ) {
|
389 |
|
|
|
390 |
$meta = get_post_meta($id, '_kraken_size', true);
|
391 |
|
392 |
// Is it optimized? Show some stats
|
395 |
$type = $meta['type'];
|
396 |
$savings_percentage = $meta['savings_percent'];
|
397 |
echo '<strong>' . $kraked_size .'</strong><br /><small>Type: ' . $type . '</small><br /><small>Savings: ' . $savings_percentage . '</small>';
|
398 |
+
|
399 |
+
$thumbs_data = get_post_meta( $id, '_kraked_thumbs', true );
|
400 |
+
$thumbs_count = count( $thumbs_data );
|
401 |
+
|
402 |
+
if ( !empty( $thumbs_data ) ) {
|
403 |
+
echo '<br /><small>' . $thumbs_count . ' thumbs optimized' . '</small>';
|
404 |
+
}
|
405 |
+
|
406 |
// Were there no savings, or was there an error?
|
407 |
} else {
|
408 |
echo '<div class="buttonWrap"><button type="button" class="kraken_req" data-id="' . $id . '" id="krakenid-' . $id .'">Optimize This Image</button><span class="krakenSpinner"></span></div>';
|
409 |
|
|
|
|
|
|
|
|
|
|
|
410 |
if ( !empty( $meta['no_savings'] ) ) {
|
411 |
echo '<div class="noSavings"><strong>No savings found</strong><br /><small>Type: ' . $meta['type'] . '</small></div>';
|
412 |
+
} else if ( isset( $meta['error'] ) ) {
|
413 |
+
$error = $meta['error'];
|
414 |
+
echo '<div class="krakenErrorWrap"><a class="krakenError" title="' . $error . '">Failed! Hover here</a></div>';
|
415 |
}
|
|
|
416 |
}
|
417 |
+
} else {
|
418 |
+
echo 'n/a';
|
419 |
+
}
|
420 |
}
|
421 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
422 |
|
423 |
function replace_image($image_path, $kraked_url) {
|
424 |
|
461 |
$upload_dir = wp_upload_dir();
|
462 |
$upload_path = $upload_dir['path'];
|
463 |
$upload_url = $upload_dir['url'];
|
464 |
+
$sizes = array();
|
465 |
+
|
466 |
if ( isset( $image_data['sizes'] ) ) {
|
467 |
$sizes = $image_data['sizes'];
|
468 |
}
|
472 |
$thumb_url = '';
|
473 |
$thumb_path = '';
|
474 |
|
475 |
+
$thumbs_optimized_store = array();
|
476 |
+
$this_thumb = array();
|
477 |
+
|
478 |
+
foreach ( $sizes as $key => $size ) {
|
479 |
|
480 |
$thumb_path = $upload_path . '/' . $size['file'];
|
481 |
$thumb_url = $upload_url . '/' . $size['file'];
|
486 |
if ( !empty($result) && isset($result['success']) && isset( $result['kraked_url'] ) ) {
|
487 |
$kraked_url = $result["kraked_url"];
|
488 |
if ( $this->replace_image( $thumb_path, $kraked_url ) ) {
|
489 |
+
$this_thumb = array( 'thumb' => $key, 'file' => $size['file'], 'original_size' => $result['original_size'], 'kraked_size' => $result['kraked_size'] );
|
490 |
+
$thumbs_optimized_store [] = $this_thumb;
|
491 |
}
|
492 |
}
|
493 |
}
|
494 |
}
|
495 |
}
|
496 |
+
update_post_meta( $image_id, '_kraked_thumbs', $thumbs_optimized_store, false );
|
497 |
return $image_data;
|
498 |
}
|
499 |
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Tags: Image Optimizer, Optimize, Images, Media, Performance, SEO, smushit, compr
|
|
4 |
Requires at least: 3.0.1
|
5 |
Tested up to: 3.8.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 |
|
@@ -22,13 +22,18 @@ This plugin allows you to optimize new and existing Wordpress image uploads thro
|
|
22 |
* All images already present in the media library can be optimized individually.
|
23 |
* This plugin does not require any root or command-line access. No compilation and installation of any binaries is necessary.
|
24 |
* All optimization is carried out by sending images to Kraken.io's infrastructure, and pulling the optimized files to your Wordpress installation.
|
25 |
-
* To use this plugin, you must obtain a full API key and secret from [
|
26 |
|
27 |
|
28 |
-
Once you have obtained your credentials, from your Wordpress admin, go to Settings->Media. The Kraken Wordpress plugin adds a Kraken.io Settings section to the bottom of the page, from where you can enter your API credentials, and select your optimization preferences. Once you have done this, click **Save**. If everything is in order, it will simply say "settings saved" and give you a reassuring green tick in the **Kraken.io settings** section. You can now start optimizing images from within Media Library. Any image you upload from now on, through any of the media upload screens will be optimized on-the-fly by Kraken.
|
29 |
|
30 |
Please send bug reports, problems, feature requests and so on to support (at) Kraken dot io, or directly to the author of this plugin.
|
31 |
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
== Installation ==
|
34 |
|
@@ -52,6 +57,10 @@ To install the Kraken Wordpress Plugin:
|
|
52 |
No, you can't. You can, however, directly contact Kraken.io support for a private demonstration, if you like.
|
53 |
To test the performance and results of Kraken Image Optimizer, you can try the free Web Interface at https://kraken.io/web-interface
|
54 |
|
|
|
|
|
|
|
|
|
55 |
|
56 |
== Changelog ==
|
57 |
|
@@ -63,3 +72,11 @@ To test the performance and results of Kraken Image Optimizer, you can try the f
|
|
63 |
= 1.0.1 =
|
64 |
* Minor cleanup release.
|
65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
Requires at least: 3.0.1
|
5 |
Tested up to: 3.8.1
|
6 |
Donate link: https://kraken.io
|
7 |
+
Stable tag: 1.0.2
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
10 |
|
22 |
* All images already present in the media library can be optimized individually.
|
23 |
* This plugin does not require any root or command-line access. No compilation and installation of any binaries is necessary.
|
24 |
* All optimization is carried out by sending images to Kraken.io's infrastructure, and pulling the optimized files to your Wordpress installation.
|
25 |
+
* To use this plugin, you must obtain a full API key and secret from [https://kraken.io/plans](https://kraken.io/plans "Kraken Image Optimizer"). The Developer API key/secret will **not** work with this plugin.
|
26 |
|
27 |
|
28 |
+
Once you have obtained your credentials, from your Wordpress admin, go to the Settings->Media page. The Kraken Wordpress plugin adds a Kraken.io Settings section to the bottom of the page, from where you can enter your API credentials, and select your optimization preferences. Once you have done this, click **Save**. If everything is in order, it will simply say "settings saved" and give you a reassuring green tick in the **Kraken.io settings** section. You can now start optimizing images from within Media Library. Any image you upload from now on, through any of the media upload screens will be optimized on-the-fly by Kraken.
|
29 |
|
30 |
Please send bug reports, problems, feature requests and so on to support (at) Kraken dot io, or directly to the author of this plugin.
|
31 |
|
32 |
+
= Connect with Kraken.io =
|
33 |
+
* Website: https://kraken.io
|
34 |
+
* [Twitter](https://twitter.com/KrakenIO "@KrakenIO")
|
35 |
+
* [Google+](https://plus.google.com/107209047753760492207/ "Google+")
|
36 |
+
* [Facebook](https://www.facebook.com/krakenio "Kraken Image Optimizer")
|
37 |
|
38 |
== Installation ==
|
39 |
|
57 |
No, you can't. You can, however, directly contact Kraken.io support for a private demonstration, if you like.
|
58 |
To test the performance and results of Kraken Image Optimizer, you can try the free Web Interface at https://kraken.io/web-interface
|
59 |
|
60 |
+
= Where can I purchase an API key and secret? =
|
61 |
+
|
62 |
+
From our plans page, right [here](https://kraken.io/plans "Kraken.io plans and pricing"). In addition to being able to use our Wordpress Plugin, you can also use the API in your own applications, and take advantage of our [Web Interface PRO ](https://kraken.io/pro "Kraken Web Interface PRO") feature.
|
63 |
+
|
64 |
|
65 |
== Changelog ==
|
66 |
|
72 |
= 1.0.1 =
|
73 |
* Minor cleanup release.
|
74 |
|
75 |
+
= 1.0.2 =
|
76 |
+
* Thumbnails are now optimized when triggering an image optimization from within the media library.
|
77 |
+
* Number of Kraked thumbnails is now shown in media library in "Kraked Size" column.
|
78 |
+
* "Failed! Hover here" error notification does not persist where an image was not optimized. It goes away after page refresh.
|
79 |
+
* Optimize Image button no longer shown for incompatible media types.
|
80 |
+
* Information about thumbnail optimization is persisted for future fun-stats page/widget.
|
81 |
+
* Minor CSS tweaks.
|
82 |
+
|