Version Description
- fixed issue with "missing" images
- save plugin version for easier debugging
- list mode is set for media library for first time run
- fixed bug that prevented backuped files to remove when the original was removed
Download this release
Release Info
Developer | ShortPixel |
Plugin | ShortPixel Image Optimizer |
Version | 2.0.7 |
Comparing to | |
See all releases |
Code changes from version 2.0.6 to 2.0.7
- readme.txt +8 -1
- shortpixel_api.php +77 -66
- wp-shortpixel.php +90 -38
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Contributors: AlexSP
|
|
4 |
Tags: picture, optimization, image editor, pngout, upload speed, shortpixel, compression, jpegmini, webp, lossless, cwebp, media, tinypng, jpegtran,image, image optimisation, shrink, picture, photo, optimize photos, compress, performance, tinypng, crunch, pngquant, attachment, optimize, pictures,fast, images, image files, image quality, lossy, upload, kraken, resize, seo, smushit, optipng, kraken image optimizer, ewww, photo optimization, gifsicle, image optimizer, images, krakenio, png, gmagick, image optimize, pdf, pdf optimisation, optimise pdf, shrink pdf, jpg, jpeg, jpg optimisation, optimise jpg, shrink jpg, gif, animated gif, optimise gif
|
5 |
Requires at least: 3.0.0 or higher
|
6 |
Tested up to: 4.1.1
|
7 |
-
Stable tag: 2.0.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -107,6 +107,13 @@ The ShortPixel team is here to help. <a href="https://shortpixel.com/contact">Co
|
|
107 |
|
108 |
== Changelog ==
|
109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
= 2.0.6 =
|
111 |
|
112 |
* different small fixes
|
4 |
Tags: picture, optimization, image editor, pngout, upload speed, shortpixel, compression, jpegmini, webp, lossless, cwebp, media, tinypng, jpegtran,image, image optimisation, shrink, picture, photo, optimize photos, compress, performance, tinypng, crunch, pngquant, attachment, optimize, pictures,fast, images, image files, image quality, lossy, upload, kraken, resize, seo, smushit, optipng, kraken image optimizer, ewww, photo optimization, gifsicle, image optimizer, images, krakenio, png, gmagick, image optimize, pdf, pdf optimisation, optimise pdf, shrink pdf, jpg, jpeg, jpg optimisation, optimise jpg, shrink jpg, gif, animated gif, optimise gif
|
5 |
Requires at least: 3.0.0 or higher
|
6 |
Tested up to: 4.1.1
|
7 |
+
Stable tag: 2.0.7
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
107 |
|
108 |
== Changelog ==
|
109 |
|
110 |
+
= 2.0.7 =
|
111 |
+
|
112 |
+
* fixed issue with "missing" images
|
113 |
+
* save plugin version for easier debugging
|
114 |
+
* list mode is set for media library for first time run
|
115 |
+
* fixed bug that prevented backuped files to remove when the original was removed
|
116 |
+
|
117 |
= 2.0.6 =
|
118 |
|
119 |
* different small fixes
|
shortpixel_api.php
CHANGED
@@ -55,11 +55,12 @@ class shortpixel_api {
|
|
55 |
if(!is_array($imageList)) return false;
|
56 |
|
57 |
$requestParameters = array(
|
|
|
58 |
'key' => $this->_apiKey,
|
59 |
'lossy' => $this->_compressionType,
|
60 |
'urllist' => $imageList
|
61 |
);
|
62 |
-
|
63 |
$response = wp_remote_post($this->_apiEndPoint, array(
|
64 |
'method' => 'POST',
|
65 |
'timeout' => 45,
|
@@ -110,7 +111,7 @@ class shortpixel_api {
|
|
110 |
}
|
111 |
|
112 |
$firstImage = $data[0];//extract as object first image
|
113 |
-
|
114 |
switch($firstImage->Status->Code) {
|
115 |
case 1:
|
116 |
//handle image has been scheduled
|
@@ -139,7 +140,7 @@ class shortpixel_api {
|
|
139 |
|
140 |
|
141 |
public function handleSuccess($callData, $url, $filePath, $ID) {
|
142 |
-
|
143 |
$counter = 0;
|
144 |
if($this->_compressionType)
|
145 |
{
|
@@ -152,78 +153,88 @@ class shortpixel_api {
|
|
152 |
$fileSize = "LoselessSize";
|
153 |
}
|
154 |
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
if ( $counter == 0 )//save percent improvement for main file
|
159 |
-
$percentImprovement = $fileData->PercentImprovement;
|
160 |
-
|
161 |
-
$correctFileSize = $fileData->$fileSize;
|
162 |
-
$tempFiles[$counter] = download_url(urldecode($fileData->$fileType));
|
163 |
-
|
164 |
-
if(is_wp_error( $tempFiles[$counter] )) //also tries with http instead of https
|
165 |
-
$tempFiles[$counter] = download_url(str_replace('https://', 'http://', urldecode($fileData->$fileType)));
|
166 |
|
167 |
-
|
168 |
-
|
169 |
-
return sprintf("Error downloading file (%s)", $tempFiles[$counter]->get_error_message());
|
170 |
-
die;
|
171 |
-
}
|
172 |
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
|
|
|
|
194 |
}
|
195 |
-
$meta = wp_get_attachment_metadata($ID);
|
196 |
-
$source = $filePath;
|
197 |
|
198 |
-
//
|
199 |
-
|
200 |
-
|
201 |
-
$destination[$imageIndex] = SP_BACKUP_FOLDER . $uploadDir['subdir'] . DIRECTORY_SEPARATOR . basename($source[$imageIndex]);
|
202 |
-
|
203 |
-
if ( strtolower(substr($source[0], strrpos($source[0],".") + 1 )) <> "pdf" )//backup works differently if it is a PDF file
|
204 |
{
|
205 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
206 |
{
|
207 |
-
$
|
208 |
-
$
|
209 |
-
$
|
|
|
|
|
|
|
|
|
|
|
210 |
}
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
foreach ( $
|
217 |
{
|
218 |
-
$
|
219 |
-
|
220 |
-
|
|
|
221 |
}
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
227 |
|
228 |
$counter = 0;
|
229 |
$meta = wp_get_attachment_metadata($ID);//we'll need the metadata for subdir
|
55 |
if(!is_array($imageList)) return false;
|
56 |
|
57 |
$requestParameters = array(
|
58 |
+
'plugin_version' => PLUGIN_VERSION,
|
59 |
'key' => $this->_apiKey,
|
60 |
'lossy' => $this->_compressionType,
|
61 |
'urllist' => $imageList
|
62 |
);
|
63 |
+
|
64 |
$response = wp_remote_post($this->_apiEndPoint, array(
|
65 |
'method' => 'POST',
|
66 |
'timeout' => 45,
|
111 |
}
|
112 |
|
113 |
$firstImage = $data[0];//extract as object first image
|
114 |
+
|
115 |
switch($firstImage->Status->Code) {
|
116 |
case 1:
|
117 |
//handle image has been scheduled
|
140 |
|
141 |
|
142 |
public function handleSuccess($callData, $url, $filePath, $ID) {
|
143 |
+
|
144 |
$counter = 0;
|
145 |
if($this->_compressionType)
|
146 |
{
|
153 |
$fileSize = "LoselessSize";
|
154 |
}
|
155 |
|
156 |
+
foreach ( $callData as $fileData )//download each file from array and process it
|
157 |
+
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
|
159 |
+
if ( $counter == 0 )//save percent improvement for main file
|
160 |
+
$percentImprovement = $fileData->PercentImprovement;
|
|
|
|
|
|
|
161 |
|
162 |
+
$correctFileSize = $fileData->$fileSize;
|
163 |
+
$tempFiles[$counter] = download_url(urldecode($fileData->$fileType));
|
164 |
+
|
165 |
+
if(is_wp_error( $tempFiles[$counter] )) //also tries with http instead of https
|
166 |
+
$tempFiles[$counter] = download_url(str_replace('https://', 'http://', urldecode($fileData->$fileType)));
|
167 |
+
|
168 |
+
if ( is_wp_error( $tempFiles[$counter] ) ) {
|
169 |
+
@unlink($tempFiles[$counter]);
|
170 |
+
return sprintf("Error downloading file (%s)", $tempFiles[$counter]->get_error_message());
|
171 |
+
die;
|
172 |
+
}
|
173 |
+
|
174 |
+
//check response so that download is OK
|
175 |
+
if( filesize($tempFiles[$counter]) != $correctFileSize) {
|
176 |
+
return sprintf("Error downloading file - incorrect file size");
|
177 |
+
die;
|
178 |
+
}
|
179 |
+
|
180 |
+
if (!file_exists($tempFiles[$counter])) {
|
181 |
+
return sprintf("Unable to locate downloaded file (%s)", $tempFiles[$counter]);
|
182 |
+
die;
|
183 |
+
}
|
184 |
+
$counter++;
|
185 |
}
|
|
|
|
|
186 |
|
187 |
+
//if backup is enabled
|
188 |
+
if(get_option('wp-short-backup_images'))
|
|
|
|
|
|
|
|
|
189 |
{
|
190 |
+
$imageIndex = 0;
|
191 |
+
$uploadDir = wp_upload_dir();
|
192 |
+
|
193 |
+
if(!file_exists(SP_BACKUP_FOLDER) && !mkdir(SP_BACKUP_FOLDER, 0777, true)) {
|
194 |
+
return sprintf("Backup folder does not exist and it could not be created");
|
195 |
+
}
|
196 |
+
$meta = wp_get_attachment_metadata($ID);
|
197 |
+
$source = $filePath;
|
198 |
+
$SubDir = trim(substr($meta['file'],0,strrpos($meta['file'],"/")+1));
|
199 |
+
|
200 |
+
if ( empty($SubDir) ) //its a PDF?
|
201 |
{
|
202 |
+
$uploadFilePath = get_attached_file($ID);
|
203 |
+
$tmp = str_replace($uploadDir['basedir'],"", $uploadFilePath);
|
204 |
+
$SubDir = trim(substr($tmp,0,strrpos($tmp,"/")));
|
205 |
+
|
206 |
+
//create destination dir if it isn't already created
|
207 |
+
@mkdir( SP_BACKUP_FOLDER . $SubDir, 0777, true);
|
208 |
+
$destination[$imageIndex] = SP_BACKUP_FOLDER . $SubDir . DIRECTORY_SEPARATOR . basename($uploadFilePath);
|
209 |
+
|
210 |
}
|
211 |
+
else //it is not PDF, its an image
|
212 |
+
{
|
213 |
+
@mkdir( SP_BACKUP_FOLDER . DIRECTORY_SEPARATOR. $SubDir, 0777, true);
|
214 |
+
$destination[$imageIndex] = SP_BACKUP_FOLDER . DIRECTORY_SEPARATOR . $SubDir . basename($source[$imageIndex]);//for main file
|
215 |
+
|
216 |
+
foreach ( $meta['sizes'] as $pictureDetails )
|
217 |
{
|
218 |
+
$imageIndex++;
|
219 |
+
$source[$imageIndex] = $uploadDir['basedir'] . DIRECTORY_SEPARATOR . $SubDir . $pictureDetails['file'];
|
220 |
+
$destination[$imageIndex] = SP_BACKUP_FOLDER . DIRECTORY_SEPARATOR . $SubDir . basename($source[$imageIndex]);
|
221 |
+
}
|
222 |
}
|
223 |
+
|
224 |
+
if(is_writable(SP_BACKUP_FOLDER)) {
|
225 |
+
if(!file_exists($destination[0]))
|
226 |
+
{
|
227 |
+
foreach ( $source as $imageIndex => $fileSource )
|
228 |
+
{
|
229 |
+
$fileDestination = $destination[$imageIndex];
|
230 |
+
@copy($fileSource, $fileDestination);
|
231 |
+
}
|
232 |
+
}
|
233 |
+
} else {
|
234 |
+
return sprintf("Backup folder exists but is not writable");
|
235 |
+
}
|
236 |
+
|
237 |
+
}//end backup section
|
238 |
|
239 |
$counter = 0;
|
240 |
$meta = wp_get_attachment_metadata($ID);//we'll need the metadata for subdir
|
wp-shortpixel.php
CHANGED
@@ -3,21 +3,25 @@
|
|
3 |
* Plugin Name: ShortPixel Image Optimiser
|
4 |
* Plugin URI: https://shortpixel.com/
|
5 |
* Description: ShortPixel is an image compression tool that helps improve your website performance. The plugin optimises images automatically using both lossy and lossless compression. Resulting, smaller, images are no different in quality from the original. To install: 1) Click the "Activate" link to the left of this description. 2) <a href="https://shortpixel.com/wp-apikey" target="_blank">Free Sign up</a> for your unique API Key . 3) Check your email for your API key. 4) Use your API key to activate ShortPixel plugin in the 'Plugins' menu in WordPress. 5) Done!
|
6 |
-
* Version: 2.0.
|
7 |
* Author: ShortPixel
|
8 |
* Author URI: https://shortpixel.com
|
9 |
*/
|
10 |
|
11 |
require_once('shortpixel_api.php');
|
12 |
require_once( ABSPATH . 'wp-admin/includes/image.php' );
|
|
|
13 |
|
|
|
14 |
define('SP_DEBUG', false);
|
15 |
define('SP_LOG', false);
|
16 |
define('SP_MAX_TIMEOUT', 10);
|
17 |
define('SP_BACKUP_FOLDER', WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . 'ShortpixelBackups');
|
18 |
define('MUST_HAVE_KEY', true);
|
19 |
define('BATCH_SIZE', 1);
|
20 |
-
|
|
|
|
|
21 |
|
22 |
class WPShortPixel {
|
23 |
|
@@ -30,6 +34,7 @@ class WPShortPixel {
|
|
30 |
|
31 |
public function __construct() {
|
32 |
$this->populateOptions();
|
|
|
33 |
|
34 |
$this->_apiInterface = new shortpixel_api($this->_apiKey, $this->_compressionType);
|
35 |
|
@@ -58,6 +63,7 @@ class WPShortPixel {
|
|
58 |
$this->migrateBackupFolder();
|
59 |
}
|
60 |
|
|
|
61 |
public function populateOptions() {
|
62 |
|
63 |
if(get_option('wp-short-pixel-apiKey') !== false) {
|
@@ -100,6 +106,24 @@ class WPShortPixel {
|
|
100 |
add_option( 'wp-short-pixel-averageCompression', 0, '', 'yes' );
|
101 |
}
|
102 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
|
104 |
static function log($message) {
|
105 |
if(SP_DEBUG) {
|
@@ -144,27 +168,40 @@ class WPShortPixel {
|
|
144 |
}
|
145 |
|
146 |
public function handleImageUpload($meta, $ID = null) {
|
147 |
-
if(MUST_HAVE_KEY && $this->_verifiedKey)
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
$
|
153 |
-
$filePath[] = $path;
|
154 |
-
|
155 |
-
//send request for thumbs as well, if needed
|
156 |
-
if( !empty($meta['sizes']) )
|
157 |
{
|
158 |
-
|
159 |
-
|
160 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
}
|
162 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
163 |
}
|
164 |
-
} else {
|
165 |
-
$meta['ShortPixelImprovement'] = 'File is not an image';
|
166 |
-
return $meta;
|
167 |
-
}
|
168 |
} else {
|
169 |
|
170 |
}
|
@@ -197,7 +234,7 @@ class WPShortPixel {
|
|
197 |
$ID = $post->post_id;
|
198 |
$imageURL = wp_get_attachment_url($ID);
|
199 |
$imagePath = get_attached_file($ID);
|
200 |
-
$meta = wp_get_attachment_metadata($ID);
|
201 |
|
202 |
if ( !isset($meta['file']) )//this could be a PDF file
|
203 |
{
|
@@ -233,11 +270,13 @@ class WPShortPixel {
|
|
233 |
wp_update_attachment_metadata($ID, $meta);
|
234 |
die;
|
235 |
}
|
236 |
-
|
237 |
-
//figure out the base URL
|
|
|
238 |
$uploadDir = wp_upload_dir();
|
239 |
-
$
|
240 |
-
$
|
|
|
241 |
//create the images' URL list
|
242 |
$imageURLs[$imageIndex] = $filesURL . basename($meta['file']);//main image first
|
243 |
$imagePaths[$imageIndex] = $filesPath . basename($meta['file']);
|
@@ -367,12 +406,26 @@ class WPShortPixel {
|
|
367 |
$meta = wp_get_attachment_metadata($ID);
|
368 |
if(self::isProcesable($uploadFilePath) != false) {
|
369 |
try {
|
370 |
-
|
371 |
-
|
372 |
-
//
|
373 |
-
|
374 |
-
|
375 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
376 |
}
|
377 |
}
|
378 |
} catch(Exception $e) {
|
@@ -405,10 +458,10 @@ class WPShortPixel {
|
|
405 |
}
|
406 |
|
407 |
function registerAdminPage( ) {
|
408 |
-
add_media_page( 'ShortPixel Bulk Process', 'Bulk ShortPixel', 'edit_others_posts', 'wp-short-pixel-bulk', array( &$this, '
|
409 |
}
|
410 |
|
411 |
-
public function
|
412 |
echo '<h1>Bulk Image Optimisation by ShortPixel</h1>';
|
413 |
|
414 |
if(MUST_HAVE_KEY && $this->_verifiedKey == false) {//invalid API Key
|
@@ -439,8 +492,8 @@ class WPShortPixel {
|
|
439 |
$attachments = array_merge($attachments_images, $attachments_pdf);
|
440 |
|
441 |
|
442 |
-
if($_POST["bulkProcess"])
|
443 |
-
|
444 |
$uploadDir = wp_upload_dir();
|
445 |
$uploadDir = $uploadDir['basedir'];
|
446 |
|
@@ -472,7 +525,7 @@ class WPShortPixel {
|
|
472 |
$imageDiskPath[] = $imageOnDisk;
|
473 |
}
|
474 |
}
|
475 |
-
}
|
476 |
|
477 |
$meta['ShortPixel']['BulkProcessing'] = true;
|
478 |
wp_update_attachment_metadata($attachment->ID, $meta);
|
@@ -496,11 +549,10 @@ class WPShortPixel {
|
|
496 |
} else {
|
497 |
// $this->_apiInterface->doBulkRequest($imageList);
|
498 |
}
|
499 |
-
echo "again<BR>";
|
500 |
|
501 |
|
502 |
update_option('bulkProcessingStatus', 'running');
|
503 |
-
}//end bulk process
|
504 |
|
505 |
global $wpdb;
|
506 |
$qry = "SELECT * FROM " . $wpdb->prefix . "postmeta
|
3 |
* Plugin Name: ShortPixel Image Optimiser
|
4 |
* Plugin URI: https://shortpixel.com/
|
5 |
* Description: ShortPixel is an image compression tool that helps improve your website performance. The plugin optimises images automatically using both lossy and lossless compression. Resulting, smaller, images are no different in quality from the original. To install: 1) Click the "Activate" link to the left of this description. 2) <a href="https://shortpixel.com/wp-apikey" target="_blank">Free Sign up</a> for your unique API Key . 3) Check your email for your API key. 4) Use your API key to activate ShortPixel plugin in the 'Plugins' menu in WordPress. 5) Done!
|
6 |
+
* Version: 2.0.7
|
7 |
* Author: ShortPixel
|
8 |
* Author URI: https://shortpixel.com
|
9 |
*/
|
10 |
|
11 |
require_once('shortpixel_api.php');
|
12 |
require_once( ABSPATH . 'wp-admin/includes/image.php' );
|
13 |
+
require_once( ABSPATH . 'wp-includes/pluggable.php' );
|
14 |
|
15 |
+
define('PLUGIN_VERSION', "2.0.7");
|
16 |
define('SP_DEBUG', false);
|
17 |
define('SP_LOG', false);
|
18 |
define('SP_MAX_TIMEOUT', 10);
|
19 |
define('SP_BACKUP_FOLDER', WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . 'ShortpixelBackups');
|
20 |
define('MUST_HAVE_KEY', true);
|
21 |
define('BATCH_SIZE', 1);
|
22 |
+
$MAX_EXECUTION_TIME = ini_get('max_execution_time');
|
23 |
+
if ( is_numeric($MAX_EXECUTION_TIME) )
|
24 |
+
define('MAX_EXECUTION_TIME', $MAX_EXECUTION_TIME - 1 ); //in seconds
|
25 |
|
26 |
class WPShortPixel {
|
27 |
|
34 |
|
35 |
public function __construct() {
|
36 |
$this->populateOptions();
|
37 |
+
$this->setDefaultViewModeList();//set default mode as list. only @ first run
|
38 |
|
39 |
$this->_apiInterface = new shortpixel_api($this->_apiKey, $this->_compressionType);
|
40 |
|
63 |
$this->migrateBackupFolder();
|
64 |
}
|
65 |
|
66 |
+
|
67 |
public function populateOptions() {
|
68 |
|
69 |
if(get_option('wp-short-pixel-apiKey') !== false) {
|
106 |
add_option( 'wp-short-pixel-averageCompression', 0, '', 'yes' );
|
107 |
}
|
108 |
}
|
109 |
+
|
110 |
+
public function setDefaultViewModeList()
|
111 |
+
{
|
112 |
+
if(get_option('wp-short-pixel-view-mode') === false)
|
113 |
+
{
|
114 |
+
add_option('wp-short-pixel-view-mode', 1, '', 'yes' );
|
115 |
+
if ( function_exists(get_currentuserinfo) )
|
116 |
+
{
|
117 |
+
global $current_user;
|
118 |
+
get_currentuserinfo();
|
119 |
+
$currentUserID = $current_user->ID;
|
120 |
+
update_user_meta($currentUserID, "wp_media_library_mode", "list");
|
121 |
+
echo "OK";
|
122 |
+
}
|
123 |
+
}
|
124 |
+
|
125 |
+
}
|
126 |
+
|
127 |
|
128 |
static function log($message) {
|
129 |
if(SP_DEBUG) {
|
168 |
}
|
169 |
|
170 |
public function handleImageUpload($meta, $ID = null) {
|
171 |
+
if(MUST_HAVE_KEY && $this->_verifiedKey)
|
172 |
+
{
|
173 |
+
self::log("Processing image id {$ID}");
|
174 |
+
$url = wp_get_attachment_url($ID);
|
175 |
+
$path = get_attached_file($ID);
|
176 |
+
if(self::isProcesable($path) != false)
|
|
|
|
|
|
|
|
|
177 |
{
|
178 |
+
$urlList[] = $url;
|
179 |
+
$filePath[] = $path;
|
180 |
+
//send request for thumbs as well, if needed
|
181 |
+
if( !empty($meta['sizes']) )
|
182 |
+
{
|
183 |
+
foreach($meta['sizes'] as $thumbnailInfo)
|
184 |
+
{
|
185 |
+
$urlList[] = str_replace(basename($url), $thumbnailInfo['file'], $url);
|
186 |
+
$filePath[] = str_replace(basename($path), $thumbnailInfo['file'], $path);
|
187 |
+
}
|
188 |
+
$this->_apiInterface->doRequests($urlList, $filePath);//send a processing request right after a file was uploaded
|
189 |
}
|
190 |
+
else//file is PDF maybe?
|
191 |
+
{
|
192 |
+
$uploadFilePath = get_attached_file($ID);
|
193 |
+
if ( strtolower(substr($uploadFilePath,strrpos($uploadFilePath, ".")+1)) == "pdf" ) //is a PDF file
|
194 |
+
{
|
195 |
+
$filePath[0] = $uploadFilePath;
|
196 |
+
$this->_apiInterface->doRequests($urlList, $filePath);//send a processing request right after a file was uploaded
|
197 |
+
}
|
198 |
+
}
|
199 |
+
}
|
200 |
+
else
|
201 |
+
{
|
202 |
+
$meta['ShortPixelImprovement'] = 'File is not an image';
|
203 |
+
return $meta;
|
204 |
}
|
|
|
|
|
|
|
|
|
205 |
} else {
|
206 |
|
207 |
}
|
234 |
$ID = $post->post_id;
|
235 |
$imageURL = wp_get_attachment_url($ID);
|
236 |
$imagePath = get_attached_file($ID);
|
237 |
+
$meta = wp_get_attachment_metadata($ID);
|
238 |
|
239 |
if ( !isset($meta['file']) )//this could be a PDF file
|
240 |
{
|
270 |
wp_update_attachment_metadata($ID, $meta);
|
271 |
die;
|
272 |
}
|
273 |
+
|
274 |
+
//figure out the base URL
|
275 |
+
$SubDir = substr($meta['file'],0,strrpos($meta['file'],"/")+1);
|
276 |
$uploadDir = wp_upload_dir();
|
277 |
+
$filesPath = $uploadDir['basedir'] . DIRECTORY_SEPARATOR . $SubDir;//base upload path
|
278 |
+
$filesURL = $uploadDir['baseurl'] . DIRECTORY_SEPARATOR . $SubDir;//base upload url
|
279 |
+
|
280 |
//create the images' URL list
|
281 |
$imageURLs[$imageIndex] = $filesURL . basename($meta['file']);//main image first
|
282 |
$imagePaths[$imageIndex] = $filesPath . basename($meta['file']);
|
406 |
$meta = wp_get_attachment_metadata($ID);
|
407 |
if(self::isProcesable($uploadFilePath) != false) {
|
408 |
try {
|
409 |
+
$uploadDir = wp_upload_dir();
|
410 |
+
$SubDir = substr($meta['file'],0,strrpos($meta['file'],"/")+1);
|
411 |
+
if ( empty($SubDir) ) //its a PDF?
|
412 |
+
{
|
413 |
+
$uploadFilePath = get_attached_file($ID);
|
414 |
+
$tmp = str_replace($uploadDir['basedir'],"", $uploadFilePath);
|
415 |
+
$SubDir = trim(substr($tmp,0,strrpos($tmp,"/")));
|
416 |
+
@unlink(SP_BACKUP_FOLDER . $SubDir . DIRECTORY_SEPARATOR . basename($uploadFilePath));
|
417 |
+
}
|
418 |
+
else
|
419 |
+
{//remove images
|
420 |
+
$filesPath = SP_BACKUP_FOLDER . DIRECTORY_SEPARATOR . $SubDir;//base BACKUP path
|
421 |
+
//remove main imgage/file
|
422 |
+
@unlink($filesPath . basename($meta['file']));
|
423 |
+
|
424 |
+
//remove thumbs thumbnails
|
425 |
+
if(isset($meta["sizes"])) {
|
426 |
+
foreach($meta["sizes"] as $size => $imageData) {
|
427 |
+
@unlink($filesPath . basename($imageData['file']));//remove thumbs
|
428 |
+
}
|
429 |
}
|
430 |
}
|
431 |
} catch(Exception $e) {
|
458 |
}
|
459 |
|
460 |
function registerAdminPage( ) {
|
461 |
+
add_media_page( 'ShortPixel Bulk Process', 'Bulk ShortPixel', 'edit_others_posts', 'wp-short-pixel-bulk', array( &$this, 'bulkProcess' ) );
|
462 |
}
|
463 |
|
464 |
+
public function bulkProcess() {
|
465 |
echo '<h1>Bulk Image Optimisation by ShortPixel</h1>';
|
466 |
|
467 |
if(MUST_HAVE_KEY && $this->_verifiedKey == false) {//invalid API Key
|
492 |
$attachments = array_merge($attachments_images, $attachments_pdf);
|
493 |
|
494 |
|
495 |
+
if($_POST["bulkProcess"])
|
496 |
+
{
|
497 |
$uploadDir = wp_upload_dir();
|
498 |
$uploadDir = $uploadDir['basedir'];
|
499 |
|
525 |
$imageDiskPath[] = $imageOnDisk;
|
526 |
}
|
527 |
}
|
528 |
+
}
|
529 |
|
530 |
$meta['ShortPixel']['BulkProcessing'] = true;
|
531 |
wp_update_attachment_metadata($attachment->ID, $meta);
|
549 |
} else {
|
550 |
// $this->_apiInterface->doBulkRequest($imageList);
|
551 |
}
|
|
|
552 |
|
553 |
|
554 |
update_option('bulkProcessingStatus', 'running');
|
555 |
+
}//end bulk process was clicked
|
556 |
|
557 |
global $wpdb;
|
558 |
$qry = "SELECT * FROM " . $wpdb->prefix . "postmeta
|