ShortPixel Image Optimizer - Version 4.22.10

Version Description

Release date June 2nd, 2022 * Fix: updated all add_query_arg and remove_query_arg functions for enhanced security; * Fix: in some cases, the offloading via WP Offload Media wasn't properly done when converting from PNG to JPG; * Fix: PDF files weren't offloaded via WP Offload Media when running out of credits; * Fix: removed the backups folder calculation because it was making the settings page very slow in certain cases; * Fix: removed the consumed credits from the statistics tab, because it wasn't working correctly; * Fix: increased the default image resize options; * Fix: a potential fatal error on PHP 8 was corrected; * Tweak: added a new filter for the requests that are sent to the optimization API, documented above in the Developers section; * Language: 0 new strings added, 0 updated, 0 fuzzed, and 0 obsoleted.

Download this release

Release Info

Developer petredobrescu
Plugin Icon 128x128 ShortPixel Image Optimizer
Version 4.22.10
Comparing to
See all releases

Code changes from version 4.22.9 to 4.22.10

class/Controller/AdminNoticesController.php CHANGED
@@ -694,7 +694,7 @@ class AdminNoticesController extends \ShortPixel\Controller
694
  'key' => $keyModel->getKey(),
695
  'version' => SHORTPIXEL_IMAGE_OPTIMISER_VERSION,
696
  'target' => 3,
697
- ), $url);
698
 
699
 
700
  if ( $notices === false ) {
694
  'key' => $keyModel->getKey(),
695
  'version' => SHORTPIXEL_IMAGE_OPTIMISER_VERSION,
696
  'target' => 3,
697
+ ), $url); // has url
698
 
699
 
700
  if ( $notices === false ) {
class/Controller/SettingsController.php CHANGED
@@ -281,7 +281,7 @@ class SettingsController extends \ShortPixel\Controller
281
  // http not ok, redirect etc. Shouldn't happen.
282
  if (is_null($response) || strpos($response, '200') === false)
283
  {
284
- $error_detail = sprintf(__('The AVIF check could not be completed, because the plugin couldn\'t fetch %s %s %s. %s Please check the security/firewall settings and try again', 'shortpixel-image-optimiser'), '<a href="' . $url . '">', $url, '</a>', '<br>');
285
  }
286
  elseif(is_null($contentType) || strpos($contentType, 'avif') === false)
287
  {
@@ -589,9 +589,9 @@ class SettingsController extends \ShortPixel\Controller
589
  {
590
  if ($redirect == 'self')
591
  {
592
- $url = add_query_arg('part', $this->display_part);
593
- $url = remove_query_arg('noheader', $url);
594
- $url = remove_query_arg('sp-action', $url);
595
  }
596
  elseif($redirect == 'bulk')
597
  {
281
  // http not ok, redirect etc. Shouldn't happen.
282
  if (is_null($response) || strpos($response, '200') === false)
283
  {
284
+ $error_detail = sprintf(__('The AVIF check could not be completed, because the plugin couldn\'t fetch %s %s %s. %s Please check the security/firewall settings and try again', 'shortpixel-image-optimiser'), '<a href="' . esc_url($url) . '">', esc_url($url), '</a>', '<br>');
285
  }
286
  elseif(is_null($contentType) || strpos($contentType, 'avif') === false)
287
  {
589
  {
590
  if ($redirect == 'self')
591
  {
592
+ $url = esc_url_raw(add_query_arg('part', $this->display_part));
593
+ $url = remove_query_arg('noheader', $url); // has url
594
+ $url = remove_query_arg('sp-action', $url); // has url
595
  }
596
  elseif($redirect == 'bulk')
597
  {
class/Controller/View/BulkViewController.php CHANGED
@@ -45,7 +45,7 @@ protected $selected_folders = array();
45
  global $wpdb;
46
 
47
  $qry_left = "SELECT count(meta_id) FilesLeftToBeProcessed FROM " . $wpdb->prefix . "postmeta
48
- WHERE meta_key = '_wp_attached_file' AND post_id <= " . (0 + $prioQ->getStartBulkId());
49
  $filesLeft = $wpdb->get_results($qry_left);
50
 
51
  //check the custom bulk
45
  global $wpdb;
46
 
47
  $qry_left = "SELECT count(meta_id) FilesLeftToBeProcessed FROM " . $wpdb->prefix . "postmeta
48
+ WHERE meta_key = '_wp_attached_file' AND post_id <= " . ((int) $prioQ->getStartBulkId());
49
  $filesLeft = $wpdb->get_results($qry_left);
50
 
51
  //check the custom bulk
class/Controller/View/OtherMediaViewController.php CHANGED
@@ -328,7 +328,7 @@ class OtherMediaViewController extends \ShortPixel\Controller
328
 
329
  // Try with controller URL, if not present, try with upload URL and page param.
330
  $admin_url = admin_url('upload.php');
331
- $url = (is_null($this->url)) ? add_query_arg('page','wp-short-pixel-custom', $admin_url) : $this->url;
332
 
333
  $page_args = array_filter(wp_parse_args($args, $defaults));
334
  return add_query_arg($page_args, $url);
@@ -387,7 +387,7 @@ class OtherMediaViewController extends \ShortPixel\Controller
387
  $total_pages_before = '<span class="paging-input">';
388
  $total_pages_after = '</span></span>';
389
 
390
- $current_url = remove_query_arg( 'paged', $this->getPageURL());
391
 
392
  $output = '<form method="GET" action="'. $current_url . '">'; //'<span class="pagination-links">';
393
  $output .= '<span class="displaying-num">'. sprintf(__('%d Items', 'shortpixel-image-optimiser'), $this->total_items) . '</span>';
@@ -408,7 +408,7 @@ class OtherMediaViewController extends \ShortPixel\Controller
408
  } else {
409
  $page_links[] = sprintf(
410
  "<a class='prev-page button' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
411
- esc_url( add_query_arg( 'paged', max( 1, $current - 1 ), $current_url ) ),
412
  __( 'Previous page' ),
413
  '&lsaquo;'
414
  );
@@ -574,7 +574,7 @@ class OtherMediaViewController extends \ShortPixel\Controller
574
  $class = (isset($action['class'])) ? $action['class'] : '';
575
 
576
 
577
- $link = '<a href="' . $url . '" class="action-' . $action_arg . ' ' . $class . '">' . $text . '</a>';
578
  }
579
 
580
  $actions[$index] = $link;
@@ -700,7 +700,7 @@ class OtherMediaViewController extends \ShortPixel\Controller
700
  {
701
  $sorturl = add_query_arg('order', 'asc', $sorturl);
702
  }
703
- $output = '<a href="' . $sorturl . '"><span>' . $title . '</span><span class="sorting-indicator '. $sorted . '">&nbsp;</span></a>';
704
  }
705
  else
706
  {
328
 
329
  // Try with controller URL, if not present, try with upload URL and page param.
330
  $admin_url = admin_url('upload.php');
331
+ $url = (is_null($this->url)) ? add_query_arg('page','wp-short-pixel-custom', $admin_url) : $this->url; // has url
332
 
333
  $page_args = array_filter(wp_parse_args($args, $defaults));
334
  return add_query_arg($page_args, $url);
387
  $total_pages_before = '<span class="paging-input">';
388
  $total_pages_after = '</span></span>';
389
 
390
+ $current_url = remove_query_arg( 'paged', $this->getPageURL()); // has url
391
 
392
  $output = '<form method="GET" action="'. $current_url . '">'; //'<span class="pagination-links">';
393
  $output .= '<span class="displaying-num">'. sprintf(__('%d Items', 'shortpixel-image-optimiser'), $this->total_items) . '</span>';
408
  } else {
409
  $page_links[] = sprintf(
410
  "<a class='prev-page button' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
411
+ esc_url( add_query_arg( 'paged', max( 1, $current - 1 ), $current_url ) ), // has url
412
  __( 'Previous page' ),
413
  '&lsaquo;'
414
  );
574
  $class = (isset($action['class'])) ? $action['class'] : '';
575
 
576
 
577
+ $link = '<a href="' . esc_url($url) . '" class="action-' . $action_arg . ' ' . $class . '">' . $text . '</a>';
578
  }
579
 
580
  $actions[$index] = $link;
700
  {
701
  $sorturl = add_query_arg('order', 'asc', $sorturl);
702
  }
703
+ $output = '<a href="' . esc_url($sorturl) . '"><span>' . $title . '</span><span class="sorting-indicator '. $sorted . '">&nbsp;</span></a>';
704
  }
705
  else
706
  {
class/external/securi.php CHANGED
@@ -22,7 +22,7 @@ class securiVersion
22
  $time = get_post_modified_time('U', false, $id );
23
  foreach($urls as $index => $url)
24
  {
25
- $urls[$index] = add_query_arg('ver', $time, $url);
26
  }
27
 
28
  Log::addDebug('SecuriVersion - URLS being versioned', $urls);
22
  $time = get_post_modified_time('U', false, $id );
23
  foreach($urls as $index => $url)
24
  {
25
+ $urls[$index] = add_query_arg('ver', $time, $url); // has url
26
  }
27
 
28
  Log::addDebug('SecuriVersion - URLS being versioned', $urls);
class/external/wp-offload-media.php CHANGED
@@ -253,20 +253,20 @@ class wpOffload
253
  *
254
  * @param MediaItem Object SPIO
255
  */
256
- public function image_converted($mediaItem)
257
  {
258
  $fs = \wpSPIO()->fileSystem();
259
 
260
  // Do nothing if not successfull
261
- if ($params['success'] === false)
262
- return;
263
 
264
- Log::addTemp('S3Off Converting ');
265
- $id = $mediaItem->get('id');
266
  $this->remove_remote($id);
267
 
268
  $item = $this->getItemById($id);
269
- $item->delete();
270
 
271
  $this->image_upload($id);
272
  return;
@@ -302,6 +302,7 @@ class wpOffload
302
  }
303
 
304
 
 
305
  public function image_converted_legacy($id)
306
  {
307
  $fs = \wpSPIO()->fileSystem();
@@ -316,8 +317,10 @@ class wpOffload
316
  // delete the old file
317
  $mediaItem = $this->getItemById($id);
318
  if ($mediaItem === false) // mediaItem seems not present. Probably not a remote file
319
- return;
320
-
 
 
321
  $this->as3cf->remove_attachment_files_from_provider($id, $mediaItem);
322
  $providerSourcePath = $mediaItem->source_path();
323
 
@@ -399,6 +402,12 @@ class wpOffload
399
  {
400
  $settings = \wpSPIO()->settings();
401
 
 
 
 
 
 
 
402
  if ($settings->autoMediaLibrary)
403
  {
404
  // Don't prevent whaffever if shortpixel is already done. This can be caused by plugins doing a metadata update, we don't care then.
@@ -426,7 +435,14 @@ class wpOffload
426
  foreach($paths as $size => $path)
427
  {
428
  $file = $fs->getFile($path);
429
- $basepath = $file->getFileDir()->getPath();
 
 
 
 
 
 
 
430
  $newPaths[$size] = $path;
431
 
432
  $webpformat1 = $basepath . $file->getFileName() . '.webp';
253
  *
254
  * @param MediaItem Object SPIO
255
  */
256
+ public function image_converted($id)
257
  {
258
  $fs = \wpSPIO()->fileSystem();
259
 
260
  // Do nothing if not successfull
261
+ //if ($params['success'] === false)
262
+ // return;
263
 
264
+ Log::addTemp('S3Off Converting ' . $id);
265
+ //$id = $mediaItem->get('id');
266
  $this->remove_remote($id);
267
 
268
  $item = $this->getItemById($id);
269
+ // $item->delete();
270
 
271
  $this->image_upload($id);
272
  return;
302
  }
303
 
304
 
305
+ // This is legacy for old S3-Offload plugins.
306
  public function image_converted_legacy($id)
307
  {
308
  $fs = \wpSPIO()->fileSystem();
317
  // delete the old file
318
  $mediaItem = $this->getItemById($id);
319
  if ($mediaItem === false) // mediaItem seems not present. Probably not a remote file
320
+ {
321
+ Log::addTemp('Legacy converted didnt return item');
322
+ return;
323
+ }
324
  $this->as3cf->remove_attachment_files_from_provider($id, $mediaItem);
325
  $providerSourcePath = $mediaItem->source_path();
326
 
402
  {
403
  $settings = \wpSPIO()->settings();
404
 
405
+ // If no quota, unlikely we need to directly optimize.
406
+ if ($settings->quotaExceeded)
407
+ {
408
+ return $bool;
409
+ }
410
+
411
  if ($settings->autoMediaLibrary)
412
  {
413
  // Don't prevent whaffever if shortpixel is already done. This can be caused by plugins doing a metadata update, we don't care then.
435
  foreach($paths as $size => $path)
436
  {
437
  $file = $fs->getFile($path);
438
+ $basedir = $file->getFileDir();
439
+
440
+ if (is_null($basedir)) // This could only happen if path is completely empty.
441
+ {
442
+ continue;
443
+ }
444
+
445
+ $basepath = $basedir->getPath();
446
  $newPaths[$size] = $path;
447
 
448
  $webpformat1 = $basepath . $file->getFileName() . '.webp';
class/shortpixel-png2jpg.php CHANGED
@@ -376,7 +376,10 @@ class ShortPixelPng2Jpg {
376
  $itemHandler->deleteItemCache(); // remove cache since filetype changes.
377
  Log::addDebug("Updated meta: " . json_encode($meta));
378
  wp_update_post(array('ID' => $ID, 'post_mime_type' => 'image/jpeg' ));
379
- do_action('shortpixel/image/convertpng2jpg_after', $ID, $meta);
 
 
 
380
  }
381
 
382
  if(count($toReplace)) {
376
  $itemHandler->deleteItemCache(); // remove cache since filetype changes.
377
  Log::addDebug("Updated meta: " . json_encode($meta));
378
  wp_update_post(array('ID' => $ID, 'post_mime_type' => 'image/jpeg' ));
379
+
380
+ do_action('shortpixel/image/convertpng2jpg_after', $ID, $meta); //@deprecated
381
+ do_action('shortpixel/image/convertpng2jpg_success', $ID, $meta); // Will change in V5.
382
+
383
  }
384
 
385
  if(count($toReplace)) {
class/view/settings/part-debug.php CHANGED
@@ -2,6 +2,8 @@
2
  namespace ShortPixel;
3
  use ShortPixel\Notices\NoticeController as Notices;
4
 
 
 
5
  ?>
6
 
7
  <section id="tab-debug" <?php echo ($this->display_part == 'debug') ? ' class="sel-tab" ' :''; ?>>
@@ -9,6 +11,7 @@ use ShortPixel\Notices\NoticeController as Notices;
9
  <?php _e('Debug','shortpixel-image-optimiser');?></a>
10
  </h2>
11
 
 
12
  <div class="wp-shortpixel-options wp-shortpixel-tab-content" style="visibility: hidden">
13
  <div class='env'>
14
  <h3><?php _e('Environment', 'shortpixel'); ?></h3>
@@ -39,7 +42,7 @@ use ShortPixel\Notices\NoticeController as Notices;
39
 
40
  <h3>Tools</h3>
41
  <div class='debug-images'>
42
- <form method="POST" action="<?php echo add_query_arg(array('sp-action' => 'action_debug_medialibrary')) ?>"
43
  id="shortpixel-form-debug-medialib">
44
  <button class='button' type='submit'>Reacquire Thumbnails on Media Library</button>
45
  </form>
2
  namespace ShortPixel;
3
  use ShortPixel\Notices\NoticeController as Notices;
4
 
5
+
6
+
7
  ?>
8
 
9
  <section id="tab-debug" <?php echo ($this->display_part == 'debug') ? ' class="sel-tab" ' :''; ?>>
11
  <?php _e('Debug','shortpixel-image-optimiser');?></a>
12
  </h2>
13
 
14
+
15
  <div class="wp-shortpixel-options wp-shortpixel-tab-content" style="visibility: hidden">
16
  <div class='env'>
17
  <h3><?php _e('Environment', 'shortpixel'); ?></h3>
42
 
43
  <h3>Tools</h3>
44
  <div class='debug-images'>
45
+ <form method="POST" action="<?php echo esc_url( add_query_arg(array('sp-action' => 'action_debug_medialibrary')) ); ?>"
46
  id="shortpixel-form-debug-medialib">
47
  <button class='button' type='submit'>Reacquire Thumbnails on Media Library</button>
48
  </form>
class/view/settings/part-general.php CHANGED
@@ -167,10 +167,10 @@
167
  <input name="resizeImages" type="checkbox" id="resize" value="1" <?php checked( $view->data->resizeImages, true );?>>
168
  <label for="resize"><?php _e('to maximum','shortpixel-image-optimiser');?></label>
169
  <input type="text" name="resizeWidth" id="width" style="width:70px" class="resize-sizes"
170
- value="<?php echo( $view->data->resizeWidth > 0 ? $view->data->resizeWidth : min(924, $view->minSizes['width']) );?>" <?php echo( $resizeDisabled );?>/> <?php
171
  _e('pixels wide &times;','shortpixel-image-optimiser');?>
172
  <input type="text" name="resizeHeight" id="height" class="resize-sizes" style="width:70px"
173
- value="<?php echo( $view->data->resizeHeight > 0 ? $view->data->resizeHeight : min(924, $view->minSizes['height']) );?>" <?php echo( $resizeDisabled );?>/> <?php
174
  _e('pixels high (original aspect ratio is preserved and image is not cropped)','shortpixel-image-optimiser');?>
175
  <input type="hidden" id="min-resizeWidth" value="<?php echo($view->minSizes['width']);?>" data-nicename="<?php _e('Width', 'shortpixel-image-optimiser'); ?>" />
176
  <input type="hidden" id="min-resizeHeight" value="<?php echo($view->minSizes['height']);?>" data-nicename="<?php _e('Height', 'shortpixel-image-optimiser'); ?>"/>
167
  <input name="resizeImages" type="checkbox" id="resize" value="1" <?php checked( $view->data->resizeImages, true );?>>
168
  <label for="resize"><?php _e('to maximum','shortpixel-image-optimiser');?></label>
169
  <input type="text" name="resizeWidth" id="width" style="width:70px" class="resize-sizes"
170
+ value="<?php echo( $view->data->resizeWidth > 0 ? $view->data->resizeWidth : min(1200, $view->minSizes['width']) );?>" <?php echo( $resizeDisabled );?>/> <?php
171
  _e('pixels wide &times;','shortpixel-image-optimiser');?>
172
  <input type="text" name="resizeHeight" id="height" class="resize-sizes" style="width:70px"
173
+ value="<?php echo( $view->data->resizeHeight > 0 ? $view->data->resizeHeight : min(1200, $view->minSizes['height']) );?>" <?php echo( $resizeDisabled );?>/> <?php
174
  _e('pixels high (original aspect ratio is preserved and image is not cropped)','shortpixel-image-optimiser');?>
175
  <input type="hidden" id="min-resizeWidth" value="<?php echo($view->minSizes['width']);?>" data-nicename="<?php _e('Width', 'shortpixel-image-optimiser'); ?>" />
176
  <input type="hidden" id="min-resizeHeight" value="<?php echo($view->minSizes['height']);?>" data-nicename="<?php _e('Height', 'shortpixel-image-optimiser'); ?>"/>
class/view/settings/part-nokey.php CHANGED
@@ -84,7 +84,7 @@ if($adminEmail == 'noreply@addendio.com') $adminEmail = false; //hack for the ad
84
  <?php _e('If you already have an API Key please input it below and press Validate.','shortpixel-image-optimiser');?>
85
  </p>
86
 
87
- <form method="POST" action="<?php echo add_query_arg(array('noheader' => 'true', 'sp-action' => 'action_addkey')) ?>"
88
  id="shortpixel-form-nokey">
89
  <?php wp_nonce_field($this->form_action, 'sp-nonce'); ?>
90
 
84
  <?php _e('If you already have an API Key please input it below and press Validate.','shortpixel-image-optimiser');?>
85
  </p>
86
 
87
+ <form method="POST" action="<?php echo esc_url(add_query_arg(array('noheader' => 'true', 'sp-action' => 'action_addkey'))); ?>"
88
  id="shortpixel-form-nokey">
89
  <?php wp_nonce_field($this->form_action, 'sp-nonce'); ?>
90
 
class/view/settings/part-statistics.php CHANGED
@@ -126,26 +126,17 @@ $quotaData = $this->quotaData;
126
  </a></th>
127
  <td>&nbsp;</td>
128
  </tr>
129
- <tr>
130
- <th scope="row">
131
- <?php _e('Credits consumed on','shortpixel-image-optimiser');?>
132
- <?php echo(parse_url(get_site_url(),PHP_URL_HOST));?>:
133
- </th>
134
- <td><strong><?php echo($view->data->fileCount);?></strong></td>
135
- </tr>
136
  <?php
137
  // @todo This is always true, but must it be?
138
  if(true || $view->data->backupImages) { ?>
139
  <tr>
140
  <th scope="row">
141
- <?php _e('Original images are stored in a backup folder. Your backup folder\'s size is now:','shortpixel-image-optimiser');?>
142
  </th>
143
  <td>
144
  <form action="" method="POST">
145
  <?php $backupFolderSize = null; ?>
146
- <?php if ($backupFolderSize === null) { ?>
147
- <span id='backup-folder-size'>Calculating...</span>
148
- <?php } else { echo($backupFolderSize); }?>
149
  <input type="submit" style="margin-left: 15px; vertical-align: middle;" class="button button-secondary shortpixel-confirm"
150
  name="emptyBackup" value="<?php _e('Empty backups','shortpixel-image-optimiser');?>"
151
  data-confirm="<?php _e('Are you sure you want to delete all the backup images? You won\'t be able to restore from backup or to reoptimize with different settings if you delete the backups.','shortpixel-image-optimiser'); ?>"/>
126
  </a></th>
127
  <td>&nbsp;</td>
128
  </tr>
129
+
 
 
 
 
 
 
130
  <?php
131
  // @todo This is always true, but must it be?
132
  if(true || $view->data->backupImages) { ?>
133
  <tr>
134
  <th scope="row">
135
+ <?php _e('Original images are stored in a backup folder.','shortpixel-image-optimiser');?>
136
  </th>
137
  <td>
138
  <form action="" method="POST">
139
  <?php $backupFolderSize = null; ?>
 
 
 
140
  <input type="submit" style="margin-left: 15px; vertical-align: middle;" class="button button-secondary shortpixel-confirm"
141
  name="emptyBackup" value="<?php _e('Empty backups','shortpixel-image-optimiser');?>"
142
  data-confirm="<?php _e('Are you sure you want to delete all the backup images? You won\'t be able to restore from backup or to reoptimize with different settings if you delete the backups.','shortpixel-image-optimiser'); ?>"/>
class/view/shortpixel-list-table.php CHANGED
@@ -52,33 +52,33 @@ class ShortPixelListTable extends WP_List_Table {
52
  $url = ShortPixelMetaFacade::pathToWebPath($item->folder);
53
 
54
  $admin_url = admin_url('upload.php');
55
- $admin_url = add_query_arg(array('page' => sanitize_text_field($_REQUEST['page']), 'image' => absint($item->id), 'noheader' => 'true'), $admin_url);
56
 
57
  // add the order options if active
58
  if (isset($_GET['orderby']))
59
  {
60
  $order = isset($_GET['order']) ? sanitize_text_field($_GET['order']) : 'desc';
61
- $admin_url = add_query_arg(array('orderby' => sanitize_text_field($_GET['orderby']), 'order' => $order), $admin_url);
62
  }
63
  if (isset($_GET['paged']))
64
  {
65
- $admin_url = add_query_arg('paged', intval($_GET['paged']), $admin_url);
66
  }
67
 
68
  $actions = array(
69
- 'optimize' => sprintf('<a href="%s">%s</a>', add_query_arg(array('action' => 'optimize', '_wpnonce' => wp_create_nonce( 'sp_optimize_image' ), ), $admin_url), __('Optimize','shortpixel-image-optimiser')),
70
 
71
- 'retry' => sprintf('<a href="%s">%s</a>', add_query_arg(array('action' => 'optimize', '_wpnonce' => wp_create_nonce( 'sp_optimize_image' ), ), $admin_url), __('Retry','shortpixel-image-optimiser')),
72
 
73
- 'redolossless' => sprintf('<a href="%s">%s</a>', add_query_arg(array('action' => 'redo', '_wpnonce' => wp_create_nonce( 'sp_redo_image'), 'type' => 'lossless'),$admin_url), __('Re-optimize lossless','shortpixel-image-optimiser')),
74
 
75
- 'redolossy' => sprintf('<a href="%s">%s</a>', add_query_arg(array('action' => 'redo', '_wpnonce' => wp_create_nonce( 'sp_redo_image'), 'type' => 'lossy'), $admin_url), __('Re-optimize lossy','shortpixel-image-optimiser')),
76
 
77
- 'redoglossy' => sprintf('<a href="%s">%s</a>', add_query_arg(array('action' => 'redo', '_wpnonce' => wp_create_nonce( 'sp_redo_image'), 'type' => 'glossy'), $admin_url), __('Re-optimize glossy','shortpixel-image-optimiser')),
78
 
79
- 'quota' => sprintf('<a href="%s">%s</a>', add_query_arg(array('action' => 'quota', '_wpnonce' => wp_create_nonce( 'sp_check_quota')), $admin_url), __('Check quota','shortpixel-image-optimiser')),
80
 
81
- 'restore' => sprintf('<a href="%s">%s</a>', add_query_arg(array('action' => 'restore', '_wpnonce' => wp_create_nonce( 'sp_restore_image')), $admin_url), __('Restore','shortpixel-image-optimiser')),
82
 
83
 
84
  'compare' => sprintf( '<a href="javascript:ShortPixel.loadComparer(\'C-' . absint($item->id) . '\');">%s</a>"',
52
  $url = ShortPixelMetaFacade::pathToWebPath($item->folder);
53
 
54
  $admin_url = admin_url('upload.php');
55
+ $admin_url = add_query_arg(array('page' => sanitize_text_field($_REQUEST['page']), 'image' => absint($item->id), 'noheader' => 'true'), $admin_url); // has url
56
 
57
  // add the order options if active
58
  if (isset($_GET['orderby']))
59
  {
60
  $order = isset($_GET['order']) ? sanitize_text_field($_GET['order']) : 'desc';
61
+ $admin_url = add_query_arg(array('orderby' => sanitize_text_field($_GET['orderby']), 'order' => $order), $admin_url); // has url
62
  }
63
  if (isset($_GET['paged']))
64
  {
65
+ $admin_url = add_query_arg('paged', intval($_GET['paged']), $admin_url); // has url
66
  }
67
 
68
  $actions = array(
69
+ 'optimize' => sprintf('<a href="%s">%s</a>', esc_url(add_query_arg(array('action' => 'optimize', '_wpnonce' => wp_create_nonce( 'sp_optimize_image' ), ), $admin_url)), __('Optimize','shortpixel-image-optimiser')),
70
 
71
+ 'retry' => sprintf('<a href="%s">%s</a>', esc_url(add_query_arg(array('action' => 'optimize', '_wpnonce' => wp_create_nonce( 'sp_optimize_image' ), ), $admin_url)), __('Retry','shortpixel-image-optimiser')),
72
 
73
+ 'redolossless' => sprintf('<a href="%s">%s</a>', esc_url(add_query_arg(array('action' => 'redo', '_wpnonce' => wp_create_nonce( 'sp_redo_image'), 'type' => 'lossless'),$admin_url)), __('Re-optimize lossless','shortpixel-image-optimiser')),
74
 
75
+ 'redolossy' => sprintf('<a href="%s">%s</a>', esc_url(add_query_arg(array('action' => 'redo', '_wpnonce' => wp_create_nonce( 'sp_redo_image'), 'type' => 'lossy'), $admin_url)), __('Re-optimize lossy','shortpixel-image-optimiser')),
76
 
77
+ 'redoglossy' => sprintf('<a href="%s">%s</a>', esc_url(add_query_arg(array('action' => 'redo', '_wpnonce' => wp_create_nonce( 'sp_redo_image'), 'type' => 'glossy'), $admin_url)), __('Re-optimize glossy','shortpixel-image-optimiser')),
78
 
79
+ 'quota' => sprintf('<a href="%s">%s</a>', esc_url(add_query_arg(array('action' => 'quota', '_wpnonce' => wp_create_nonce( 'sp_check_quota')), $admin_url)), __('Check quota','shortpixel-image-optimiser')),
80
 
81
+ 'restore' => sprintf('<a href="%s">%s</a>', esc_url(add_query_arg(array('action' => 'restore', '_wpnonce' => wp_create_nonce( 'sp_restore_image')), $admin_url)), __('Restore','shortpixel-image-optimiser')),
82
 
83
 
84
  'compare' => sprintf( '<a href="javascript:ShortPixel.loadComparer(\'C-' . absint($item->id) . '\');">%s</a>"',
class/view/shortpixel_view.php CHANGED
@@ -185,7 +185,7 @@ class ShortPixelView {
185
  <div style="position: absolute;bottom: 10px;right: 10px;">
186
  <?php /* <input type='submit' name='bulkRestore' id='bulkRestore' class='button' value='<?php _e('Bulk Restore Media Library','shortpixel-image-optimiser');?>' onclick="ShortPixel.confirmBulkAction('Restore', event)" style="margin-bottom:10px;">
187
  */ ?>
188
- <p><a class='button' style="width:100%; text-align: center" href='<?php echo add_query_arg('part','bulk-restore-all'); ?> '><?php _e('Bulk Restore Images','shortpixel-image-optimiser'); ?></a></p>
189
 
190
 
191
  <input type='submit' name='bulkCleanup' id='bulkCleanup' class='button' value='<?php _e('Bulk Delete SP Metadata','shortpixel-image-optimiser');?>'
@@ -475,7 +475,7 @@ class ShortPixelView {
475
 
476
  </div><br>
477
 
478
- <a class='button' style="float: right;" href='<?php echo add_query_arg('part','bulk-restore-all'); ?> '><?php _e('Bulk Restore Images','shortpixel-image-optimiser'); ?></a>
479
 
480
  <input type='submit' name='bulkProcess' id='bulkProcess' class='button button-primary' value='<?php _e('Restart Optimizing','shortpixel-image-optimiser');?>'
481
  <?php echo($settings->quotaExceeded? "disabled title=\"" . __("Top-up your account to optimize more images.",'shortpixel-image-optimiser')."\"" : ""); ?>>
185
  <div style="position: absolute;bottom: 10px;right: 10px;">
186
  <?php /* <input type='submit' name='bulkRestore' id='bulkRestore' class='button' value='<?php _e('Bulk Restore Media Library','shortpixel-image-optimiser');?>' onclick="ShortPixel.confirmBulkAction('Restore', event)" style="margin-bottom:10px;">
187
  */ ?>
188
+ <p><a class='button' style="width:100%; text-align: center" href='<?php echo esc_url(add_query_arg('part','bulk-restore-all')); ?> '><?php _e('Bulk Restore Images','shortpixel-image-optimiser'); ?></a></p>
189
 
190
 
191
  <input type='submit' name='bulkCleanup' id='bulkCleanup' class='button' value='<?php _e('Bulk Delete SP Metadata','shortpixel-image-optimiser');?>'
475
 
476
  </div><br>
477
 
478
+ <a class='button' style="float: right;" href='<?php echo esc_url(add_query_arg('part','bulk-restore-all')); ?> '><?php _e('Bulk Restore Images','shortpixel-image-optimiser'); ?></a>
479
 
480
  <input type='submit' name='bulkProcess' id='bulkProcess' class='button button-primary' value='<?php _e('Restart Optimizing','shortpixel-image-optimiser');?>'
481
  <?php echo($settings->quotaExceeded? "disabled title=\"" . __("Top-up your account to optimize more images.",'shortpixel-image-optimiser')."\"" : ""); ?>>
class/view/view-restore-all.php CHANGED
@@ -1,6 +1,6 @@
1
 
2
  <div class="wrap short-pixel-bulk-page bulk-restore-all">
3
- <form action='<?php echo remove_query_arg('part'); ?>' method='POST' >
4
  <?php wp_nonce_field('sp-bulk', 'sp-nonce'); ?>
5
  <h1><?php _e('Bulk Image Optimization by ShortPixel','shortpixel-image-optimiser');?></h1>
6
 
@@ -41,7 +41,7 @@
41
  </section>
42
 
43
  <div class='form-controls'>
44
- <a class='button' href="<?php echo remove_query_arg('part') ?>"><?php _e('Back', 'shortpixel-image-optimiser'); ?></a>
45
  <button disabled aria-disabled="true" type='submit' class='button bulk restore disabled' name='bulkRestore' id='bulkRestore'><?php _e('Bulk Restore', 'shortpixel-image-optimiser'); ?></button>
46
  </div>
47
 
1
 
2
  <div class="wrap short-pixel-bulk-page bulk-restore-all">
3
+ <form action='<?php echo esc_url(remove_query_arg('part')); ?>' method='POST' >
4
  <?php wp_nonce_field('sp-bulk', 'sp-nonce'); ?>
5
  <h1><?php _e('Bulk Image Optimization by ShortPixel','shortpixel-image-optimiser');?></h1>
6
 
41
  </section>
42
 
43
  <div class='form-controls'>
44
+ <a class='button' href="<?php echo esc_url(remove_query_arg('part')) ?>"><?php _e('Back', 'shortpixel-image-optimiser'); ?></a>
45
  <button disabled aria-disabled="true" type='submit' class='button bulk restore disabled' name='bulkRestore' id='bulkRestore'><?php _e('Bulk Restore', 'shortpixel-image-optimiser'); ?></button>
46
  </div>
47
 
class/view/view-settings.php CHANGED
@@ -27,7 +27,7 @@ HelpScout::outputBeacon();
27
  <?php
28
  if ($this->is_verifiedkey):
29
  ?>
30
- <form name='wp_shortpixel_options' action='<?php echo add_query_arg('noheader', 'true') ?>' method='post' id='wp_shortpixel_options'>
31
  <input type='hidden' name='display_part' value="<?php echo $this->display_part ?>" />
32
  <?php wp_nonce_field($this->form_action, 'sp-nonce'); ?>
33
  <div class='section-wrapper'>
27
  <?php
28
  if ($this->is_verifiedkey):
29
  ?>
30
+ <form name='wp_shortpixel_options' action='<?php echo esc_url(add_query_arg('noheader', 'true')) ?>' method='post' id='wp_shortpixel_options'>
31
  <input type='hidden' name='display_part' value="<?php echo $this->display_part ?>" />
32
  <?php wp_nonce_field($this->form_action, 'sp-nonce'); ?>
33
  <div class='section-wrapper'>
class/wp-short-pixel.php CHANGED
@@ -106,7 +106,6 @@ class WPShortPixel {
106
  //custom hook
107
  add_action( 'shortpixel-optimize-now', array( &$this, 'optimizeNowHook' ), 10, 1);
108
 
109
-
110
  add_filter( 'shortpixel_get_backup', array( &$this, 'shortpixelGetBackupFilter' ), 10, 1 );
111
 
112
  if($isAdminUser) {
@@ -3169,6 +3168,8 @@ class WPShortPixel {
3169
  return $mimes;
3170
  }
3171
 
 
 
3172
  /**
3173
  *
3174
  * @param type $apiKey
106
  //custom hook
107
  add_action( 'shortpixel-optimize-now', array( &$this, 'optimizeNowHook' ), 10, 1);
108
 
 
109
  add_filter( 'shortpixel_get_backup', array( &$this, 'shortpixelGetBackupFilter' ), 10, 1 );
110
 
111
  if($isAdminUser) {
3168
  return $mimes;
3169
  }
3170
 
3171
+
3172
+
3173
  /**
3174
  *
3175
  * @param type $apiKey
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: convert webp, optimize images, image optimization, resize, compressor, ima
4
  Requires at least: 4.2.0
5
  Tested up to: 6.0
6
  Requires PHP: 5.6
7
- Stable tag: 4.22.9
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -260,7 +260,10 @@ the `$chunk` is the value ShortPixel chooses to use as number of selected record
260
  filters the array of paths of the images sent for backup and can be used to exclude certain paths/images/thumbs from being backed up, based on the image path. `$mainPath` is the path of the main image, while `$PATHs` is an array with all files to be backed up (including thumbnails);
261
 
262
  `apply_filters('shortpixel/settings/image_sizes', $sizes);`
263
- filters the array (`$sizes`) of image sizes which can be excluded from processing (displayed in the plugin Advanced settings).
 
 
 
264
 
265
  In order to define custom thumbnails to be picked up by the optimization you have two options, both comma separated defines:
266
 
@@ -319,6 +322,18 @@ Alternatively, you can use this filter in your theme's functions.php file:
319
 
320
  == Changelog ==
321
 
 
 
 
 
 
 
 
 
 
 
 
 
322
  = 4.22.9 =
323
  Release date March 31st, 2022
324
  * Fix: fixed the integration with the WP Media Offload plugin, which was broken in version 3.6.0;
4
  Requires at least: 4.2.0
5
  Tested up to: 6.0
6
  Requires PHP: 5.6
7
+ Stable tag: 4.22.10
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
260
  filters the array of paths of the images sent for backup and can be used to exclude certain paths/images/thumbs from being backed up, based on the image path. `$mainPath` is the path of the main image, while `$PATHs` is an array with all files to be backed up (including thumbnails);
261
 
262
  `apply_filters('shortpixel/settings/image_sizes', $sizes);`
263
+ filters the array (`$sizes`) of image sizes which can be excluded from processing (displayed in the plugin Advanced settings);
264
+
265
+ `apply_filters('shortpixel/api/request', $requestParameters, $item_id);`
266
+ filters the parameters sent to the optimization API (through `$requestParameters`), described in detail here: <a href="https://shortpixel.com/api-docs" target="_blank">ShortPixel Reducer API</a>; `$item_id` contains the ID of the Media Library item, or the ID of the Custom Media item (when used). In short, this filter can be used to alter any parameters sent to the API, depending on the needs. For example, you can set different resize parameters for different post types, different compression levels, remove EXIF or not, covert WebP/AVIF, and basically any other parameter that is sent to the API for a specific image (together with all its thumbnails).
267
 
268
  In order to define custom thumbnails to be picked up by the optimization you have two options, both comma separated defines:
269
 
322
 
323
  == Changelog ==
324
 
325
+ = 4.22.10 =
326
+ Release date June 2nd, 2022
327
+ * Fix: updated all `add_query_arg` and `remove_query_arg` functions for enhanced security;
328
+ * Fix: in some cases, the offloading via WP Offload Media wasn't properly done when converting from PNG to JPG;
329
+ * Fix: PDF files weren't offloaded via WP Offload Media when running out of credits;
330
+ * Fix: removed the backups folder calculation because it was making the settings page very slow in certain cases;
331
+ * Fix: removed the consumed credits from the statistics tab, because it wasn't working correctly;
332
+ * Fix: increased the default image resize options;
333
+ * Fix: a potential fatal error on PHP 8 was corrected;
334
+ * Tweak: added a new filter for the requests that are sent to the optimization API, documented above in the Developers section;
335
+ * Language: 0 new strings added, 0 updated, 0 fuzzed, and 0 obsoleted.
336
+
337
  = 4.22.9 =
338
  Release date March 31st, 2022
339
  * Fix: fixed the integration with the WP Media Offload plugin, which was broken in version 3.6.0;
res/js/shortpixel.js CHANGED
@@ -24,9 +24,9 @@ var ShortPixel = function() {
24
  // Extracting the protected Array from within the 0 element of the parent array
25
  ShortPixel.setOptions(ShortPixelConstants[0]);
26
 
27
- if(jQuery('#backup-folder-size').length) {
28
  jQuery('#backup-folder-size').html(ShortPixel.getBackupSize());
29
- }
30
 
31
  if( ShortPixel.MEDIA_ALERT == 'todo' && jQuery('div.media-frame.mode-grid').length > 0) {
32
  //the media table is not in the list mode, alert the user
24
  // Extracting the protected Array from within the 0 element of the parent array
25
  ShortPixel.setOptions(ShortPixelConstants[0]);
26
 
27
+ /* if(jQuery('#backup-folder-size').length) {
28
  jQuery('#backup-folder-size').html(ShortPixel.getBackupSize());
29
+ } */
30
 
31
  if( ShortPixel.MEDIA_ALERT == 'todo' && jQuery('div.media-frame.mode-grid').length > 0) {
32
  //the media table is not in the list mode, alert the user
shortpixel_api.php CHANGED
@@ -137,13 +137,18 @@ class ShortPixelAPI {
137
  'resize_height' => $this->_settings->resizeHeight,
138
  'urllist' => $URLs
139
  );
140
- if(/*false &&*/ $this->_settings->downloadArchive == 7 && class_exists('PharData')) {
 
 
141
  $requestParameters['group'] = $itemHandler->getId();
142
  }
143
  if($refresh) {
144
  $requestParameters['refresh'] = 1;
145
  }
146
 
 
 
 
147
  //WpShortPixel::log("ShortPixel API Request Settings: " . json_encode($requestParameters));
148
  $response = wp_remote_post($this->_apiEndPoint, $this->prepareRequest($requestParameters, $Blocking) );
149
  Log::addDebug('ShortPixel API Request sent', $requestParameters);
137
  'resize_height' => $this->_settings->resizeHeight,
138
  'urllist' => $URLs
139
  );
140
+
141
+
142
+ if(/*false &&*/ $this->_settings->downloadArchive == 7 && class_exists('PharData')) {
143
  $requestParameters['group'] = $itemHandler->getId();
144
  }
145
  if($refresh) {
146
  $requestParameters['refresh'] = 1;
147
  }
148
 
149
+ $requestParameters = apply_filters('shortpixel/api/request', $requestParameters, $itemHandler->getId());
150
+
151
+
152
  //WpShortPixel::log("ShortPixel API Request Settings: " . json_encode($requestParameters));
153
  $response = wp_remote_post($this->_apiEndPoint, $this->prepareRequest($requestParameters, $Blocking) );
154
  Log::addDebug('ShortPixel API Request sent', $requestParameters);
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="/wp-admin/options-general.php?page=wp-shortpixel-settings" target="_blank">Settings &gt; ShortPixel</a> page on how to start optimizing your image library and make your website load faster.
6
- * Version: 4.22.9
7
  * Author: ShortPixel
8
  * Author URI: https://shortpixel.com
9
  * GitHub Plugin URI: https://github.com/short-pixel-optimizer/shortpixel-image-optimiser
@@ -33,7 +33,7 @@ define('SHORTPIXEL_PLUGIN_DIR', __DIR__);
33
 
34
  //define('SHORTPIXEL_AFFILIATE_CODE', '');
35
 
36
- define('SHORTPIXEL_IMAGE_OPTIMISER_VERSION', "4.22.9");
37
  define('SHORTPIXEL_MAX_TIMEOUT', 10);
38
  define('SHORTPIXEL_VALIDATE_MAX_TIMEOUT', 15);
39
  define('SHORTPIXEL_BACKUP', 'ShortpixelBackups');
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="/wp-admin/options-general.php?page=wp-shortpixel-settings" target="_blank">Settings &gt; ShortPixel</a> page on how to start optimizing your image library and make your website load faster.
6
+ * Version: 4.22.10
7
  * Author: ShortPixel
8
  * Author URI: https://shortpixel.com
9
  * GitHub Plugin URI: https://github.com/short-pixel-optimizer/shortpixel-image-optimiser
33
 
34
  //define('SHORTPIXEL_AFFILIATE_CODE', '');
35
 
36
+ define('SHORTPIXEL_IMAGE_OPTIMISER_VERSION', "4.22.10");
37
  define('SHORTPIXEL_MAX_TIMEOUT', 10);
38
  define('SHORTPIXEL_VALIDATE_MAX_TIMEOUT', 15);
39
  define('SHORTPIXEL_BACKUP', 'ShortpixelBackups');