Smush Image Compression and Optimization - Version 1.4.0

Version Description

Download this release

Release Info

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

Code changes from version 1.3.4 to 1.4.0

Files changed (4) hide show
  1. bulk.php +54 -0
  2. readme.txt +10 -3
  3. theme.php +0 -144
  4. wp-smushit.php +25 -24
bulk.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="wrap">
2
+ <div id="icon-upload" class="icon32"><br /></div><h2>Bulk WP Smush.it </h2>
3
+
4
+ <?php
5
+
6
+ if ( sizeof($attachments) < 1 ):
7
+ echo '<p>You don’t appear to have uploaded any images yet.</p>';
8
+ else:
9
+ if ( empty($_POST) ): // instructions page
10
+ ?>
11
+ <p>This tool will run all of the images in your media library through the WP Smush.it web service.</p>
12
+
13
+ <p>It uploads each and every file to Yahoo! and then downloads the resulting file. It can take a long time.</p>
14
+
15
+ <p>We found <?php echo sizeof($attachments); ?> images in your media library. Be forewarned, <strong>it will take <em>at least</em> <?php echo (sizeof($attachments) * 3 / 60); ?> minutes</strong> to process all these images.</p>
16
+
17
+ <p><em>N.B. If your server <tt>gzip</tt>s content you may not see the progress updates as your files are processed.</em></p>
18
+
19
+ <p><strong>This is an experimental feature.</strong> Please post any feedback to the <a href="http://wordpress.org/tags/wp-smushit">WordPress WP Smush.it forums</a>.</p>
20
+
21
+ <form method="post" action="">
22
+ <?php wp_nonce_field( 'wp-smushit-bulk', '_wp-smushit-bulk-nonce'); ?>
23
+ <button type="submit" class="button-secondary action">Run all my images through WP Smush.it right now</button>
24
+ </form>
25
+
26
+ <?php
27
+ else: // run the script
28
+
29
+ if (!wp_verify_nonce( $_POST['_wp-smushit-bulk-nonce'], 'wp-smushit-bulk' ) || !current_user_can( 'edit_others_posts' ) ) {
30
+ wp_die( __( 'Cheatin&#8217; uh?' ) );
31
+ }
32
+
33
+ ob_implicit_flush(true);
34
+ ob_end_flush();
35
+
36
+ foreach( $attachments as $attachment ) {
37
+ printf( "<p>Processing <strong>%s</strong>&hellip;<br>", esc_html($attachment->post_name) );
38
+ $meta = wp_smushit_resize_from_meta_data( wp_get_attachment_metadata( $attachment->ID, true ), $attachment->ID );
39
+ foreach( $meta['sizes'] as $size ) {
40
+ printf( "– %s<br>", $size['wp_smushit'] );
41
+ }
42
+ echo "</p>";
43
+
44
+ wp_update_attachment_metadata( $attachment->ID, $meta );
45
+
46
+ // rate limiting is good manners, let's be nice to Yahoo!
47
+ // sleep(0.5);
48
+ @ob_flush();
49
+ flush();
50
+ }
51
+ endif;
52
+ endif;
53
+ ?>
54
+ </div>
readme.txt CHANGED
@@ -1,13 +1,13 @@
1
  === WP Smush.it ===
2
  Plugin Name: WP Smush.it
3
- Version: 1.3.4
4
  Author: Dialect
5
  Author URI: http://dialect.ca/?wp_smush_it
6
  Contributors: alexdunae
7
  Tags: images, image, attachments, attachment
8
  Requires at least: 2.8
9
- Tested up to: 3.0.4
10
- Stable tag: 1.3.4
11
 
12
  Reduce image file sizes and improve performance using the <a href="http://smush.it/">Smush.it</a> API within WordPress.
13
 
@@ -28,6 +28,8 @@ Every image you add to a page or post will be automatically run through Smush.it
28
  = Existing images =
29
  You can also run your existing images through Smush.it via the WordPress `Media Library`. Click on the `Smush.it now!` link for any image you'd like to smush.
30
 
 
 
31
  = Privacy =
32
  Be sure you&rsquo;re comfortable with Smush.it&rsquo;s privacy policy (found on their <a href="http://info.yahoo.com/legal/us/yahoo/smush_it/smush_it-4378.html">FAQ</a>).
33
 
@@ -47,6 +49,11 @@ Plugin updates are announced on [http://www.twitter.com/TheCHANGELOG](http://www
47
 
48
  == Changelog ==
49
 
 
 
 
 
 
50
 
51
  = 1.3.3
52
  * add debugging output on failure
1
  === WP Smush.it ===
2
  Plugin Name: WP Smush.it
3
+ Version: 1.4.0
4
  Author: Dialect
5
  Author URI: http://dialect.ca/?wp_smush_it
6
  Contributors: alexdunae
7
  Tags: images, image, attachments, attachment
8
  Requires at least: 2.8
9
+ Tested up to: 3.2.1
10
+ Stable tag: 1.4.0
11
 
12
  Reduce image file sizes and improve performance using the <a href="http://smush.it/">Smush.it</a> API within WordPress.
13
 
28
  = Existing images =
29
  You can also run your existing images through Smush.it via the WordPress `Media Library`. Click on the `Smush.it now!` link for any image you'd like to smush.
30
 
31
+ As of version 1.3.5 there is a new, experimental `Bulk Smush.it` feature. You can find the link under the `Media Library` tab.
32
+
33
  = Privacy =
34
  Be sure you&rsquo;re comfortable with Smush.it&rsquo;s privacy policy (found on their <a href="http://info.yahoo.com/legal/us/yahoo/smush_it/smush_it-4378.html">FAQ</a>).
35
 
49
 
50
  == Changelog ==
51
 
52
+ = 1.4.0
53
+ * bulk smush.it
54
+
55
+ = 1.3.4
56
+ * bug fixes
57
 
58
  = 1.3.3
59
  * add debugging output on failure
theme.php DELETED
@@ -1,144 +0,0 @@
1
- <?php
2
- /**
3
- * Admin page for smushing all the images in a given WordPress theme.
4
- *
5
- * Expects a `theme` in the query string.
6
- *
7
- * @version 1.3
8
- * @package WP_SmushIt
9
- */
10
-
11
- if ( FALSE == is_admin() ) {
12
- wp_die(__('You are not logged in to the dashboard.', WP_SMUSHIT_DOMAIN));
13
- }
14
-
15
- if ( FALSE === current_user_can('edit_themes') ) {
16
- wp_die(__('You don\'t have permission to work with themes.', WP_SMUSHIT_DOMAIN));
17
- }
18
-
19
- ob_start();
20
-
21
- $theme = null;
22
- $theme_path = null;
23
- $theme_url = null;
24
-
25
-
26
- if ( isset($_GET['theme']) && !empty($_GET['theme']) ) {
27
-
28
- $theme = attribute_escape($_GET['theme']);
29
- $theme_path = get_theme_root() . '/' . $theme;
30
- $theme_url = get_theme_root_uri() . '/' . $theme;
31
- }
32
-
33
-
34
- ?>
35
- <div class="wrap">
36
- <div id="icon-plugins" class="icon32"><br /></div><h2>WP Smush.it: Smush Theme Assets</h2>
37
-
38
- <?php
39
- // Smush files
40
- if (isset($_POST['action']) && $_POST['action'] == 'smush_theme' ):
41
-
42
- if ( function_exists('check_admin_referer') ) check_admin_referer('wp-smushit_smush-theme' . $theme);
43
-
44
-
45
- ?>
46
-
47
- <p>Processing files in the <strong><?php echo $theme; ?></strong> theme.</p>
48
-
49
- <?php
50
-
51
- foreach($_POST['smushitlink'] as $l) {
52
- // decode and sanitize the file path
53
- $asset_url = base64_decode($l);
54
- $asset_path = str_replace($theme_url, $theme_path, $asset_url);
55
-
56
- print "<p>Smushing <span class='code'>$asset_url</span><br/>";
57
-
58
- list($processed_path, $msg) = wp_smushit($asset_path);
59
-
60
- echo "<em>&#x2013; $msg</em>.</p>\n";
61
- ob_flush();
62
- }
63
-
64
-
65
- ?>
66
-
67
- <p>Finished processing all the files in the <strong><?php echo $theme; ?></strong> theme.</p>
68
-
69
- <p><strong>Actions:</strong>
70
- <a href="themes.php?page=<?php echo basename(dirname(__FILE__)) . '/theme.php&amp;theme=' . $theme; ?>" title="<?php _e('Smush other files in this theme', WP_SMUSHIT_DOMAIN); ?>" target="_parent"><?php _e('Smush other files in this theme', WP_SMUSHIT_DOMAIN); ?></a> |
71
-
72
- <a href="<?php echo '?page=' . basename(dirname(__FILE__)) . '/theme.php'; ?>" title="<?php _e('Work with a different theme', WP_SMUSHIT_DOMAIN); ?>" target="_parent"><?php _e('Work with a different theme', WP_SMUSHIT_DOMAIN); ?></a>
73
- </p>
74
-
75
-
76
- <?php
77
- // Select files to smush
78
- elseif( $theme ):
79
- $td = get_theme_data($theme_path . '/style.css');
80
-
81
- ?>
82
-
83
- <form method="post" action="">
84
- <input type="hidden" name="action" value="smush_theme"/>
85
- <?php
86
- if ( function_exists('wp_nonce_field') ) wp_nonce_field('wp-smushit_smush-theme' . $theme);
87
- ?>
88
-
89
- <table class="widefat fixed" cellspacing="0">
90
- <thead>
91
- <tr>
92
- <th scope="col" id="cb" class="manage-column column-cb check-column" style=""><input type="checkbox" /></th>
93
- <th scope="col" id="name" class="manage-column column-name" style="">File name</th>
94
- </tr>
95
- <tbody>
96
- <?php
97
-
98
- $theme_files = list_files($theme_path, 5);
99
-
100
- foreach($theme_files as $file) {
101
-
102
- if ( preg_match('/\.(jpg|jpeg|png|gif)$/i', $file) < 1 ) {
103
- continue;
104
- }
105
-
106
- $file = str_replace(TEMPLATEPATH, '', $file);
107
-
108
- $file_url = $theme_url . $file;
109
-
110
-
111
- ?>
112
- <tr valign="middle">
113
- <th scope="row" class="check-column"><input type="checkbox" name="smushitlink[]" value="<?php echo attribute_escape(base64_encode($file_url)); ?>" /></th>
114
- <td class="column-name"><strong><a class='row-title' href='<?php echo $file_url; ?>'><?php echo $file_url; ?></a></strong></td>
115
- </tr>
116
- <?php
117
-
118
- }
119
- // closedir($handle);
120
- ?>
121
- </table>
122
-
123
- <input type="submit">
124
- </form>
125
-
126
-
127
- <?php else: ?>
128
-
129
-
130
- <p>Select a theme.</p>
131
- <ul>
132
- <?php
133
- $themes = get_themes();
134
-
135
- foreach($themes as $t) {
136
- printf("\t<li><a href=\"?page=%s&amp;theme=%s\">%s</a></li>\n",
137
- basename(dirname(__FILE__)) . '/theme.php',
138
- $t['Template'],
139
- $t['Name']);
140
- }
141
- ?>
142
- </ul>
143
- <?php endif; ?>
144
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
wp-smushit.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /**
3
  * Integrate the Smush.it API into WordPress.
4
- * @version 1.3.4
5
  * @package WP_SmushIt
6
  */
7
  /*
@@ -9,7 +9,7 @@ Plugin Name: WP Smush.it
9
  Plugin URI: http://dialect.ca/code/wp-smushit/
10
  Description: Reduce image file sizes and improve performance using the <a href="http://smush.it/">Smush.it</a> API within WordPress.
11
  Author: Dialect
12
- Version: 1.3.4
13
  Author URI: http://dialect.ca/
14
  */
15
 
@@ -28,7 +28,7 @@ define('SMUSHIT_REQ_URL', 'http://www.smushit.com/ysmush.it/ws.php?img=%s');
28
  define('SMUSHIT_BASE_URL', 'http://www.smushit.com/');
29
 
30
  define('WP_SMUSHIT_DOMAIN', 'wp_smushit');
31
- define('WP_SMUSHIT_UA', 'WP Smush.it/1.3.0 (+http://dialect.ca/code/wp-smushit)');
32
  define('WP_SMUSHIT_GIF_TO_PNG', intval(get_option('wp_smushit_gif_to_png')));
33
  define('WP_SMUSHIT_PLUGIN_DIR', dirname(plugin_basename(__FILE__)));
34
 
@@ -38,13 +38,11 @@ define('WP_SMUSHIT_PLUGIN_DIR', dirname(plugin_basename(__FILE__)));
38
  */
39
  register_activation_hook(__FILE__,'wp_smushit_install');
40
 
41
- add_filter('wp_generate_attachment_metadata', 'wp_smushit_resize_from_meta_data');
42
  add_filter('manage_media_columns', 'wp_smushit_columns');
43
  add_action('manage_media_custom_column', 'wp_smushit_custom_column', 10, 2);
44
  add_action('admin_init', 'wp_smushit_admin_init');
45
  add_action('admin_action_wp_smushit_manual', 'wp_smushit_manual');
46
- //add_action('admin_action_wp_smushit_theme', 'wp_smushit_theme');
47
-
48
 
49
  /**
50
  * Plugin admin functions
@@ -57,24 +55,29 @@ function wp_smushit_install() {
57
  function wp_smushit_admin_init() {
58
  load_plugin_textdomain(WP_SMUSHIT_DOMAIN);
59
  wp_enqueue_script('common');
 
60
  }
61
 
62
- function wp_smushit_filter_plugin_actions($links, $file) {
63
- if ( 'wp-smushit/wp-smushit.php' === $file ) {
64
- $settings_link = '<a href="options-general.php?page=wp-smushit/options.php">' . __('Settings') . '</a>';
65
- array_unshift( $links, $settings_link ); // before other links
66
- }
67
- return $links;
68
  }
69
-
70
- /**
71
- * Process all the images from a given theme
72
- */
73
- function wp_smushit_theme() {
74
- require_once('theme.php');
 
 
 
 
 
 
 
 
 
75
  }
76
 
77
-
78
  /**
79
  * Manually process an image from the Media Library
80
  */
@@ -91,7 +94,7 @@ function wp_smushit_manual() {
91
 
92
  $original_meta = wp_get_attachment_metadata( $attachment_ID );
93
 
94
- $new_meta = wp_smushit_resize_from_meta_data( $original_meta );
95
  wp_update_attachment_metadata( $attachment_ID, $new_meta );
96
 
97
  $sendback = wp_get_referer();
@@ -212,8 +215,7 @@ function wp_smushit($file) {
212
  *
213
  * Called after `wp_generate_attachment_metadata` is completed.
214
  */
215
- function wp_smushit_resize_from_meta_data($meta) {
216
-
217
  $file_path = $meta['file'];
218
  $store_absolute_path = true;
219
  $upload_dir = wp_upload_dir();
@@ -224,7 +226,6 @@ function wp_smushit_resize_from_meta_data($meta) {
224
  $store_absolute_path = false;
225
  $file_path = $upload_path . $file_path;
226
  }
227
-
228
 
229
  list($file, $msg) = wp_smushit($file_path);
230
 
@@ -327,7 +328,7 @@ function wp_smushit_custom_column($column_name, $id) {
327
  }
328
  }
329
  /**
330
- * http_request_timeout filter -- bumpbed up to 25 seconds for larger images
331
  */
332
  function wp_smushit_http_request_timeout($time) {
333
  return 25;
1
  <?php
2
  /**
3
  * Integrate the Smush.it API into WordPress.
4
+ * @version 1.4.0
5
  * @package WP_SmushIt
6
  */
7
  /*
9
  Plugin URI: http://dialect.ca/code/wp-smushit/
10
  Description: Reduce image file sizes and improve performance using the <a href="http://smush.it/">Smush.it</a> API within WordPress.
11
  Author: Dialect
12
+ Version: 1.4.0
13
  Author URI: http://dialect.ca/
14
  */
15
 
28
  define('SMUSHIT_BASE_URL', 'http://www.smushit.com/');
29
 
30
  define('WP_SMUSHIT_DOMAIN', 'wp_smushit');
31
+ define('WP_SMUSHIT_UA', 'WP Smush.it/1.4.0 (+http://dialect.ca/code/wp-smushit)');
32
  define('WP_SMUSHIT_GIF_TO_PNG', intval(get_option('wp_smushit_gif_to_png')));
33
  define('WP_SMUSHIT_PLUGIN_DIR', dirname(plugin_basename(__FILE__)));
34
 
38
  */
39
  register_activation_hook(__FILE__,'wp_smushit_install');
40
 
41
+ add_filter('wp_generate_attachment_metadata', 'wp_smushit_resize_from_meta_data', 10, 2);
42
  add_filter('manage_media_columns', 'wp_smushit_columns');
43
  add_action('manage_media_custom_column', 'wp_smushit_custom_column', 10, 2);
44
  add_action('admin_init', 'wp_smushit_admin_init');
45
  add_action('admin_action_wp_smushit_manual', 'wp_smushit_manual');
 
 
46
 
47
  /**
48
  * Plugin admin functions
55
  function wp_smushit_admin_init() {
56
  load_plugin_textdomain(WP_SMUSHIT_DOMAIN);
57
  wp_enqueue_script('common');
58
+
59
  }
60
 
61
+ function wp_smushit_admin_menu() {
62
+ add_media_page( 'Bulk Smush.it', 'Bulk Smush.it', 'edit_others_posts', 'wp-smushit-bulk', 'wp_smushit_bulk_preview');
 
 
 
 
63
  }
64
+ add_action( 'admin_menu', 'wp_smushit_admin_menu' );
65
+
66
+ function wp_smushit_bulk_preview() {
67
+ if ( function_exists( 'apache_setenv' ) ) {
68
+ @apache_setenv('no-gzip', 1);
69
+ }
70
+ @ini_set('output_buffering','on');
71
+ @ini_set('zlib.output_compression', 0);
72
+ @ini_set('implicit_flush', 1);
73
+ $attachments = get_posts( array(
74
+ 'numberposts' => -1,
75
+ 'post_type' => 'attachment',
76
+ 'post_mime_type' => 'image'
77
+ ));
78
+ require( dirname(__FILE__) . '/bulk.php' );
79
  }
80
 
 
81
  /**
82
  * Manually process an image from the Media Library
83
  */
94
 
95
  $original_meta = wp_get_attachment_metadata( $attachment_ID );
96
 
97
+ $new_meta = wp_smushit_resize_from_meta_data( $original_meta, $attachment_ID );
98
  wp_update_attachment_metadata( $attachment_ID, $new_meta );
99
 
100
  $sendback = wp_get_referer();
215
  *
216
  * Called after `wp_generate_attachment_metadata` is completed.
217
  */
218
+ function wp_smushit_resize_from_meta_data($meta, $ID = null) {
 
219
  $file_path = $meta['file'];
220
  $store_absolute_path = true;
221
  $upload_dir = wp_upload_dir();
226
  $store_absolute_path = false;
227
  $file_path = $upload_path . $file_path;
228
  }
 
229
 
230
  list($file, $msg) = wp_smushit($file_path);
231
 
328
  }
329
  }
330
  /**
331
+ * http_request_timeout filter -- bumped up to 25 seconds for larger images
332
  */
333
  function wp_smushit_http_request_timeout($time) {
334
  return 25;