Version Description
- check image size before uploading (1 MB limit)
- attempt to smush more than one image before bailing (kind thanks to xrampage16)
- allow setting timeout value under
Media > Settings
(default is 60 seconds)
Download this release
Release Info
Developer | alexdunae |
Plugin | Smush Image Compression and Optimization |
Version | 1.6.3 |
Comparing to | |
See all releases |
Code changes from version 1.6.2 to 1.6.3
- readme.txt +20 -5
- settings.php +21 -16
- wp-smushit.php +43 -22
readme.txt
CHANGED
@@ -1,13 +1,13 @@
|
|
1 |
=== WP Smush.it ===
|
2 |
Plugin Name: WP Smush.it
|
3 |
-
Version: 1.6.
|
4 |
Author: Dialect
|
5 |
Author URI: http://dialect.ca/?wp_smush_it
|
6 |
Contributors: alexdunae, WPMUDEV
|
7 |
Tags: images, image, attachments, attachment
|
8 |
Requires at least: 2.9
|
9 |
-
Tested up to: 3.
|
10 |
-
Stable tag: 1.6.
|
11 |
|
12 |
Reduce image file sizes and improve performance using the <a href="http://smush.it/">Smush.it</a> API within WordPress.
|
13 |
|
@@ -36,6 +36,8 @@ As of version 1.4.0 there is a new, experimental `Bulk Smush.it` feature. You c
|
|
36 |
|
37 |
Sometimes the Smush.it service goes down or is under heavy load. If the plugin has difficulty connecting to Smush.it then automatically smushing is temporarily disabled (currently for 6 hours). You can always re-enable it via the `Media > Settings` screen or manually smush the image from the Media Library.
|
38 |
|
|
|
|
|
39 |
= NextGEN Gallery =
|
40 |
NextGEN user? Also download the <a href="http://wordpress.org/extend/plugins/wp-smushit-nextgen-gallery-integration/">WP Smush.it NextGEN Integration</a> plugin.
|
41 |
|
@@ -55,12 +57,25 @@ Be sure you’re comfortable with Smush.it’s privacy policy (found on
|
|
55 |
|
56 |
== Upgrade Notice ==
|
57 |
|
58 |
-
= 1.6.2 =
|
59 |
-
|
60 |
Dear Smushers: WP Smush.it has found a new maintainer. Stay tuned for a fresh release.
|
61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
== Changelog ==
|
63 |
|
|
|
|
|
|
|
|
|
|
|
64 |
= 1.6.2 =
|
65 |
* about to get a new lease on life notice
|
66 |
|
1 |
=== WP Smush.it ===
|
2 |
Plugin Name: WP Smush.it
|
3 |
+
Version: 1.6.3
|
4 |
Author: Dialect
|
5 |
Author URI: http://dialect.ca/?wp_smush_it
|
6 |
Contributors: alexdunae, WPMUDEV
|
7 |
Tags: images, image, attachments, attachment
|
8 |
Requires at least: 2.9
|
9 |
+
Tested up to: 3.5.1
|
10 |
+
Stable tag: 1.6.3
|
11 |
|
12 |
Reduce image file sizes and improve performance using the <a href="http://smush.it/">Smush.it</a> API within WordPress.
|
13 |
|
36 |
|
37 |
Sometimes the Smush.it service goes down or is under heavy load. If the plugin has difficulty connecting to Smush.it then automatically smushing is temporarily disabled (currently for 6 hours). You can always re-enable it via the `Media > Settings` screen or manually smush the image from the Media Library.
|
38 |
|
39 |
+
You can also define how long you want to wait for the Smush.it server to respond.
|
40 |
+
|
41 |
= NextGEN Gallery =
|
42 |
NextGEN user? Also download the <a href="http://wordpress.org/extend/plugins/wp-smushit-nextgen-gallery-integration/">WP Smush.it NextGEN Integration</a> plugin.
|
43 |
|
57 |
|
58 |
== Upgrade Notice ==
|
59 |
|
|
|
|
|
60 |
Dear Smushers: WP Smush.it has found a new maintainer. Stay tuned for a fresh release.
|
61 |
|
62 |
+
In this release, my last official one, we've got:
|
63 |
+
|
64 |
+
* check image size before uploading (1 MB limit)
|
65 |
+
* attempt to smush more than one image before bailing (kind thanks to <a href="http://wordpress.org/support/profile/xrampage16">xrampage16</a>)
|
66 |
+
* allow setting timeout value under `Media > Settings` (default is 60 seconds)
|
67 |
+
|
68 |
+
Cheers from Vancouver Island, and thanks for all the smushing.
|
69 |
+
|
70 |
+
- Alex
|
71 |
+
|
72 |
== Changelog ==
|
73 |
|
74 |
+
= 1.6.3 =
|
75 |
+
* check image size before uploading (1 MB limit)
|
76 |
+
* attempt to smush more than one image before bailing (kind thanks to <a href="http://wordpress.org/support/profile/xrampage16">xrampage16</a>)
|
77 |
+
* allow setting timeout value under `Media > Settings` (default is 60 seconds)
|
78 |
+
|
79 |
= 1.6.2 =
|
80 |
* about to get a new lease on life notice
|
81 |
|
settings.php
CHANGED
@@ -1,44 +1,49 @@
|
|
1 |
<?php
|
2 |
|
3 |
/*
|
4 |
-
|
5 |
Each service has a setting specifying whether it should be used automatically on upload.
|
6 |
-
|
7 |
Values are:
|
8 |
-1 Don't use (until manually enabled via Media > Settings)
|
9 |
0 Use automatically
|
10 |
n Any other number is a Unix timestamp indicating when the service can be used again
|
11 |
-
|
12 |
*/
|
13 |
-
|
14 |
define('WP_SMUSHIT_AUTO_OK', 0);
|
15 |
define('WP_SMUSHIT_AUTO_NEVER', -1);
|
16 |
|
17 |
|
18 |
function wp_smushit_register_settings() {
|
19 |
add_settings_section( 'wp_smushit_settings', 'WP Smush.it', 'wp_smushit_settings_cb', 'media' );
|
20 |
-
|
21 |
-
|
|
|
|
|
22 |
}
|
23 |
add_action('admin_init', 'wp_smushit_register_settings');
|
24 |
|
25 |
function wp_smushit_settings_cb() {
|
26 |
}
|
27 |
|
28 |
-
function
|
29 |
-
|
30 |
-
}
|
31 |
-
|
32 |
-
function wp_smushit_render_auto_opts( $key ) {
|
33 |
$val = intval( get_option( $key, WP_SMUSHIT_AUTO_OK ) );
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
|
38 |
if ( $val > 0 ) {
|
39 |
-
|
40 |
}
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
}
|
43 |
|
44 |
// default is 6hrs
|
1 |
<?php
|
2 |
|
3 |
/*
|
4 |
+
|
5 |
Each service has a setting specifying whether it should be used automatically on upload.
|
6 |
+
|
7 |
Values are:
|
8 |
-1 Don't use (until manually enabled via Media > Settings)
|
9 |
0 Use automatically
|
10 |
n Any other number is a Unix timestamp indicating when the service can be used again
|
11 |
+
|
12 |
*/
|
13 |
+
|
14 |
define('WP_SMUSHIT_AUTO_OK', 0);
|
15 |
define('WP_SMUSHIT_AUTO_NEVER', -1);
|
16 |
|
17 |
|
18 |
function wp_smushit_register_settings() {
|
19 |
add_settings_section( 'wp_smushit_settings', 'WP Smush.it', 'wp_smushit_settings_cb', 'media' );
|
20 |
+
add_settings_field( 'wp_smushit_smushit_auto', 'Use Smush.it on upload?', 'wp_smushit_render_auto_opts', 'media', 'wp_smushit_settings' );
|
21 |
+
add_settings_field( 'wp_smushit_smushit_timeout', 'How many seconds should we wait for a response from Smush.it?', 'wp_smushit_render_timeout_opts', 'media', 'wp_smushit_settings' );
|
22 |
+
register_setting( 'media', 'wp_smushit_smushit_auto');
|
23 |
+
register_setting( 'media', 'wp_smushit_smushit_timeout');
|
24 |
}
|
25 |
add_action('admin_init', 'wp_smushit_register_settings');
|
26 |
|
27 |
function wp_smushit_settings_cb() {
|
28 |
}
|
29 |
|
30 |
+
function wp_smushit_render_auto_opts() {
|
31 |
+
$key = 'wp_smushit_smushit_auto';
|
|
|
|
|
|
|
32 |
$val = intval( get_option( $key, WP_SMUSHIT_AUTO_OK ) );
|
33 |
+
printf( "<select name='%1\$s' id='%1\$s'>", esc_attr( $key ) );
|
34 |
+
echo '<option value=' . WP_SMUSHIT_AUTO_OK . ' ' . selected( WP_SMUSHIT_AUTO_OK, $val ) . '>Automatically process on upload</option>';
|
35 |
+
echo '<option value=' . WP_SMUSHIT_AUTO_NEVER . ' ' . selected( WP_SMUSHIT_AUTO_NEVER, $val ) . '>Do not process on upload</option>';
|
36 |
|
37 |
if ( $val > 0 ) {
|
38 |
+
printf( '<option value="%d" selected="selected">Temporarily disabled until %s</option>', $val, date( 'M j, Y \a\t H:i', $val ) );
|
39 |
}
|
40 |
+
echo '</select>';
|
41 |
+
}
|
42 |
+
|
43 |
+
function wp_smushit_render_timeout_opts( $key ) {
|
44 |
+
$key = 'wp_smushit_smushit_timeout';
|
45 |
+
$val = intval( get_option( $key, WP_SMUSHIT_AUTO_OK ) );
|
46 |
+
printf( "<input type='text' name='%1\$s' id='%1\$s' value='%2\%d'>", esc_attr( $key ), intval( get_option( $key, 60 ) ) );
|
47 |
}
|
48 |
|
49 |
// default is 6hrs
|
wp-smushit.php
CHANGED
@@ -4,7 +4,7 @@ Plugin Name: WP Smush.it
|
|
4 |
Plugin URI: http://dialect.ca/code/wp-smushit/
|
5 |
Description: Reduce image file sizes and improve performance using the <a href="http://smush.it/">Smush.it</a> API within WordPress.
|
6 |
Author: Dialect
|
7 |
-
Version: 1.6.
|
8 |
Author URI: http://dialect.ca/
|
9 |
*/
|
10 |
|
@@ -23,10 +23,17 @@ define('SMUSHIT_REQ_URL', 'http://www.smushit.com/ysmush.it/ws.php?img=%s');
|
|
23 |
define('SMUSHIT_BASE_URL', 'http://www.smushit.com/');
|
24 |
|
25 |
define('WP_SMUSHIT_DOMAIN', 'wp_smushit');
|
26 |
-
define('WP_SMUSHIT_UA', 'WP Smush.it/1.6.
|
27 |
define('WP_SMUSHIT_PLUGIN_DIR', dirname(plugin_basename(__FILE__)));
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
define('WP_SMUSHIT_AUTO', intval(get_option('wp_smushit_smushit_auto', 0)));
|
|
|
30 |
require( dirname(__FILE__) . '/settings.php' );
|
31 |
|
32 |
/**
|
@@ -62,10 +69,10 @@ function wp_smushit_bulk_preview() {
|
|
62 |
@ini_set('output_buffering','on');
|
63 |
@ini_set('zlib.output_compression', 0);
|
64 |
@ini_set('implicit_flush', 1);
|
65 |
-
|
66 |
$attachments = null;
|
67 |
$auto_start = false;
|
68 |
-
|
69 |
if ( isset($_REQUEST['ids'])) {
|
70 |
$attachments = get_posts( array(
|
71 |
'numberposts' => -1,
|
@@ -81,7 +88,7 @@ function wp_smushit_bulk_preview() {
|
|
81 |
'post_mime_type' => 'image'
|
82 |
));
|
83 |
}
|
84 |
-
|
85 |
|
86 |
require( dirname(__FILE__) . '/bulk.php' );
|
87 |
}
|
@@ -126,10 +133,17 @@ function wp_smushit($file, $file_url = null) {
|
|
126 |
// return array($file, __('Not processed (local file)', WP_SMUSHIT_DOMAIN));
|
127 |
|
128 |
// canonicalize path - disabled 2011-02-1 troubleshooting 'Could not find...' errors.
|
129 |
-
// From the PHP docs: "The running script must have executable permissions on
|
130 |
// all directories in the hierarchy, otherwise realpath() will return FALSE."
|
131 |
// $file_path = realpath($file);
|
132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
$file_path = $file;
|
134 |
// check that the file exists
|
135 |
if ( FALSE === file_exists($file_path) || FALSE === is_file($file_path) ) {
|
@@ -143,6 +157,12 @@ function wp_smushit($file, $file_url = null) {
|
|
143 |
return array($file, $msg);
|
144 |
}
|
145 |
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
// check that the file is within the WP_CONTENT_DIR
|
147 |
$upload_dir = wp_upload_dir();
|
148 |
$wp_upload_dir = $upload_dir['basedir'];
|
@@ -160,8 +180,10 @@ function wp_smushit($file, $file_url = null) {
|
|
160 |
|
161 |
$data = wp_smushit_post($file_url);
|
162 |
|
163 |
-
if ( FALSE === $data )
|
|
|
164 |
return array($file, __('Error posting to Smush.it', WP_SMUSHIT_DOMAIN));
|
|
|
165 |
|
166 |
// make sure the response looks like JSON -- added 2008-12-19 when
|
167 |
// Smush.it was returning PHP warnings before the JSON output
|
@@ -180,7 +202,7 @@ function wp_smushit($file, $file_url = null) {
|
|
180 |
if ( -1 === intval($data->dest_size) )
|
181 |
return array($file, __('No savings', WP_SMUSHIT_DOMAIN));
|
182 |
|
183 |
-
if (
|
184 |
$err = ($data->error ? 'Smush.it error: ' . $data->error : 'unknown error');
|
185 |
$err .= " while processing <span class='code'>$file_url</span> (<span class='code'>$file_path</span>)";
|
186 |
return array($file, __($err, WP_SMUSHIT_DOMAIN) );
|
@@ -220,7 +242,7 @@ function wp_smushit_should_resmush($previous_status) {
|
|
220 |
if ( !$previous_status || empty($previous_status) ) {
|
221 |
return TRUE;
|
222 |
}
|
223 |
-
|
224 |
if ( stripos($previous_status, 'no savings') !== FALSE || stripos($previous_status, 'reduced') !== FALSE ) {
|
225 |
return FALSE;
|
226 |
}
|
@@ -249,7 +271,7 @@ function wp_smushit_resize_from_meta_data($meta, $ID = null, $force_resmush = tr
|
|
249 |
$upload_path = trailingslashit( $upload_dir['basedir'] );
|
250 |
|
251 |
// WordPress >= 2.6.2: determine the absolute $file_path (http://core.trac.wordpress.org/changeset/8796)
|
252 |
-
if ( FALSE === strpos($
|
253 |
$store_absolute_path = false;
|
254 |
$file_path = $upload_path . $file_path;
|
255 |
}
|
@@ -293,21 +315,20 @@ function wp_smushit_post($file_url) {
|
|
293 |
$req = sprintf( SMUSHIT_REQ_URL, urlencode( $file_url ) );
|
294 |
|
295 |
$data = false;
|
296 |
-
|
297 |
-
if ( function_exists('wp_remote_get') ) {
|
298 |
-
$response = wp_remote_get($req, array('user-agent' => WP_SMUSHIT_UA, 'timeout' => 20));
|
299 |
-
|
300 |
-
if( is_wp_error( $response ) ) {
|
301 |
-
wp_smushit_temporarily_disable();
|
302 |
-
$msg = 'Automatic smushing has been disabled temporarily due to an error. ' . $response->get_error_message();
|
303 |
-
wp_die( $msg );
|
304 |
-
}
|
305 |
|
306 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
307 |
} else {
|
308 |
wp_die( __('WP Smush.it requires WordPress 2.8 or greater', WP_SMUSHIT_DOMAIN) );
|
309 |
}
|
310 |
-
|
|
|
|
|
311 |
return $data;
|
312 |
}
|
313 |
|
4 |
Plugin URI: http://dialect.ca/code/wp-smushit/
|
5 |
Description: Reduce image file sizes and improve performance using the <a href="http://smush.it/">Smush.it</a> API within WordPress.
|
6 |
Author: Dialect
|
7 |
+
Version: 1.6.3
|
8 |
Author URI: http://dialect.ca/
|
9 |
*/
|
10 |
|
23 |
define('SMUSHIT_BASE_URL', 'http://www.smushit.com/');
|
24 |
|
25 |
define('WP_SMUSHIT_DOMAIN', 'wp_smushit');
|
26 |
+
define('WP_SMUSHIT_UA', 'WP Smush.it/1.6.3 (+http://wordpress.org/extend/plugins/wp-smushit/)');
|
27 |
define('WP_SMUSHIT_PLUGIN_DIR', dirname(plugin_basename(__FILE__)));
|
28 |
+
define('WP_SMUSHIT_MAX_BYTES', 1048576);
|
29 |
+
|
30 |
+
// The number of images (including generated sizes) that can return errors before abandoning all hope.
|
31 |
+
// N.B. this doesn't work with the bulk uploader, since it creates a new HTTP request
|
32 |
+
// for each image. It does work with the bulk smusher, though.
|
33 |
+
define('WP_SMUSHIT_ERRORS_BEFORE_QUITTING', 3 * count(get_intermediate_image_sizes()));
|
34 |
|
35 |
define('WP_SMUSHIT_AUTO', intval(get_option('wp_smushit_smushit_auto', 0)));
|
36 |
+
define('WP_SMUSHIT_TIMEOUT', intval(get_option('wp_smushit_smushit_timeout', 60)));
|
37 |
require( dirname(__FILE__) . '/settings.php' );
|
38 |
|
39 |
/**
|
69 |
@ini_set('output_buffering','on');
|
70 |
@ini_set('zlib.output_compression', 0);
|
71 |
@ini_set('implicit_flush', 1);
|
72 |
+
|
73 |
$attachments = null;
|
74 |
$auto_start = false;
|
75 |
+
|
76 |
if ( isset($_REQUEST['ids'])) {
|
77 |
$attachments = get_posts( array(
|
78 |
'numberposts' => -1,
|
88 |
'post_mime_type' => 'image'
|
89 |
));
|
90 |
}
|
91 |
+
|
92 |
|
93 |
require( dirname(__FILE__) . '/bulk.php' );
|
94 |
}
|
133 |
// return array($file, __('Not processed (local file)', WP_SMUSHIT_DOMAIN));
|
134 |
|
135 |
// canonicalize path - disabled 2011-02-1 troubleshooting 'Could not find...' errors.
|
136 |
+
// From the PHP docs: "The running script must have executable permissions on
|
137 |
// all directories in the hierarchy, otherwise realpath() will return FALSE."
|
138 |
// $file_path = realpath($file);
|
139 |
+
|
140 |
+
static $error_count = 0;
|
141 |
+
|
142 |
+
if ( $error_count >= WP_SMUSHIT_ERRORS_BEFORE_QUITTING ) {
|
143 |
+
$msg = __("Did not smush due to previous errors", WP_SMUSHIT_DOMAIN);
|
144 |
+
return array($file, $msg);
|
145 |
+
}
|
146 |
+
|
147 |
$file_path = $file;
|
148 |
// check that the file exists
|
149 |
if ( FALSE === file_exists($file_path) || FALSE === is_file($file_path) ) {
|
157 |
return array($file, $msg);
|
158 |
}
|
159 |
|
160 |
+
$file_size = filesize($file_path);
|
161 |
+
if ( $file_size > WP_SMUSHIT_MAX_BYTES ) {
|
162 |
+
$msg = sprintf(__("<a href='http://developer.yahoo.com/yslow/smushit/faq.html#faq_restrict'>Too big</a> for Smush.it (%s)", WP_SMUSHIT_DOMAIN), wp_smushit_format_bytes($file_size));
|
163 |
+
return array($file, $msg);
|
164 |
+
}
|
165 |
+
|
166 |
// check that the file is within the WP_CONTENT_DIR
|
167 |
$upload_dir = wp_upload_dir();
|
168 |
$wp_upload_dir = $upload_dir['basedir'];
|
180 |
|
181 |
$data = wp_smushit_post($file_url);
|
182 |
|
183 |
+
if ( FALSE === $data ) {
|
184 |
+
$error_count++;
|
185 |
return array($file, __('Error posting to Smush.it', WP_SMUSHIT_DOMAIN));
|
186 |
+
}
|
187 |
|
188 |
// make sure the response looks like JSON -- added 2008-12-19 when
|
189 |
// Smush.it was returning PHP warnings before the JSON output
|
202 |
if ( -1 === intval($data->dest_size) )
|
203 |
return array($file, __('No savings', WP_SMUSHIT_DOMAIN));
|
204 |
|
205 |
+
if ( !isset($data->dest) ) {
|
206 |
$err = ($data->error ? 'Smush.it error: ' . $data->error : 'unknown error');
|
207 |
$err .= " while processing <span class='code'>$file_url</span> (<span class='code'>$file_path</span>)";
|
208 |
return array($file, __($err, WP_SMUSHIT_DOMAIN) );
|
242 |
if ( !$previous_status || empty($previous_status) ) {
|
243 |
return TRUE;
|
244 |
}
|
245 |
+
|
246 |
if ( stripos($previous_status, 'no savings') !== FALSE || stripos($previous_status, 'reduced') !== FALSE ) {
|
247 |
return FALSE;
|
248 |
}
|
271 |
$upload_path = trailingslashit( $upload_dir['basedir'] );
|
272 |
|
273 |
// WordPress >= 2.6.2: determine the absolute $file_path (http://core.trac.wordpress.org/changeset/8796)
|
274 |
+
if ( FALSE === strpos($file_path, $upload_path) ) {
|
275 |
$store_absolute_path = false;
|
276 |
$file_path = $upload_path . $file_path;
|
277 |
}
|
315 |
$req = sprintf( SMUSHIT_REQ_URL, urlencode( $file_url ) );
|
316 |
|
317 |
$data = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
318 |
|
319 |
+
if ( function_exists('wp_remote_get') ) {
|
320 |
+
$response = wp_remote_get($req, array('user-agent' => WP_SMUSHIT_UA, 'timeout' => WP_SMUSHIT_TIMEOUT));
|
321 |
+
if ( !$response || is_wp_error($response)) {
|
322 |
+
$data = FALSE;
|
323 |
+
} else {
|
324 |
+
$data = wp_remote_retrieve_body($response);
|
325 |
+
}
|
326 |
} else {
|
327 |
wp_die( __('WP Smush.it requires WordPress 2.8 or greater', WP_SMUSHIT_DOMAIN) );
|
328 |
}
|
329 |
+
|
330 |
+
$data = FALSE;
|
331 |
+
|
332 |
return $data;
|
333 |
}
|
334 |
|