Version Description
- replace back the PNG links when restoring a PNG converted to JPG
- fix incompatibility with Dynamics 365 Integration plugin
- improve restore capabilities after certain types of PNG to JPG errors which left the media item in an unconsistent state.
- remove AUTH credentials on server too, if removed in plugin's settings.
- more performance improvements to PNG 2 JPG conversion
- fix replacing PNG urls having http:// instead of https:// for a SSL site. (and viceversa)
- fix string not appearing in translations
Download this release
Release Info
| Developer | ShortPixel |
| Plugin | |
| Version | 4.10.4 |
| Comparing to | |
| See all releases | |
Code changes from version 4.10.3 to 4.10.4
- class/db/shortpixel-meta-facade.php +2 -2
- class/shortpixel-png2jpg.php +24 -14
- class/view/shortpixel_view.php +4 -1
- class/wp-short-pixel.php +88 -55
- readme.txt +10 -1
- wp-shortpixel.php +23 -23
class/db/shortpixel-meta-facade.php
CHANGED
|
@@ -330,7 +330,7 @@ class ShortPixelMetaFacade {
|
|
| 330 |
|
| 331 |
if($this->type == self::CUSTOM_TYPE) {
|
| 332 |
$meta = $this->getMeta();
|
| 333 |
-
|
| 334 |
//fix for situations where site_url is lala.com/en and home_url is lala.com - if using the site_url will get a duplicated /en in the URL
|
| 335 |
$homeUrl = self::getHomeUrl();
|
| 336 |
$urlList[] = self::replaceHomePath($meta->getPath(), $homeUrl);
|
|
@@ -363,7 +363,7 @@ class ShortPixelMetaFacade {
|
|
| 363 |
$TmpCount = count($Tmp);
|
| 364 |
$StichString = $Tmp[$TmpCount-2] . "/" . $Tmp[$TmpCount-1];
|
| 365 |
|
| 366 |
-
$count =
|
| 367 |
foreach( $sizes as $thumbnailName => $thumbnailInfo ) {
|
| 368 |
|
| 369 |
if(!isset($thumbnailInfo['file'])) { //cases when $thumbnailInfo is NULL
|
| 330 |
|
| 331 |
if($this->type == self::CUSTOM_TYPE) {
|
| 332 |
$meta = $this->getMeta();
|
| 333 |
+
|
| 334 |
//fix for situations where site_url is lala.com/en and home_url is lala.com - if using the site_url will get a duplicated /en in the URL
|
| 335 |
$homeUrl = self::getHomeUrl();
|
| 336 |
$urlList[] = self::replaceHomePath($meta->getPath(), $homeUrl);
|
| 363 |
$TmpCount = count($Tmp);
|
| 364 |
$StichString = $Tmp[$TmpCount-2] . "/" . $Tmp[$TmpCount-1];
|
| 365 |
|
| 366 |
+
$count = 1;
|
| 367 |
foreach( $sizes as $thumbnailName => $thumbnailInfo ) {
|
| 368 |
|
| 369 |
if(!isset($thumbnailInfo['file'])) { //cases when $thumbnailInfo is NULL
|
class/shortpixel-png2jpg.php
CHANGED
|
@@ -113,6 +113,7 @@ class ShortPixelPng2Jpg {
|
|
| 113 |
//backup?
|
| 114 |
if($backup) {
|
| 115 |
$imageForBk = trailingslashit(dirname($image)) . ShortPixelAPI::MB_basename($newPath, '.jpg') . '.png';
|
|
|
|
| 116 |
if($image != $imageForBk) {
|
| 117 |
WPShortPixel::log("PNG2JPG doConvert rename $image to $imageForBk");
|
| 118 |
@rename($image, $imageForBk);
|
|
@@ -130,6 +131,7 @@ class ShortPixelPng2Jpg {
|
|
| 130 |
}
|
| 131 |
//unlink($image);
|
| 132 |
$params['file'] = $newPath;
|
|
|
|
| 133 |
$params['original_file'] = $image;
|
| 134 |
$params['url'] = $newUrl;
|
| 135 |
$params['type'] = 'image/jpeg';
|
|
@@ -195,7 +197,7 @@ class ShortPixelPng2Jpg {
|
|
| 195 |
$imagePath = get_attached_file($ID);
|
| 196 |
$basePath = trailingslashit(str_replace($image, "", $imagePath));
|
| 197 |
$imageUrl = wp_get_attachment_url($ID);
|
| 198 |
-
$baseUrl = trailingslashit(str_replace($image, "", $imageUrl));
|
| 199 |
|
| 200 |
// set a temporary error in order to make sure user gets something if the image failed from memory limit.
|
| 201 |
if( isset($meta['ShortPixel']['Retries']) && $meta['ShortPixel']['Retries'] > 3
|
|
@@ -217,7 +219,9 @@ class ShortPixelPng2Jpg {
|
|
| 217 |
return $meta; //cannot convert it
|
| 218 |
}
|
| 219 |
|
|
|
|
| 220 |
$retMain = $this->doConvertPng2Jpg(array('file' => $imagePath, 'url' => false, 'type' => 'image/png'), $this->_settings->backupImages, false, $retC['img']);
|
|
|
|
| 221 |
WPShortPixel::log("PNG2JPG doConvert Main RETURNED " . json_encode($retMain));
|
| 222 |
$ret = $retMain->params;
|
| 223 |
$toUnlink = array();
|
|
@@ -233,11 +237,12 @@ class ShortPixelPng2Jpg {
|
|
| 233 |
$toUnlink[] = $retMain->unlink;
|
| 234 |
//convert to the new URLs the urls in the existing posts.
|
| 235 |
$baseRelPath = trailingslashit(dirname($image));
|
| 236 |
-
$toReplace[$imageUrl] = $baseUrl . $baseRelPath . wp_basename($ret['file']);
|
| 237 |
-
//$this->png2JpgUpdateUrls(array(), $imageUrl, $baseUrl . $baseRelPath . wp_basename($ret['file']));
|
| 238 |
$pngSize = $ret['png_size'];
|
| 239 |
$jpgSize = $ret['jpg_size'];
|
|
|
|
| 240 |
$imagePath = isset($ret['original_file']) ? $ret['original_file'] : $imagePath;
|
|
|
|
| 241 |
|
| 242 |
//conversion succeeded for the main image, update meta and proceed to thumbs. (It could also not succeed if the converted file is not smaller)
|
| 243 |
$meta['file'] = str_replace($basePath, '', $ret['file']);
|
|
@@ -261,18 +266,19 @@ class ShortPixelPng2Jpg {
|
|
| 261 |
$jpgSize += $rett['jpg_size'];
|
| 262 |
WPShortPixel::log("PNG2JPG total PNG size: $pngSize total JPG size: $jpgSize");
|
| 263 |
$originalSizes[$size]['file'] = wp_basename($rett['file'], '.jpg') . '.png';
|
|
|
|
| 264 |
$toReplace[$baseUrl . $baseRelPath . $info['file']] = $baseUrl . $baseRelPath . wp_basename($rett['file']);
|
| 265 |
-
//$this->png2JpgUpdateUrls(array(), $baseUrl . $baseRelPath . $info['file'], $baseUrl . $baseRelPath . wp_basename($rett['file']));
|
| 266 |
wp_update_attachment_metadata($ID, $meta);
|
| 267 |
}
|
| 268 |
}
|
| 269 |
-
|
|
|
|
| 270 |
'backup' => $this->_settings->backupImages,
|
| 271 |
'optimizationPercent' => round(100.0 * (1.00 - $jpgSize / $pngSize)));
|
| 272 |
wp_update_attachment_metadata($ID, $meta);
|
| 273 |
}
|
| 274 |
|
| 275 |
-
|
| 276 |
foreach($toUnlink as $unlink) {
|
| 277 |
if($unlink) {
|
| 278 |
WPShortPixel::log("PNG2JPG unlink $unlink");
|
|
@@ -291,7 +297,7 @@ class ShortPixelPng2Jpg {
|
|
| 291 |
* @param $newurl
|
| 292 |
* @return array
|
| 293 |
*/
|
| 294 |
-
|
| 295 |
global $wpdb;
|
| 296 |
WPShortPixel::log("PNG2JPG update URLS " . json_encode($map));
|
| 297 |
$results = array();
|
|
@@ -316,9 +322,9 @@ class ShortPixelPng2Jpg {
|
|
| 316 |
|
| 317 |
for( $page = 0; $page < $pages; $page++ ) {
|
| 318 |
$start = $page * $page_size;
|
| 319 |
-
$pmquery = "SELECT * FROM $wpdb->postmeta WHERE meta_value <> '' AND
|
| 320 |
$items = $wpdb->get_results( $pmquery );
|
| 321 |
-
foreach( $items as $item ){
|
| 322 |
$value = $item->meta_value;
|
| 323 |
if( trim($value) == '' )
|
| 324 |
continue;
|
|
@@ -326,7 +332,7 @@ class ShortPixelPng2Jpg {
|
|
| 326 |
$edited = (object)array('data' => $value, 'replaced' => false);
|
| 327 |
foreach($map as $oldurl => $newurl) {
|
| 328 |
if (strlen($newurl)) {
|
| 329 |
-
$editedOne =
|
| 330 |
$edited->data = $editedOne->data;
|
| 331 |
$edited->replaced = $edited->replaced || $editedOne->replaced;
|
| 332 |
}
|
|
@@ -352,6 +358,10 @@ class ShortPixelPng2Jpg {
|
|
| 352 |
return $results;
|
| 353 |
}
|
| 354 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 355 |
/**
|
| 356 |
* taken from Velvet Blues Update URLs plugin
|
| 357 |
* @param string $from
|
|
@@ -360,7 +370,7 @@ class ShortPixelPng2Jpg {
|
|
| 360 |
* @param bool|false $serialised
|
| 361 |
* @return array|mixed|string
|
| 362 |
*/
|
| 363 |
-
function png2JpgUnserializeReplace( $from = '', $to = '', $data = '', $serialised = false ) {
|
| 364 |
$replaced = false;
|
| 365 |
try {
|
| 366 |
if ( false !== is_serialized( $data ) ) {
|
|
@@ -370,14 +380,14 @@ class ShortPixelPng2Jpg {
|
|
| 370 |
}
|
| 371 |
|
| 372 |
$unserialized = unserialize( $data );
|
| 373 |
-
$ret =
|
| 374 |
$data = $ret->data;
|
| 375 |
$replaced = $replaced || $ret->replaced;
|
| 376 |
}
|
| 377 |
elseif ( is_array( $data ) ) {
|
| 378 |
$_tmp = array( );
|
| 379 |
foreach ( $data as $key => $value ) {
|
| 380 |
-
$ret =
|
| 381 |
$_tmp[ $key ] = $ret->data;
|
| 382 |
$replaced = $replaced || $ret->replaced;
|
| 383 |
}
|
|
@@ -386,7 +396,7 @@ class ShortPixelPng2Jpg {
|
|
| 386 |
}
|
| 387 |
elseif(is_object( $data )) {
|
| 388 |
foreach(get_object_vars($data) as $key => $value) {
|
| 389 |
-
$ret =
|
| 390 |
$_tmp[ $key ] = $ret->data;
|
| 391 |
$replaced = $replaced || $ret->replaced;
|
| 392 |
}
|
| 113 |
//backup?
|
| 114 |
if($backup) {
|
| 115 |
$imageForBk = trailingslashit(dirname($image)) . ShortPixelAPI::MB_basename($newPath, '.jpg') . '.png';
|
| 116 |
+
WPShortPixel::log("imageForBk should be PNG: $imageForBk");
|
| 117 |
if($image != $imageForBk) {
|
| 118 |
WPShortPixel::log("PNG2JPG doConvert rename $image to $imageForBk");
|
| 119 |
@rename($image, $imageForBk);
|
| 131 |
}
|
| 132 |
//unlink($image);
|
| 133 |
$params['file'] = $newPath;
|
| 134 |
+
WPShortPixel::log("original_file should be PNG: $image");
|
| 135 |
$params['original_file'] = $image;
|
| 136 |
$params['url'] = $newUrl;
|
| 137 |
$params['type'] = 'image/jpeg';
|
| 197 |
$imagePath = get_attached_file($ID);
|
| 198 |
$basePath = trailingslashit(str_replace($image, "", $imagePath));
|
| 199 |
$imageUrl = wp_get_attachment_url($ID);
|
| 200 |
+
$baseUrl = self::removeUrlProtocol(trailingslashit(str_replace($image, "", $imageUrl))); //make the base url protocol agnostic if it's not already
|
| 201 |
|
| 202 |
// set a temporary error in order to make sure user gets something if the image failed from memory limit.
|
| 203 |
if( isset($meta['ShortPixel']['Retries']) && $meta['ShortPixel']['Retries'] > 3
|
| 219 |
return $meta; //cannot convert it
|
| 220 |
}
|
| 221 |
|
| 222 |
+
WPShortPixel::log(" CONVERTING MAIN: $imagePath");
|
| 223 |
$retMain = $this->doConvertPng2Jpg(array('file' => $imagePath, 'url' => false, 'type' => 'image/png'), $this->_settings->backupImages, false, $retC['img']);
|
| 224 |
+
WPShortPixel::log(" CONVERTED MAIN: " . json_encode($retMain));
|
| 225 |
WPShortPixel::log("PNG2JPG doConvert Main RETURNED " . json_encode($retMain));
|
| 226 |
$ret = $retMain->params;
|
| 227 |
$toUnlink = array();
|
| 237 |
$toUnlink[] = $retMain->unlink;
|
| 238 |
//convert to the new URLs the urls in the existing posts.
|
| 239 |
$baseRelPath = trailingslashit(dirname($image));
|
| 240 |
+
$toReplace[self::removeUrlProtocol($imageUrl)] = $baseUrl . $baseRelPath . wp_basename($ret['file']);
|
|
|
|
| 241 |
$pngSize = $ret['png_size'];
|
| 242 |
$jpgSize = $ret['jpg_size'];
|
| 243 |
+
WPShortPixel::log(" IMAGE PATH: $imagePath");
|
| 244 |
$imagePath = isset($ret['original_file']) ? $ret['original_file'] : $imagePath;
|
| 245 |
+
WPShortPixel::log(" SET IMAGE PATH: $imagePath");
|
| 246 |
|
| 247 |
//conversion succeeded for the main image, update meta and proceed to thumbs. (It could also not succeed if the converted file is not smaller)
|
| 248 |
$meta['file'] = str_replace($basePath, '', $ret['file']);
|
| 266 |
$jpgSize += $rett['jpg_size'];
|
| 267 |
WPShortPixel::log("PNG2JPG total PNG size: $pngSize total JPG size: $jpgSize");
|
| 268 |
$originalSizes[$size]['file'] = wp_basename($rett['file'], '.jpg') . '.png';
|
| 269 |
+
WPShortPixel::log("PNG2JPG thumb original: " . $originalSizes[$size]['file']);
|
| 270 |
$toReplace[$baseUrl . $baseRelPath . $info['file']] = $baseUrl . $baseRelPath . wp_basename($rett['file']);
|
|
|
|
| 271 |
wp_update_attachment_metadata($ID, $meta);
|
| 272 |
}
|
| 273 |
}
|
| 274 |
+
WPShortPixel::log("ORIGINAL SIZESSSS: " . json_encode($originalSizes));
|
| 275 |
+
$meta['ShortPixelPng2Jpg'] = array('originalFile' => $imagePath, 'originalSizes' => $originalSizes, 'originalSizes2' => $originalSizes,
|
| 276 |
'backup' => $this->_settings->backupImages,
|
| 277 |
'optimizationPercent' => round(100.0 * (1.00 - $jpgSize / $pngSize)));
|
| 278 |
wp_update_attachment_metadata($ID, $meta);
|
| 279 |
}
|
| 280 |
|
| 281 |
+
self::png2JpgUpdateUrls(array(), $toReplace);
|
| 282 |
foreach($toUnlink as $unlink) {
|
| 283 |
if($unlink) {
|
| 284 |
WPShortPixel::log("PNG2JPG unlink $unlink");
|
| 297 |
* @param $newurl
|
| 298 |
* @return array
|
| 299 |
*/
|
| 300 |
+
public static function png2JpgUpdateUrls($options, $map){
|
| 301 |
global $wpdb;
|
| 302 |
WPShortPixel::log("PNG2JPG update URLS " . json_encode($map));
|
| 303 |
$results = array();
|
| 322 |
|
| 323 |
for( $page = 0; $page < $pages; $page++ ) {
|
| 324 |
$start = $page * $page_size;
|
| 325 |
+
$pmquery = "SELECT * FROM $wpdb->postmeta WHERE meta_value <> '' AND meta_key <> '_wp_attachment_metadata' AND meta_key <> '_wp_attached_file' LIMIT $start, $page_size";
|
| 326 |
$items = $wpdb->get_results( $pmquery );
|
| 327 |
+
foreach( $items as $item ) {
|
| 328 |
$value = $item->meta_value;
|
| 329 |
if( trim($value) == '' )
|
| 330 |
continue;
|
| 332 |
$edited = (object)array('data' => $value, 'replaced' => false);
|
| 333 |
foreach($map as $oldurl => $newurl) {
|
| 334 |
if (strlen($newurl)) {
|
| 335 |
+
$editedOne = self::png2JpgUnserializeReplace($oldurl, $newurl, $edited->data);
|
| 336 |
$edited->data = $editedOne->data;
|
| 337 |
$edited->replaced = $edited->replaced || $editedOne->replaced;
|
| 338 |
}
|
| 358 |
return $results;
|
| 359 |
}
|
| 360 |
|
| 361 |
+
public static function removeUrlProtocol($url) {
|
| 362 |
+
return preg_replace("/^http[s]{0,1}:\/\//", "//", $url);
|
| 363 |
+
}
|
| 364 |
+
|
| 365 |
/**
|
| 366 |
* taken from Velvet Blues Update URLs plugin
|
| 367 |
* @param string $from
|
| 370 |
* @param bool|false $serialised
|
| 371 |
* @return array|mixed|string
|
| 372 |
*/
|
| 373 |
+
static function png2JpgUnserializeReplace( $from = '', $to = '', $data = '', $serialised = false ) {
|
| 374 |
$replaced = false;
|
| 375 |
try {
|
| 376 |
if ( false !== is_serialized( $data ) ) {
|
| 380 |
}
|
| 381 |
|
| 382 |
$unserialized = unserialize( $data );
|
| 383 |
+
$ret = self::png2JpgUnserializeReplace( $from, $to, $unserialized, true );
|
| 384 |
$data = $ret->data;
|
| 385 |
$replaced = $replaced || $ret->replaced;
|
| 386 |
}
|
| 387 |
elseif ( is_array( $data ) ) {
|
| 388 |
$_tmp = array( );
|
| 389 |
foreach ( $data as $key => $value ) {
|
| 390 |
+
$ret = self::png2JpgUnserializeReplace( $from, $to, $value, false );
|
| 391 |
$_tmp[ $key ] = $ret->data;
|
| 392 |
$replaced = $replaced || $ret->replaced;
|
| 393 |
}
|
| 396 |
}
|
| 397 |
elseif(is_object( $data )) {
|
| 398 |
foreach(get_object_vars($data) as $key => $value) {
|
| 399 |
+
$ret = self::png2JpgUnserializeReplace( $from, $to, $value, false );
|
| 400 |
$_tmp[ $key ] = $ret->data;
|
| 401 |
$replaced = $replaced || $ret->replaced;
|
| 402 |
}
|
class/view/shortpixel_view.php
CHANGED
|
@@ -1181,7 +1181,7 @@ class ShortPixelView {
|
|
| 1181 |
_e('name:keepbig, path:/ignore_regex/i, size:1000x2000','shortpixel-image-optimiser');?>">
|
| 1182 |
<?php _e('Exclude certain images from being optimized, based on patterns.','shortpixel-image-optimiser');?>
|
| 1183 |
<p class="settings-info">
|
| 1184 |
-
<?php _e('Add patterns separated by comma. A pattern
|
| 1185 |
<strong>"name"</strong>, <strong>"path"</strong> and <strong>"size"</strong>.
|
| 1186 |
A file will be excluded if it matches any of the patterns.
|
| 1187 |
<br>For a <strong>"name"</strong> pattern only the filename will be matched but for a <strong>"path"</strong>,
|
|
@@ -1191,6 +1191,9 @@ class ShortPixelView {
|
|
| 1191 |
<br>For the <strong>"size"</strong> type,
|
| 1192 |
which applies only to Media Library images, <strong>the main images (not thumbnails)</strong> that have the size in the specified range will be excluded.
|
| 1193 |
The format for the "size" exclude is: <strong>minWidth</strong>-<strong>maxWidth</strong>x<strong>minHeight</strong>-<strong>maxHeight</strong>, for example <strong>size:1000-1100x2000-2200</strong>. You can also specify a precise size, as <strong>1000x2000</strong>.','shortpixel-image-optimiser');?>
|
|
|
|
|
|
|
|
|
|
| 1194 |
</p>
|
| 1195 |
</td>
|
| 1196 |
</tr>
|
| 1181 |
_e('name:keepbig, path:/ignore_regex/i, size:1000x2000','shortpixel-image-optimiser');?>">
|
| 1182 |
<?php _e('Exclude certain images from being optimized, based on patterns.','shortpixel-image-optimiser');?>
|
| 1183 |
<p class="settings-info">
|
| 1184 |
+
<?php _e('Add patterns separated by comma. A pattern consist of a <strong>type:value</strong> pair; the accepted types are
|
| 1185 |
<strong>"name"</strong>, <strong>"path"</strong> and <strong>"size"</strong>.
|
| 1186 |
A file will be excluded if it matches any of the patterns.
|
| 1187 |
<br>For a <strong>"name"</strong> pattern only the filename will be matched but for a <strong>"path"</strong>,
|
| 1191 |
<br>For the <strong>"size"</strong> type,
|
| 1192 |
which applies only to Media Library images, <strong>the main images (not thumbnails)</strong> that have the size in the specified range will be excluded.
|
| 1193 |
The format for the "size" exclude is: <strong>minWidth</strong>-<strong>maxWidth</strong>x<strong>minHeight</strong>-<strong>maxHeight</strong>, for example <strong>size:1000-1100x2000-2200</strong>. You can also specify a precise size, as <strong>1000x2000</strong>.','shortpixel-image-optimiser');?>
|
| 1194 |
+
<a href="http://blog.shortpixel.com/shortpixel-how-to-exclude-images-and-folders-from-optimization/" target="_blank" class="shortpixel-help-link">
|
| 1195 |
+
<span class="dashicons dashicons-editor-help"></span><?php _e('More info','shortpixel-image-optimiser');?>
|
| 1196 |
+
</a>
|
| 1197 |
</p>
|
| 1198 |
</td>
|
| 1199 |
</tr>
|
class/wp-short-pixel.php
CHANGED
|
@@ -1409,23 +1409,36 @@ class WPShortPixel {
|
|
| 1409 |
}
|
| 1410 |
|
| 1411 |
//TODO specific to Media Lib., move accordingly
|
| 1412 |
-
protected function doRestore($attachmentID, $
|
| 1413 |
$file = $origFile = get_attached_file($attachmentID);
|
| 1414 |
-
|
| 1415 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1416 |
}
|
|
|
|
|
|
|
| 1417 |
$pathInfo = pathinfo($file);
|
| 1418 |
-
$sizes = isset($
|
| 1419 |
|
| 1420 |
//check if the images were converted from PNG
|
| 1421 |
-
$png2jpgMain = isset($
|
| 1422 |
-
$jpgFile = false; $jpgSizes = array();
|
| 1423 |
-
$png2jpgSizes = $png2jpgMain ? $meta['ShortPixelPng2Jpg']['originalSizes'] : array();
|
| 1424 |
$bkFolder = $this->getBackupFolderAny($file, $sizes);
|
| 1425 |
-
|
| 1426 |
-
|
| 1427 |
-
$
|
| 1428 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1429 |
$sizes = $png2jpgSizes;
|
| 1430 |
}
|
| 1431 |
$bkFile = trailingslashit($bkFolder) . ShortPixelAPI::MB_basename($file);
|
|
@@ -1433,44 +1446,43 @@ class WPShortPixel {
|
|
| 1433 |
//first check if the file is readable by the current user - otherwise it will be unaccessible for the web browser
|
| 1434 |
// - collect the thumbs paths in the process
|
| 1435 |
$bkCount = 0;
|
| 1436 |
-
if(isset($
|
| 1437 |
$lastStatus = $this->_settings->bulkLastStatus;
|
| 1438 |
-
if($lastStatus['ImageID'] == $attachmentID) {
|
| 1439 |
$this->_settings->bulkLastStatus = null;
|
| 1440 |
}
|
| 1441 |
-
}
|
| 1442 |
-
|
| 1443 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1444 |
$this->throwNotice('generic-err',
|
| 1445 |
sprintf(__("File %s cannot be restored due to lack of permissions, please contact your hosting provider to assist you in fixing this.",'shortpixel-image-optimiser'),
|
| 1446 |
-
|
| 1447 |
return false;
|
| 1448 |
}
|
| 1449 |
$bkCount++;
|
| 1450 |
-
$
|
| 1451 |
-
}
|
| 1452 |
-
$thumbsPaths = array();
|
| 1453 |
-
if($bkFolder && !empty($meta['file']) && count($sizes) ) {
|
| 1454 |
-
foreach($sizes as $size => $imageData) {
|
| 1455 |
-
$dest = $pathInfo['dirname'] . '/' . $imageData['file'];
|
| 1456 |
-
$source = trailingslashit($bkFolder) . $imageData['file'];
|
| 1457 |
-
if(!file_exists($source)) continue; // if thumbs were not optimized, then the backups will not be there.
|
| 1458 |
-
if(!$this->setFilePerms($source) || (file_exists($dest) && !$this->setFilePerms($dest))) {
|
| 1459 |
-
$failedFile = ($this->setFilePerms($bkFile) ? $file : $bkFile);
|
| 1460 |
-
$this->throwNotice('generic-err',
|
| 1461 |
-
sprintf(__("File %s cannot be restored due to lack of permissions, please contact your hosting provider to assist you in fixing this.",'shortpixel-image-optimiser'),
|
| 1462 |
-
"$failedFile (current permissions: " . sprintf("%o", fileperms($failedFile)) . ")"));
|
| 1463 |
-
return false;
|
| 1464 |
-
}
|
| 1465 |
-
$bkCount++;
|
| 1466 |
-
$thumbsPaths[$source] = $dest;
|
| 1467 |
-
}
|
| 1468 |
-
}
|
| 1469 |
-
if(!$bkCount) {
|
| 1470 |
-
$this->throwNotice('generic-err', __("No backup files found. Restore not performed.",'shortpixel-image-optimiser'));
|
| 1471 |
-
return false;
|
| 1472 |
}
|
| 1473 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1474 |
//either backups exist, or it was error so it's normal no backup is present
|
| 1475 |
try {
|
| 1476 |
$width = false;
|
|
@@ -1494,7 +1506,7 @@ class WPShortPixel {
|
|
| 1494 |
|
| 1495 |
$duplicates = ShortPixelMetaFacade::getWPMLDuplicates($attachmentID);
|
| 1496 |
foreach($duplicates as $ID) {
|
| 1497 |
-
$crtMeta = $attachmentID == $ID ? $
|
| 1498 |
if( isset($crtMeta["ShortPixelImprovement"]) && is_numeric($crtMeta["ShortPixelImprovement"])
|
| 1499 |
&& 0 + $crtMeta["ShortPixelImprovement"] < 5 && $this->_settings->under5Percent > 0) {
|
| 1500 |
$this->_settings->under5Percent = $this->_settings->under5Percent - 1; // - (isset($crtMeta["ShortPixel"]["thumbsOpt"]) ? $crtMeta["ShortPixel"]["thumbsOpt"] : 0);
|
|
@@ -1520,15 +1532,29 @@ class WPShortPixel {
|
|
| 1520 |
}
|
| 1521 |
wp_update_attachment_metadata($ID, $crtMeta);
|
| 1522 |
}
|
| 1523 |
-
unset($
|
| 1524 |
-
unset($
|
| 1525 |
-
unset($
|
| 1526 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1527 |
} catch(Exception $e) {
|
| 1528 |
$this->throwNotice('generic-err', $e->getMessage());
|
| 1529 |
return false;
|
| 1530 |
}
|
| 1531 |
-
return $
|
| 1532 |
}
|
| 1533 |
|
| 1534 |
/**
|
|
@@ -1552,11 +1578,15 @@ class WPShortPixel {
|
|
| 1552 |
|
| 1553 |
protected function renameWithRetina($bkFile, $file) {
|
| 1554 |
@rename($bkFile, $file);
|
| 1555 |
-
$
|
| 1556 |
-
@rename(substr($bkFile, 0, strlen($bkFile) - 1 - strlen($ext)) . "@2x." . $ext, substr($file, 0, strlen($file) - 1 - strlen($ext)) . "@2x." . $ext);
|
| 1557 |
|
| 1558 |
}
|
| 1559 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1560 |
public function doCustomRestore($ID) {
|
| 1561 |
$meta = $this->spMetaDao->getMeta($ID);
|
| 1562 |
if(!$meta || $meta->getStatus() != 2) return false;
|
|
@@ -1915,7 +1945,7 @@ class WPShortPixel {
|
|
| 1915 |
$qry_left = "SELECT count(*) FilesLeftToBeProcessed FROM " . $wpdb->prefix . "postmeta
|
| 1916 |
WHERE meta_key = '_wp_attached_file' AND post_id <= " . (0 + $this->prioQ->getStartBulkId());
|
| 1917 |
$filesLeft = $wpdb->get_results($qry_left);
|
| 1918 |
-
|
| 1919 |
//check the custom bulk
|
| 1920 |
$pendingMeta = $this->_settings->hasCustomFolders ? $this->spMetaDao->getPendingMetaCount() : 0;
|
| 1921 |
|
|
@@ -2286,6 +2316,12 @@ class WPShortPixel {
|
|
| 2286 |
}
|
| 2287 |
else
|
| 2288 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2289 |
$validityData = $this->getQuotaInformation($_POST['key'], true, isset($_POST['validate']) && $_POST['validate'] == "validate");
|
| 2290 |
|
| 2291 |
$this->_settings->apiKey = $_POST['key'];
|
|
@@ -2335,9 +2371,6 @@ class WPShortPixel {
|
|
| 2335 |
$this->_settings->resizeType = (isset($_POST['resize_type']) ? $_POST['resize_type']: false);
|
| 2336 |
$this->_settings->resizeWidth = (isset($_POST['width']) ? $_POST['width']: $this->_settings->resizeWidth);
|
| 2337 |
$this->_settings->resizeHeight = (isset($_POST['height']) ? $_POST['height']: $this->_settings->resizeHeight);
|
| 2338 |
-
$this->_settings->siteAuthUser = (isset($_POST['siteAuthUser']) ? $_POST['siteAuthUser']: $this->_settings->siteAuthUser);
|
| 2339 |
-
$this->_settings->siteAuthPass = (isset($_POST['siteAuthPass']) ? $_POST['siteAuthPass']: $this->_settings->siteAuthPass);
|
| 2340 |
-
|
| 2341 |
$uploadDir = wp_upload_dir();
|
| 2342 |
$uploadPath = realpath($uploadDir["basedir"]);
|
| 2343 |
|
|
@@ -2518,11 +2551,12 @@ class WPShortPixel {
|
|
| 2518 |
$args['body']['ThumbsCount'] = $imageCount['totalFiles'] - $imageCount['mainFiles'];
|
| 2519 |
$argsStr .= "&DomainCheck={$args['body']['DomainCheck']}&Info={$args['body']['Info']}&ImagesCount={$imageCount['mainFiles']}&ThumbsCount={$args['body']['ThumbsCount']}";
|
| 2520 |
}
|
| 2521 |
-
|
| 2522 |
-
|
| 2523 |
-
|
|
|
|
| 2524 |
$args['body']['pass'] = urlencode($this->_settings->siteAuthPass);
|
| 2525 |
-
$argsStr .= "&
|
| 2526 |
}
|
| 2527 |
|
| 2528 |
$comm = array();
|
|
@@ -2767,7 +2801,6 @@ class WPShortPixel {
|
|
| 2767 |
. ' (<a href="https://shortpixel.com/image-compression-test?site-url=' . urlencode(ShortPixelMetaFacade::safeGetAttachmentUrl($id)) . '" target="_blank">'
|
| 2768 |
. __('Test for free','shortpixel-image-optimiser') . '</a>)';
|
| 2769 |
}
|
| 2770 |
-
|
| 2771 |
$this->view->renderCustomColumn($id, $renderData, $extended);
|
| 2772 |
}
|
| 2773 |
}
|
| 1409 |
}
|
| 1410 |
|
| 1411 |
//TODO specific to Media Lib., move accordingly
|
| 1412 |
+
protected function doRestore($attachmentID, $rawMeta = null) {
|
| 1413 |
$file = $origFile = get_attached_file($attachmentID);
|
| 1414 |
+
|
| 1415 |
+
$itemHandler = new ShortPixelMetaFacade($attachmentID);
|
| 1416 |
+
if($rawMeta) {
|
| 1417 |
+
$itemHandler->setRawMeta($rawMeta); //prevent another database trip
|
| 1418 |
+
} else {
|
| 1419 |
+
$itemHandler->getMeta();
|
| 1420 |
+
$rawMeta = $itemHandler->getRawMeta();
|
| 1421 |
}
|
| 1422 |
+
$toUnlink = $itemHandler->getURLsAndPATHs(true, false, true, array(), true);
|
| 1423 |
+
|
| 1424 |
$pathInfo = pathinfo($file);
|
| 1425 |
+
$sizes = isset($rawMeta["sizes"]) ? $rawMeta["sizes"] : array();
|
| 1426 |
|
| 1427 |
//check if the images were converted from PNG
|
| 1428 |
+
$png2jpgMain = isset($rawMeta['ShortPixelPng2Jpg']['originalFile']) ? $rawMeta['ShortPixelPng2Jpg']['originalFile'] : false;
|
|
|
|
|
|
|
| 1429 |
$bkFolder = $this->getBackupFolderAny($file, $sizes);
|
| 1430 |
+
$toReplace = array();
|
| 1431 |
+
if($png2jpgMain) {
|
| 1432 |
+
$png2jpgSizes = $png2jpgMain ? $rawMeta['ShortPixelPng2Jpg']['originalSizes'] : array();
|
| 1433 |
+
$image = $rawMeta['file'];
|
| 1434 |
+
$imageUrl = wp_get_attachment_url($attachmentID);
|
| 1435 |
+
$baseUrl = ShortPixelPng2Jpg::removeUrlProtocol(trailingslashit(str_replace($image, "", $imageUrl))); //make the base url protocol agnostic if it's not already
|
| 1436 |
+
$baseRelPath = trailingslashit(dirname($image));
|
| 1437 |
+
$toReplace[ShortPixelPng2Jpg::removeUrlProtocol($imageUrl)] = $baseUrl . $baseRelPath . wp_basename($png2jpgMain);
|
| 1438 |
+
foreach($sizes as $key => $size) {
|
| 1439 |
+
$toReplace[$baseUrl . $baseRelPath . $size['file']] = $baseUrl . $baseRelPath . wp_basename($png2jpgSizes[$key]['file']);
|
| 1440 |
+
}
|
| 1441 |
+
$file = $png2jpgMain;
|
| 1442 |
$sizes = $png2jpgSizes;
|
| 1443 |
}
|
| 1444 |
$bkFile = trailingslashit($bkFolder) . ShortPixelAPI::MB_basename($file);
|
| 1446 |
//first check if the file is readable by the current user - otherwise it will be unaccessible for the web browser
|
| 1447 |
// - collect the thumbs paths in the process
|
| 1448 |
$bkCount = 0;
|
| 1449 |
+
if(isset($rawMeta["ShortPixel"]['ErrCode'])) {
|
| 1450 |
$lastStatus = $this->_settings->bulkLastStatus;
|
| 1451 |
+
if(isset($lastStatus['ImageID']) && $lastStatus['ImageID'] == $attachmentID) {
|
| 1452 |
$this->_settings->bulkLastStatus = null;
|
| 1453 |
}
|
| 1454 |
+
}
|
| 1455 |
+
if(file_exists($bkFile)) {
|
| 1456 |
+
if(!is_readable($bkFile) || (file_exists($file) && !$this->setFilePerms($file)) ) {
|
| 1457 |
+
$this->throwNotice('generic-err',
|
| 1458 |
+
sprintf(__("File %s cannot be restored due to lack of permissions, please contact your hosting provider to assist you in fixing this.",'shortpixel-image-optimiser'),
|
| 1459 |
+
(is_readable($bkFile) ? "" : "$bkFile and ") . "$file"));
|
| 1460 |
+
return false;
|
| 1461 |
+
}
|
| 1462 |
+
$bkCount++;
|
| 1463 |
+
$main = true;
|
| 1464 |
+
}
|
| 1465 |
+
$thumbsPaths = array();
|
| 1466 |
+
if($bkFolder && !empty($rawMeta['file']) && count($sizes) ) {
|
| 1467 |
+
foreach($sizes as $size => $imageData) {
|
| 1468 |
+
$dest = $pathInfo['dirname'] . '/' . $imageData['file'];
|
| 1469 |
+
$source = trailingslashit($bkFolder) . $imageData['file'];
|
| 1470 |
+
if(!file_exists($source)) continue; // if thumbs were not optimized, then the backups will not be there.
|
| 1471 |
+
if(!$this->setFilePerms($source) || (file_exists($dest) && !$this->setFilePerms($dest))) {
|
| 1472 |
+
$failedFile = ($this->setFilePerms($bkFile) ? $file : $bkFile);
|
| 1473 |
$this->throwNotice('generic-err',
|
| 1474 |
sprintf(__("File %s cannot be restored due to lack of permissions, please contact your hosting provider to assist you in fixing this.",'shortpixel-image-optimiser'),
|
| 1475 |
+
"$failedFile (current permissions: " . sprintf("%o", fileperms($failedFile)) . ")"));
|
| 1476 |
return false;
|
| 1477 |
}
|
| 1478 |
$bkCount++;
|
| 1479 |
+
$thumbsPaths[$source] = $dest;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1480 |
}
|
| 1481 |
}
|
| 1482 |
+
if(!$bkCount) {
|
| 1483 |
+
$this->throwNotice('generic-err', __("No backup files found. Restore not performed.",'shortpixel-image-optimiser'));
|
| 1484 |
+
return false;
|
| 1485 |
+
}
|
| 1486 |
//either backups exist, or it was error so it's normal no backup is present
|
| 1487 |
try {
|
| 1488 |
$width = false;
|
| 1506 |
|
| 1507 |
$duplicates = ShortPixelMetaFacade::getWPMLDuplicates($attachmentID);
|
| 1508 |
foreach($duplicates as $ID) {
|
| 1509 |
+
$crtMeta = $attachmentID == $ID ? $rawMeta : wp_get_attachment_metadata($ID);
|
| 1510 |
if( isset($crtMeta["ShortPixelImprovement"]) && is_numeric($crtMeta["ShortPixelImprovement"])
|
| 1511 |
&& 0 + $crtMeta["ShortPixelImprovement"] < 5 && $this->_settings->under5Percent > 0) {
|
| 1512 |
$this->_settings->under5Percent = $this->_settings->under5Percent - 1; // - (isset($crtMeta["ShortPixel"]["thumbsOpt"]) ? $crtMeta["ShortPixel"]["thumbsOpt"] : 0);
|
| 1532 |
}
|
| 1533 |
wp_update_attachment_metadata($ID, $crtMeta);
|
| 1534 |
}
|
| 1535 |
+
unset($rawMeta["ShortPixelImprovement"]);
|
| 1536 |
+
unset($rawMeta['ShortPixel']);
|
| 1537 |
+
unset($rawMeta['ShortPixelPng2Jpg']);
|
| 1538 |
|
| 1539 |
+
if($png2jpgMain) {
|
| 1540 |
+
$spPng2Jpg = new ShortPixelPng2Jpg($this->_settings);
|
| 1541 |
+
$spPng2Jpg->png2JpgUpdateUrls(array(), $toReplace);
|
| 1542 |
+
}
|
| 1543 |
+
if(isset($toUnlink['PATHs'])) foreach($toUnlink['PATHs'] as $unlink) {
|
| 1544 |
+
if($png2jpgMain) {
|
| 1545 |
+
WPShortPixel::log("PNG2JPG unlink $unlink");
|
| 1546 |
+
@unlink($unlink);
|
| 1547 |
+
}
|
| 1548 |
+
//try also the .webp
|
| 1549 |
+
$unlinkWebp = trailingslashit(dirname($unlink)) . wp_basename($unlink, '.' . pathinfo($unlink, PATHINFO_EXTENSION)) . '.webp';
|
| 1550 |
+
WPShortPixel::log("PNG2JPG unlink $unlinkWebp");
|
| 1551 |
+
@unlink($unlinkWebp);
|
| 1552 |
+
}
|
| 1553 |
} catch(Exception $e) {
|
| 1554 |
$this->throwNotice('generic-err', $e->getMessage());
|
| 1555 |
return false;
|
| 1556 |
}
|
| 1557 |
+
return $rawMeta;
|
| 1558 |
}
|
| 1559 |
|
| 1560 |
/**
|
| 1578 |
|
| 1579 |
protected function renameWithRetina($bkFile, $file) {
|
| 1580 |
@rename($bkFile, $file);
|
| 1581 |
+
@rename($this->retinaName($bkFile), $this->retinaName($file));
|
|
|
|
| 1582 |
|
| 1583 |
}
|
| 1584 |
|
| 1585 |
+
protected function retinaName($file) {
|
| 1586 |
+
$ext = pathinfo($file, PATHINFO_EXTENSION);
|
| 1587 |
+
return substr($file, 0, strlen($file) - 1 - strlen($ext)) . "@2x." . $ext;
|
| 1588 |
+
}
|
| 1589 |
+
|
| 1590 |
public function doCustomRestore($ID) {
|
| 1591 |
$meta = $this->spMetaDao->getMeta($ID);
|
| 1592 |
if(!$meta || $meta->getStatus() != 2) return false;
|
| 1945 |
$qry_left = "SELECT count(*) FilesLeftToBeProcessed FROM " . $wpdb->prefix . "postmeta
|
| 1946 |
WHERE meta_key = '_wp_attached_file' AND post_id <= " . (0 + $this->prioQ->getStartBulkId());
|
| 1947 |
$filesLeft = $wpdb->get_results($qry_left);
|
| 1948 |
+
|
| 1949 |
//check the custom bulk
|
| 1950 |
$pendingMeta = $this->_settings->hasCustomFolders ? $this->spMetaDao->getPendingMetaCount() : 0;
|
| 1951 |
|
| 2316 |
}
|
| 2317 |
else
|
| 2318 |
{
|
| 2319 |
+
if(isset($_POST['save']) || isset($_POST['saveAdv'])) {
|
| 2320 |
+
//these are needed for the call to api-status, set them first.
|
| 2321 |
+
$this->_settings->siteAuthUser = (isset($_POST['siteAuthUser']) ? $_POST['siteAuthUser'] : $this->_settings->siteAuthUser);
|
| 2322 |
+
$this->_settings->siteAuthPass = (isset($_POST['siteAuthPass']) ? $_POST['siteAuthPass'] : $this->_settings->siteAuthPass);
|
| 2323 |
+
}
|
| 2324 |
+
|
| 2325 |
$validityData = $this->getQuotaInformation($_POST['key'], true, isset($_POST['validate']) && $_POST['validate'] == "validate");
|
| 2326 |
|
| 2327 |
$this->_settings->apiKey = $_POST['key'];
|
| 2371 |
$this->_settings->resizeType = (isset($_POST['resize_type']) ? $_POST['resize_type']: false);
|
| 2372 |
$this->_settings->resizeWidth = (isset($_POST['width']) ? $_POST['width']: $this->_settings->resizeWidth);
|
| 2373 |
$this->_settings->resizeHeight = (isset($_POST['height']) ? $_POST['height']: $this->_settings->resizeHeight);
|
|
|
|
|
|
|
|
|
|
| 2374 |
$uploadDir = wp_upload_dir();
|
| 2375 |
$uploadPath = realpath($uploadDir["basedir"]);
|
| 2376 |
|
| 2551 |
$args['body']['ThumbsCount'] = $imageCount['totalFiles'] - $imageCount['mainFiles'];
|
| 2552 |
$argsStr .= "&DomainCheck={$args['body']['DomainCheck']}&Info={$args['body']['Info']}&ImagesCount={$imageCount['mainFiles']}&ThumbsCount={$args['body']['ThumbsCount']}";
|
| 2553 |
}
|
| 2554 |
+
$args['body']['host'] = parse_url(get_site_url(),PHP_URL_HOST);
|
| 2555 |
+
$argsStr .= "&url={$args['body']['host']}";
|
| 2556 |
+
if(strlen($this->_settings->siteAuthUser)) {
|
| 2557 |
+
$args['body']['user'] = $this->_settings->siteAuthUser;
|
| 2558 |
$args['body']['pass'] = urlencode($this->_settings->siteAuthPass);
|
| 2559 |
+
$argsStr .= "&user={$args['body']['user']}&pass={$args['body']['pass']}";
|
| 2560 |
}
|
| 2561 |
|
| 2562 |
$comm = array();
|
| 2801 |
. ' (<a href="https://shortpixel.com/image-compression-test?site-url=' . urlencode(ShortPixelMetaFacade::safeGetAttachmentUrl($id)) . '" target="_blank">'
|
| 2802 |
. __('Test for free','shortpixel-image-optimiser') . '</a>)';
|
| 2803 |
}
|
|
|
|
| 2804 |
$this->view->renderCustomColumn($id, $renderData, $extended);
|
| 2805 |
}
|
| 2806 |
}
|
readme.txt
CHANGED
|
@@ -4,7 +4,7 @@ Tags: compress, image, compression, optimize, image optimizer, image optimiser,
|
|
| 4 |
Requires at least: 3.2.0
|
| 5 |
Tested up to: 4.9
|
| 6 |
Requires PHP: 5.2
|
| 7 |
-
Stable tag: 4.10.
|
| 8 |
License: GPLv2 or later
|
| 9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
| 10 |
|
|
@@ -228,6 +228,15 @@ The ShortPixel team is here to help. <a href="https://shortpixel.com/contact">Co
|
|
| 228 |
|
| 229 |
== Changelog ==
|
| 230 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
= 4.10.3 =
|
| 232 |
* improvements to context help beacon
|
| 233 |
* performance improvements to PNG to JPG conversion
|
| 4 |
Requires at least: 3.2.0
|
| 5 |
Tested up to: 4.9
|
| 6 |
Requires PHP: 5.2
|
| 7 |
+
Stable tag: 4.10.4
|
| 8 |
License: GPLv2 or later
|
| 9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
| 10 |
|
| 228 |
|
| 229 |
== Changelog ==
|
| 230 |
|
| 231 |
+
= 4.10.4 =
|
| 232 |
+
* replace back the PNG links when restoring a PNG converted to JPG
|
| 233 |
+
* fix incompatibility with Dynamics 365 Integration plugin
|
| 234 |
+
* improve restore capabilities after certain types of PNG to JPG errors which left the media item in an unconsistent state.
|
| 235 |
+
* remove AUTH credentials on server too, if removed in plugin's settings.
|
| 236 |
+
* more performance improvements to PNG 2 JPG conversion
|
| 237 |
+
* fix replacing PNG urls having http:// instead of https:// for a SSL site. (and viceversa)
|
| 238 |
+
* fix string not appearing in translations
|
| 239 |
+
|
| 240 |
= 4.10.3 =
|
| 241 |
* improvements to context help beacon
|
| 242 |
* performance improvements to PNG to JPG conversion
|
wp-shortpixel.php
CHANGED
|
@@ -3,7 +3,7 @@
|
|
| 3 |
* Plugin Name: ShortPixel Image Optimizer
|
| 4 |
* Plugin URI: https://shortpixel.com/
|
| 5 |
* Description: ShortPixel optimizes images automatically, while guarding the quality of your images. Check your <a href="options-general.php?page=wp-shortpixel" target="_blank">Settings > ShortPixel</a> page on how to start optimizing your image library and make your website load faster.
|
| 6 |
-
* Version: 4.10.
|
| 7 |
* Author: ShortPixel
|
| 8 |
* Author URI: https://shortpixel.com
|
| 9 |
* Text Domain: shortpixel-image-optimiser
|
|
@@ -18,7 +18,7 @@ define('SHORTPIXEL_PLUGIN_FILE', __FILE__);
|
|
| 18 |
|
| 19 |
//define('SHORTPIXEL_AFFILIATE_CODE', '');
|
| 20 |
|
| 21 |
-
define('SHORTPIXEL_IMAGE_OPTIMISER_VERSION', "4.10.
|
| 22 |
define('SHORTPIXEL_MAX_TIMEOUT', 10);
|
| 23 |
define('SHORTPIXEL_VALIDATE_MAX_TIMEOUT', 15);
|
| 24 |
define('SHORTPIXEL_BACKUP', 'ShortpixelBackups');
|
|
@@ -54,19 +54,19 @@ define('SHORTPIXEL_MAX_EXECUTION_TIME2', 2 );
|
|
| 54 |
define("SHORTPIXEL_MAX_RESULTS_QUERY", 30);
|
| 55 |
|
| 56 |
function shortpixelInit() {
|
| 57 |
-
global $
|
| 58 |
//limit to certain admin pages if function available
|
| 59 |
$loadOnThisPage = !function_exists('get_current_screen');
|
| 60 |
if(!$loadOnThisPage) {
|
| 61 |
$screen = get_current_screen();
|
| 62 |
-
if(is_object($screen) && in_array($screen->id, array('upload', 'edit', 'edit-tags', 'post-new', 'post'))) {
|
| 63 |
-
|
| 64 |
}
|
| 65 |
}
|
| 66 |
require_once('class/shortpixel_queue.php');
|
| 67 |
$prio = ShortPixelQueue::get();
|
| 68 |
$isAjaxButNotSP = defined( 'DOING_AJAX' ) && DOING_AJAX && !(isset($_REQUEST['action']) && (strpos($_REQUEST['action'], 'shortpixel_') === 0));
|
| 69 |
-
if (!isset($
|
| 70 |
&& ( ($prio && is_array($prio) && count($prio) && get_option('wp-short-pixel-front-bootstrap'))
|
| 71 |
|| is_admin() && !$isAjaxButNotSP
|
| 72 |
&& (function_exists("is_user_logged_in") && is_user_logged_in()) //is admin, is logged in - :) seems funny but it's not, ajax scripts are admin even if no admin is logged in.
|
|
@@ -78,47 +78,47 @@ function shortpixelInit() {
|
|
| 78 |
)
|
| 79 |
{
|
| 80 |
require_once('wp-shortpixel-req.php');
|
| 81 |
-
$
|
| 82 |
}
|
| 83 |
}
|
| 84 |
|
| 85 |
function shortPixelHandleImageUploadHook($meta, $ID = null) {
|
| 86 |
-
global $
|
| 87 |
-
if(!isset($
|
| 88 |
require_once('wp-shortpixel-req.php');
|
| 89 |
-
$
|
| 90 |
}
|
| 91 |
-
return $
|
| 92 |
}
|
| 93 |
|
| 94 |
function shortPixelReplaceHook($params) {
|
| 95 |
if(isset($params['post_id'])) { //integration with EnableMediaReplace - that's an upload for replacing an existing ID
|
| 96 |
-
global $
|
| 97 |
-
if (!isset($
|
| 98 |
require_once('wp-shortpixel-req.php');
|
| 99 |
-
$
|
| 100 |
}
|
| 101 |
-
$itemHandler = $
|
| 102 |
$itemHandler->deleteAllSPMeta();
|
| 103 |
}
|
| 104 |
}
|
| 105 |
|
| 106 |
function shortPixelPng2JpgHook($params) {
|
| 107 |
-
global $
|
| 108 |
-
if(!isset($
|
| 109 |
require_once('wp-shortpixel-req.php');
|
| 110 |
-
$
|
| 111 |
}
|
| 112 |
-
return $
|
| 113 |
}
|
| 114 |
|
| 115 |
function shortPixelNggAdd($image) {
|
| 116 |
-
global $
|
| 117 |
-
if(!isset($
|
| 118 |
require_once('wp-shortpixel-req.php');
|
| 119 |
-
$
|
| 120 |
}
|
| 121 |
-
$
|
| 122 |
}
|
| 123 |
|
| 124 |
function shortPixelActivatePlugin () {
|
| 3 |
* Plugin Name: ShortPixel Image Optimizer
|
| 4 |
* Plugin URI: https://shortpixel.com/
|
| 5 |
* Description: ShortPixel optimizes images automatically, while guarding the quality of your images. Check your <a href="options-general.php?page=wp-shortpixel" target="_blank">Settings > ShortPixel</a> page on how to start optimizing your image library and make your website load faster.
|
| 6 |
+
* Version: 4.10.4
|
| 7 |
* Author: ShortPixel
|
| 8 |
* Author URI: https://shortpixel.com
|
| 9 |
* Text Domain: shortpixel-image-optimiser
|
| 18 |
|
| 19 |
//define('SHORTPIXEL_AFFILIATE_CODE', '');
|
| 20 |
|
| 21 |
+
define('SHORTPIXEL_IMAGE_OPTIMISER_VERSION', "4.10.4");
|
| 22 |
define('SHORTPIXEL_MAX_TIMEOUT', 10);
|
| 23 |
define('SHORTPIXEL_VALIDATE_MAX_TIMEOUT', 15);
|
| 24 |
define('SHORTPIXEL_BACKUP', 'ShortpixelBackups');
|
| 54 |
define("SHORTPIXEL_MAX_RESULTS_QUERY", 30);
|
| 55 |
|
| 56 |
function shortpixelInit() {
|
| 57 |
+
global $shortPixelPluginInstance;
|
| 58 |
//limit to certain admin pages if function available
|
| 59 |
$loadOnThisPage = !function_exists('get_current_screen');
|
| 60 |
if(!$loadOnThisPage) {
|
| 61 |
$screen = get_current_screen();
|
| 62 |
+
if(is_object($screen) && !in_array($screen->id, array('upload', 'edit', 'edit-tags', 'post-new', 'post'))) {
|
| 63 |
+
return;
|
| 64 |
}
|
| 65 |
}
|
| 66 |
require_once('class/shortpixel_queue.php');
|
| 67 |
$prio = ShortPixelQueue::get();
|
| 68 |
$isAjaxButNotSP = defined( 'DOING_AJAX' ) && DOING_AJAX && !(isset($_REQUEST['action']) && (strpos($_REQUEST['action'], 'shortpixel_') === 0));
|
| 69 |
+
if (!isset($shortPixelPluginInstance)
|
| 70 |
&& ( ($prio && is_array($prio) && count($prio) && get_option('wp-short-pixel-front-bootstrap'))
|
| 71 |
|| is_admin() && !$isAjaxButNotSP
|
| 72 |
&& (function_exists("is_user_logged_in") && is_user_logged_in()) //is admin, is logged in - :) seems funny but it's not, ajax scripts are admin even if no admin is logged in.
|
| 78 |
)
|
| 79 |
{
|
| 80 |
require_once('wp-shortpixel-req.php');
|
| 81 |
+
$shortPixelPluginInstance = new WPShortPixel;
|
| 82 |
}
|
| 83 |
}
|
| 84 |
|
| 85 |
function shortPixelHandleImageUploadHook($meta, $ID = null) {
|
| 86 |
+
global $shortPixelPluginInstance;
|
| 87 |
+
if(!isset($shortPixelPluginInstance)) {
|
| 88 |
require_once('wp-shortpixel-req.php');
|
| 89 |
+
$shortPixelPluginInstance = new WPShortPixel;
|
| 90 |
}
|
| 91 |
+
return $shortPixelPluginInstance->handleMediaLibraryImageUpload($meta, $ID);
|
| 92 |
}
|
| 93 |
|
| 94 |
function shortPixelReplaceHook($params) {
|
| 95 |
if(isset($params['post_id'])) { //integration with EnableMediaReplace - that's an upload for replacing an existing ID
|
| 96 |
+
global $shortPixelPluginInstance;
|
| 97 |
+
if (!isset($shortPixelPluginInstance)) {
|
| 98 |
require_once('wp-shortpixel-req.php');
|
| 99 |
+
$shortPixelPluginInstance = new WPShortPixel;
|
| 100 |
}
|
| 101 |
+
$itemHandler = $shortPixelPluginInstance->onDeleteImage($params['post_id']);
|
| 102 |
$itemHandler->deleteAllSPMeta();
|
| 103 |
}
|
| 104 |
}
|
| 105 |
|
| 106 |
function shortPixelPng2JpgHook($params) {
|
| 107 |
+
global $shortPixelPluginInstance;
|
| 108 |
+
if(!isset($shortPixelPluginInstance)) {
|
| 109 |
require_once('wp-shortpixel-req.php');
|
| 110 |
+
$shortPixelPluginInstance = new WPShortPixel;
|
| 111 |
}
|
| 112 |
+
return $shortPixelPluginInstance->convertPng2Jpg($params);
|
| 113 |
}
|
| 114 |
|
| 115 |
function shortPixelNggAdd($image) {
|
| 116 |
+
global $shortPixelPluginInstance;
|
| 117 |
+
if(!isset($shortPixelPluginInstance)) {
|
| 118 |
require_once('wp-shortpixel-req.php');
|
| 119 |
+
$shortPixelPluginInstance = new WPShortPixel;
|
| 120 |
}
|
| 121 |
+
$shortPixelPluginInstance->handleNextGenImageUpload($image);
|
| 122 |
}
|
| 123 |
|
| 124 |
function shortPixelActivatePlugin () {
|
