Kraken.io Image Optimizer - Version 1.0.3.1

Version Description

  • When using the Regenerate Thumbnails plugin with kraked images, meta data is now correctly updated per image.
  • Optimization mode (lossy/lossless) is now stored with kraken thumbnail metadata (for future Stats page).
Download this release

Release Info

Developer karim79
Plugin Icon 128x128 Kraken.io Image Optimizer
Version 1.0.3.1
Comparing to
See all releases

Code changes from version 1.0.3 to 1.0.3.1

Files changed (2) hide show
  1. kraken.php +17 -14
  2. readme.txt +5 -2
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.3
25
- * Stable Tag: 1.0.3
26
  * Author URI: https://kraken.io
27
  * License GPL2
28
  */
@@ -38,16 +38,19 @@ if ( !class_exists( 'Wp_Kraken' ) ) {
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' );
44
  $this->kraken_settings = get_option( '_kraken_options' );
 
45
  add_action( 'admin_init', array( &$this, 'admin_init' ) );
46
  add_action( 'admin_enqueue_scripts', array( &$this, 'my_enqueue' ) );
47
  add_action( 'wp_ajax_kraken_request', array( &$this, 'kraken_media_library_ajax_callback' ) );
48
  add_action( 'manage_media_custom_column', array( &$this, 'fill_media_columns' ), 10, 2 );
49
  add_filter( 'manage_media_columns', array( &$this, 'add_media_columns') );
50
- add_filter( 'wp_generate_attachment_metadata', array( &$this, 'optimize_thumbnails' ) );
51
  add_action( 'add_attachment', array( &$this, 'kraken_media_uploader_callback' ) );
52
  }
53
 
@@ -186,7 +189,7 @@ if ( !class_exists( 'Wp_Kraken' ) ) {
186
 
187
  // get metadata for thumbnails
188
  $image_data = wp_get_attachment_metadata( $image_id );
189
- $this->optimize_thumbnails( $image_data, $type );
190
 
191
  // store kraked info to DB
192
  update_post_meta( $image_id, '_kraken_size', $kv );
@@ -470,16 +473,15 @@ if ( !class_exists( 'Wp_Kraken' ) ) {
470
  return $data;
471
  }
472
 
473
- function optimize_thumbnails( $image_data, $type = 'lossy' ) {
474
-
475
- if ( empty( $type ) ) {
476
- $settings = $this->kraken_settings;
477
- $optimizationType = $settings['api_lossy'];
478
- } else {
479
- $optimizationType = $type;
480
- }
481
 
482
  $image_id = $this->id;
 
 
 
 
 
 
483
  $path_parts = pathinfo( $image_data['file'] );
484
 
485
  // e.g. 04/02, for use in getting correct path or URL
@@ -515,12 +517,13 @@ if ( !class_exists( 'Wp_Kraken' ) ) {
515
  $thumb_url = $upload_url . '/' . $size['file'];
516
 
517
  if ( file_exists( $thumb_path ) !== false ) {
518
- $result = $this->optimize_image( $thumb_url, $optimizationType );
 
519
 
520
  if ( !empty($result) && isset($result['success']) && isset( $result['kraked_url'] ) ) {
521
  $kraked_url = $result["kraked_url"];
522
  if ( $this->replace_image( $thumb_path, $kraked_url ) ) {
523
- $this_thumb = array( 'thumb' => $key, 'file' => $size['file'], 'original_size' => $result['original_size'], 'kraked_size' => $result['kraked_size'] );
524
  $thumbs_optimized_store [] = $this_thumb;
525
  }
526
  }
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.3.1
25
+ * Stable Tag: 1.0.3.1
26
  * Author URI: https://kraken.io
27
  * License GPL2
28
  */
38
 
39
  private $thumbs_data = array();
40
 
41
+ private $optimization_type = '';
42
+
43
  function __construct() {
44
  $plugin_dir_path = dirname( __FILE__ );
45
  require_once( $plugin_dir_path . '/lib/Kraken.php' );
46
  $this->kraken_settings = get_option( '_kraken_options' );
47
+ $this->optimization_type = $this->kraken_settings['api_lossy'];
48
  add_action( 'admin_init', array( &$this, 'admin_init' ) );
49
  add_action( 'admin_enqueue_scripts', array( &$this, 'my_enqueue' ) );
50
  add_action( 'wp_ajax_kraken_request', array( &$this, 'kraken_media_library_ajax_callback' ) );
51
  add_action( 'manage_media_custom_column', array( &$this, 'fill_media_columns' ), 10, 2 );
52
  add_filter( 'manage_media_columns', array( &$this, 'add_media_columns') );
53
+ add_filter( 'wp_generate_attachment_metadata', array( &$this, 'optimize_thumbnails') );
54
  add_action( 'add_attachment', array( &$this, 'kraken_media_uploader_callback' ) );
55
  }
56
 
189
 
190
  // get metadata for thumbnails
191
  $image_data = wp_get_attachment_metadata( $image_id );
192
+ $this->optimize_thumbnails( $image_data );
193
 
194
  // store kraked info to DB
195
  update_post_meta( $image_id, '_kraken_size', $kv );
473
  return $data;
474
  }
475
 
476
+ function optimize_thumbnails( $image_data ) {
 
 
 
 
 
 
 
477
 
478
  $image_id = $this->id;
479
+ if ( empty( $image_id ) ) {
480
+ global $wpdb;
481
+ $post = $wpdb->get_row( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_value = %s LIMIT 1", $image_data['file'] ) );
482
+ $image_id = $post->post_id;
483
+ }
484
+
485
  $path_parts = pathinfo( $image_data['file'] );
486
 
487
  // e.g. 04/02, for use in getting correct path or URL
517
  $thumb_url = $upload_url . '/' . $size['file'];
518
 
519
  if ( file_exists( $thumb_path ) !== false ) {
520
+
521
+ $result = $this->optimize_image( $thumb_url, $this->optimization_type );
522
 
523
  if ( !empty($result) && isset($result['success']) && isset( $result['kraked_url'] ) ) {
524
  $kraked_url = $result["kraked_url"];
525
  if ( $this->replace_image( $thumb_path, $kraked_url ) ) {
526
+ $this_thumb = array( 'thumb' => $key, 'file' => $size['file'], 'original_size' => $result['original_size'], 'kraked_size' => $result['kraked_size'], 'type' => $optimization_type );
527
  $thumbs_optimized_store [] = $this_thumb;
528
  }
529
  }
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.3
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10
 
@@ -27,7 +27,7 @@ This plugin allows you to optimize new and existing Wordpress image uploads thro
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
- Features on the way:
31
  * Optimize images directly to Amazon S3.
32
  * Optimize entire media library in one click.
33
  * Optimize your currently active theme.
@@ -95,5 +95,8 @@ From our plans page, right [here](https://kraken.io/plans "Kraken.io plans and p
95
  * Fixed a bug which caused old images' thumbnails to not be optimized.
96
  * Fixed a failure condition which occured only on WPEngine-hosted systems.
97
 
 
 
 
98
 
99
 
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.3.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10
 
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
+ = Features on the way =
31
  * Optimize images directly to Amazon S3.
32
  * Optimize entire media library in one click.
33
  * Optimize your currently active theme.
95
  * Fixed a bug which caused old images' thumbnails to not be optimized.
96
  * Fixed a failure condition which occured only on WPEngine-hosted systems.
97
 
98
+ = 1.0.3.1 =
99
+ * When using the Regenerate Thumbnails plugin with kraked images, meta data is now correctly updated per image.
100
+ * Optimization mode (lossy/lossless) is now stored with kraken thumbnail metadata (for future Stats page).
101
 
102