EWWW Image Optimizer - Version 4.7.3

Version Description

  • added: disable WebP script block on certain pages by defining EWWW_IMAGE_OPTIMIZER_NO_JS as true
  • changed: use SVG inline image placeholder if width and height are known when LQIP is disabled or ExactDN is not available
  • changed: Lazy Load ignores images using browser-native loading attribute
  • fixed: page parsers (ExactDN, Lazy, JS WebP) do not properly handle attributes that start on a new line
  • fixed: page parsers do not recognize img elements with unquoted attributes
  • fixed: uninstaller cannot clear queue table due to undefined table name
  • fixed: implode throws notice when image sizes array is multi-dimensional
  • fixed: srcset url replaced incorrectly when using pixel density descriptors
  • fixed: srcset url added with 0 width when width attribute is empty
Download this release

Release Info

Developer nosilver4u
Plugin Icon 128x128 EWWW Image Optimizer
Version 4.7.3
Comparing to
See all releases

Code changes from version 4.7.2 to 4.7.3

aux-optimize.php CHANGED
@@ -160,12 +160,12 @@ function ewww_image_optimizer_aux_images_table() {
160
  $image_name = str_replace( ABSPATH, '', $file );
161
  $image_url = esc_url( site_url( 'wp-includes/images/media/default.png' ) );
162
  ewwwio_debug_message( "name is $image_name after replacing ABSPATH" );
163
- if ( $file != $image_name ) {
164
  $image_url = esc_url( site_url( $image_name ) );
165
  } else {
166
  $image_name = str_replace( WP_CONTENT_DIR, '', $file );
167
  ewwwio_debug_message( "name is $image_name after replacing WP_CONTENT_DIR" );
168
- if ( $file != $image_name ) {
169
  $image_url = esc_url( content_url( $image_name ) );
170
  }
171
  }
@@ -529,7 +529,7 @@ function ewww_image_optimizer_image_scan( $dir, $started = 0 ) {
529
  if ( ! is_array( $folders_completed ) ) {
530
  $folders_completed = array();
531
  }
532
- if ( in_array( $dir, $folders_completed ) ) {
533
  ewwwio_debug_message( "$dir already completed" );
534
  return;
535
  }
@@ -631,7 +631,7 @@ function ewww_image_optimizer_image_scan( $dir, $started = 0 ) {
631
  } else {
632
  $mime = ewww_image_optimizer_quick_mimetype( $path );
633
  }
634
- if ( ! in_array( $mime, $enabled_types ) ) {
635
  continue;
636
  }
637
  if ( apply_filters( 'ewww_image_optimizer_bypass', false, $path ) === true ) {
@@ -656,11 +656,11 @@ function ewww_image_optimizer_image_scan( $dir, $started = 0 ) {
656
  ewwwio_debug_message( "file skipped due to filesize: $path" );
657
  continue;
658
  }
659
- if ( 'image/png' == $mime && ewww_image_optimizer_get_option( 'ewww_image_optimizer_skip_png_size' ) && $image_size > ewww_image_optimizer_get_option( 'ewww_image_optimizer_skip_png_size' ) ) {
660
  ewwwio_debug_message( "file skipped due to PNG filesize: $path" );
661
  continue;
662
  }
663
- if ( $already_optimized['image_size'] == $image_size && empty( $_REQUEST['ewww_force'] ) ) {
664
  ewwwio_debug_message( "match found for $path" );
665
  continue;
666
  } else {
@@ -673,7 +673,7 @@ function ewww_image_optimizer_image_scan( $dir, $started = 0 ) {
673
  ewwwio_debug_message( "file skipped due to filesize: $path" );
674
  continue;
675
  }
676
- if ( 'image/png' == $mime && ewww_image_optimizer_get_option( 'ewww_image_optimizer_skip_png_size' ) && $image_size > ewww_image_optimizer_get_option( 'ewww_image_optimizer_skip_png_size' ) ) {
677
  ewwwio_debug_message( "file skipped due to PNG filesize: $path" );
678
  continue;
679
  }
@@ -825,7 +825,7 @@ function ewww_image_optimizer_aux_images_script( $hook = '' ) {
825
  foreach ( $slides as $slide ) {
826
  $type = get_post_meta( $slide, 'ml-slider_type', true );
827
  $type = $type ? $type : 'image'; // For backwards compatibility, fall back to 'image'.
828
- if ( 'image' != $type ) {
829
  continue;
830
  }
831
  $backup_sizes = get_post_meta( $slide, '_wp_attachment_backup_sizes', true );
@@ -850,7 +850,7 @@ function ewww_image_optimizer_aux_images_script( $hook = '' ) {
850
  'orig_size' => $image_size,
851
  );
852
  // This is a changed image.
853
- } elseif ( preg_match( '/^image\/(jpeg|png|gif)/', $mimetype ) && ! empty( $already_optimized ) && $already_optimized['image_size'] != $image_size ) {
854
  $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->ewwwio_images SET pending = 1 WHERE id = %d", $already_optimized['id'] ) );
855
  }
856
  }
@@ -872,7 +872,7 @@ function ewww_image_optimizer_aux_images_script( $hook = '' ) {
872
  }
873
  }
874
  // Scan images in two most recent media library folders if the option is enabled, and this is a scheduled optimization.
875
- if ( 'ewww-image-optimizer-auto' == $hook && ewww_image_optimizer_get_option( 'ewww_image_optimizer_include_media_paths' ) ) {
876
  // Retrieve the location of the WordPress upload folder.
877
  $upload_dir = wp_upload_dir();
878
  // Retrieve the path of the upload folder.
160
  $image_name = str_replace( ABSPATH, '', $file );
161
  $image_url = esc_url( site_url( 'wp-includes/images/media/default.png' ) );
162
  ewwwio_debug_message( "name is $image_name after replacing ABSPATH" );
163
+ if ( $file !== $image_name ) {
164
  $image_url = esc_url( site_url( $image_name ) );
165
  } else {
166
  $image_name = str_replace( WP_CONTENT_DIR, '', $file );
167
  ewwwio_debug_message( "name is $image_name after replacing WP_CONTENT_DIR" );
168
+ if ( $file !== $image_name ) {
169
  $image_url = esc_url( content_url( $image_name ) );
170
  }
171
  }
529
  if ( ! is_array( $folders_completed ) ) {
530
  $folders_completed = array();
531
  }
532
+ if ( in_array( $dir, $folders_completed, true ) ) {
533
  ewwwio_debug_message( "$dir already completed" );
534
  return;
535
  }
631
  } else {
632
  $mime = ewww_image_optimizer_quick_mimetype( $path );
633
  }
634
+ if ( ! in_array( $mime, $enabled_types, true ) ) {
635
  continue;
636
  }
637
  if ( apply_filters( 'ewww_image_optimizer_bypass', false, $path ) === true ) {
656
  ewwwio_debug_message( "file skipped due to filesize: $path" );
657
  continue;
658
  }
659
+ if ( 'image/png' === $mime && ewww_image_optimizer_get_option( 'ewww_image_optimizer_skip_png_size' ) && $image_size > ewww_image_optimizer_get_option( 'ewww_image_optimizer_skip_png_size' ) ) {
660
  ewwwio_debug_message( "file skipped due to PNG filesize: $path" );
661
  continue;
662
  }
663
+ if ( (int) $already_optimized['image_size'] === $image_size && empty( $_REQUEST['ewww_force'] ) ) {
664
  ewwwio_debug_message( "match found for $path" );
665
  continue;
666
  } else {
673
  ewwwio_debug_message( "file skipped due to filesize: $path" );
674
  continue;
675
  }
676
+ if ( 'image/png' === $mime && ewww_image_optimizer_get_option( 'ewww_image_optimizer_skip_png_size' ) && $image_size > ewww_image_optimizer_get_option( 'ewww_image_optimizer_skip_png_size' ) ) {
677
  ewwwio_debug_message( "file skipped due to PNG filesize: $path" );
678
  continue;
679
  }
825
  foreach ( $slides as $slide ) {
826
  $type = get_post_meta( $slide, 'ml-slider_type', true );
827
  $type = $type ? $type : 'image'; // For backwards compatibility, fall back to 'image'.
828
+ if ( 'image' !== $type ) {
829
  continue;
830
  }
831
  $backup_sizes = get_post_meta( $slide, '_wp_attachment_backup_sizes', true );
850
  'orig_size' => $image_size,
851
  );
852
  // This is a changed image.
853
+ } elseif ( preg_match( '/^image\/(jpeg|png|gif)/', $mimetype ) && ! empty( $already_optimized ) && (int) $already_optimized['image_size'] !== $image_size ) {
854
  $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->ewwwio_images SET pending = 1 WHERE id = %d", $already_optimized['id'] ) );
855
  }
856
  }
872
  }
873
  }
874
  // Scan images in two most recent media library folders if the option is enabled, and this is a scheduled optimization.
875
+ if ( 'ewww-image-optimizer-auto' === $hook && ewww_image_optimizer_get_option( 'ewww_image_optimizer_include_media_paths' ) ) {
876
  // Retrieve the location of the WordPress upload folder.
877
  $upload_dir = wp_upload_dir();
878
  // Retrieve the path of the upload folder.
bulk.php CHANGED
@@ -34,7 +34,7 @@ function ewww_image_optimizer_bulk_preview() {
34
  if ( empty( $resume ) ) {
35
  $fullsize_count = ewww_image_optimizer_count_optimized( 'media' );
36
  $button_text = esc_attr__( 'Start optimizing', 'ewww-image-optimizer' );
37
- } elseif ( 'scanning' == $resume ) {
38
  $fullsize_count = ewww_image_optimizer_count_optimized( 'media' );
39
  $button_text = esc_attr__( 'Start optimizing', 'ewww-image-optimizer' );
40
  } else {
@@ -47,7 +47,7 @@ function ewww_image_optimizer_bulk_preview() {
47
  if ( $fullsize_count < 1 ) {
48
  echo '<p>' . esc_html__( 'You do not appear to have uploaded any images yet.', 'ewww-image-optimizer' ) . '</p>';
49
  } else {
50
- if ( 'true' == $resume ) {
51
  /* translators: %d: number of images */
52
  echo '<p class="ewww-media-info ewww-bulk-info">' . sprintf( esc_html( _n( 'There is %d image ready to optimize.', 'There are %d images ready to optimize.', $fullsize_count, 'ewww-image-optimizer' ) ), $fullsize_count ) . '</p>';
53
  } else {
@@ -63,7 +63,7 @@ function ewww_image_optimizer_bulk_preview() {
63
  ewww_image_optimizer_bulk_action_output( $button_text, $fullsize_count, $resume );
64
  }
65
  // If the 'bulk resume' option was not empty, offer to reset it so the user can start back from the beginning.
66
- if ( 'true' == $resume ) {
67
  ewww_image_optimizer_bulk_reset_form_output();
68
  }
69
  echo '</div>';
@@ -131,7 +131,7 @@ function ewww_image_optimizer_bulk_action_output( $button_text, $fullsize_count,
131
  $loading_image = plugins_url( '/images/wpspin.gif', __FILE__ );
132
  /* translators: %d: number of images */
133
  $scanning_starter_message = sprintf( esc_html__( 'Stage 1, %d images left to scan.', 'ewww-image-optimizer' ), $fullsize_count );
134
- if ( 'true' == $resume ) {
135
  $scan_hide = 'style="display:none"';
136
  $start_hide = '';
137
  } else {
@@ -239,8 +239,9 @@ function ewww_image_optimizer_count_optimized( $gallery ) {
239
  // Get an array of sizes available for the $image.
240
  $sizes = $storage->get_image_sizes();
241
  global $ewwwngg;
242
- $offset = 0;
243
- while ( $attachments = $wpdb->get_col( "SELECT meta_data FROM $wpdb->nggpictures $attachment_query LIMIT $offset, $max_query" ) ) { // phpcs:ignore WordPress.DB.PreparedSQL
 
244
  foreach ( $attachments as $attachment ) {
245
  if ( class_exists( 'Ngg_Serializable' ) ) {
246
  $serializer = new Ngg_Serializable();
@@ -280,6 +281,7 @@ function ewww_image_optimizer_count_optimized( $gallery ) {
280
  }
281
  $attachment_query = 'WHERE pid IN (' . substr( $attachment_query, 0, -1 ) . ')';
282
  }
 
283
  } // End while().
284
  break;
285
  case 'flag':
@@ -293,8 +295,9 @@ function ewww_image_optimizer_count_optimized( $gallery ) {
293
  }
294
  $attachment_query = 'WHERE pid IN (' . substr( $attachment_query, 0, -1 ) . ')';
295
  }
296
- $offset = 0;
297
- while ( $attachments = $wpdb->get_col( "SELECT meta_data FROM $wpdb->flagpictures $attachment_query LIMIT $offset, $max_query" ) ) { // phpcs:ignore WordPress.DB.PreparedSQL
 
298
  foreach ( $attachments as $attachment ) {
299
  $meta = unserialize( $attachment );
300
  if ( ! is_array( $meta ) ) {
@@ -328,6 +331,7 @@ function ewww_image_optimizer_count_optimized( $gallery ) {
328
  }
329
  $attachment_query = 'WHERE pid IN (' . substr( $attachment_query, 0, -1 ) . ')';
330
  }
 
331
  }
332
  break;
333
  } // End switch().
@@ -356,7 +360,7 @@ function ewww_image_optimizer_count_optimized( $gallery ) {
356
  function ewww_image_optimizer_bulk_script( $hook ) {
357
  ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
358
  // Make sure we are being called from the bulk optimization page.
359
- if ( 'media_page_ewww-image-optimizer-bulk' != $hook ) {
360
  return;
361
  }
362
  global $wpdb;
@@ -398,7 +402,7 @@ function ewww_image_optimizer_bulk_script( $hook ) {
398
  $sample_post_type = get_post_type( $ids[0] );
399
  // ewwwio_debug_message( "ids: " . $request_ids[0] ); // keeping just in case.
400
  ewwwio_debug_message( "post type (checking for ims_gallery): $sample_post_type" );
401
- if ( 'ims_gallery' == $sample_post_type ) {
402
  $attachments = array();
403
  foreach ( $ids as $gid ) {
404
  ewwwio_debug_message( "gallery id: $gid" );
@@ -413,7 +417,7 @@ function ewww_image_optimizer_bulk_script( $hook ) {
413
  // Unset the 'bulk resume' option since we were given specific IDs to optimize.
414
  update_option( 'ewww_image_optimizer_bulk_resume', '' );
415
  // Check if there is a previous bulk operation to resume.
416
- } elseif ( 'scanning' == $resume ) {
417
  ewwwio_debug_message( 'scanning, nothing doing' );
418
  // TODO: do nothing...
419
  } elseif ( $scanning || $resume ) {
@@ -514,7 +518,8 @@ function ewww_image_optimizer_optimized_list() {
514
  return;
515
  }
516
  $starting_memory_usage = memory_get_usage( true );
517
- while ( $already_optimized = $ewwwdb->get_results( "SELECT id,path,image_size,pending,attachment_id,updated FROM $ewwwdb->ewwwio_images LIMIT $offset,$max_query", ARRAY_A ) ) {
 
518
  $ewwwdb->flush();
519
  foreach ( $already_optimized as $optimized ) {
520
  $optimized_path = ewww_image_optimizer_absolutize_path( $optimized['path'] );
@@ -551,6 +556,7 @@ function ewww_image_optimizer_optimized_list() {
551
  set_transient( 'ewww_image_optimizer_low_memory_mode', 'large_list', 600 ); // Use low memory mode so that we don't waste lots of time pulling a huge list of images repeatedly.
552
  return;
553
  }
 
554
  } // End while().
555
  }
556
 
@@ -577,19 +583,19 @@ function ewww_image_optimizer_fetch_metadata_batch( $attachments_in ) {
577
  $wpdb->flush();
578
  $attachment_meta = array();
579
  foreach ( $attachments as $attachment ) {
580
- if ( '_wp_attached_file' == $attachment['meta_key'] ) {
581
  $attachment_meta[ $attachment['post_id'] ]['_wp_attached_file'] = $attachment['meta_value'];
582
  if ( ! empty( $attachment['post_mime_type'] ) && empty( $attachment_meta[ $attachment['post_id'] ]['type'] ) ) {
583
  $attachment_meta[ $attachment['post_id'] ]['type'] = $attachment['post_mime_type'];
584
  }
585
  continue;
586
- } elseif ( '_wp_attachment_metadata' == $attachment['meta_key'] ) {
587
  $attachment_meta[ $attachment['post_id'] ]['meta'] = $attachment['meta_value'];
588
  if ( ! empty( $attachment['post_mime_type'] ) && empty( $attachment_meta[ $attachment['post_id'] ]['type'] ) ) {
589
  $attachment_meta[ $attachment['post_id'] ]['type'] = $attachment['post_mime_type'];
590
  }
591
  continue;
592
- } elseif ( 'tiny_compress_images' == $attachment['meta_key'] ) {
593
  $attachment_meta[ $attachment['post_id'] ]['tinypng'] = true;
594
  }
595
  if ( ! empty( $attachment['post_mime_type'] ) && empty( $attachment_meta[ $attachment['post_id'] ]['type'] ) ) {
@@ -743,7 +749,7 @@ function ewww_image_optimizer_media_scan( $hook = '' ) {
743
  ewwwio_debug_message( 'remaining items after selection: ' . count( $attachment_ids ) );
744
  foreach ( $attachment_ids as $selected_id ) {
745
  $attachments_processed++;
746
- if ( 0 == $attachments_processed % 5 && ( microtime( true ) - $started > apply_filters( 'ewww_image_optimizer_timeout', 22 ) || ! ewwwio_check_memory_available( 2194304 ) ) ) {
747
  ewwwio_debug_message( 'time exceeded, or memory exceeded' );
748
  ewww_image_optimizer_debug_log();
749
  if ( defined( 'WP_CLI' ) && WP_CLI ) {
@@ -760,7 +766,7 @@ function ewww_image_optimizer_media_scan( $hook = '' ) {
760
  clearstatcache();
761
  $pending = false;
762
  $remote_file = false;
763
- if ( in_array( $selected_id, $bad_attachments ) ) { // a known broken attachment, which would mean we already tried this once before...
764
  ewwwio_debug_message( "skipping bad attachment $selected_id" );
765
  $skipped_ids[] = $selected_id;
766
  continue;
@@ -798,11 +804,11 @@ function ewww_image_optimizer_media_scan( $hook = '' ) {
798
  ewwwio_debug_message( "missing mime for $selected_id" );
799
  }
800
 
801
- if ( 'application/pdf' != $mime // NOT a pdf...
802
  && ( // AND...
803
  empty( $meta ) // metadata is empty...
804
- || ( is_string( $meta ) && 'processing' == $meta ) // OR the string 'processing'...
805
- || ( is_array( $meta ) && ! empty( $meta[0] ) && 'processing' == $meta[0] ) // OR array( 'processing' ).
806
  )
807
  ) {
808
  // Attempt to rebuild the metadata.
@@ -818,7 +824,7 @@ function ewww_image_optimizer_media_scan( $hook = '' ) {
818
  }
819
  }
820
 
821
- if ( ! in_array( $mime, $enabled_types ) ) {
822
  $skipped_ids[] = $selected_id;
823
  continue;
824
  }
@@ -875,7 +881,7 @@ function ewww_image_optimizer_media_scan( $hook = '' ) {
875
  if ( ! empty( $disabled_sizes[ $size ] ) ) {
876
  continue;
877
  }
878
- if ( ! empty( $disabled_sizes['pdf-full'] ) && 'full' == $size ) {
879
  continue;
880
  }
881
  if ( empty( $data['file'] ) ) {
@@ -889,7 +895,7 @@ function ewww_image_optimizer_media_scan( $hook = '' ) {
889
  $base_dir = trailingslashit( dirname( $file_path ) );
890
  $ims_temp_path = $base_dir . $data['file'];
891
  ewwwio_debug_message( "ims path: $ims_path" );
892
- if ( $file_path != $ims_temp_path && is_array( $optimized_list ) && isset( $optimized_list[ $ims_temp_path ] ) ) {
893
  $optimized_list[ $ims_path ] = $optimized_list[ $ims_temp_path ];
894
  ewwwio_debug_message( "updating record {$optimized_list[ $ims_temp_path ]['id']} with $ims_path" );
895
  // Update our records so that we have the correct path going forward.
@@ -910,13 +916,13 @@ function ewww_image_optimizer_media_scan( $hook = '' ) {
910
  // Check through all the sizes we've processed so far.
911
  foreach ( $processed as $proc => $scan ) {
912
  // If a previous resize had identical dimensions...
913
- if ( $scan['height'] == $data['height'] && $scan['width'] == $data['width'] ) {
914
  // Found a duplicate size, get outta here!
915
  continue( 2 );
916
  }
917
  }
918
  $resize_path = $base_dir . $data['file'];
919
- if ( ( $remote_file || is_file( $resize_path ) ) && 'application/pdf' == $mime && 'full' == $size ) {
920
  $attachment_images[ 'pdf-' . $size ] = $resize_path;
921
  } elseif ( $remote_file || is_file( $resize_path ) ) {
922
  $attachment_images[ $size ] = $resize_path;
@@ -1020,12 +1026,12 @@ function ewww_image_optimizer_media_scan( $hook = '' ) {
1020
  ewww_image_optimizer_debug_log();
1021
  continue;
1022
  }
1023
- if ( 'image/png' == $mime && ewww_image_optimizer_get_option( 'ewww_image_optimizer_skip_png_size' ) && $image_size > ewww_image_optimizer_get_option( 'ewww_image_optimizer_skip_png_size' ) ) {
1024
  ewwwio_debug_message( "file skipped due to PNG filesize: $file_path" );
1025
  ewww_image_optimizer_debug_log();
1026
  continue;
1027
  }
1028
- if ( $already_optimized['image_size'] == $image_size && empty( $_REQUEST['ewww_force'] ) ) {
1029
  ewwwio_debug_message( "match found for $file_path" );
1030
  ewww_image_optimizer_debug_log();
1031
  continue;
@@ -1079,7 +1085,7 @@ function ewww_image_optimizer_media_scan( $hook = '' ) {
1079
  ewww_image_optimizer_debug_log();
1080
  continue;
1081
  }
1082
- if ( 'image/png' == $mime && ewww_image_optimizer_get_option( 'ewww_image_optimizer_skip_png_size' ) && $image_size > ewww_image_optimizer_get_option( 'ewww_image_optimizer_skip_png_size' ) ) {
1083
  ewwwio_debug_message( "file skipped due to PNG filesize: $file_path" );
1084
  ewww_image_optimizer_debug_log();
1085
  continue;
@@ -1135,7 +1141,7 @@ function ewww_image_optimizer_media_scan( $hook = '' ) {
1135
  $attachment_images = array();
1136
  ewwwio_debug_message( 'checking for bad attachment' );
1137
  ewww_image_optimizer_debug_log();
1138
- if ( $selected_id == $bad_attachment ) {
1139
  ewwwio_debug_message( 'found bad attachment, bailing to reset the counter' );
1140
  ewww_image_optimizer_debug_log();
1141
  if ( ! defined( 'WP_CLI' ) || ! WP_CLI ) {
@@ -1180,7 +1186,7 @@ function ewww_image_optimizer_media_scan( $hook = '' ) {
1180
  return;
1181
  }
1182
  $loading_image = plugins_url( '/images/wpspin.gif', __FILE__ );
1183
- $notice = ( 'low_memory' == get_transient( 'ewww_image_optimizer_low_memory_mode' ) ? esc_html__( "Increasing PHP's memory_limit setting will allow for faster scanning with fewer database queries. Please allow up to 10 minutes for changes to memory limit to be detected.", 'ewww-image-optimizer' ) : '' );
1184
  $remaining = ewww_image_optimizer_count_unscanned_attachments();
1185
  if ( $remaining ) {
1186
  ewwwio_ob_clean();
@@ -1241,46 +1247,6 @@ function ewww_image_optimizer_bulk_initialize() {
1241
  session_write_close();
1242
  $output = array();
1243
 
1244
- /*
1245
- $attachments = get_option( 'ewww_image_optimizer_bulk_attachments' );
1246
- if ( ! is_array( $attachments ) && ! empty( $attachments ) ) {
1247
- $attachments = unserialize( $attachments );
1248
- }
1249
- if ( ! is_array( $attachments ) ) {
1250
- // See if we care about the attachment list missing: resizing or converting to be done.
1251
- if ( ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_maxmediawidth' ) ||
1252
- ewww_image_optimizer_get_option( 'ewww_image_optimizer_maxmediaheight' ) ||
1253
- ewww_image_optimizer_get_option( 'ewww_image_optimizer_maxotherwidth' ) ||
1254
- ewww_image_optimizer_get_option( 'ewww_image_optimizer_maxotherheight' ) ||
1255
- ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_to_png' ) ||
1256
- ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_to_jpg' ) ||
1257
- ewww_image_optimizer_get_option( 'ewww_image_optimizer_gif_to_png' ) ) &&
1258
- ewww_image_optimizer_aux_images_table_count_pending_media()
1259
- ) {
1260
- if ( ewww_image_optimizer_function_exists( 'print_r' ) ) {
1261
- ewwwio_ob_clean();
1262
- die(
1263
- ewwwio_json_encode(
1264
- array(
1265
- 'error' => esc_html__( 'Error retrieving list of images', 'ewww-image-optimizer' ),
1266
- 'data' => print_r( $attachments, true ),
1267
- )
1268
- )
1269
- );
1270
- } else {
1271
- ewwwio_ob_clean();
1272
- die(
1273
- ewwwio_json_encode(
1274
- array(
1275
- 'error' => esc_html__( 'Error retrieving list of images', 'ewww-image-optimizer' ),
1276
- 'data' => 'print_r disabled',
1277
- )
1278
- )
1279
- );
1280
- }
1281
- }
1282
- }
1283
- */
1284
  // Update the 'bulk resume' option to show that an operation is in progress.
1285
  update_option( 'ewww_image_optimizer_bulk_resume', 'true' );
1286
  // $attachment = (int) array_shift( $attachments );
@@ -1321,7 +1287,7 @@ function ewww_image_optimizer_bulk_counter_measures( $image ) {
1321
  ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
1322
  if ( ! empty( $_REQUEST['ewww_error_counter'] ) ) {
1323
  $error_counter = (int) $_REQUEST['ewww_error_counter'];
1324
- if ( 30 != $error_counter ) {
1325
  $failed_file = get_transient( 'ewww_image_optimizer_failed_file' );
1326
  $previous_incomplete_file = get_transient( 'ewww_image_optimizer_bulk_current_image' );
1327
  if ( is_array( get_transient( 'ewww_image_optimizer_bulk_counter_measures' ) ) ) {
@@ -1339,11 +1305,11 @@ function ewww_image_optimizer_bulk_counter_measures( $image ) {
1339
  'pdf20' => false,
1340
  );
1341
  }
1342
- if ( $failed_file == $image->file || $previous_incomplete_file == $image->file ) {
1343
  ewwwio_debug_message( "failed file detected, taking evasive action: $failed_file" );
1344
  // Use the constants for temporary overrides, while keeping track of which ones we've used.
1345
- if ( 'image/png' == ewww_image_optimizer_quick_mimetype( $image->file ) ) {
1346
- if ( empty( $previous_countermeasures['png50'] ) && ! defined( 'EWWW_IMAGE_OPTIMIZER_PNG_LEVEL' ) && 50 == ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) ) {
1347
  ewwwio_debug_message( 'png50' );
1348
  // If the file is a PNG and compression is 50, try 40.
1349
  define( 'EWWW_IMAGE_OPTIMIZER_PNG_LEVEL', 40 );
@@ -1363,7 +1329,7 @@ function ewww_image_optimizer_bulk_counter_measures( $image ) {
1363
  }
1364
  $previous_countermeasures['png2jpg'] = true;
1365
  } elseif ( empty( $previous_countermeasures['pngdefaults'] )
1366
- && 10 == ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' )
1367
  && ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_optipng_level' ) > 2
1368
  || ! ewww_image_optimizer_get_option( 'ewww_image_optimizer_disable_pngout' ) )
1369
  ) {
@@ -1383,7 +1349,7 @@ function ewww_image_optimizer_bulk_counter_measures( $image ) {
1383
  if ( ! defined( 'EWWW_IMAGE_OPTIMIZER_PNG_LEVEL' ) && 40 <= ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) ) {
1384
  define( 'EWWW_IMAGE_OPTIMIZER_PNG_LEVEL', 20 );
1385
  }
1386
- if ( 10 == ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) ) {
1387
  if ( ! defined( 'EWWW_IMAGE_OPTIMIZER_OPTIPNG_LEVEL' ) && 2 < ewww_image_optimizer_get_option( 'ewww_image_optimizer_optipng_level' ) ) {
1388
  define( 'EWWW_IMAGE_OPTIMIZER_OPTIPNG_LEVEL', 2 );
1389
  }
@@ -1397,13 +1363,13 @@ function ewww_image_optimizer_bulk_counter_measures( $image ) {
1397
  ewww_image_optimizer_bulk_skip_image( $image );
1398
  } // End if().
1399
  } // End if().
1400
- if ( 'image/jpeg' == ewww_image_optimizer_quick_mimetype( $image->file ) ) {
1401
  if ( empty( $previous_countermeasures['jpg2png'] ) && ! defined( 'EWWW_IMAGE_OPTIMIZER_JPG_TO_PNG' ) && ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_to_png' ) ) {
1402
  ewwwio_debug_message( 'jpg2png' );
1403
  // If the file is a JPG and JPG2PNG is enabled.
1404
  define( 'EWWW_IMAGE_OPTIMIZER_JPG_TO_PNG', false );
1405
  $previous_countermeasures['jpg2png'] = true;
1406
- } elseif ( empty( $previous_countermeasures['jpg40'] ) && ! defined( 'EWWW_IMAGE_OPTIMIZER_JPG_LEVEL' ) && 40 == ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) ) {
1407
  ewwwio_debug_message( 'jpg40' );
1408
  // If the file is a JPG and level 40 is enabled, drop it to 30 (and nuke jpg2png).
1409
  define( 'EWWW_IMAGE_OPTIMIZER_JPG_LEVEL', 30 );
@@ -1415,7 +1381,7 @@ function ewww_image_optimizer_bulk_counter_measures( $image ) {
1415
  ewwwio_debug_message( 'resize_existing' );
1416
  // If resizing is enabled, try to disable it.
1417
  define( 'EWWW_IMAGE_OPTIMIZER_RESIZE_EXISTING', false );
1418
- if ( ! defined( 'EWWW_IMAGE_OPTIMIZER_JPG_LEVEL' ) && 40 == ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) ) {
1419
  define( 'EWWW_IMAGE_OPTIMIZER_JPG_LEVEL', 30 );
1420
  }
1421
  if ( ! defined( 'EWWW_IMAGE_OPTIMIZER_JPG_TO_PNG' ) ) {
@@ -1427,7 +1393,7 @@ function ewww_image_optimizer_bulk_counter_measures( $image ) {
1427
  ewww_image_optimizer_bulk_skip_image( $image );
1428
  }
1429
  }
1430
- if ( 'image/gif' == ewww_image_optimizer_quick_mimetype( $image->file ) ) {
1431
  if ( empty( $previous_countermeasures['gif2png'] ) && ! defined( 'EWWW_IMAGE_OPTIMIZER_GIF_TO_PNG' ) && ewww_image_optimzer_get_option( 'ewww_image_optimizer_gif_to_png' ) ) {
1432
  ewwwio_debug_message( 'gif2png' );
1433
  // If the file is a GIF and GIF2PNG is enabled.
@@ -1438,8 +1404,8 @@ function ewww_image_optimizer_bulk_counter_measures( $image ) {
1438
  ewww_image_optimizer_bulk_skip_image( $image );
1439
  }
1440
  }
1441
- if ( 'application/pdf' == ewww_image_optimizer_quick_mimetype( $image->file ) ) {
1442
- if ( empty( $previous_countermeasures['pdf20'] ) && ! defined( 'EWWW_IMAGE_OPTIMIZER_PDF_LEVEL' ) && 20 == ewww_image_optimzer_get_option( 'ewww_image_optimizer_pdf_level' ) ) {
1443
  ewwwio_debug_message( 'pdf20' );
1444
  // If lossy PDF is enabled, drop it down a notch.
1445
  define( 'EWWW_IMAGE_OPTIMIZER_PDF_LEVEL', 10 );
@@ -1450,7 +1416,6 @@ function ewww_image_optimizer_bulk_counter_measures( $image ) {
1450
  }
1451
  }
1452
  set_transient( 'ewww_image_optimizer_bulk_counter_measures', $previous_countermeasures, 600 );
1453
- // MAYBE:::In any of the cases, output some sort of warning to let the user know we took evasive action, and they might need to adjust their settings.
1454
  } // End if().
1455
  set_transient( 'ewww_image_optimizer_failed_file', $image->file, 600 );
1456
  return $previous_countermeasures;
@@ -1461,6 +1426,7 @@ function ewww_image_optimizer_bulk_counter_measures( $image ) {
1461
  } // End if().
1462
  return false;
1463
  }
 
1464
  /**
1465
  * Called by AJAX to process each image in the queue.
1466
  *
@@ -1544,7 +1510,7 @@ function ewww_image_optimizer_bulk_loop( $hook = '', $delay = 0 ) {
1544
  }
1545
  }
1546
  // If a resize is missing, see if it should (and can) be regenerated.
1547
- if ( $image->resize && 'full' != $image->resize && ! is_file( $image->file ) ) {
1548
  // TODO: Make sure this is optional, because of CDN offloading: resized image does not exist, regenerate it.
1549
  }
1550
  $countermeasures = ewww_image_optimizer_bulk_counter_measures( $image );
@@ -1562,7 +1528,7 @@ function ewww_image_optimizer_bulk_loop( $hook = '', $delay = 0 ) {
1562
  $meta['height'] = $new_dimensions[1];
1563
  }
1564
  }
1565
- list( $file, $msg, $converted, $original ) = ewww_image_optimizer( $image->file, 1, false, false, 'full' == $image->resize );
1566
  // Gotta make sure we don't delete a pending record if the license is exceeded, so the license check goes first.
1567
  $ewww_status = get_transient( 'ewww_image_optimizer_cloud_status' );
1568
  if ( ! empty( $ewww_status ) && preg_match( '/exceeded/', $ewww_status ) ) {
@@ -1584,7 +1550,7 @@ function ewww_image_optimizer_bulk_loop( $hook = '', $delay = 0 ) {
1584
  );
1585
  }
1586
  // If this is a full size image and it was converted.
1587
- if ( 'full' == $image->resize && ( false !== $image->increment || false !== $converted ) ) {
1588
  if ( ! $meta || ! is_array( $meta ) ) {
1589
  $meta = wp_get_attachment_metadata( $image->attachment_id );
1590
  }
@@ -1606,7 +1572,7 @@ function ewww_image_optimizer_bulk_loop( $hook = '', $delay = 0 ) {
1606
  $output['results'] .= "$msg</p>";
1607
 
1608
  // Do metadata update after full-size is processed, usually because of conversion or resizing.
1609
- if ( 'full' == $image->resize && $image->attachment_id ) {
1610
  if ( $meta && is_array( $meta ) ) {
1611
  $meta_saved = wp_update_attachment_metadata( $image->attachment_id, $meta );
1612
  if ( ! $meta_saved ) {
@@ -1619,11 +1585,11 @@ function ewww_image_optimizer_bulk_loop( $hook = '', $delay = 0 ) {
1619
  $next_image = new EWWW_Image( $attachment, 'media' );
1620
 
1621
  // When we finish all the sizes, we want to fire off any filters for plugins that might need to take action when an image is updated.
1622
- if ( $attachment && $attachment != $next_image->attachment_id ) {
1623
  $meta = apply_filters( 'wp_update_attachment_metadata', wp_get_attachment_metadata( $image->attachment_id ), $image->attachment_id );
1624
  }
1625
  // When an image (attachment) is done, pull the next attachment ID off the stack.
1626
- if ( ( 'full' == $next_image->resize || empty( $next_image->resize ) ) && ! empty( $attachment ) && $attachment != $next_image->attachment_id ) {
1627
  ewww_image_optimizer_delete_queued_images( array( $attachment ) );
1628
  $attachment = (int) array_shift( $attachments ); // Pull the first image off the stack.
1629
  if ( ! empty( $attachments ) && is_array( $attachments ) ) {
34
  if ( empty( $resume ) ) {
35
  $fullsize_count = ewww_image_optimizer_count_optimized( 'media' );
36
  $button_text = esc_attr__( 'Start optimizing', 'ewww-image-optimizer' );
37
+ } elseif ( 'scanning' === $resume ) {
38
  $fullsize_count = ewww_image_optimizer_count_optimized( 'media' );
39
  $button_text = esc_attr__( 'Start optimizing', 'ewww-image-optimizer' );
40
  } else {
47
  if ( $fullsize_count < 1 ) {
48
  echo '<p>' . esc_html__( 'You do not appear to have uploaded any images yet.', 'ewww-image-optimizer' ) . '</p>';
49
  } else {
50
+ if ( 'true' === $resume ) {
51
  /* translators: %d: number of images */
52
  echo '<p class="ewww-media-info ewww-bulk-info">' . sprintf( esc_html( _n( 'There is %d image ready to optimize.', 'There are %d images ready to optimize.', $fullsize_count, 'ewww-image-optimizer' ) ), $fullsize_count ) . '</p>';
53
  } else {
63
  ewww_image_optimizer_bulk_action_output( $button_text, $fullsize_count, $resume );
64
  }
65
  // If the 'bulk resume' option was not empty, offer to reset it so the user can start back from the beginning.
66
+ if ( 'true' === $resume ) {
67
  ewww_image_optimizer_bulk_reset_form_output();
68
  }
69
  echo '</div>';
131
  $loading_image = plugins_url( '/images/wpspin.gif', __FILE__ );
132
  /* translators: %d: number of images */
133
  $scanning_starter_message = sprintf( esc_html__( 'Stage 1, %d images left to scan.', 'ewww-image-optimizer' ), $fullsize_count );
134
+ if ( 'true' === $resume ) {
135
  $scan_hide = 'style="display:none"';
136
  $start_hide = '';
137
  } else {
239
  // Get an array of sizes available for the $image.
240
  $sizes = $storage->get_image_sizes();
241
  global $ewwwngg;
242
+ $offset = 0;
243
+ $attachments = $wpdb->get_col( "SELECT meta_data FROM $wpdb->nggpictures $attachment_query LIMIT $offset, $max_query" ); // phpcs:ignore WordPress.DB.PreparedSQL
244
+ while ( $attachments ) {
245
  foreach ( $attachments as $attachment ) {
246
  if ( class_exists( 'Ngg_Serializable' ) ) {
247
  $serializer = new Ngg_Serializable();
281
  }
282
  $attachment_query = 'WHERE pid IN (' . substr( $attachment_query, 0, -1 ) . ')';
283
  }
284
+ $attachments = $wpdb->get_col( "SELECT meta_data FROM $wpdb->nggpictures $attachment_query LIMIT $offset, $max_query" ); // phpcs:ignore WordPress.DB.PreparedSQL
285
  } // End while().
286
  break;
287
  case 'flag':
295
  }
296
  $attachment_query = 'WHERE pid IN (' . substr( $attachment_query, 0, -1 ) . ')';
297
  }
298
+ $offset = 0;
299
+ $attachments = $wpdb->get_col( "SELECT meta_data FROM $wpdb->flagpictures $attachment_query LIMIT $offset, $max_query" ); // phpcs:ignore WordPress.DB.PreparedSQL
300
+ while ( $attachments ) {
301
  foreach ( $attachments as $attachment ) {
302
  $meta = unserialize( $attachment );
303
  if ( ! is_array( $meta ) ) {
331
  }
332
  $attachment_query = 'WHERE pid IN (' . substr( $attachment_query, 0, -1 ) . ')';
333
  }
334
+ $attachments = $wpdb->get_col( "SELECT meta_data FROM $wpdb->flagpictures $attachment_query LIMIT $offset, $max_query" ); // phpcs:ignore WordPress.DB.PreparedSQL
335
  }
336
  break;
337
  } // End switch().
360
  function ewww_image_optimizer_bulk_script( $hook ) {
361
  ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
362
  // Make sure we are being called from the bulk optimization page.
363
+ if ( 'media_page_ewww-image-optimizer-bulk' !== $hook ) {
364
  return;
365
  }
366
  global $wpdb;
402
  $sample_post_type = get_post_type( $ids[0] );
403
  // ewwwio_debug_message( "ids: " . $request_ids[0] ); // keeping just in case.
404
  ewwwio_debug_message( "post type (checking for ims_gallery): $sample_post_type" );
405
+ if ( 'ims_gallery' === $sample_post_type ) {
406
  $attachments = array();
407
  foreach ( $ids as $gid ) {
408
  ewwwio_debug_message( "gallery id: $gid" );
417
  // Unset the 'bulk resume' option since we were given specific IDs to optimize.
418
  update_option( 'ewww_image_optimizer_bulk_resume', '' );
419
  // Check if there is a previous bulk operation to resume.
420
+ } elseif ( 'scanning' === $resume ) {
421
  ewwwio_debug_message( 'scanning, nothing doing' );
422
  // TODO: do nothing...
423
  } elseif ( $scanning || $resume ) {
518
  return;
519
  }
520
  $starting_memory_usage = memory_get_usage( true );
521
+ $already_optimized = $ewwwdb->get_results( "SELECT id,path,image_size,pending,attachment_id,updated FROM $ewwwdb->ewwwio_images LIMIT $offset,$max_query", ARRAY_A );
522
+ while ( $already_optimized ) {
523
  $ewwwdb->flush();
524
  foreach ( $already_optimized as $optimized ) {
525
  $optimized_path = ewww_image_optimizer_absolutize_path( $optimized['path'] );
556
  set_transient( 'ewww_image_optimizer_low_memory_mode', 'large_list', 600 ); // Use low memory mode so that we don't waste lots of time pulling a huge list of images repeatedly.
557
  return;
558
  }
559
+ $already_optimized = $ewwwdb->get_results( "SELECT id,path,image_size,pending,attachment_id,updated FROM $ewwwdb->ewwwio_images LIMIT $offset,$max_query", ARRAY_A );
560
  } // End while().
561
  }
562
 
583
  $wpdb->flush();
584
  $attachment_meta = array();
585
  foreach ( $attachments as $attachment ) {
586
+ if ( '_wp_attached_file' === $attachment['meta_key'] ) {
587
  $attachment_meta[ $attachment['post_id'] ]['_wp_attached_file'] = $attachment['meta_value'];
588
  if ( ! empty( $attachment['post_mime_type'] ) && empty( $attachment_meta[ $attachment['post_id'] ]['type'] ) ) {
589
  $attachment_meta[ $attachment['post_id'] ]['type'] = $attachment['post_mime_type'];
590
  }
591
  continue;
592
+ } elseif ( '_wp_attachment_metadata' === $attachment['meta_key'] ) {
593
  $attachment_meta[ $attachment['post_id'] ]['meta'] = $attachment['meta_value'];
594
  if ( ! empty( $attachment['post_mime_type'] ) && empty( $attachment_meta[ $attachment['post_id'] ]['type'] ) ) {
595
  $attachment_meta[ $attachment['post_id'] ]['type'] = $attachment['post_mime_type'];
596
  }
597
  continue;
598
+ } elseif ( 'tiny_compress_images' === $attachment['meta_key'] ) {
599
  $attachment_meta[ $attachment['post_id'] ]['tinypng'] = true;
600
  }
601
  if ( ! empty( $attachment['post_mime_type'] ) && empty( $attachment_meta[ $attachment['post_id'] ]['type'] ) ) {
749
  ewwwio_debug_message( 'remaining items after selection: ' . count( $attachment_ids ) );
750
  foreach ( $attachment_ids as $selected_id ) {
751
  $attachments_processed++;
752
+ if ( 0 === $attachments_processed % 5 && ( microtime( true ) - $started > apply_filters( 'ewww_image_optimizer_timeout', 22 ) || ! ewwwio_check_memory_available( 2194304 ) ) ) {
753
  ewwwio_debug_message( 'time exceeded, or memory exceeded' );
754
  ewww_image_optimizer_debug_log();
755
  if ( defined( 'WP_CLI' ) && WP_CLI ) {
766
  clearstatcache();
767
  $pending = false;
768
  $remote_file = false;
769
+ if ( in_array( $selected_id, $bad_attachments, true ) ) { // a known broken attachment, which would mean we already tried this once before...
770
  ewwwio_debug_message( "skipping bad attachment $selected_id" );
771
  $skipped_ids[] = $selected_id;
772
  continue;
804
  ewwwio_debug_message( "missing mime for $selected_id" );
805
  }
806
 
807
+ if ( 'application/pdf' !== $mime // NOT a pdf...
808
  && ( // AND...
809
  empty( $meta ) // metadata is empty...
810
+ || ( is_string( $meta ) && 'processing' === $meta ) // OR the string 'processing'...
811
+ || ( is_array( $meta ) && ! empty( $meta[0] ) && 'processing' === $meta[0] ) // OR array( 'processing' ).
812
  )
813
  ) {
814
  // Attempt to rebuild the metadata.
824
  }
825
  }
826
 
827
+ if ( ! in_array( $mime, $enabled_types, true ) ) {
828
  $skipped_ids[] = $selected_id;
829
  continue;
830
  }
881
  if ( ! empty( $disabled_sizes[ $size ] ) ) {
882
  continue;
883
  }
884
+ if ( ! empty( $disabled_sizes['pdf-full'] ) && 'full' === $size ) {
885
  continue;
886
  }
887
  if ( empty( $data['file'] ) ) {
895
  $base_dir = trailingslashit( dirname( $file_path ) );
896
  $ims_temp_path = $base_dir . $data['file'];
897
  ewwwio_debug_message( "ims path: $ims_path" );
898
+ if ( $file_path !== $ims_temp_path && is_array( $optimized_list ) && isset( $optimized_list[ $ims_temp_path ] ) ) {
899
  $optimized_list[ $ims_path ] = $optimized_list[ $ims_temp_path ];
900
  ewwwio_debug_message( "updating record {$optimized_list[ $ims_temp_path ]['id']} with $ims_path" );
901
  // Update our records so that we have the correct path going forward.
916
  // Check through all the sizes we've processed so far.
917
  foreach ( $processed as $proc => $scan ) {
918
  // If a previous resize had identical dimensions...
919
+ if ( $scan['height'] === $data['height'] && $scan['width'] === $data['width'] ) {
920
  // Found a duplicate size, get outta here!
921
  continue( 2 );
922
  }
923
  }
924
  $resize_path = $base_dir . $data['file'];
925
+ if ( ( $remote_file || is_file( $resize_path ) ) && 'application/pdf' === $mime && 'full' === $size ) {
926
  $attachment_images[ 'pdf-' . $size ] = $resize_path;
927
  } elseif ( $remote_file || is_file( $resize_path ) ) {
928
  $attachment_images[ $size ] = $resize_path;
1026
  ewww_image_optimizer_debug_log();
1027
  continue;
1028
  }
1029
+ if ( 'image/png' === $mime && ewww_image_optimizer_get_option( 'ewww_image_optimizer_skip_png_size' ) && $image_size > ewww_image_optimizer_get_option( 'ewww_image_optimizer_skip_png_size' ) ) {
1030
  ewwwio_debug_message( "file skipped due to PNG filesize: $file_path" );
1031
  ewww_image_optimizer_debug_log();
1032
  continue;
1033
  }
1034
+ if ( (int) $already_optimized['image_size'] === (int) $image_size && empty( $_REQUEST['ewww_force'] ) ) {
1035
  ewwwio_debug_message( "match found for $file_path" );
1036
  ewww_image_optimizer_debug_log();
1037
  continue;
1085
  ewww_image_optimizer_debug_log();
1086
  continue;
1087
  }
1088
+ if ( 'image/png' === $mime && ewww_image_optimizer_get_option( 'ewww_image_optimizer_skip_png_size' ) && $image_size > ewww_image_optimizer_get_option( 'ewww_image_optimizer_skip_png_size' ) ) {
1089
  ewwwio_debug_message( "file skipped due to PNG filesize: $file_path" );
1090
  ewww_image_optimizer_debug_log();
1091
  continue;
1141
  $attachment_images = array();
1142
  ewwwio_debug_message( 'checking for bad attachment' );
1143
  ewww_image_optimizer_debug_log();
1144
+ if ( $selected_id === $bad_attachment ) {
1145
  ewwwio_debug_message( 'found bad attachment, bailing to reset the counter' );
1146
  ewww_image_optimizer_debug_log();
1147
  if ( ! defined( 'WP_CLI' ) || ! WP_CLI ) {
1186
  return;
1187
  }
1188
  $loading_image = plugins_url( '/images/wpspin.gif', __FILE__ );
1189
+ $notice = ( 'low_memory' === get_transient( 'ewww_image_optimizer_low_memory_mode' ) ? esc_html__( "Increasing PHP's memory_limit setting will allow for faster scanning with fewer database queries. Please allow up to 10 minutes for changes to memory limit to be detected.", 'ewww-image-optimizer' ) : '' );
1190
  $remaining = ewww_image_optimizer_count_unscanned_attachments();
1191
  if ( $remaining ) {
1192
  ewwwio_ob_clean();
1247
  session_write_close();
1248
  $output = array();
1249
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1250
  // Update the 'bulk resume' option to show that an operation is in progress.
1251
  update_option( 'ewww_image_optimizer_bulk_resume', 'true' );
1252
  // $attachment = (int) array_shift( $attachments );
1287
  ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
1288
  if ( ! empty( $_REQUEST['ewww_error_counter'] ) ) {
1289
  $error_counter = (int) $_REQUEST['ewww_error_counter'];
1290
+ if ( 30 !== $error_counter ) {
1291
  $failed_file = get_transient( 'ewww_image_optimizer_failed_file' );
1292
  $previous_incomplete_file = get_transient( 'ewww_image_optimizer_bulk_current_image' );
1293
  if ( is_array( get_transient( 'ewww_image_optimizer_bulk_counter_measures' ) ) ) {
1305
  'pdf20' => false,
1306
  );
1307
  }
1308
+ if ( $failed_file === $image->file || $previous_incomplete_file === $image->file ) {
1309
  ewwwio_debug_message( "failed file detected, taking evasive action: $failed_file" );
1310
  // Use the constants for temporary overrides, while keeping track of which ones we've used.
1311
+ if ( 'image/png' === ewww_image_optimizer_quick_mimetype( $image->file ) ) {
1312
+ if ( empty( $previous_countermeasures['png50'] ) && ! defined( 'EWWW_IMAGE_OPTIMIZER_PNG_LEVEL' ) && 50 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) ) {
1313
  ewwwio_debug_message( 'png50' );
1314
  // If the file is a PNG and compression is 50, try 40.
1315
  define( 'EWWW_IMAGE_OPTIMIZER_PNG_LEVEL', 40 );
1329
  }
1330
  $previous_countermeasures['png2jpg'] = true;
1331
  } elseif ( empty( $previous_countermeasures['pngdefaults'] )
1332
+ && 10 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' )
1333
  && ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_optipng_level' ) > 2
1334
  || ! ewww_image_optimizer_get_option( 'ewww_image_optimizer_disable_pngout' ) )
1335
  ) {
1349
  if ( ! defined( 'EWWW_IMAGE_OPTIMIZER_PNG_LEVEL' ) && 40 <= ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) ) {
1350
  define( 'EWWW_IMAGE_OPTIMIZER_PNG_LEVEL', 20 );
1351
  }
1352
+ if ( 10 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) ) {
1353
  if ( ! defined( 'EWWW_IMAGE_OPTIMIZER_OPTIPNG_LEVEL' ) && 2 < ewww_image_optimizer_get_option( 'ewww_image_optimizer_optipng_level' ) ) {
1354
  define( 'EWWW_IMAGE_OPTIMIZER_OPTIPNG_LEVEL', 2 );
1355
  }
1363
  ewww_image_optimizer_bulk_skip_image( $image );
1364
  } // End if().
1365
  } // End if().
1366
+ if ( 'image/jpeg' === ewww_image_optimizer_quick_mimetype( $image->file ) ) {
1367
  if ( empty( $previous_countermeasures['jpg2png'] ) && ! defined( 'EWWW_IMAGE_OPTIMIZER_JPG_TO_PNG' ) && ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_to_png' ) ) {
1368
  ewwwio_debug_message( 'jpg2png' );
1369
  // If the file is a JPG and JPG2PNG is enabled.
1370
  define( 'EWWW_IMAGE_OPTIMIZER_JPG_TO_PNG', false );
1371
  $previous_countermeasures['jpg2png'] = true;
1372
+ } elseif ( empty( $previous_countermeasures['jpg40'] ) && ! defined( 'EWWW_IMAGE_OPTIMIZER_JPG_LEVEL' ) && 40 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) ) {
1373
  ewwwio_debug_message( 'jpg40' );
1374
  // If the file is a JPG and level 40 is enabled, drop it to 30 (and nuke jpg2png).
1375
  define( 'EWWW_IMAGE_OPTIMIZER_JPG_LEVEL', 30 );
1381
  ewwwio_debug_message( 'resize_existing' );
1382
  // If resizing is enabled, try to disable it.
1383
  define( 'EWWW_IMAGE_OPTIMIZER_RESIZE_EXISTING', false );
1384
+ if ( ! defined( 'EWWW_IMAGE_OPTIMIZER_JPG_LEVEL' ) && 40 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) ) {
1385
  define( 'EWWW_IMAGE_OPTIMIZER_JPG_LEVEL', 30 );
1386
  }
1387
  if ( ! defined( 'EWWW_IMAGE_OPTIMIZER_JPG_TO_PNG' ) ) {
1393
  ewww_image_optimizer_bulk_skip_image( $image );
1394
  }
1395
  }
1396
+ if ( 'image/gif' === ewww_image_optimizer_quick_mimetype( $image->file ) ) {
1397
  if ( empty( $previous_countermeasures['gif2png'] ) && ! defined( 'EWWW_IMAGE_OPTIMIZER_GIF_TO_PNG' ) && ewww_image_optimzer_get_option( 'ewww_image_optimizer_gif_to_png' ) ) {
1398
  ewwwio_debug_message( 'gif2png' );
1399
  // If the file is a GIF and GIF2PNG is enabled.
1404
  ewww_image_optimizer_bulk_skip_image( $image );
1405
  }
1406
  }
1407
+ if ( 'application/pdf' === ewww_image_optimizer_quick_mimetype( $image->file ) ) {
1408
+ if ( empty( $previous_countermeasures['pdf20'] ) && ! defined( 'EWWW_IMAGE_OPTIMIZER_PDF_LEVEL' ) && 20 === (int) ewww_image_optimzer_get_option( 'ewww_image_optimizer_pdf_level' ) ) {
1409
  ewwwio_debug_message( 'pdf20' );
1410
  // If lossy PDF is enabled, drop it down a notch.
1411
  define( 'EWWW_IMAGE_OPTIMIZER_PDF_LEVEL', 10 );
1416
  }
1417
  }
1418
  set_transient( 'ewww_image_optimizer_bulk_counter_measures', $previous_countermeasures, 600 );
 
1419
  } // End if().
1420
  set_transient( 'ewww_image_optimizer_failed_file', $image->file, 600 );
1421
  return $previous_countermeasures;
1426
  } // End if().
1427
  return false;
1428
  }
1429
+
1430
  /**
1431
  * Called by AJAX to process each image in the queue.
1432
  *
1510
  }
1511
  }
1512
  // If a resize is missing, see if it should (and can) be regenerated.
1513
+ if ( $image->resize && 'full' !== $image->resize && ! is_file( $image->file ) ) {
1514
  // TODO: Make sure this is optional, because of CDN offloading: resized image does not exist, regenerate it.
1515
  }
1516
  $countermeasures = ewww_image_optimizer_bulk_counter_measures( $image );
1528
  $meta['height'] = $new_dimensions[1];
1529
  }
1530
  }
1531
+ list( $file, $msg, $converted, $original ) = ewww_image_optimizer( $image->file, 1, false, false, 'full' === $image->resize );
1532
  // Gotta make sure we don't delete a pending record if the license is exceeded, so the license check goes first.
1533
  $ewww_status = get_transient( 'ewww_image_optimizer_cloud_status' );
1534
  if ( ! empty( $ewww_status ) && preg_match( '/exceeded/', $ewww_status ) ) {
1550
  );
1551
  }
1552
  // If this is a full size image and it was converted.
1553
+ if ( 'full' === $image->resize && ( false !== $image->increment || false !== $converted ) ) {
1554
  if ( ! $meta || ! is_array( $meta ) ) {
1555
  $meta = wp_get_attachment_metadata( $image->attachment_id );
1556
  }
1572
  $output['results'] .= "$msg</p>";
1573
 
1574
  // Do metadata update after full-size is processed, usually because of conversion or resizing.
1575
+ if ( 'full' === $image->resize && $image->attachment_id ) {
1576
  if ( $meta && is_array( $meta ) ) {
1577
  $meta_saved = wp_update_attachment_metadata( $image->attachment_id, $meta );
1578
  if ( ! $meta_saved ) {
1585
  $next_image = new EWWW_Image( $attachment, 'media' );
1586
 
1587
  // When we finish all the sizes, we want to fire off any filters for plugins that might need to take action when an image is updated.
1588
+ if ( $attachment && (int) $attachment !== (int) $next_image->attachment_id ) {
1589
  $meta = apply_filters( 'wp_update_attachment_metadata', wp_get_attachment_metadata( $image->attachment_id ), $image->attachment_id );
1590
  }
1591
  // When an image (attachment) is done, pull the next attachment ID off the stack.
1592
+ if ( ( 'full' === $next_image->resize || empty( $next_image->resize ) ) && ! empty( $attachment ) && (int) $attachment !== (int) $next_image->attachment_id ) {
1593
  ewww_image_optimizer_delete_queued_images( array( $attachment ) );
1594
  $attachment = (int) array_shift( $attachments ); // Pull the first image off the stack.
1595
  if ( ! empty( $attachments ) && is_array( $attachments ) ) {
changelog.txt CHANGED
@@ -1,3 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
1
  = 4.7.2 =
2
  * changed: JS WebP no longer necessary with ExactDN
3
  * fixed: fatal error from NextGEN get_image_sizes() method
1
+ = 4.7.3 =
2
+ * added: disable WebP script block on certain pages by defining EWWW_IMAGE_OPTIMIZER_NO_JS as true
3
+ * changed: use SVG inline image placeholder if width and height are known when LQIP is disabled or ExactDN is not available
4
+ * changed: Lazy Load ignores images using browser-native loading attribute
5
+ * fixed: page parsers (ExactDN, Lazy, JS WebP) do not properly handle attributes that start on a new line
6
+ * fixed: page parsers do not recognize img elements with unquoted attributes
7
+ * fixed: uninstaller cannot clear queue table due to undefined table name
8
+ * fixed: implode throws notice when image sizes array is multi-dimensional
9
+ * fixed: srcset url replaced incorrectly when using pixel density descriptors
10
+ * fixed: srcset url added with 0 width when width attribute is empty
11
+
12
  = 4.7.2 =
13
  * changed: JS WebP no longer necessary with ExactDN
14
  * fixed: fatal error from NextGEN get_image_sizes() method
classes/class-ewww-flag.php CHANGED
@@ -181,15 +181,15 @@ if ( ! class_exists( 'EWWW_Flag' ) ) {
181
  function ewww_flag_bulk_script( $hook ) {
182
  ewwwio_debug_message( '<b>' . __METHOD__ . '()</b>' );
183
  // Make sure we are being hooked from a valid location.
184
- if ( 'flagallery_page_flag-bulk-optimize' != $hook && 'flagallery_page_flag-manage-gallery' != $hook ) {
185
  return;
186
  }
187
  // If there is no requested bulk action, do nothing.
188
- if ( 'flagallery_page_flag-manage-gallery' == $hook && ( empty( $_REQUEST['bulkaction'] ) || ! preg_match( '/^bulk_optimize/', $_REQUEST['bulkaction'] ) ) ) {
189
  return;
190
  }
191
  // If there is no media to optimize, do nothing.
192
- if ( 'flagallery_page_flag-manage-gallery' == $hook && ( empty( $_REQUEST['doaction'] ) || ! is_array( $_REQUEST['doaction'] ) ) ) {
193
  return;
194
  }
195
  $ids = null;
@@ -203,7 +203,7 @@ if ( ! class_exists( 'EWWW_Flag' ) ) {
203
  if ( ! empty( $_REQUEST['doaction'] ) ) {
204
  ewwwio_debug_message( 'possible batch image request' );
205
  // See if the bulk operation requested is from the manage images page.
206
- if ( 'manage-images' == $_REQUEST['page'] && 'bulk_optimize_images' == $_REQUEST['bulkaction'] ) {
207
  // Check the referring page and nonce.
208
  check_admin_referer( 'flag_updategallery' );
209
  // We don't allow previous operations to resume if the user is asking to optimize specific images.
@@ -213,7 +213,7 @@ if ( ! class_exists( 'EWWW_Flag' ) ) {
213
  ewwwio_debug_message( 'batch image request from image list' );
214
  }
215
  // See if the bulk operation requested is from the manage galleries page.
216
- if ( 'manage-galleries' == $_REQUEST['page'] && 'bulk_optimize_galleries' == $_REQUEST['bulkaction'] ) {
217
  // Check the referring page and nonce.
218
  check_admin_referer( 'flag_bulkgallery' );
219
  global $flagdb;
@@ -234,7 +234,7 @@ if ( ! class_exists( 'EWWW_Flag' ) ) {
234
  } elseif ( ! empty( $resume ) ) {
235
  // If there is an operation to resume, get those IDs from the db.
236
  $ids = get_option( 'ewww_image_optimizer_bulk_flag_attachments' );
237
- } elseif ( 'flagallery_page_flag-bulk-optimize' == $hook ) {
238
  // Otherwise, if we are on the main bulk optimize page, just get all the IDs available.
239
  global $wpdb;
240
  $ids = $wpdb->get_col( "SELECT pid FROM $wpdb->flagpictures ORDER BY sortorder ASC" );
@@ -636,7 +636,7 @@ if ( ! class_exists( 'EWWW_Flag' ) ) {
636
  */
637
  function ewww_flag_manual_actions_script( $hook ) {
638
  ewwwio_debug_message( '<b>' . __METHOD__ . '()</b>' );
639
- if ( 'flagallery_page_flag-manage-gallery' != $hook ) {
640
  return;
641
  }
642
  if ( ! current_user_can( apply_filters( 'ewww_image_optimizer_manual_permissions', '' ) ) ) {
@@ -781,7 +781,7 @@ if ( ! class_exists( 'EWWW_Flag' ) ) {
781
  */
782
  function ewww_manage_image_custom_column_wrapper( $column_name, $id ) {
783
  // Check to make sure we're outputing our custom column.
784
- if ( 'ewww_image_optimizer' == $column_name ) {
785
  echo $this->ewww_manage_image_custom_column( $id );
786
  }
787
  }
181
  function ewww_flag_bulk_script( $hook ) {
182
  ewwwio_debug_message( '<b>' . __METHOD__ . '()</b>' );
183
  // Make sure we are being hooked from a valid location.
184
+ if ( 'flagallery_page_flag-bulk-optimize' !== $hook && 'flagallery_page_flag-manage-gallery' !== $hook ) {
185
  return;
186
  }
187
  // If there is no requested bulk action, do nothing.
188
+ if ( 'flagallery_page_flag-manage-gallery' === $hook && ( empty( $_REQUEST['bulkaction'] ) || 0 === strpos( $_REQUEST['bulkaction'], 'bulk_optimize' ) ) ) {
189
  return;
190
  }
191
  // If there is no media to optimize, do nothing.
192
+ if ( 'flagallery_page_flag-manage-gallery' === $hook && ( empty( $_REQUEST['doaction'] ) || ! is_array( $_REQUEST['doaction'] ) ) ) {
193
  return;
194
  }
195
  $ids = null;
203
  if ( ! empty( $_REQUEST['doaction'] ) ) {
204
  ewwwio_debug_message( 'possible batch image request' );
205
  // See if the bulk operation requested is from the manage images page.
206
+ if ( 'manage-images' === $_REQUEST['page'] && 'bulk_optimize_images' === $_REQUEST['bulkaction'] ) {
207
  // Check the referring page and nonce.
208
  check_admin_referer( 'flag_updategallery' );
209
  // We don't allow previous operations to resume if the user is asking to optimize specific images.
213
  ewwwio_debug_message( 'batch image request from image list' );
214
  }
215
  // See if the bulk operation requested is from the manage galleries page.
216
+ if ( 'manage-galleries' === $_REQUEST['page'] && 'bulk_optimize_galleries' === $_REQUEST['bulkaction'] ) {
217
  // Check the referring page and nonce.
218
  check_admin_referer( 'flag_bulkgallery' );
219
  global $flagdb;
234
  } elseif ( ! empty( $resume ) ) {
235
  // If there is an operation to resume, get those IDs from the db.
236
  $ids = get_option( 'ewww_image_optimizer_bulk_flag_attachments' );
237
+ } elseif ( 'flagallery_page_flag-bulk-optimize' === $hook ) {
238
  // Otherwise, if we are on the main bulk optimize page, just get all the IDs available.
239
  global $wpdb;
240
  $ids = $wpdb->get_col( "SELECT pid FROM $wpdb->flagpictures ORDER BY sortorder ASC" );
636
  */
637
  function ewww_flag_manual_actions_script( $hook ) {
638
  ewwwio_debug_message( '<b>' . __METHOD__ . '()</b>' );
639
+ if ( 'flagallery_page_flag-manage-gallery' !== $hook ) {
640
  return;
641
  }
642
  if ( ! current_user_can( apply_filters( 'ewww_image_optimizer_manual_permissions', '' ) ) ) {
781
  */
782
  function ewww_manage_image_custom_column_wrapper( $column_name, $id ) {
783
  // Check to make sure we're outputing our custom column.
784
+ if ( 'ewww_image_optimizer' === $column_name ) {
785
  echo $this->ewww_manage_image_custom_column( $id );
786
  }
787
  }
classes/class-ewww-image.php CHANGED
@@ -130,12 +130,12 @@ class EWWW_Image {
130
  $this->orig_size = filesize( $path );
131
  $this->gallery = $gallery;
132
  if ( $id ) {
133
- $this->attachment_id = $id;
134
  }
135
  return;
136
  } elseif ( is_array( $new_image ) ) {
137
  if ( $id && empty( $new_image['attachment_id'] ) ) {
138
- $new_image['attachment_id'] = $id;
139
  }
140
  if ( $gallery && empty( $new_image['gallery'] ) ) {
141
  $new_image['gallery'] = $gallery;
@@ -174,13 +174,14 @@ class EWWW_Image {
174
  }
175
  $this->id = $new_image['id'];
176
  $this->file = ewww_image_optimizer_absolutize_path( $new_image['path'] );
177
- $this->attachment_id = $new_image['attachment_id'];
178
- $this->opt_size = $new_image['image_size'];
179
- $this->orig_size = $new_image['orig_size'];
180
  $this->resize = $new_image['resize'];
181
  $this->converted = ewww_image_optimizer_absolutize_path( $new_image['converted'] );
182
  $this->gallery = ( empty( $gallery ) ? $new_image['gallery'] : $gallery );
183
  $this->backup = $new_image['backup'];
 
184
  $this->record = $new_image;
185
  }
186
 
@@ -244,7 +245,7 @@ class EWWW_Image {
244
  $sizes_queried = $ewwwdb->get_results( "SELECT * FROM $ewwwdb->ewwwio_images WHERE attachment_id = $this->attachment_id AND resize <> 'full' AND resize <> ''", ARRAY_A );
245
  /* ewwwio_debug_message( 'found some images in the db: ' . count( $sizes_queried ) ); */
246
  $sizes = array();
247
- if ( 'ims_image' == get_post_type( $this->attachment_id ) ) {
248
  $base_dir = trailingslashit( dirname( $this->file ) ) . '_resized/';
249
  } else {
250
  $base_dir = trailingslashit( dirname( $this->file ) );
@@ -305,7 +306,7 @@ class EWWW_Image {
305
  if ( empty( $done['height'] ) || empty( $done['width'] ) ) {
306
  continue;
307
  }
308
- if ( $data['height'] == $done['height'] && $data['width'] == $done['width'] ) {
309
  continue( 2 );
310
  }
311
  }
@@ -440,7 +441,7 @@ class EWWW_Image {
440
  // Look for any 'duplicate' sizes that have the same dimensions as the current queried size.
441
  if ( isset( $meta['sizes'] ) && ewww_image_optimizer_iterable( $meta['sizes'] ) ) {
442
  foreach ( $meta['sizes'] as $size => $data ) {
443
- if ( $meta['sizes'][ $size_queried['resize'] ]['height'] == $data['height'] && $meta['sizes'][ $size_queried['resize'] ]['width'] == $data['width'] ) {
444
  $meta['sizes'][ $size ]['file'] = $meta['sizes'][ $size_queried['resize'] ]['file'];
445
  $meta['sizes'][ $size ]['mime-type'] = $meta['sizes'][ $size_queried['resize'] ]['mime-type'];
446
  }
@@ -539,17 +540,17 @@ class EWWW_Image {
539
  }
540
  ewwwio_debug_message( "converted PNG size: $png_size" );
541
  // If the PNG exists, and we didn't end up with an empty file.
542
- if ( ! $check_size && $png_size && is_file( $newfile ) && ewww_image_optimizer_mimetype( $newfile, 'i' ) == 'image/png' ) {
543
  ewwwio_debug_message( 'JPG to PNG successful' );
544
  // Check to see if the user wants the originals deleted.
545
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_delete_originals' ) == true ) {
546
  // Delete the original JPG.
547
  unlink( $file );
548
  }
549
- } elseif ( $check_size && is_file( $newfile ) && $png_size < ewww_image_optimizer_filesize( $file ) && ewww_image_optimizer_mimetype( $newfile, 'i' ) == 'image/png' ) {
550
  ewwwio_debug_message( 'JPG to PNG successful, after comparing size' );
551
  // Check to see if the user wants the originals deleted.
552
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_delete_originals' ) == true ) {
553
  // Delete the original JPG.
554
  unlink( $file );
555
  }
@@ -644,17 +645,17 @@ class EWWW_Image {
644
  }
645
  ewwwio_debug_message( "converted JPG size: $jpg_size" );
646
  // If the new JPG is smaller than the original PNG.
647
- if ( ! $check_size && $jpg_size && is_file( $newfile ) && ewww_image_optimizer_mimetype( $newfile, 'i' ) == 'image/jpeg' ) {
648
  ewwwio_debug_message( 'JPG to PNG successful' );
649
  // If the user wants originals delted after a conversion.
650
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_delete_originals' ) == true ) {
651
  // Delete the original PNG.
652
  unlink( $file );
653
  }
654
- } elseif ( $check_size && is_file( $newfile ) && $jpg_size < ewww_image_optimizer_filesize( $file ) && ewww_image_optimizer_mimetype( $newfile, 'i' ) == 'image/jpeg' ) {
655
  ewwwio_debug_message( 'PNG to JPG successful, after comparing size' );
656
  // If the user wants originals delted after a conversion.
657
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_delete_originals' ) == true ) {
658
  // Delete the original PNG.
659
  unlink( $file );
660
  }
@@ -700,17 +701,17 @@ class EWWW_Image {
700
  }
701
  ewwwio_debug_message( "converted PNG size: $png_size" );
702
  // If the PNG exists, and we didn't end up with an empty file.
703
- if ( ! $check_size && $png_size && is_file( $newfile ) && ewww_image_optimizer_mimetype( $newfile, 'i' ) == 'image/png' ) {
704
  ewwwio_debug_message( 'GIF to PNG successful' );
705
  // Check to see if the user wants the originals deleted.
706
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_delete_originals' ) == true ) {
707
  // Delete the original JPG.
708
  unlink( $file );
709
  }
710
- } elseif ( $check_size && is_file( $newfile ) && $png_size < ewww_image_optimizer_filesize( $file ) && ewww_image_optimizer_mimetype( $newfile, 'i' ) == 'image/png' ) {
711
  ewwwio_debug_message( 'GIF to PNG successful, after comparing size' );
712
  // Check to see if the user wants the originals deleted.
713
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_delete_originals' ) == true ) {
714
  // Delete the original JPG.
715
  unlink( $file );
716
  }
@@ -801,7 +802,7 @@ class EWWW_Image {
801
  // Construct the new guid based on the filename from the attachment metadata.
802
  ewwwio_debug_message( "old guid: $old_guid" );
803
  ewwwio_debug_message( "new guid: $guid" );
804
- if ( substr( $old_guid, -1 ) == '/' || substr( $guid, -1 ) == '/' ) {
805
  ewwwio_debug_message( 'could not obtain full url for current and previous image, bailing' );
806
  return;
807
  }
@@ -958,37 +959,37 @@ class EWWW_Image {
958
  $time += 20;
959
  } elseif ( $image_size > 5000000 ) { // greater than 5MB.
960
  $time += 10;
961
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) == 40 ) {
962
  $time += 25;
963
- } elseif ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) == 30 ) {
964
  $time += 7;
965
- } elseif ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) == 20 ) {
966
  $time += 2;
967
  }
968
  } elseif ( $image_size > 1000000 ) { // greater than 1MB.
969
  $time += 5;
970
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) == 40 ) {
971
  if ( $image_size > 2000000 ) { // greater than 2MB.
972
  $time += 15;
973
  } else {
974
  $time += 11;
975
  }
976
- } elseif ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) == 30 ) {
977
  $time += 6;
978
- } elseif ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) == 20 ) {
979
  $time += 2;
980
  }
981
  } else {
982
  $time++;
983
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) == 40 ) {
984
  if ( $image_size > 200000 ) { // greater than 200k.
985
  $time += 11;
986
  } else {
987
  $time += 5;
988
  }
989
- } elseif ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) == 30 ) {
990
  $time += 3;
991
- } elseif ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) == 20 ) {
992
  $time += 3;
993
  }
994
  } // End if().
@@ -1001,53 +1002,53 @@ class EWWW_Image {
1001
  $time += 35;
1002
  } elseif ( $image_size > 1000000 ) { // greater than 1MB.
1003
  $time += 15;
1004
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) == 50 ) {
1005
  $time += 8;
1006
- } elseif ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) == 40 ) {
1007
  /* $time++; */
1008
- } elseif ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) == 30 ) {
1009
  $time += 10;
1010
- } elseif ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) == 20 ) {
1011
  $time++;
1012
  }
1013
  } elseif ( $image_size > 500000 ) { // greater than 500kb.
1014
  $time += 7;
1015
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) == 50 ) {
1016
  $time += 5;
1017
- } elseif ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) == 40 ) {
1018
  /* $time++; */
1019
- } elseif ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) == 30 ) {
1020
  $time += 8;
1021
- } elseif ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) == 20 ) {
1022
  $time++;
1023
  }
1024
  } elseif ( $image_size > 100000 ) { // greater than 100kb.
1025
  $time += 4;
1026
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) == 50 ) {
1027
  $time += 5;
1028
- } elseif ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) == 40 ) {
1029
  /* $time++; */
1030
- } elseif ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) == 30 ) {
1031
  $time += 9;
1032
- } elseif ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) == 20 ) {
1033
  $time++;
1034
  }
1035
  } else {
1036
  $time++;
1037
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) == 50 ) {
1038
  $time += 2;
1039
- } elseif ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) == 40 ) {
1040
  $time ++;
1041
- } elseif ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) == 30 ) {
1042
  $time += 3;
1043
- } elseif ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) == 20 ) {
1044
  $time++;
1045
  }
1046
  } // End if().
1047
  break;
1048
  case 'image/gif':
1049
  $time++;
1050
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_gif_level' ) == 10 && ewww_image_optimizer_get_option( 'ewww_image_optimizer_cloud_key' ) ) {
1051
  $time++;
1052
  }
1053
  if ( $image_size > 1000000 ) { // greater than 1MB.
@@ -1060,22 +1061,22 @@ class EWWW_Image {
1060
  }
1061
  if ( $image_size > 25000000 ) { // greater than 25MB.
1062
  $time += 20;
1063
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_pdf_level' ) == 20 ) {
1064
  $time += 16;
1065
  }
1066
  } elseif ( $image_size > 10000000 ) { // greater than 10MB.
1067
  $time += 10;
1068
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_pdf_level' ) == 20 ) {
1069
  $time += 20;
1070
  }
1071
  } elseif ( $image_size > 4000000 ) { // greater than 4MB.
1072
  $time += 3;
1073
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_pdf_level' ) == 20 ) {
1074
  $time += 12;
1075
  }
1076
  } elseif ( $image_size > 1000000 ) { // greater than 1MB.
1077
  $time++;
1078
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_pdf_level' ) == 20 ) {
1079
  $time += 10;
1080
  }
1081
  }
130
  $this->orig_size = filesize( $path );
131
  $this->gallery = $gallery;
132
  if ( $id ) {
133
+ $this->attachment_id = (int) $id;
134
  }
135
  return;
136
  } elseif ( is_array( $new_image ) ) {
137
  if ( $id && empty( $new_image['attachment_id'] ) ) {
138
+ $new_image['attachment_id'] = (int) $id;
139
  }
140
  if ( $gallery && empty( $new_image['gallery'] ) ) {
141
  $new_image['gallery'] = $gallery;
174
  }
175
  $this->id = $new_image['id'];
176
  $this->file = ewww_image_optimizer_absolutize_path( $new_image['path'] );
177
+ $this->attachment_id = (int) $new_image['attachment_id'];
178
+ $this->opt_size = (int) $new_image['image_size'];
179
+ $this->orig_size = (int) $new_image['orig_size'];
180
  $this->resize = $new_image['resize'];
181
  $this->converted = ewww_image_optimizer_absolutize_path( $new_image['converted'] );
182
  $this->gallery = ( empty( $gallery ) ? $new_image['gallery'] : $gallery );
183
  $this->backup = $new_image['backup'];
184
+ $this->level = (int) $new_image['level'];
185
  $this->record = $new_image;
186
  }
187
 
245
  $sizes_queried = $ewwwdb->get_results( "SELECT * FROM $ewwwdb->ewwwio_images WHERE attachment_id = $this->attachment_id AND resize <> 'full' AND resize <> ''", ARRAY_A );
246
  /* ewwwio_debug_message( 'found some images in the db: ' . count( $sizes_queried ) ); */
247
  $sizes = array();
248
+ if ( 'ims_image' === get_post_type( $this->attachment_id ) ) {
249
  $base_dir = trailingslashit( dirname( $this->file ) ) . '_resized/';
250
  } else {
251
  $base_dir = trailingslashit( dirname( $this->file ) );
306
  if ( empty( $done['height'] ) || empty( $done['width'] ) ) {
307
  continue;
308
  }
309
+ if ( $data['height'] === $done['height'] && $data['width'] === $done['width'] ) {
310
  continue( 2 );
311
  }
312
  }
441
  // Look for any 'duplicate' sizes that have the same dimensions as the current queried size.
442
  if ( isset( $meta['sizes'] ) && ewww_image_optimizer_iterable( $meta['sizes'] ) ) {
443
  foreach ( $meta['sizes'] as $size => $data ) {
444
+ if ( $meta['sizes'][ $size_queried['resize'] ]['height'] === $data['height'] && $meta['sizes'][ $size_queried['resize'] ]['width'] === $data['width'] ) {
445
  $meta['sizes'][ $size ]['file'] = $meta['sizes'][ $size_queried['resize'] ]['file'];
446
  $meta['sizes'][ $size ]['mime-type'] = $meta['sizes'][ $size_queried['resize'] ]['mime-type'];
447
  }
540
  }
541
  ewwwio_debug_message( "converted PNG size: $png_size" );
542
  // If the PNG exists, and we didn't end up with an empty file.
543
+ if ( ! $check_size && $png_size && is_file( $newfile ) && ewww_image_optimizer_mimetype( $newfile, 'i' ) === 'image/png' ) {
544
  ewwwio_debug_message( 'JPG to PNG successful' );
545
  // Check to see if the user wants the originals deleted.
546
+ if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_delete_originals' ) ) {
547
  // Delete the original JPG.
548
  unlink( $file );
549
  }
550
+ } elseif ( $check_size && is_file( $newfile ) && $png_size < ewww_image_optimizer_filesize( $file ) && ewww_image_optimizer_mimetype( $newfile, 'i' ) === 'image/png' ) {
551
  ewwwio_debug_message( 'JPG to PNG successful, after comparing size' );
552
  // Check to see if the user wants the originals deleted.
553
+ if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_delete_originals' ) ) {
554
  // Delete the original JPG.
555
  unlink( $file );
556
  }
645
  }
646
  ewwwio_debug_message( "converted JPG size: $jpg_size" );
647
  // If the new JPG is smaller than the original PNG.
648
+ if ( ! $check_size && $jpg_size && is_file( $newfile ) && ewww_image_optimizer_mimetype( $newfile, 'i' ) === 'image/jpeg' ) {
649
  ewwwio_debug_message( 'JPG to PNG successful' );
650
  // If the user wants originals delted after a conversion.
651
+ if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_delete_originals' ) ) {
652
  // Delete the original PNG.
653
  unlink( $file );
654
  }
655
+ } elseif ( $check_size && is_file( $newfile ) && $jpg_size < ewww_image_optimizer_filesize( $file ) && ewww_image_optimizer_mimetype( $newfile, 'i' ) === 'image/jpeg' ) {
656
  ewwwio_debug_message( 'PNG to JPG successful, after comparing size' );
657
  // If the user wants originals delted after a conversion.
658
+ if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_delete_originals' ) ) {
659
  // Delete the original PNG.
660
  unlink( $file );
661
  }
701
  }
702
  ewwwio_debug_message( "converted PNG size: $png_size" );
703
  // If the PNG exists, and we didn't end up with an empty file.
704
+ if ( ! $check_size && $png_size && is_file( $newfile ) && ewww_image_optimizer_mimetype( $newfile, 'i' ) === 'image/png' ) {
705
  ewwwio_debug_message( 'GIF to PNG successful' );
706
  // Check to see if the user wants the originals deleted.
707
+ if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_delete_originals' ) ) {
708
  // Delete the original JPG.
709
  unlink( $file );
710
  }
711
+ } elseif ( $check_size && is_file( $newfile ) && $png_size < ewww_image_optimizer_filesize( $file ) && ewww_image_optimizer_mimetype( $newfile, 'i' ) === 'image/png' ) {
712
  ewwwio_debug_message( 'GIF to PNG successful, after comparing size' );
713
  // Check to see if the user wants the originals deleted.
714
+ if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_delete_originals' ) ) {
715
  // Delete the original JPG.
716
  unlink( $file );
717
  }
802
  // Construct the new guid based on the filename from the attachment metadata.
803
  ewwwio_debug_message( "old guid: $old_guid" );
804
  ewwwio_debug_message( "new guid: $guid" );
805
+ if ( substr( $old_guid, -1 ) === '/' || substr( $guid, -1 ) === '/' ) {
806
  ewwwio_debug_message( 'could not obtain full url for current and previous image, bailing' );
807
  return;
808
  }
959
  $time += 20;
960
  } elseif ( $image_size > 5000000 ) { // greater than 5MB.
961
  $time += 10;
962
+ if ( 40 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) ) {
963
  $time += 25;
964
+ } elseif ( 30 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) ) {
965
  $time += 7;
966
+ } elseif ( 20 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) ) {
967
  $time += 2;
968
  }
969
  } elseif ( $image_size > 1000000 ) { // greater than 1MB.
970
  $time += 5;
971
+ if ( 40 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) ) {
972
  if ( $image_size > 2000000 ) { // greater than 2MB.
973
  $time += 15;
974
  } else {
975
  $time += 11;
976
  }
977
+ } elseif ( 30 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) ) {
978
  $time += 6;
979
+ } elseif ( 20 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) ) {
980
  $time += 2;
981
  }
982
  } else {
983
  $time++;
984
+ if ( 40 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) ) {
985
  if ( $image_size > 200000 ) { // greater than 200k.
986
  $time += 11;
987
  } else {
988
  $time += 5;
989
  }
990
+ } elseif ( 30 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) ) {
991
  $time += 3;
992
+ } elseif ( 20 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) ) {
993
  $time += 3;
994
  }
995
  } // End if().
1002
  $time += 35;
1003
  } elseif ( $image_size > 1000000 ) { // greater than 1MB.
1004
  $time += 15;
1005
+ if ( 50 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) ) {
1006
  $time += 8;
1007
+ } elseif ( 40 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) ) {
1008
  /* $time++; */
1009
+ } elseif ( 30 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) ) {
1010
  $time += 10;
1011
+ } elseif ( 20 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) ) {
1012
  $time++;
1013
  }
1014
  } elseif ( $image_size > 500000 ) { // greater than 500kb.
1015
  $time += 7;
1016
+ if ( 50 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) ) {
1017
  $time += 5;
1018
+ } elseif ( 40 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) ) {
1019
  /* $time++; */
1020
+ } elseif ( 30 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) ) {
1021
  $time += 8;
1022
+ } elseif ( 20 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) ) {
1023
  $time++;
1024
  }
1025
  } elseif ( $image_size > 100000 ) { // greater than 100kb.
1026
  $time += 4;
1027
+ if ( 50 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) ) {
1028
  $time += 5;
1029
+ } elseif ( 40 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) ) {
1030
  /* $time++; */
1031
+ } elseif ( 30 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) ) {
1032
  $time += 9;
1033
+ } elseif ( 20 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) ) {
1034
  $time++;
1035
  }
1036
  } else {
1037
  $time++;
1038
+ if ( 50 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) ) {
1039
  $time += 2;
1040
+ } elseif ( 40 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) ) {
1041
  $time ++;
1042
+ } elseif ( 30 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) ) {
1043
  $time += 3;
1044
+ } elseif ( 20 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) ) {
1045
  $time++;
1046
  }
1047
  } // End if().
1048
  break;
1049
  case 'image/gif':
1050
  $time++;
1051
+ if ( 10 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_gif_level' ) && ewww_image_optimizer_get_option( 'ewww_image_optimizer_cloud_key' ) ) {
1052
  $time++;
1053
  }
1054
  if ( $image_size > 1000000 ) { // greater than 1MB.
1061
  }
1062
  if ( $image_size > 25000000 ) { // greater than 25MB.
1063
  $time += 20;
1064
+ if ( 20 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_pdf_level' ) ) {
1065
  $time += 16;
1066
  }
1067
  } elseif ( $image_size > 10000000 ) { // greater than 10MB.
1068
  $time += 10;
1069
+ if ( 20 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_pdf_level' ) ) {
1070
  $time += 20;
1071
  }
1072
  } elseif ( $image_size > 4000000 ) { // greater than 4MB.
1073
  $time += 3;
1074
+ if ( 20 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_pdf_level' ) ) {
1075
  $time += 12;
1076
  }
1077
  } elseif ( $image_size > 1000000 ) { // greater than 1MB.
1078
  $time++;
1079
+ if ( 20 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_pdf_level' ) ) {
1080
  $time += 10;
1081
  }
1082
  }
classes/class-ewww-nextcellent.php CHANGED
@@ -288,7 +288,7 @@ if ( ! class_exists( 'EWWW_Nextcellent' ) ) {
288
  */
289
  function ewww_manage_image_custom_column( $column_name, $id, $return = false ) {
290
  // Once we've found our custom column.
291
- if ( 'ewww_image_optimizer' == $column_name ) {
292
  // Need this file to work with metadata.
293
  require_once( WP_CONTENT_DIR . '/plugins/nextcellent-gallery-nextgen-legacy/lib/meta.php' );
294
  // Get the metadata for the image.
@@ -494,13 +494,13 @@ if ( ! class_exists( 'EWWW_Nextcellent' ) ) {
494
  $i18ngg = strtolower( __( 'Galleries', 'nggallery' ) );
495
  ewwwio_debug_message( "i18n string for galleries: $i18ngg" );
496
  // Make sure we are on a legitimate page and that we have the proper POST variables if necessary.
497
- if ( $i18ngg . '_page_ewww-ngg-bulk' != $hook && $i18ngg . '_page_nggallery-manage-gallery' != $hook ) {
498
  return;
499
  }
500
- if ( $i18ngg . '_page_nggallery-manage-gallery' == $hook && ( empty( $_REQUEST['bulkaction'] ) || 'bulk_optimize' != $_REQUEST['bulkaction'] ) ) {
501
  return;
502
  }
503
- if ( $i18ngg . '_page_nggallery-manage-gallery' == $hook && ( empty( $_REQUEST['doaction'] ) || ! is_array( $_REQUEST['doaction'] ) ) ) {
504
  return;
505
  }
506
  $images = null;
@@ -513,7 +513,7 @@ if ( ! class_exists( 'EWWW_Nextcellent' ) ) {
513
  // If we've been given a bulk action to perform.
514
  if ( ! empty( $_REQUEST['doaction'] ) ) {
515
  // If we are optimizing a specific group of images.
516
- if ( 'manage-images' == $_REQUEST['page'] && 'bulk_optimize' == $_REQUEST['bulkaction'] ) {
517
  ewwwio_debug_message( 'optimizing a group of images' );
518
  check_admin_referer( 'ngg_updategallery' );
519
  // Reset the resume status, not allowed here.
@@ -522,7 +522,7 @@ if ( ! class_exists( 'EWWW_Nextcellent' ) ) {
522
  $images = array_map( 'intval', $_REQUEST['doaction'] );
523
  }
524
  // If we are optimizing a specific group of galleries.
525
- if ( 'manage-galleries' == $_REQUEST['page'] && 'bulk_optimize' == $_REQUEST['bulkaction'] ) {
526
  ewwwio_debug_message( 'optimizing a group of galleries' );
527
  check_admin_referer( 'ngg_bulkgallery' );
528
  global $nggdb;
@@ -547,7 +547,7 @@ if ( ! class_exists( 'EWWW_Nextcellent' ) ) {
547
  // Get the list of attachment IDs from the db.
548
  $images = get_option( 'ewww_image_optimizer_bulk_ngg_attachments' );
549
  // Otherwise, if we are on the standard bulk page, get all the images in the db.
550
- } elseif ( $hook == $i18ngg . '_page_ewww-ngg-bulk' ) {
551
  ewwwio_debug_message( 'starting from scratch, grabbing all the images' );
552
  global $wpdb;
553
  $images = $wpdb->get_col( "SELECT pid FROM $wpdb->nggpictures ORDER BY sortorder ASC" );
@@ -729,7 +729,7 @@ if ( ! class_exists( 'EWWW_Nextcellent' ) ) {
729
  * @param string $hook The hook value for the current page.
730
  */
731
  function ewww_ngg_manual_actions_script( $hook ) {
732
- if ( 'galleries_page_nggallery-manage' != $hook ) {
733
  return;
734
  }
735
  if ( ! current_user_can( apply_filters( 'ewww_image_optimizer_manual_permissions', '' ) ) ) {
288
  */
289
  function ewww_manage_image_custom_column( $column_name, $id, $return = false ) {
290
  // Once we've found our custom column.
291
+ if ( 'ewww_image_optimizer' === $column_name ) {
292
  // Need this file to work with metadata.
293
  require_once( WP_CONTENT_DIR . '/plugins/nextcellent-gallery-nextgen-legacy/lib/meta.php' );
294
  // Get the metadata for the image.
494
  $i18ngg = strtolower( __( 'Galleries', 'nggallery' ) );
495
  ewwwio_debug_message( "i18n string for galleries: $i18ngg" );
496
  // Make sure we are on a legitimate page and that we have the proper POST variables if necessary.
497
+ if ( $i18ngg . '_page_ewww-ngg-bulk' !== $hook && $i18ngg . '_page_nggallery-manage-gallery' !== $hook ) {
498
  return;
499
  }
500
+ if ( $i18ngg . '_page_nggallery-manage-gallery' === $hook && ( empty( $_REQUEST['bulkaction'] ) || 'bulk_optimize' !== $_REQUEST['bulkaction'] ) ) {
501
  return;
502
  }
503
+ if ( $i18ngg . '_page_nggallery-manage-gallery' === $hook && ( empty( $_REQUEST['doaction'] ) || ! is_array( $_REQUEST['doaction'] ) ) ) {
504
  return;
505
  }
506
  $images = null;
513
  // If we've been given a bulk action to perform.
514
  if ( ! empty( $_REQUEST['doaction'] ) ) {
515
  // If we are optimizing a specific group of images.
516
+ if ( 'manage-images' === $_REQUEST['page'] && 'bulk_optimize' === $_REQUEST['bulkaction'] ) {
517
  ewwwio_debug_message( 'optimizing a group of images' );
518
  check_admin_referer( 'ngg_updategallery' );
519
  // Reset the resume status, not allowed here.
522
  $images = array_map( 'intval', $_REQUEST['doaction'] );
523
  }
524
  // If we are optimizing a specific group of galleries.
525
+ if ( 'manage-galleries' === $_REQUEST['page'] && 'bulk_optimize' === $_REQUEST['bulkaction'] ) {
526
  ewwwio_debug_message( 'optimizing a group of galleries' );
527
  check_admin_referer( 'ngg_bulkgallery' );
528
  global $nggdb;
547
  // Get the list of attachment IDs from the db.
548
  $images = get_option( 'ewww_image_optimizer_bulk_ngg_attachments' );
549
  // Otherwise, if we are on the standard bulk page, get all the images in the db.
550
+ } elseif ( $hook === $i18ngg . '_page_ewww-ngg-bulk' ) {
551
  ewwwio_debug_message( 'starting from scratch, grabbing all the images' );
552
  global $wpdb;
553
  $images = $wpdb->get_col( "SELECT pid FROM $wpdb->nggpictures ORDER BY sortorder ASC" );
729
  * @param string $hook The hook value for the current page.
730
  */
731
  function ewww_ngg_manual_actions_script( $hook ) {
732
+ if ( 'galleries_page_nggallery-manage' !== $hook ) {
733
  return;
734
  }
735
  if ( ! current_user_can( apply_filters( 'ewww_image_optimizer_manual_permissions', '' ) ) ) {
classes/class-ewww-nextgen.php CHANGED
@@ -82,7 +82,7 @@ if ( ! class_exists( 'EWWW_Nextgen' ) ) {
82
  $settings = C_NextGen_Settings::get_instance();
83
  if ( is_array( $params ) ) {
84
  ewwwio_debug_message( 'params is an array' );
85
- if ( ! empty( $params['quality'] ) && 100 == $params['quality'] ) {
86
  $wp_quality = (int) apply_filters( 'jpeg_quality', 82, 'image_resize' );
87
  // If the size is full and the WP default has not been altered, go for higher quality. Otherwise, obey the current WP setting.
88
  $params['quality'] = 'full' === $size && 82 === $wp_quality ? 90 : $wp_quality;
@@ -112,7 +112,7 @@ if ( ! class_exists( 'EWWW_Nextgen' ) ) {
112
  * @return array The full list of known image sizes for this image.
113
  */
114
  function maybe_get_more_sizes( $sizes, $meta ) {
115
- if ( 2 == count( $sizes ) && ewww_image_optimizer_iterable( $meta ) ) {
116
  foreach ( $meta as $meta_key => $meta_val ) {
117
  if ( is_array( $meta_val ) && isset( $meta_val['width'] ) ) {
118
  $sizes[] = $meta_key;
@@ -280,7 +280,7 @@ if ( ! class_exists( 'EWWW_Nextgen' ) ) {
280
  $image = $storage->object->_image_mapper->find( $id );
281
  $image = $this->ewww_added_new_image( $image, $storage );
282
  $success = $this->ewww_manage_image_custom_column( '', $image );
283
- if ( get_transient( 'ewww_image_optimizer_cloud_status' ) == 'exceeded' || ewww_image_optimizer_get_option( 'ewww_image_optimizer_cloud_exceeded' ) > time() ) {
284
  ewwwio_ob_clean();
285
  wp_die( ewwwio_json_encode( array( 'error' => esc_html__( 'License exceeded', 'ewww-image-optimizer' ) ) ) );
286
  }
@@ -344,7 +344,7 @@ if ( ! class_exists( 'EWWW_Nextgen' ) ) {
344
  */
345
  function ewww_ngg_manual_actions_script( $hook ) {
346
  $screen = get_current_screen();
347
- if ( is_null( $screen ) || 'nggallery-manage-images' != $screen->id ) {
348
  return;
349
  }
350
  if ( ! current_user_can( apply_filters( 'ewww_image_optimizer_manual_permissions', '' ) ) ) {
@@ -416,7 +416,7 @@ if ( ! class_exists( 'EWWW_Nextgen' ) ) {
416
  */
417
  function ewww_manage_image_custom_column( $column_name, $id ) {
418
  // Once we've found our custom column (newer versions will be blank).
419
- if ( 'ewww_image_optimizer' == $column_name || '' == $column_name ) {
420
  // Creating the 'registry' object for working with nextgen.
421
  $registry = C_Component_Registry::get_instance();
422
  // Creating a database storage object from the 'registry' object.
@@ -524,17 +524,17 @@ if ( ! class_exists( 'EWWW_Nextgen' ) ) {
524
  *
525
  * @global object $wpdb
526
  *
527
- * @param int $id The ID number of the nextgen image.
528
- * @param object $image A nextgen image object.
529
- * @param bool $optimized Optional. True if the image has already been optimized. Default false.
530
- * @param bool $restorable Optional. True if the image can be restored via the API. Default false.
531
  * @return string The link HTML to display.
532
  */
533
  function ewww_render_optimize_action_link( $id, $image = null, $optimized = false, $restorable = false ) {
534
  if ( ! current_user_can( apply_filters( 'ewww_image_optimizer_manual_permissions', '' ) ) ) {
535
  return '';
536
  }
537
- if ( is_string( $id ) && 'optimize' == $id && is_object( $image ) && ! empty( $image->pid ) ) {
538
  $id = $image->pid;
539
  global $wpdb;
540
  $optimized_images = $wpdb->get_results( $wpdb->prepare( "SELECT image_size,orig_size,resize,converted,level,backup,updated FROM $wpdb->ewwwio_images WHERE attachment_id = %d AND gallery = 'nextgen' AND image_size <> 0 ORDER BY orig_size DESC", $id ), ARRAY_A );
@@ -709,7 +709,7 @@ if ( ! class_exists( 'EWWW_Nextgen' ) ) {
709
  if ( strpos( $hook, 'ewww-ngg-bulk' ) === false ) {
710
  return;
711
  }
712
- if ( ! empty( $_REQUEST['bulkaction'] ) && 'bulk_optimize' != $_REQUEST['bulkaction'] ) {
713
  return;
714
  }
715
  if ( ! empty( $_REQUEST['doaction'] ) && ! is_array( $_REQUEST['doaction'] ) ) {
@@ -725,7 +725,7 @@ if ( ! class_exists( 'EWWW_Nextgen' ) ) {
725
  // If we've been given a bulk action to perform.
726
  if ( ! empty( $_REQUEST['doaction'] ) ) {
727
  // If we are optimizing a specific group of images.
728
- if ( 'images' == $_REQUEST['bulk_type'] && 'bulk_optimize' == $_REQUEST['bulkaction'] ) {
729
  ewwwio_debug_message( 'detected bulk action from manage images' );
730
  check_admin_referer( 'ngg_updategallery' );
731
  // Reset the resume status, not allowed here.
@@ -735,7 +735,7 @@ if ( ! class_exists( 'EWWW_Nextgen' ) ) {
735
  ewwwio_debug_message( 'requested images: ' . implode( ',', $images ) );
736
  }
737
  // If we are optimizing a specific group of galleries.
738
- if ( 'galleries' == $_REQUEST['bulk_type'] && 'bulk_optimize' == $_REQUEST['bulkaction'] ) {
739
  ewwwio_debug_message( 'detected bulk action from manage galleries' );
740
  check_admin_referer( 'ngg_bulkgallery' );
741
  global $nggdb;
@@ -982,7 +982,7 @@ if ( ! class_exists( 'EWWW_Nextgen' ) ) {
982
  function ewww_ngg_bulk_action_handler() {
983
  ewwwio_debug_message( '<b>' . __METHOD__ . '()</b>' );
984
  // If the requested page is blank, or not a bulk_optimize, do nothing.
985
- if ( empty( $_REQUEST['page'] ) || empty( $_REQUEST['bulkaction'] ) || 'bulk_optimize' != $_REQUEST['bulkaction'] ) {
986
  return;
987
  }
988
  // If there is no media to optimize, do nothing.
@@ -990,7 +990,7 @@ if ( ! class_exists( 'EWWW_Nextgen' ) ) {
990
  return;
991
  }
992
  // If the requested page does not matche, do nothing.
993
- if ( 'manage-galleries' !== $_REQUEST['page'] && 'manage-images' != $_REQUEST['page'] ) {
994
  return;
995
  }
996
 
82
  $settings = C_NextGen_Settings::get_instance();
83
  if ( is_array( $params ) ) {
84
  ewwwio_debug_message( 'params is an array' );
85
+ if ( ! empty( $params['quality'] ) && 100 === (int) $params['quality'] ) {
86
  $wp_quality = (int) apply_filters( 'jpeg_quality', 82, 'image_resize' );
87
  // If the size is full and the WP default has not been altered, go for higher quality. Otherwise, obey the current WP setting.
88
  $params['quality'] = 'full' === $size && 82 === $wp_quality ? 90 : $wp_quality;
112
  * @return array The full list of known image sizes for this image.
113
  */
114
  function maybe_get_more_sizes( $sizes, $meta ) {
115
+ if ( 2 === count( $sizes ) && ewww_image_optimizer_iterable( $meta ) ) {
116
  foreach ( $meta as $meta_key => $meta_val ) {
117
  if ( is_array( $meta_val ) && isset( $meta_val['width'] ) ) {
118
  $sizes[] = $meta_key;
280
  $image = $storage->object->_image_mapper->find( $id );
281
  $image = $this->ewww_added_new_image( $image, $storage );
282
  $success = $this->ewww_manage_image_custom_column( '', $image );
283
+ if ( get_transient( 'ewww_image_optimizer_cloud_status' ) === 'exceeded' || ewww_image_optimizer_get_option( 'ewww_image_optimizer_cloud_exceeded' ) > time() ) {
284
  ewwwio_ob_clean();
285
  wp_die( ewwwio_json_encode( array( 'error' => esc_html__( 'License exceeded', 'ewww-image-optimizer' ) ) ) );
286
  }
344
  */
345
  function ewww_ngg_manual_actions_script( $hook ) {
346
  $screen = get_current_screen();
347
+ if ( is_null( $screen ) || 'nggallery-manage-images' !== $screen->id ) {
348
  return;
349
  }
350
  if ( ! current_user_can( apply_filters( 'ewww_image_optimizer_manual_permissions', '' ) ) ) {
416
  */
417
  function ewww_manage_image_custom_column( $column_name, $id ) {
418
  // Once we've found our custom column (newer versions will be blank).
419
+ if ( 'ewww_image_optimizer' === $column_name || ! $column_name ) {
420
  // Creating the 'registry' object for working with nextgen.
421
  $registry = C_Component_Registry::get_instance();
422
  // Creating a database storage object from the 'registry' object.
524
  *
525
  * @global object $wpdb
526
  *
527
+ * @param int|string $id The ID number of the nextgen image, or the string 'optimize'.
528
+ * @param object $image A nextgen image object.
529
+ * @param bool $optimized Optional. True if the image has already been optimized. Default false.
530
+ * @param bool $restorable Optional. True if the image can be restored via the API. Default false.
531
  * @return string The link HTML to display.
532
  */
533
  function ewww_render_optimize_action_link( $id, $image = null, $optimized = false, $restorable = false ) {
534
  if ( ! current_user_can( apply_filters( 'ewww_image_optimizer_manual_permissions', '' ) ) ) {
535
  return '';
536
  }
537
+ if ( 'optimize' === $id && is_object( $image ) && ! empty( $image->pid ) ) {
538
  $id = $image->pid;
539
  global $wpdb;
540
  $optimized_images = $wpdb->get_results( $wpdb->prepare( "SELECT image_size,orig_size,resize,converted,level,backup,updated FROM $wpdb->ewwwio_images WHERE attachment_id = %d AND gallery = 'nextgen' AND image_size <> 0 ORDER BY orig_size DESC", $id ), ARRAY_A );
709
  if ( strpos( $hook, 'ewww-ngg-bulk' ) === false ) {
710
  return;
711
  }
712
+ if ( ! empty( $_REQUEST['bulkaction'] ) && 'bulk_optimize' !== $_REQUEST['bulkaction'] ) {
713
  return;
714
  }
715
  if ( ! empty( $_REQUEST['doaction'] ) && ! is_array( $_REQUEST['doaction'] ) ) {
725
  // If we've been given a bulk action to perform.
726
  if ( ! empty( $_REQUEST['doaction'] ) ) {
727
  // If we are optimizing a specific group of images.
728
+ if ( 'images' === $_REQUEST['bulk_type'] && 'bulk_optimize' === $_REQUEST['bulkaction'] ) {
729
  ewwwio_debug_message( 'detected bulk action from manage images' );
730
  check_admin_referer( 'ngg_updategallery' );
731
  // Reset the resume status, not allowed here.
735
  ewwwio_debug_message( 'requested images: ' . implode( ',', $images ) );
736
  }
737
  // If we are optimizing a specific group of galleries.
738
+ if ( 'galleries' === $_REQUEST['bulk_type'] && 'bulk_optimize' === $_REQUEST['bulkaction'] ) {
739
  ewwwio_debug_message( 'detected bulk action from manage galleries' );
740
  check_admin_referer( 'ngg_bulkgallery' );
741
  global $nggdb;
982
  function ewww_ngg_bulk_action_handler() {
983
  ewwwio_debug_message( '<b>' . __METHOD__ . '()</b>' );
984
  // If the requested page is blank, or not a bulk_optimize, do nothing.
985
+ if ( empty( $_REQUEST['page'] ) || empty( $_REQUEST['bulkaction'] ) || 'bulk_optimize' !== $_REQUEST['bulkaction'] ) {
986
  return;
987
  }
988
  // If there is no media to optimize, do nothing.
990
  return;
991
  }
992
  // If the requested page does not matche, do nothing.
993
+ if ( 'manage-galleries' !== $_REQUEST['page'] && 'manage-images' !== $_REQUEST['page'] ) {
994
  return;
995
  }
996
 
classes/class-ewwwio-alt-webp.php CHANGED
@@ -533,7 +533,7 @@ class EWWWIO_Alt_Webp extends EWWWIO_Page_Parser {
533
  }
534
  }
535
  }
536
- if ( $picture != $pictures[ $index ] ) {
537
  ewwwio_debug_message( 'found webp for picture element' );
538
  $buffer = str_replace( $pictures[ $index ], $picture, $buffer );
539
  }
@@ -559,7 +559,7 @@ class EWWWIO_Alt_Webp extends EWWWIO_Page_Parser {
559
  ewwwio_debug_message( "found webp for ngg data-thumbnail: $thumb" );
560
  }
561
  }
562
- if ( $link != $links[ $index ] ) {
563
  $buffer = str_replace( $links[ $index ], $link, $buffer );
564
  }
565
  }
@@ -591,7 +591,7 @@ class EWWWIO_Alt_Webp extends EWWWIO_Page_Parser {
591
  }
592
  $param_num++;
593
  }
594
- if ( $listitem != $listitems[ $index ] ) {
595
  $buffer = str_replace( $listitems[ $index ], $listitem, $buffer );
596
  }
597
  }
@@ -771,6 +771,9 @@ class EWWWIO_Alt_Webp extends EWWWIO_Page_Parser {
771
  * Load minified inline version of webp script (from jscompress.com).
772
  */
773
  function inline_script() {
 
 
 
774
  ewwwio_debug_message( 'loading webp script without wp_add_inline_script' );
775
  echo "<script>$this->inline_script</script>";
776
  }
533
  }
534
  }
535
  }
536
+ if ( $picture !== $pictures[ $index ] ) {
537
  ewwwio_debug_message( 'found webp for picture element' );
538
  $buffer = str_replace( $pictures[ $index ], $picture, $buffer );
539
  }
559
  ewwwio_debug_message( "found webp for ngg data-thumbnail: $thumb" );
560
  }
561
  }
562
+ if ( $link !== $links[ $index ] ) {
563
  $buffer = str_replace( $links[ $index ], $link, $buffer );
564
  }
565
  }
591
  }
592
  $param_num++;
593
  }
594
+ if ( $listitem !== $listitems[ $index ] ) {
595
  $buffer = str_replace( $listitems[ $index ], $listitem, $buffer );
596
  }
597
  }
771
  * Load minified inline version of webp script (from jscompress.com).
772
  */
773
  function inline_script() {
774
+ if ( defined( 'EWWW_IMAGE_OPTIMIZER_NO_JS' ) && EWWW_IMAGE_OPTIMIZER_NO_JS ) {
775
+ return;
776
+ }
777
  ewwwio_debug_message( 'loading webp script without wp_add_inline_script' );
778
  echo "<script>$this->inline_script</script>";
779
  }
classes/class-ewwwio-background-process.php CHANGED
@@ -283,7 +283,7 @@ if ( ! class_exists( 'EWWWIO_Background_Process' ) ) {
283
  protected function is_queue_active( $queue_id ) {
284
  global $wpdb;
285
  $process_lock_transient = '_transient_' . $this->identifier . '_process_lock';
286
- if ( $wpdb->get_var( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name LIKE %s", $process_lock_transient ) ) == $queue_id ) {
287
  ewwwio_debug_message( "queue $queue_id is running" );
288
  return true;
289
  }
@@ -445,7 +445,7 @@ if ( ! class_exists( 'EWWWIO_Background_Process' ) ) {
445
  // Sensible default.
446
  $memory_limit = '128M';
447
  }
448
- if ( ! $memory_limit || -1 === intval( $memory_limit ) ) {
449
  // Unlimited, set to 32GB.
450
  $memory_limit = '32G';
451
  }
283
  protected function is_queue_active( $queue_id ) {
284
  global $wpdb;
285
  $process_lock_transient = '_transient_' . $this->identifier . '_process_lock';
286
+ if ( $wpdb->get_var( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name LIKE %s", $process_lock_transient ) ) === $queue_id ) {
287
  ewwwio_debug_message( "queue $queue_id is running" );
288
  return true;
289
  }
445
  // Sensible default.
446
  $memory_limit = '128M';
447
  }
448
+ if ( ! $memory_limit || -1 === (int) $memory_limit ) {
449
  // Unlimited, set to 32GB.
450
  $memory_limit = '32G';
451
  }
classes/class-ewwwio-gd-editor.php CHANGED
@@ -39,7 +39,7 @@ if ( class_exists( 'Bbpp_Animated_Gif' ) ) {
39
  if ( ( ! defined( 'EWWWIO_EDITOR_OVERWRITE' ) || ! EWWWIO_EDITOR_OVERWRITE ) && is_file( $filename ) ) {
40
  ewwwio_debug_message( "detected existing file: $filename" );
41
  $current_size = getimagesize( $filename );
42
- if ( $current_size && $this->size['width'] == $current_size[0] && $this->size['height'] == $current_size[1] ) {
43
  ewwwio_debug_message( "existing file has same dimensions, not saving $filename" );
44
  return array(
45
  'path' => $filename,
@@ -163,7 +163,7 @@ if ( class_exists( 'Bbpp_Animated_Gif' ) ) {
163
  if ( ( ! defined( 'EWWWIO_EDITOR_OVERWRITE' ) || ! EWWWIO_EDITOR_OVERWRITE ) && is_file( $filename ) ) {
164
  ewwwio_debug_message( "detected existing file: $filename" );
165
  $current_size = getimagesize( $filename );
166
- if ( $current_size && $this->size['width'] == $current_size[0] && $this->size['height'] == $current_size[1] ) {
167
  ewwwio_debug_message( "existing file has same dimensions, not saving $filename" );
168
  return array(
169
  'path' => $filename,
@@ -240,7 +240,7 @@ if ( class_exists( 'Bbpp_Animated_Gif' ) ) {
240
  if ( ( ! defined( 'EWWWIO_EDITOR_OVERWRITE' ) || ! EWWWIO_EDITOR_OVERWRITE ) && is_file( $filename ) ) {
241
  ewwwio_debug_message( "detected existing file: $filename" );
242
  $current_size = getimagesize( $filename );
243
- if ( $current_size && $this->size['width'] == $current_size[0] && $this->size['height'] == $current_size[1] ) {
244
  ewwwio_debug_message( "existing file has same dimensions, not saving $filename" );
245
  return array(
246
  'path' => $filename,
@@ -391,7 +391,7 @@ if ( class_exists( 'Bbpp_Animated_Gif' ) ) {
391
  */
392
  public function resize( $max_w, $max_h, $crop = false ) {
393
  ewwwio_debug_message( '<b>' . __METHOD__ . '()</b>' );
394
- if ( ( $this->size['width'] == $max_w ) && ( $this->size['height'] == $max_h ) ) {
395
  return true;
396
  }
397
 
@@ -454,7 +454,7 @@ if ( class_exists( 'Bbpp_Animated_Gif' ) ) {
454
  }
455
 
456
  $image = $this->_resize( $size_data['width'], $size_data['height'], $size_data['crop'] );
457
- $duplicate = ( ( $orig_size['width'] == $size_data['width'] ) && ( $orig_size['height'] == $size_data['height'] ) );
458
 
459
  if ( ! is_wp_error( $image ) && ! $duplicate ) {
460
  if ( is_resource( $image ) ) {
@@ -556,7 +556,7 @@ if ( class_exists( 'Bbpp_Animated_Gif' ) ) {
556
  if ( ( ! defined( 'EWWWIO_EDITOR_OVERWRITE' ) || ! EWWWIO_EDITOR_OVERWRITE ) && is_file( $filename ) && empty( $ewww_preempt_editor ) ) {
557
  ewwwio_debug_message( "detected existing file: $filename" );
558
  $current_size = getimagesize( $filename );
559
- if ( $current_size && $this->size['width'] == $current_size[0] && $this->size['height'] == $current_size[1] ) {
560
  ewwwio_debug_message( "existing file has same dimensions, not saving $filename" );
561
  return array(
562
  'path' => $filename,
@@ -617,7 +617,7 @@ if ( class_exists( 'Bbpp_Animated_Gif' ) ) {
617
  if ( ( ! defined( 'EWWWIO_EDITOR_OVERWRITE' ) || ! EWWWIO_EDITOR_OVERWRITE ) && is_file( $filename ) ) {
618
  ewwwio_debug_message( "detected existing file: $filename" );
619
  $current_size = getimagesize( $filename );
620
- if ( $current_size && $this->size['width'] == $current_size[0] && $this->size['height'] == $current_size[1] ) {
621
  ewwwio_debug_message( "existing file has same dimensions, not saving $filename" );
622
  return array(
623
  'path' => $filename,
39
  if ( ( ! defined( 'EWWWIO_EDITOR_OVERWRITE' ) || ! EWWWIO_EDITOR_OVERWRITE ) && is_file( $filename ) ) {
40
  ewwwio_debug_message( "detected existing file: $filename" );
41
  $current_size = getimagesize( $filename );
42
+ if ( $current_size && (int) $this->size['width'] === (int) $current_size[0] && (int) $this->size['height'] === (int) $current_size[1] ) {
43
  ewwwio_debug_message( "existing file has same dimensions, not saving $filename" );
44
  return array(
45
  'path' => $filename,
163
  if ( ( ! defined( 'EWWWIO_EDITOR_OVERWRITE' ) || ! EWWWIO_EDITOR_OVERWRITE ) && is_file( $filename ) ) {
164
  ewwwio_debug_message( "detected existing file: $filename" );
165
  $current_size = getimagesize( $filename );
166
+ if ( $current_size && (int) $this->size['width'] === (int) $current_size[0] && (int) $this->size['height'] === (int) $current_size[1] ) {
167
  ewwwio_debug_message( "existing file has same dimensions, not saving $filename" );
168
  return array(
169
  'path' => $filename,
240
  if ( ( ! defined( 'EWWWIO_EDITOR_OVERWRITE' ) || ! EWWWIO_EDITOR_OVERWRITE ) && is_file( $filename ) ) {
241
  ewwwio_debug_message( "detected existing file: $filename" );
242
  $current_size = getimagesize( $filename );
243
+ if ( $current_size && (int) $this->size['width'] === (int) $current_size[0] && (int) $this->size['height'] === (int) $current_size[1] ) {
244
  ewwwio_debug_message( "existing file has same dimensions, not saving $filename" );
245
  return array(
246
  'path' => $filename,
391
  */
392
  public function resize( $max_w, $max_h, $crop = false ) {
393
  ewwwio_debug_message( '<b>' . __METHOD__ . '()</b>' );
394
+ if ( (int) $this->size['width'] === (int) $max_w && (int) $this->size['height'] === (int) $max_h ) {
395
  return true;
396
  }
397
 
454
  }
455
 
456
  $image = $this->_resize( $size_data['width'], $size_data['height'], $size_data['crop'] );
457
+ $duplicate = ( (int) $orig_size['width'] === (int) $size_data['width'] && (int) $orig_size['height'] === (int) $size_data['height'] );
458
 
459
  if ( ! is_wp_error( $image ) && ! $duplicate ) {
460
  if ( is_resource( $image ) ) {
556
  if ( ( ! defined( 'EWWWIO_EDITOR_OVERWRITE' ) || ! EWWWIO_EDITOR_OVERWRITE ) && is_file( $filename ) && empty( $ewww_preempt_editor ) ) {
557
  ewwwio_debug_message( "detected existing file: $filename" );
558
  $current_size = getimagesize( $filename );
559
+ if ( $current_size && (int) $this->size['width'] === (int) $current_size[0] && (int) $this->size['height'] === (int) $current_size[1] ) {
560
  ewwwio_debug_message( "existing file has same dimensions, not saving $filename" );
561
  return array(
562
  'path' => $filename,
617
  if ( ( ! defined( 'EWWWIO_EDITOR_OVERWRITE' ) || ! EWWWIO_EDITOR_OVERWRITE ) && is_file( $filename ) ) {
618
  ewwwio_debug_message( "detected existing file: $filename" );
619
  $current_size = getimagesize( $filename );
620
+ if ( $current_size && (int) $this->size['width'] === (int) $current_size[0] && (int) $this->size['height'] === (int) $current_size[1] ) {
621
  ewwwio_debug_message( "existing file has same dimensions, not saving $filename" );
622
  return array(
623
  'path' => $filename,
classes/class-ewwwio-gmagick-editor.php CHANGED
@@ -37,7 +37,7 @@ if ( class_exists( 'WP_Image_Editor_Gmagick' ) ) {
37
  if ( ( ! defined( 'EWWWIO_EDITOR_OVERWRITE' ) || ! EWWWIO_EDITOR_OVERWRITE ) && is_file( $filename ) ) {
38
  ewwwio_debug_message( "detected existing file: $filename" );
39
  $current_size = getimagesize( $filename );
40
- if ( $current_size && $this->size['width'] == $current_size[0] && $this->size['height'] == $current_size[1] ) {
41
  ewwwio_debug_message( "existing file has same dimensions, not saving $filename" );
42
  return array(
43
  'path' => $filename,
37
  if ( ( ! defined( 'EWWWIO_EDITOR_OVERWRITE' ) || ! EWWWIO_EDITOR_OVERWRITE ) && is_file( $filename ) ) {
38
  ewwwio_debug_message( "detected existing file: $filename" );
39
  $current_size = getimagesize( $filename );
40
+ if ( $current_size && (int) $this->size['width'] === (int) $current_size[0] && (int) $this->size['height'] === (int) $current_size[1] ) {
41
  ewwwio_debug_message( "existing file has same dimensions, not saving $filename" );
42
  return array(
43
  'path' => $filename,
classes/class-ewwwio-hs-beacon.php CHANGED
@@ -72,10 +72,10 @@ class EWWWIO_HS_Beacon {
72
  public function admin_notice( $network_class = '' ) {
73
  ewwwio_debug_message( '<b>' . __METHOD__ . '()</b>' );
74
  $hide_notice = ewww_image_optimizer_get_option( 'ewww_image_optimizer_enable_help_notice' );
75
- if ( 'network-multisite' == $network_class && get_site_option( 'ewww_image_optimizer_allow_multisite_override' ) ) {
76
  return;
77
  }
78
- if ( 'network-singlesite' == $network_class && ! get_site_option( 'ewww_image_optimizer_allow_multisite_override' ) ) {
79
  return;
80
  }
81
 
72
  public function admin_notice( $network_class = '' ) {
73
  ewwwio_debug_message( '<b>' . __METHOD__ . '()</b>' );
74
  $hide_notice = ewww_image_optimizer_get_option( 'ewww_image_optimizer_enable_help_notice' );
75
+ if ( 'network-multisite' === $network_class && get_site_option( 'ewww_image_optimizer_allow_multisite_override' ) ) {
76
  return;
77
  }
78
+ if ( 'network-singlesite' === $network_class && ! get_site_option( 'ewww_image_optimizer_allow_multisite_override' ) ) {
79
  return;
80
  }
81
 
classes/class-ewwwio-imagick-editor.php CHANGED
@@ -38,7 +38,7 @@ if ( class_exists( 'WP_Thumb_Image_Editor_Imagick' ) ) {
38
  if ( ( ! defined( 'EWWWIO_EDITOR_OVERWRITE' ) || ! EWWWIO_EDITOR_OVERWRITE ) && is_file( $filename ) ) {
39
  ewwwio_debug_message( "detected existing file: $filename" );
40
  $current_size = getimagesize( $filename );
41
- if ( $current_size && $this->size['width'] == $current_size[0] && $this->size['height'] == $current_size[1] ) {
42
  ewwwio_debug_message( "existing file has same dimensions, not saving $filename" );
43
  return array(
44
  'path' => $filename,
@@ -115,7 +115,7 @@ if ( class_exists( 'WP_Thumb_Image_Editor_Imagick' ) ) {
115
  if ( ( ! defined( 'EWWWIO_EDITOR_OVERWRITE' ) || ! EWWWIO_EDITOR_OVERWRITE ) && is_file( $filename ) ) {
116
  ewwwio_debug_message( "detected existing file: $filename" );
117
  $current_size = getimagesize( $filename );
118
- if ( $current_size && $this->size['width'] == $current_size[0] && $this->size['height'] == $current_size[1] ) {
119
  ewwwio_debug_message( "existing file has same dimensions, not saving $filename" );
120
  return array(
121
  'path' => $filename,
@@ -192,7 +192,7 @@ if ( class_exists( 'WP_Thumb_Image_Editor_Imagick' ) ) {
192
  if ( ( ! defined( 'EWWWIO_EDITOR_OVERWRITE' ) || ! EWWWIO_EDITOR_OVERWRITE ) && is_file( $filename ) ) {
193
  ewwwio_debug_message( "detected existing file: $filename" );
194
  $current_size = getimagesize( $filename );
195
- if ( $current_size && $this->size['width'] == $current_size[0] && $this->size['height'] == $current_size[1] ) {
196
  ewwwio_debug_message( "existing file has same dimensions, not saving $filename" );
197
  return array(
198
  'path' => $filename,
@@ -368,7 +368,7 @@ if ( class_exists( 'WP_Thumb_Image_Editor_Imagick' ) ) {
368
  */
369
  public function resize( $max_w, $max_h, $crop = false ) {
370
  ewwwio_debug_message( '<b>wp_image_editor_gd::' . __FUNCTION__ . '()</b>' );
371
- if ( ( $this->size['width'] == $max_w ) && ( $this->size['height'] == $max_h ) ) {
372
  return true;
373
  }
374
 
@@ -547,7 +547,7 @@ if ( class_exists( 'WP_Thumb_Image_Editor_Imagick' ) ) {
547
  }
548
 
549
  $resize_result = $this->resize( $size_data['width'], $size_data['height'], $size_data['crop'] );
550
- $duplicate = ( ( $orig_size['width'] == $size_data['width'] ) && ( $orig_size['height'] == $size_data['height'] ) );
551
 
552
  if ( ! is_wp_error( $resize_result ) && ! $duplicate ) {
553
  if ( is_string( $resize_result ) ) {
@@ -660,7 +660,7 @@ if ( class_exists( 'WP_Thumb_Image_Editor_Imagick' ) ) {
660
  if ( ( ! defined( 'EWWWIO_EDITOR_OVERWRITE' ) || ! EWWWIO_EDITOR_OVERWRITE ) && is_file( $filename ) && empty( $ewww_preempt_editor ) ) {
661
  ewwwio_debug_message( "detected existing file: $filename" );
662
  $current_size = getimagesize( $filename );
663
- if ( $current_size && $this->size['width'] == $current_size[0] && $this->size['height'] == $current_size[1] ) {
664
  ewwwio_debug_message( "existing file has same dimensions, not saving $filename" );
665
  return array(
666
  'path' => $filename,
@@ -721,7 +721,7 @@ if ( class_exists( 'WP_Thumb_Image_Editor_Imagick' ) ) {
721
  if ( ( ! defined( 'EWWWIO_EDITOR_OVERWRITE' ) || ! EWWWIO_EDITOR_OVERWRITE ) && is_file( $filename ) ) {
722
  ewwwio_debug_message( "detected existing file: $filename" );
723
  $current_size = getimagesize( $filename );
724
- if ( $current_size && $this->size['width'] == $current_size[0] && $this->size['height'] == $current_size[1] ) {
725
  ewwwio_debug_message( "existing file has same dimensions, not saving $filename" );
726
  return array(
727
  'path' => $filename,
38
  if ( ( ! defined( 'EWWWIO_EDITOR_OVERWRITE' ) || ! EWWWIO_EDITOR_OVERWRITE ) && is_file( $filename ) ) {
39
  ewwwio_debug_message( "detected existing file: $filename" );
40
  $current_size = getimagesize( $filename );
41
+ if ( $current_size && (int) $this->size['width'] === (int) $current_size[0] && (int) $this->size['height'] === (int) $current_size[1] ) {
42
  ewwwio_debug_message( "existing file has same dimensions, not saving $filename" );
43
  return array(
44
  'path' => $filename,
115
  if ( ( ! defined( 'EWWWIO_EDITOR_OVERWRITE' ) || ! EWWWIO_EDITOR_OVERWRITE ) && is_file( $filename ) ) {
116
  ewwwio_debug_message( "detected existing file: $filename" );
117
  $current_size = getimagesize( $filename );
118
+ if ( $current_size && (int) $this->size['width'] === (int) $current_size[0] && (int) $this->size['height'] === (int) $current_size[1] ) {
119
  ewwwio_debug_message( "existing file has same dimensions, not saving $filename" );
120
  return array(
121
  'path' => $filename,
192
  if ( ( ! defined( 'EWWWIO_EDITOR_OVERWRITE' ) || ! EWWWIO_EDITOR_OVERWRITE ) && is_file( $filename ) ) {
193
  ewwwio_debug_message( "detected existing file: $filename" );
194
  $current_size = getimagesize( $filename );
195
+ if ( $current_size && (int) $this->size['width'] === (int) $current_size[0] && (int) $this->size['height'] === (int) $current_size[1] ) {
196
  ewwwio_debug_message( "existing file has same dimensions, not saving $filename" );
197
  return array(
198
  'path' => $filename,
368
  */
369
  public function resize( $max_w, $max_h, $crop = false ) {
370
  ewwwio_debug_message( '<b>wp_image_editor_gd::' . __FUNCTION__ . '()</b>' );
371
+ if ( (int) $this->size['width'] === (int) $max_w && (int) $this->size['height'] === (int) $max_h ) {
372
  return true;
373
  }
374
 
547
  }
548
 
549
  $resize_result = $this->resize( $size_data['width'], $size_data['height'], $size_data['crop'] );
550
+ $duplicate = ( (int) $orig_size['width'] === (int) $size_data['width'] && (int) $orig_size['height'] === (int) $size_data['height'] );
551
 
552
  if ( ! is_wp_error( $resize_result ) && ! $duplicate ) {
553
  if ( is_string( $resize_result ) ) {
660
  if ( ( ! defined( 'EWWWIO_EDITOR_OVERWRITE' ) || ! EWWWIO_EDITOR_OVERWRITE ) && is_file( $filename ) && empty( $ewww_preempt_editor ) ) {
661
  ewwwio_debug_message( "detected existing file: $filename" );
662
  $current_size = getimagesize( $filename );
663
+ if ( $current_size && (int) $this->size['width'] === (int) $current_size[0] && (int) $this->size['height'] === (int) $current_size[1] ) {
664
  ewwwio_debug_message( "existing file has same dimensions, not saving $filename" );
665
  return array(
666
  'path' => $filename,
721
  if ( ( ! defined( 'EWWWIO_EDITOR_OVERWRITE' ) || ! EWWWIO_EDITOR_OVERWRITE ) && is_file( $filename ) ) {
722
  ewwwio_debug_message( "detected existing file: $filename" );
723
  $current_size = getimagesize( $filename );
724
+ if ( $current_size && (int) $this->size['width'] === (int) $current_size[0] && (int) $this->size['height'] === (int) $current_size[1] ) {
725
  ewwwio_debug_message( "existing file has same dimensions, not saving $filename" );
726
  return array(
727
  'path' => $filename,
classes/class-ewwwio-lazy-load.php CHANGED
@@ -16,7 +16,7 @@ if ( ! defined( 'ABSPATH' ) ) {
16
  class EWWWIO_Lazy_Load extends EWWWIO_Page_Parser {
17
 
18
  /**
19
- * Base64 encoded placeholder image.
20
  *
21
  * @access protected
22
  * @var string $placeholder_src
@@ -56,6 +56,7 @@ class EWWWIO_Lazy_Load extends EWWWIO_Page_Parser {
56
 
57
  // Filter early, so that others at the default priority take precendence.
58
  add_filter( 'ewww_image_optimizer_use_lqip', array( $this, 'maybe_lqip' ), 9 );
 
59
 
60
  // Load the appropriate JS.
61
  if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) {
@@ -172,9 +173,41 @@ class EWWWIO_Lazy_Load extends EWWWIO_Page_Parser {
172
  if ( false === strpos( $file, 'nggid' ) && apply_filters( 'ewww_image_optimizer_use_lqip', true ) && $this->parsing_exactdn && strpos( $file, $this->exactdn_domain ) ) {
173
  $placeholder_src = add_query_arg( array( 'lazy' => 1 ), $file );
174
  ewwwio_debug_message( "current placeholder is $placeholder_src" );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
  }
176
 
177
  if ( $srcset ) {
 
178
  if ( strpos( $placeholder_src, '64,R0lGOD' ) ) {
179
  $this->set_attribute( $image, 'srcset', $placeholder_src, true );
180
  $this->remove_attribute( $image, 'src' );
@@ -222,7 +255,7 @@ class EWWWIO_Lazy_Load extends EWWWIO_Page_Parser {
222
  $picture = str_replace( $source, $lazy_source, $picture );
223
  }
224
  }
225
- if ( $picture != $pictures[ $index ] ) {
226
  ewwwio_debug_message( 'lazified sources for picture element' );
227
  $buffer = str_replace( $pictures[ $index ], $picture, $buffer );
228
  }
@@ -320,6 +353,13 @@ class EWWWIO_Lazy_Load extends EWWWIO_Page_Parser {
320
  if ( strpos( $image, 'data-pin-description=' ) && strpos( $image, 'width="0" height="0"' ) ) {
321
  return false;
322
  }
 
 
 
 
 
 
 
323
  $exclusions = apply_filters(
324
  'ewww_image_optimizer_lazy_exclusions',
325
  array(
@@ -366,7 +406,9 @@ class EWWWIO_Lazy_Load extends EWWWIO_Page_Parser {
366
  $exclusions = apply_filters(
367
  'ewww_image_optimizer_lazy_bg_image_exclusions',
368
  array(
 
369
  'lazyload',
 
370
  ),
371
  $tag
372
  );
@@ -391,6 +433,19 @@ class EWWWIO_Lazy_Load extends EWWWIO_Page_Parser {
391
  return $use_lqip;
392
  }
393
 
 
 
 
 
 
 
 
 
 
 
 
 
 
394
  /**
395
  * Adds a small CSS block to hide lazyload elements for no-JS browsers.
396
  */
16
  class EWWWIO_Lazy_Load extends EWWWIO_Page_Parser {
17
 
18
  /**
19
+ * Base64-encoded placeholder image.
20
  *
21
  * @access protected
22
  * @var string $placeholder_src
56
 
57
  // Filter early, so that others at the default priority take precendence.
58
  add_filter( 'ewww_image_optimizer_use_lqip', array( $this, 'maybe_lqip' ), 9 );
59
+ add_filter( 'ewww_image_optimizer_use_siip', array( $this, 'maybe_siip' ), 9 );
60
 
61
  // Load the appropriate JS.
62
  if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) {
173
  if ( false === strpos( $file, 'nggid' ) && apply_filters( 'ewww_image_optimizer_use_lqip', true ) && $this->parsing_exactdn && strpos( $file, $this->exactdn_domain ) ) {
174
  $placeholder_src = add_query_arg( array( 'lazy' => 1 ), $file );
175
  ewwwio_debug_message( "current placeholder is $placeholder_src" );
176
+ } elseif ( apply_filters( 'ewww_image_optimizer_use_siip', true ) ) {
177
+ // Get image dimensions for inline SVG placeholder.
178
+ list( $width, $height ) = $this->get_dimensions_from_filename( $file );
179
+
180
+ $width_attr = $this->get_attribute( $image, 'width' );
181
+ $height_attr = $this->get_attribute( $image, 'height' );
182
+
183
+ if ( false === $width || false === $height ) {
184
+ ewwwio_debug_message( "dimensions not found in $file, using attrs" );
185
+ $width = $width_attr;
186
+ $height = $height_attr;
187
+ }
188
+
189
+ // Can't use a relative width or height, so unset the dimensions in favor of not breaking things.
190
+ if ( false !== strpos( $width, '%' ) || false !== strpos( $height, '%' ) ) {
191
+ $width = false;
192
+ $height = false;
193
+ }
194
+
195
+ // Falsify them if empty.
196
+ $width = $width ? (int) $width : false;
197
+ $height = $height ? (int) $height : false;
198
+ if ( $width && $height ) {
199
+ $placeholder_src = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 $width $height'%3E%3C/svg%3E";
200
+ if ( empty( $width_attr ) ) {
201
+ $this->set_attribute( $image, 'width', $width );
202
+ }
203
+ if ( empty( $height_attr ) ) {
204
+ $this->set_attribute( $image, 'height', $height );
205
+ }
206
+ }
207
  }
208
 
209
  if ( $srcset ) {
210
+ $placeholder_src = apply_filters( 'ewww_image_optimizer_lazy_placeholder', $placeholder_src, $image );
211
  if ( strpos( $placeholder_src, '64,R0lGOD' ) ) {
212
  $this->set_attribute( $image, 'srcset', $placeholder_src, true );
213
  $this->remove_attribute( $image, 'src' );
255
  $picture = str_replace( $source, $lazy_source, $picture );
256
  }
257
  }
258
+ if ( $picture !== $pictures[ $index ] ) {
259
  ewwwio_debug_message( 'lazified sources for picture element' );
260
  $buffer = str_replace( $pictures[ $index ], $picture, $buffer );
261
  }
353
  if ( strpos( $image, 'data-pin-description=' ) && strpos( $image, 'width="0" height="0"' ) ) {
354
  return false;
355
  }
356
+
357
+ // Ignore native lazy loading images.
358
+ $loading_attr = $this->get_attribute( $image, 'loading' );
359
+ if ( $loading_attr && in_array( trim( $loading_attr ), array( 'auto', 'eager', 'lazy' ), true ) ) {
360
+ return false;
361
+ }
362
+
363
  $exclusions = apply_filters(
364
  'ewww_image_optimizer_lazy_exclusions',
365
  array(
406
  $exclusions = apply_filters(
407
  'ewww_image_optimizer_lazy_bg_image_exclusions',
408
  array(
409
+ 'data-no-lazy=',
410
  'lazyload',
411
+ 'skip-lazy',
412
  ),
413
  $tag
414
  );
433
  return $use_lqip;
434
  }
435
 
436
+ /**
437
+ * Check if SIIP should be used, but allow filters to alter the option.
438
+ *
439
+ * @param bool $use_siip Whether LL should use SVG inline image placeholders.
440
+ * @return bool True to use SIIP, false to skip them.
441
+ */
442
+ function maybe_siip( $use_siip ) {
443
+ if ( defined( 'EWWW_IMAGE_OPTIMIZER_USE_SIIP' ) && ! EWWW_IMAGE_OPTIMIZER_USE_SIIP ) {
444
+ return false;
445
+ }
446
+ return $use_siip;
447
+ }
448
+
449
  /**
450
  * Adds a small CSS block to hide lazyload elements for no-JS browsers.
451
  */
classes/class-ewwwio-media-background-process.php CHANGED
@@ -72,13 +72,13 @@ class EWWWIO_Media_Background_Process extends EWWWIO_Background_Process {
72
  );
73
 
74
  $meta = wp_get_attachment_metadata( $id, true );
75
- if ( in_array( $type, $image_types ) && empty( $meta ) && $item['attempts'] < $max_attempts ) {
76
  $item['attempts']++;
77
  sleep( 4 );
78
  ewwwio_debug_message( "metadata is missing, requeueing {$item['attempts']}" );
79
  ewww_image_optimizer_debug_log();
80
  return $item;
81
- } elseif ( in_array( $type, $image_types ) && empty( $meta ) ) {
82
  ewwwio_debug_message( 'metadata is missing for image, out of attempts' );
83
  ewww_image_optimizer_debug_log();
84
  delete_transient( 'ewwwio-background-in-progress-' . $id );
@@ -438,7 +438,7 @@ class EWWWIO_Async_Request extends WP_Async_Request {
438
  $id = (int) $_POST['ewwwio_id'];
439
  }
440
  global $ewww_image;
441
- if ( ! empty( $_POST['ewwwio_path'] ) && 'full' == $size ) {
442
  $file_path = $this->find_file( $_POST['ewwwio_path'] );
443
  if ( ! empty( $file_path ) ) {
444
  ewwwio_debug_message( "processing async optimization request for {$_POST['ewwwio_path']}" );
@@ -580,7 +580,7 @@ class EWWWIO_Test_Async_Handler extends WP_Async_Request {
580
  ewww_image_optimizer_debug_log();
581
  return;
582
  }
583
- if ( '949c34123cf2a4e4ce2f985135830df4a1b2adc24905f53d2fd3f5df5b162932' != $item ) {
584
  ewwwio_debug_message( 'wrong item received, not enabling background opt' );
585
  ewww_image_optimizer_debug_log();
586
  return;
72
  );
73
 
74
  $meta = wp_get_attachment_metadata( $id, true );
75
+ if ( in_array( $type, $image_types, true ) && empty( $meta ) && $item['attempts'] < $max_attempts ) {
76
  $item['attempts']++;
77
  sleep( 4 );
78
  ewwwio_debug_message( "metadata is missing, requeueing {$item['attempts']}" );
79
  ewww_image_optimizer_debug_log();
80
  return $item;
81
+ } elseif ( in_array( $type, $image_types, true ) && empty( $meta ) ) {
82
  ewwwio_debug_message( 'metadata is missing for image, out of attempts' );
83
  ewww_image_optimizer_debug_log();
84
  delete_transient( 'ewwwio-background-in-progress-' . $id );
438
  $id = (int) $_POST['ewwwio_id'];
439
  }
440
  global $ewww_image;
441
+ if ( ! empty( $_POST['ewwwio_path'] ) && 'full' === $size ) {
442
  $file_path = $this->find_file( $_POST['ewwwio_path'] );
443
  if ( ! empty( $file_path ) ) {
444
  ewwwio_debug_message( "processing async optimization request for {$_POST['ewwwio_path']}" );
580
  ewww_image_optimizer_debug_log();
581
  return;
582
  }
583
+ if ( '949c34123cf2a4e4ce2f985135830df4a1b2adc24905f53d2fd3f5df5b162932' !== $item ) {
584
  ewwwio_debug_message( 'wrong item received, not enabling background opt' );
585
  ewww_image_optimizer_debug_log();
586
  return;
classes/class-ewwwio-page-parser.php CHANGED
@@ -14,6 +14,20 @@ if ( ! defined( 'ABSPATH' ) ) {
14
  */
15
  class EWWWIO_Page_Parser {
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  /**
18
  * Match all images and any relevant <a> tags in a block of HTML.
19
  *
@@ -30,15 +44,14 @@ class EWWWIO_Page_Parser {
30
  ewwwio_debug_message( '<b>' . __METHOD__ . '()</b>' );
31
  $images = array();
32
 
33
- $fallback_pattern = '';
 
34
  if ( $hyperlinks ) {
35
- $search_pattern = '#(?:<figure[^>]+?class\s*=\s*["\'](?P<figure_class>[\w\s-]+?)["\'][^>]*?>\s*)?(?:<a[^>]+?href\s*=\s*["\'](?P<link_url>[^\s]+?)["\'][^>]*?>\s*)?(?P<img_tag><img[^>]*?\s+?src\s*=\s*["\'](?P<img_url>[^\s]+?)["\'].*?>){1}(?:\s*</a>)?#is';
36
- $fallback_pattern = '#(?:<figure[^>]+?class\s*=\s*["\'](?P<figure_class>[\w\s-]+?)["\'][^>]*?>\s*)?(?:<a[^>]+?href\s*=\s*["\'](?P<link_url>[^\s]+?)["\'][^>]*?>\s*)?(?P<img_tag><img[^>]*?\s+?src\s*=\s*["\']?(?P<img_url>[^\s]+?)["\']?.*?>){1}(?:\s*</a>)?#is';
37
  } elseif ( $src_required ) {
38
- $search_pattern = '#(?P<img_tag><img[^>]*?\s+?src\s*=\s*["\'](?P<img_url>[^\s]+?)["\'].*?>)#is';
39
- $fallback_pattern = '#(?P<img_tag><img[^>]*?\s+?src\s*=\s*["\']?(?P<img_url>[^\s]+?)["\']?.*?>)#is';
40
- } else {
41
- $search_pattern = '#(?P<img_tag><img.*?>)#is';
42
  }
43
  if ( preg_match_all( $search_pattern, $content, $images ) ) {
44
  foreach ( $images as $key => $unused ) {
@@ -47,19 +60,24 @@ class EWWWIO_Page_Parser {
47
  unset( $images[ $key ] );
48
  }
49
  }
50
- return $images;
51
  }
52
- ewwwio_debug_message( 'trying fallback pattern' );
53
- if ( preg_match_all( $fallback_pattern, $content, $images ) ) {
54
- foreach ( $images as $key => $unused ) {
55
  // Simplify the output as much as possible.
56
  if ( is_numeric( $key ) && $key > 0 ) {
57
- unset( $images[ $key ] );
58
  }
59
  }
60
- return $images;
61
  }
62
- return array();
 
 
 
 
 
 
 
63
  }
64
 
65
  /**
@@ -74,7 +92,7 @@ class EWWWIO_Page_Parser {
74
  ewwwio_debug_message( '<b>' . __METHOD__ . '()</b>' );
75
  $images = array();
76
 
77
- if ( preg_match_all( '#(?P<noscript_tag><noscript[^>]*?>\s*)(?P<img_tag><img[^>]*?\s+?src\s*=\s*["\'](?P<img_url>[^\s]+?)["\'].*?>){1}(?:\s*</noscript>)?#is', $content, $images ) ) {
78
  foreach ( $images as $key => $unused ) {
79
  // Simplify the output as much as possible, mostly for confirming test results.
80
  if ( is_numeric( $key ) && $key > 0 ) {
@@ -113,7 +131,7 @@ class EWWWIO_Page_Parser {
113
  if ( ! ctype_alpha( $tag_name ) ) {
114
  return array();
115
  }
116
- if ( preg_match_all( '#<' . $tag_name . '[^>]+?>#is', $content, $elements ) ) {
117
  return $elements[0];
118
  }
119
  return array();
@@ -145,6 +163,24 @@ class EWWWIO_Page_Parser {
145
  return array( false, false );
146
  }
147
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
  /**
149
  * Get an attribute from an HTML element.
150
  *
@@ -154,13 +190,13 @@ class EWWWIO_Page_Parser {
154
  */
155
  function get_attribute( $element, $name ) {
156
  // Don't forget, back references cannot be used in character classes.
157
- if ( preg_match( '#[\s"\']' . $name . '\s*=\s*(["\'])([^"\']+?)\1#is', $element, $attr_matches ) ) {
158
  if ( ! empty( $attr_matches[2] ) ) {
159
  return $attr_matches[2];
160
  }
161
  }
162
  // If there were not any matches with quotes, look for unquoted attributes, no spaces or quotes allowed.
163
- if ( preg_match( '#[\s"\']' . $name . '\s*=\s*([^\s"\']+?)#is', $element, $attr_matches ) ) {
164
  if ( ! empty( $attr_matches[1] ) ) {
165
  return $attr_matches[1];
166
  }
@@ -192,18 +228,18 @@ class EWWWIO_Page_Parser {
192
  * @param bool $replace Default false. True to replace, false to append.
193
  */
194
  function set_attribute( &$element, $name, $value, $replace = false ) {
195
- if ( 'class' === $name && false !== strpos( $element, " $name " ) && false === strpos( $element, " $name =" ) ) {
196
- $element = str_replace( " $name ", ' ', $element );
197
  }
198
  $value = trim( $value );
199
  if ( $replace ) {
200
  // Don't forget, back references cannot be used in character classes.
201
- $new_element = preg_replace( '# ' . $name . '\s*=\s*(["\'])[^"\']*?\1#is', " $name=$1$value$1", $element );
202
  if ( strpos( $new_element, "$name=" ) ) {
203
  $element = $new_element;
204
  return;
205
  }
206
- $element = preg_replace( '# ' . $name . '\s*=\s*[^\s"\']+?#is', ' ', $element );
207
  }
208
  $closing = ' />';
209
  if ( false === strpos( $element, '/>' ) ) {
@@ -224,8 +260,8 @@ class EWWWIO_Page_Parser {
224
  */
225
  function remove_attribute( &$element, $name ) {
226
  // Don't forget, back references cannot be used in character classes.
227
- $element = preg_replace( '# ' . $name . '\s*=\s*(["\'])[^"\']+?\1#is', ' ', $element );
228
- $element = preg_replace( '# ' . $name . '\s*=\s*[^\s"\']+?#is', ' ', $element );
229
  }
230
 
231
  /**
14
  */
15
  class EWWWIO_Page_Parser {
16
 
17
+ /**
18
+ * Allowed image extensions.
19
+ *
20
+ * @access private
21
+ * @var array $extensions
22
+ */
23
+ protected $extensions = array(
24
+ 'gif',
25
+ 'jpg',
26
+ 'jpeg',
27
+ 'jpe',
28
+ 'png',
29
+ );
30
+
31
  /**
32
  * Match all images and any relevant <a> tags in a block of HTML.
33
  *
44
  ewwwio_debug_message( '<b>' . __METHOD__ . '()</b>' );
45
  $images = array();
46
 
47
+ $unquoted_pattern = '';
48
+ $search_pattern = '#(?P<img_tag><img\s[^>]*?>)#is';
49
  if ( $hyperlinks ) {
50
+ $search_pattern = '#(?:<figure[^>]*?\s+?class\s*=\s*["\'](?P<figure_class>[\w\s-]+?)["\'][^>]*?>\s*)?(?:<a[^>]*?\s+?href\s*=\s*["\'](?P<link_url>[^\s]+?)["\'][^>]*?>\s*)?(?P<img_tag><img[^>]*?\s+?src\s*=\s*["\'](?P<img_url>[^\s]+?)["\'][^>]*?>){1}(?:\s*</a>)?#is';
51
+ $unquoted_pattern = '#(?:<figure[^>]*?\s+?class\s*=\s*(?P<figure_class>[\w-]+)[^>]*?>\s*)?(?:<a[^>]*?\s+?href\s*=\s*(?P<link_url>[^"\'][^\s>]+)[^>]*?>\s*)?(?P<img_tag><img[^>]*?\s+?src\s*=\s*(?P<img_url>[^"\'][^\s>]+)[^>]*?>){1}(?:\s*</a>)?#is';
52
  } elseif ( $src_required ) {
53
+ $search_pattern = '#(?P<img_tag><img[^>]*?\s+?src\s*=\s*["\'](?P<img_url>[^\s]+?)["\'][^>]*?>)#is';
54
+ $unquoted_pattern = '#(?P<img_tag><img[^>]*?\s+?src\s*=\s*(?P<img_url>[^"\'][^\s>]+)[^>]*?>)#is';
 
 
55
  }
56
  if ( preg_match_all( $search_pattern, $content, $images ) ) {
57
  foreach ( $images as $key => $unused ) {
60
  unset( $images[ $key ] );
61
  }
62
  }
 
63
  }
64
+ ewwwio_debug_message( 'trying unquoted pattern' );
65
+ if ( $unquoted_pattern && preg_match_all( $unquoted_pattern, $content, $unquoted_images ) ) {
66
+ foreach ( $unquoted_images as $key => $unused ) {
67
  // Simplify the output as much as possible.
68
  if ( is_numeric( $key ) && $key > 0 ) {
69
+ unset( $unquoted_images[ $key ] );
70
  }
71
  }
 
72
  }
73
+ if ( ! empty( $images ) && ! empty( $unquoted_images ) ) {
74
+ $images = array_merge_recursive( $images, $unquoted_images );
75
+ if ( ! empty( $images[0] ) && ! empty( $images[1] ) ) {
76
+ $images[0] = array_merge( $images[0], $images[1] );
77
+ unset( $images[1] );
78
+ }
79
+ }
80
+ return $images;
81
  }
82
 
83
  /**
92
  ewwwio_debug_message( '<b>' . __METHOD__ . '()</b>' );
93
  $images = array();
94
 
95
+ if ( preg_match_all( '#(?P<noscript_tag><noscript[^>]*?>\s*)(?P<img_tag><img[^>]*?\s+?src\s*=\s*["\'](?P<img_url>[^\s]+?)["\'][^>]*?>){1}(?:\s*</noscript>)?#is', $content, $images ) ) {
96
  foreach ( $images as $key => $unused ) {
97
  // Simplify the output as much as possible, mostly for confirming test results.
98
  if ( is_numeric( $key ) && $key > 0 ) {
131
  if ( ! ctype_alpha( $tag_name ) ) {
132
  return array();
133
  }
134
+ if ( preg_match_all( '#<' . $tag_name . '\s[^>]+?>#is', $content, $elements ) ) {
135
  return $elements[0];
136
  }
137
  return array();
163
  return array( false, false );
164
  }
165
 
166
+ /**
167
+ * Get the width from an image element.
168
+ *
169
+ * @param string $img The full image element.
170
+ * @return string The width found or an empty string.
171
+ */
172
+ public function get_img_width( $img ) {
173
+ $width = $this->get_attribute( $img, 'width' );
174
+ // Then check for an inline max-width directive.
175
+ $style = $this->get_attribute( $img, 'style' );
176
+ if ( $style && preg_match( '#max-width:\s?(\d+)px#', $style, $max_width_string ) ) {
177
+ if ( $max_width_string[1] && ( ! $width || $max_width_string[1] < $width ) ) {
178
+ $width = $max_width_string[1];
179
+ }
180
+ }
181
+ return $width;
182
+ }
183
+
184
  /**
185
  * Get an attribute from an HTML element.
186
  *
190
  */
191
  function get_attribute( $element, $name ) {
192
  // Don't forget, back references cannot be used in character classes.
193
+ if ( preg_match( '#[\s]' . $name . '\s*=\s*(["\'])([^"\']+?)\1#is', $element, $attr_matches ) ) {
194
  if ( ! empty( $attr_matches[2] ) ) {
195
  return $attr_matches[2];
196
  }
197
  }
198
  // If there were not any matches with quotes, look for unquoted attributes, no spaces or quotes allowed.
199
+ if ( preg_match( '#[\s]' . $name . '\s*=\s*([^"\'][^\s>]+)#is', $element, $attr_matches ) ) {
200
  if ( ! empty( $attr_matches[1] ) ) {
201
  return $attr_matches[1];
202
  }
228
  * @param bool $replace Default false. True to replace, false to append.
229
  */
230
  function set_attribute( &$element, $name, $value, $replace = false ) {
231
+ if ( 'class' === $name ) {
232
+ $element = preg_replace( "#\s$name\s+[^=]#", ' ', $element );
233
  }
234
  $value = trim( $value );
235
  if ( $replace ) {
236
  // Don't forget, back references cannot be used in character classes.
237
+ $new_element = preg_replace( '#\s' . $name . '\s*=\s*(["\'])[^"\']*?\1#is', " $name=$1$value$1", $element );
238
  if ( strpos( $new_element, "$name=" ) ) {
239
  $element = $new_element;
240
  return;
241
  }
242
+ $element = preg_replace( '#\s' . $name . '\s*=\s*[^"\'][^\s>]+#is', ' ', $element );
243
  }
244
  $closing = ' />';
245
  if ( false === strpos( $element, '/>' ) ) {
260
  */
261
  function remove_attribute( &$element, $name ) {
262
  // Don't forget, back references cannot be used in character classes.
263
+ $element = preg_replace( '#\s' . $name . '\s*=\s*(["\'])[^"\']+?\1#is', ' ', $element );
264
+ $element = preg_replace( '#\s' . $name . '\s*=\s*[^"\'][^\s>]+#is', ' ', $element );
265
  }
266
 
267
  /**
classes/class-ewwwio-tracking.php CHANGED
@@ -65,7 +65,7 @@ class EWWWIO_Tracking {
65
  $theme = $theme_data->Name . ' ' . $theme_data->Version;
66
  $data['email'] = get_bloginfo( 'admin_email' ); // Not tracked, used to issue free credits.
67
  $data['site_id'] = md5( home_url() );
68
- if ( strlen( ewww_image_optimizer_get_option( 'ewww_image_optimizer_tracking_site_id' ) ) == 32 && ctype_alnum( ewww_image_optimizer_get_option( 'ewww_image_optimizer_tracking_site_id' ) ) ) {
69
  ewwwio_debug_message( 'using pre-existing site_id' );
70
  $data['site_id'] = ewww_image_optimizer_get_option( 'ewww_image_optimizer_tracking_site_id' );
71
  } else {
@@ -88,7 +88,7 @@ class EWWWIO_Tracking {
88
  $active_plugins = get_option( 'active_plugins', array() );
89
 
90
  foreach ( $plugins as $key => $plugin ) {
91
- if ( in_array( $plugin, $active_plugins ) ) {
92
  // Remove active plugins from list so we can show active and inactive separately.
93
  unset( $plugins[ $key ] );
94
  }
@@ -286,10 +286,10 @@ class EWWWIO_Tracking {
286
  }
287
  }
288
  // We send once a week (while tracking is allowed) to check in, which can be used to determine active sites.
289
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_allow_tracking' ) == true && ! wp_next_scheduled( 'ewww_image_optimizer_site_report' ) ) {
290
  ewwwio_debug_message( 'scheduling checkin' );
291
  wp_schedule_event( time(), apply_filters( 'ewww_image_optimizer_schedule', 'daily', 'ewww_image_optimizer_site_report' ), 'ewww_image_optimizer_site_report' );
292
- } elseif ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_allow_tracking' ) == true ) {
293
  ewwwio_debug_message( 'checkin already scheduled: ' . wp_next_scheduled( 'ewww_image_optimizer_site_report' ) );
294
  } elseif ( wp_next_scheduled( 'ewww_image_optimizer_site_report' ) ) {
295
  ewwwio_debug_message( 'un-scheduling checkin' );
65
  $theme = $theme_data->Name . ' ' . $theme_data->Version;
66
  $data['email'] = get_bloginfo( 'admin_email' ); // Not tracked, used to issue free credits.
67
  $data['site_id'] = md5( home_url() );
68
+ if ( strlen( ewww_image_optimizer_get_option( 'ewww_image_optimizer_tracking_site_id' ) ) === 32 && ctype_alnum( ewww_image_optimizer_get_option( 'ewww_image_optimizer_tracking_site_id' ) ) ) {
69
  ewwwio_debug_message( 'using pre-existing site_id' );
70
  $data['site_id'] = ewww_image_optimizer_get_option( 'ewww_image_optimizer_tracking_site_id' );
71
  } else {
88
  $active_plugins = get_option( 'active_plugins', array() );
89
 
90
  foreach ( $plugins as $key => $plugin ) {
91
+ if ( in_array( $plugin, $active_plugins, true ) ) {
92
  // Remove active plugins from list so we can show active and inactive separately.
93
  unset( $plugins[ $key ] );
94
  }
286
  }
287
  }
288
  // We send once a week (while tracking is allowed) to check in, which can be used to determine active sites.
289
+ if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_allow_tracking' ) && ! wp_next_scheduled( 'ewww_image_optimizer_site_report' ) ) {
290
  ewwwio_debug_message( 'scheduling checkin' );
291
  wp_schedule_event( time(), apply_filters( 'ewww_image_optimizer_schedule', 'daily', 'ewww_image_optimizer_site_report' ), 'ewww_image_optimizer_site_report' );
292
+ } elseif ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_allow_tracking' ) ) {
293
  ewwwio_debug_message( 'checkin already scheduled: ' . wp_next_scheduled( 'ewww_image_optimizer_site_report' ) );
294
  } elseif ( wp_next_scheduled( 'ewww_image_optimizer_site_report' ) ) {
295
  ewwwio_debug_message( 'un-scheduling checkin' );
classes/class-exactdn.php CHANGED
@@ -15,21 +15,6 @@ if ( ! defined( 'ABSPATH' ) ) {
15
  */
16
  class ExactDN extends EWWWIO_Page_Parser {
17
 
18
- /**
19
- * Allowed image extensions.
20
- *
21
- * @access private
22
- * @var array $extensions
23
- */
24
- protected $extensions = array(
25
- 'gif',
26
- 'jpg',
27
- 'jpeg',
28
- 'jpe',
29
- 'png',
30
- );
31
-
32
-
33
  /**
34
  * A list of user-defined exclusions, populated by validate_user_exclusions().
35
  *
@@ -185,7 +170,7 @@ class ExactDN extends EWWWIO_Page_Parser {
185
 
186
  // Improve the default content_width for Twenty Nineteen.
187
  global $content_width;
188
- if ( function_exists( 'twentynineteen_setup' ) && 640 == $content_width ) {
189
  $content_width = 932;
190
  }
191
 
@@ -615,7 +600,7 @@ class ExactDN extends EWWWIO_Page_Parser {
615
  */
616
  function get_content_width() {
617
  $content_width = isset( $GLOBALS['content_width'] ) && is_numeric( $GLOBALS['content_width'] ) && $GLOBALS['content_width'] > 100 ? $GLOBALS['content_width'] : 1920;
618
- if ( function_exists( 'twentynineteen_setup' ) && 640 == $content_width ) {
619
  $content_width = 932;
620
  }
621
  /**
@@ -626,24 +611,6 @@ class ExactDN extends EWWWIO_Page_Parser {
626
  return (int) apply_filters( 'exactdn_content_width', $content_width );
627
  }
628
 
629
- /**
630
- * Get the width from an image element.
631
- *
632
- * @param string $img The full image element.
633
- * @return string The width found or an empty string.
634
- */
635
- public function get_img_width( $img ) {
636
- $width = $this->get_attribute( $img, 'width' );
637
- // Then check for an inline max-width directive.
638
- $style = $this->get_attribute( $img, 'style' );
639
- if ( $style && preg_match( '#max-width:\s?(\d+)px#', $style, $max_width_string ) ) {
640
- if ( $max_width_string[1] && ( ! $width || $max_width_string[1] < $width ) ) {
641
- $width = $max_width_string[1];
642
- }
643
- }
644
- return $width;
645
- }
646
-
647
  /**
648
  * Get width within an ExactDN url.
649
  *
@@ -852,7 +819,7 @@ class ExactDN extends EWWWIO_Page_Parser {
852
  $size = array_pop( $size );
853
 
854
  ewwwio_debug_message( "detected $size" );
855
- if ( false === $width && false === $height && 'full' != $size && array_key_exists( $size, $image_sizes ) ) {
856
  $width = (int) $image_sizes[ $size ]['width'];
857
  $height = (int) $image_sizes[ $size ]['height'];
858
  $transform = $image_sizes[ $size ]['crop'] ? 'resize' : 'fit';
@@ -887,7 +854,7 @@ class ExactDN extends EWWWIO_Page_Parser {
887
  $attachment = get_post( $attachment_id );
888
 
889
  // Basic check on returned post object.
890
- if ( is_object( $attachment ) && ! is_wp_error( $attachment ) && 'attachment' == $attachment->post_type ) {
891
  $src_per_wp = wp_get_attachment_image_src( $attachment_id, 'full' );
892
 
893
  if ( $src_per_wp && is_array( $src_per_wp ) ) {
@@ -909,7 +876,7 @@ class ExactDN extends EWWWIO_Page_Parser {
909
 
910
  if ( $src_per_wp && $this->validate_image_url( $src_per_wp[0] ) ) {
911
  ewwwio_debug_message( "detected $width filenamew $filename_width" );
912
- if ( $resize_existing || ( $width && $filename_width != $width ) ) {
913
  ewwwio_debug_message( 'resizing existing or width does not match' );
914
  $src = $src_per_wp[0];
915
  }
@@ -984,7 +951,7 @@ class ExactDN extends EWWWIO_Page_Parser {
984
  $args['h'] = $height;
985
  }
986
 
987
- if ( ! $resize_existing && ( ! $width || $filename_width == $width ) ) {
988
  ewwwio_debug_message( 'preventing resize' );
989
  $args = array();
990
  } elseif ( ! $fullsize_url ) {
@@ -1022,7 +989,7 @@ class ExactDN extends EWWWIO_Page_Parser {
1022
 
1023
  // Modify image tag if ExactDN function provides a URL
1024
  // Ensure changes are only applied to the current image by copying and modifying the matched tag, then replacing the entire tag with our modified version.
1025
- if ( $src != $exactdn_url ) {
1026
  $new_tag = $tag;
1027
 
1028
  // If present, replace the link href with an ExactDN URL for the full-size image.
@@ -1031,21 +998,21 @@ class ExactDN extends EWWWIO_Page_Parser {
1031
  }
1032
 
1033
  // Insert new image src into the srcset as well, if we have a width.
1034
- if ( false !== $width && false === strpos( $width, '%' ) ) {
1035
  ewwwio_debug_message( 'checking to see if srcset width already exists' );
1036
  $srcset_url = $exactdn_url . ' ' . (int) $width . 'w, ';
1037
  $new_srcset_attr = $this->get_attribute( $new_tag, $this->srcset_attr );
1038
- if ( $new_srcset_attr && false === strpos( $new_srcset_attr, ' ' . (int) $width . 'w' ) ) {
1039
  ewwwio_debug_message( 'src not in srcset, adding' );
1040
  $this->set_attribute( $new_tag, $this->srcset_attr, $srcset_url . $new_srcset_attr, true );
1041
  }
1042
  }
1043
 
1044
  // Check if content width pushed the respimg sizes attribute too far down.
1045
- if ( ! empty( $constrain_width ) && $constrain_width != $content_width ) {
1046
  $sizes_attr = $this->get_attribute( $new_tag, 'sizes' );
1047
  $new_sizes_attr = str_replace( ' ' . $content_width . 'px', ' ' . $constrain_width . 'px', $sizes_attr );
1048
- if ( $sizes_attr != $new_sizes_attr ) {
1049
  $new_tag = str_replace( $sizes_attr, $new_sizes_attr, $new_tag );
1050
  }
1051
  }
@@ -1060,7 +1027,7 @@ class ExactDN extends EWWWIO_Page_Parser {
1060
  if ( isset( $placeholder_src ) && $this->validate_image_url( $placeholder_src ) ) {
1061
  $placeholder_src = $this->generate_url( $placeholder_src );
1062
 
1063
- if ( $placeholder_src != $placeholder_src_orig ) {
1064
  $new_tag = str_replace( $placeholder_src_orig, str_replace( '&#038;', '&', esc_url( $placeholder_src ) ), $new_tag );
1065
  }
1066
 
@@ -1105,7 +1072,7 @@ class ExactDN extends EWWWIO_Page_Parser {
1105
  $new_tag = $tag;
1106
  // If Lazy Load is in use, pass placeholder image through ExactDN.
1107
  $placeholder_src = $this->generate_url( $placeholder_src );
1108
- if ( $placeholder_src != $placeholder_src_orig ) {
1109
  $new_tag = str_replace( $placeholder_src_orig, str_replace( '&#038;', '&', esc_url( $placeholder_src ) ), $new_tag );
1110
  // Replace original tag with modified version.
1111
  $content = str_replace( $tag, $new_tag, $content );
@@ -1233,11 +1200,14 @@ class ExactDN extends EWWWIO_Page_Parser {
1233
  $args = array();
1234
  $div_class = $this->get_attribute( $div, 'class' );
1235
  if ( false !== strpos( $div_class, 'alignfull' ) && current_theme_supports( 'align-wide' ) ) {
1236
- $args['w'] = apply_filters( 'exactdn_full_align_image_width', 1920 );
1237
  } elseif ( false !== strpos( $div_class, 'alignwide' ) && current_theme_supports( 'align-wide' ) ) {
1238
- $args['w'] = apply_filters( 'exactdn_wide_align_image_width', 1500 );
1239
  } elseif ( $content_width ) {
1240
- $args['w'] = $content_width;
 
 
 
1241
  }
1242
  $exactdn_bg_image_url = $this->generate_url( $bg_image_url, $args );
1243
  if ( $bg_image_url !== $exactdn_bg_image_url ) {
@@ -1267,7 +1237,7 @@ class ExactDN extends EWWWIO_Page_Parser {
1267
  $prz_match = preg_match( '#productDetailsForPrz=[^<]+?thumbnailUrl:\'([^\']+?)\'[^<]+?</script>#', $content, $prz_detail_matches );
1268
  if ( $prz_match && ! empty( $prz_detail_matches[1] ) && $this->validate_image_url( $prz_detail_matches[1] ) ) {
1269
  $prz_thumb = $this->generate_url( $prz_detail_matches[1], apply_filters( 'exactdn_personalizationdotcom_thumb_args', '', $prz_detail_matches[1] ) );
1270
- if ( $prz_thumb != $prz_detail_matches ) {
1271
  $content = str_replace( "thumbnailUrl:'{$prz_detail_matches[1]}'", "thumbnailUrl:'$prz_thumb'", $content );
1272
  }
1273
  }
@@ -1285,16 +1255,16 @@ class ExactDN extends EWWWIO_Page_Parser {
1285
  if ( ! wp_doing_ajax() ) {
1286
  return $allow;
1287
  }
1288
- if ( ! empty( $_POST['action'] ) && 'eddvbugm_viewport_downloads' == $_POST['action'] ) {
1289
  return true;
1290
  }
1291
- if ( ! empty( $_POST['action'] ) && 'vc_get_vc_grid_data' == $_POST['action'] ) {
1292
  return true;
1293
  }
1294
- if ( ! empty( $_POST['action'] ) && 'Essential_Grid_Front_request_ajax' == $_POST['action'] ) {
1295
  return true;
1296
  }
1297
- if ( ! empty( $_POST['action'] ) && 'mabel-rpn-getnew-purchased-products' == $_POST['action'] ) {
1298
  return true;
1299
  }
1300
  return $allow;
@@ -1428,7 +1398,7 @@ class ExactDN extends EWWWIO_Page_Parser {
1428
  if ( is_string( $size ) && array_key_exists( $size, $this->image_sizes() ) ) {
1429
  $image_args = $this->image_sizes();
1430
  $image_args = $image_args[ $size ];
1431
- ewwwio_debug_message( "image args for $size: " . implode( ',', $image_args ) );
1432
 
1433
  $exactdn_args = array();
1434
 
@@ -1460,16 +1430,16 @@ class ExactDN extends EWWWIO_Page_Parser {
1460
  list( $image_args['width'], $image_args['height'] ) = image_constrain_size_for_editor( $image_args['width'], $image_args['height'], $size, 'display' );
1461
 
1462
  $has_size_meta = true;
1463
- ewwwio_debug_message( 'image args constrained: ' . implode( ',', $image_args ) );
1464
  }
1465
 
1466
  $transform = $image_args['crop'] ? 'resize' : 'fit';
1467
 
1468
  // Check specified image dimensions and account for possible zero values; ExactDN fails to resize if a dimension is zero.
1469
- if ( 0 == $image_args['width'] || 0 == $image_args['height'] ) {
1470
- if ( 0 == $image_args['width'] && 0 < $image_args['height'] ) {
1471
  $exactdn_args['h'] = $image_args['height'];
1472
- } elseif ( 0 == $image_args['height'] && 0 < $image_args['width'] ) {
1473
  $exactdn_args['w'] = $image_args['width'];
1474
  }
1475
  } else {
@@ -1492,8 +1462,8 @@ class ExactDN extends EWWWIO_Page_Parser {
1492
 
1493
  if (
1494
  ! empty( $image_meta['sizes'] ) && ! empty( $image_meta['width'] ) && ! empty( $image_meta['height'] ) &&
1495
- $image_args['width'] == $image_meta['width'] &&
1496
- $image_args['height'] == $image_meta['height']
1497
  ) {
1498
  ewwwio_debug_message( 'image args match size of original, just use that' );
1499
  $size = 'full';
@@ -1669,15 +1639,15 @@ class ExactDN extends EWWWIO_Page_Parser {
1669
  $url = $source['url'];
1670
 
1671
  list( $width, $height ) = $this->get_dimensions_from_filename( $url );
1672
- if ( ! $resize_existing && 'w' === $source['descriptor'] && $source['value'] == $width ) {
1673
  ewwwio_debug_message( "preventing further processing for $url" );
1674
  $sources[ $i ]['url'] = $this->generate_url( $source['url'] );
1675
  continue;
1676
  }
1677
 
1678
  if ( $image_meta && ! empty( $image_meta['width'] ) ) {
1679
- if ( ( $height && $image_meta['height'] == $height && $width && $image_meta['width'] == $width ) ||
1680
- ( ! $height && ! $width && $image_meta['width'] == $source['value'] )
1681
  ) {
1682
  ewwwio_debug_message( "preventing further processing for (detected) full-size $url" );
1683
  $sources[ $i ]['url'] = $this->generate_url( $source['url'] );
@@ -1697,7 +1667,7 @@ class ExactDN extends EWWWIO_Page_Parser {
1697
 
1698
  $args = array();
1699
  if ( 'w' === $source['descriptor'] ) {
1700
- if ( $height && ( $source['value'] == $width ) ) {
1701
  $args['resize'] = $width . ',' . $height;
1702
  } else {
1703
  $args['w'] = $source['value'];
@@ -1764,7 +1734,7 @@ class ExactDN extends EWWWIO_Page_Parser {
1764
  foreach ( $multipliers as $multiplier ) {
1765
 
1766
  $newwidth = intval( $base * $multiplier );
1767
- if ( 1920 == $multiplier ) {
1768
  $newwidth = 1920;
1769
  }
1770
  if ( $newwidth < 50 ) {
@@ -1779,7 +1749,7 @@ class ExactDN extends EWWWIO_Page_Parser {
1779
 
1780
  if ( 1 === $multiplier && abs( $newwidth - $fullwidth ) < 5 ) {
1781
  $args = array();
1782
- } elseif ( 'soft' == $crop ) {
1783
  $args = array(
1784
  'w' => $newwidth,
1785
  );
@@ -1890,7 +1860,7 @@ class ExactDN extends EWWWIO_Page_Parser {
1890
 
1891
  foreach ( $multipliers as $multiplier ) {
1892
  $newwidth = intval( $width * $multiplier );
1893
- if ( 1920 == $multiplier ) {
1894
  $newwidth = 1920;
1895
  }
1896
  if ( $newwidth < 50 ) {
@@ -2010,7 +1980,7 @@ class ExactDN extends EWWWIO_Page_Parser {
2010
  $s_y = floor( ( $meta['height'] - $crop_h ) * $focus_point[1] );
2011
  ewwwio_debug_message( "doing the math with size_ratio of $size_ratio" );
2012
 
2013
- $args = array( 'crop' => $s_x . 'px,' . $s_y . 'px,' . $crop_w . 'px,' . $crop_h . 'px' ) + $args;
2014
  ewwwio_debug_message( $args['crop'] );
2015
  return $args;
2016
  }
@@ -2090,7 +2060,7 @@ class ExactDN extends EWWWIO_Page_Parser {
2090
 
2091
  // Bail if scheme isn't http or port is set that isn't port 80.
2092
  if (
2093
- ( 'http' != $url_info['scheme'] || ! in_array( $url_info['port'], array( 80, null ) ) ) &&
2094
  /**
2095
  * Tells ExactDN to ignore images that are served via HTTPS.
2096
  *
@@ -2127,7 +2097,7 @@ class ExactDN extends EWWWIO_Page_Parser {
2127
  }
2128
 
2129
  // Ensure image extension is acceptable, unless it's a dynamic NextGEN image.
2130
- if ( ! in_array( strtolower( pathinfo( $url_info['path'], PATHINFO_EXTENSION ) ), $this->extensions ) && false === strpos( $url_info['path'], 'nextgen-image/' ) ) {
2131
  ewwwio_debug_message( 'invalid extension' );
2132
  return false;
2133
  }
@@ -2186,7 +2156,7 @@ class ExactDN extends EWWWIO_Page_Parser {
2186
  */
2187
  protected function image_sizes() {
2188
  ewwwio_debug_message( '<b>' . __METHOD__ . '()</b>' );
2189
- if ( null == self::$image_sizes ) {
2190
  global $_wp_additional_image_sizes;
2191
 
2192
  // Populate an array matching the data structure of $_wp_additional_image_sizes so we have a consistent structure for image sizes.
@@ -2438,7 +2408,7 @@ class ExactDN extends EWWWIO_Page_Parser {
2438
 
2439
  global $wp_version;
2440
  // If a resource doesn't have a version string, we add one to help with cache-busting.
2441
- if ( ( empty( $parsed_url['query'] ) || 'ver=' . $wp_version == $parsed_url['query'] ) && false !== strpos( $url, 'wp-content/' ) ) {
2442
  $modified = ewww_image_optimizer_function_exists( 'filemtime' ) ? filemtime( get_template_directory() ) : '';
2443
  if ( empty( $modified ) ) {
2444
  $modified = (int) EWWW_IMAGE_OPTIMIZER_VERSION;
@@ -2506,7 +2476,7 @@ class ExactDN extends EWWWIO_Page_Parser {
2506
  if ( false === strpos( $image_url, 'lossy=' ) && ewww_image_optimizer_get_option( 'exactdn_lossy' ) ) {
2507
  $more_args['lossy'] = is_numeric( ewww_image_optimizer_get_option( 'exactdn_lossy' ) ) ? (int) ewww_image_optimizer_get_option( 'exactdn_lossy' ) : 80;
2508
  }
2509
- if ( false === strpos( $image_url, 'quality=' ) && ! is_null( $jpg_quality ) && 82 != $jpg_quality ) {
2510
  $more_args['quality'] = $jpg_quality;
2511
  }
2512
  // Merge given args with the automatic (option-based) args, and also makes sure args is an array if it was previously a string.
@@ -2533,7 +2503,7 @@ class ExactDN extends EWWWIO_Page_Parser {
2533
  return $image_url;
2534
  }
2535
 
2536
- if ( isset( $image_url_parts['scheme'] ) && 'https' == $image_url_parts['scheme'] ) {
2537
  if ( is_array( $args ) ) {
2538
  $args['ssl'] = 1;
2539
  }
@@ -2581,7 +2551,7 @@ class ExactDN extends EWWWIO_Page_Parser {
2581
  // However some source images are served via PHP so check the no-query-string extension.
2582
  // For future proofing, this is a blacklist of common issues rather than a whitelist.
2583
  $extension = pathinfo( $image_url_parts['path'], PATHINFO_EXTENSION );
2584
- if ( ( empty( $extension ) && false === strpos( $image_url_parts['path'], 'nextgen-image/' ) ) || in_array( $extension, array( 'php', 'ashx' ) ) ) {
2585
  ewwwio_debug_message( 'bad extension' );
2586
  return $image_url;
2587
  }
@@ -2631,7 +2601,7 @@ class ExactDN extends EWWWIO_Page_Parser {
2631
  */
2632
  function url_scheme( $url, $scheme ) {
2633
  ewwwio_debug_message( '<b>' . __METHOD__ . '()</b>' );
2634
- if ( ! in_array( $scheme, array( 'http', 'https' ) ) ) {
2635
  ewwwio_debug_message( 'not a valid scheme' );
2636
  if ( preg_match( '#^(https?:)?//#', $url ) ) {
2637
  ewwwio_debug_message( 'url has a valid scheme already' );
@@ -2704,7 +2674,7 @@ class ExactDN extends EWWWIO_Page_Parser {
2704
  */
2705
  function autoptimize_cdn_url( $domains ) {
2706
  ewwwio_debug_message( '<b>' . __METHOD__ . '()</b>' );
2707
- if ( is_array( $domains ) && ! in_array( $this->exactdn_domain, $domains ) ) {
2708
  ewwwio_debug_message( 'adding to AO list: ' . $this->exactdn_domain );
2709
  $domains[] = $this->exactdn_domain;
2710
  }
15
  */
16
  class ExactDN extends EWWWIO_Page_Parser {
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  /**
19
  * A list of user-defined exclusions, populated by validate_user_exclusions().
20
  *
170
 
171
  // Improve the default content_width for Twenty Nineteen.
172
  global $content_width;
173
+ if ( function_exists( 'twentynineteen_setup' ) && 640 === (int) $content_width ) {
174
  $content_width = 932;
175
  }
176
 
600
  */
601
  function get_content_width() {
602
  $content_width = isset( $GLOBALS['content_width'] ) && is_numeric( $GLOBALS['content_width'] ) && $GLOBALS['content_width'] > 100 ? $GLOBALS['content_width'] : 1920;
603
+ if ( function_exists( 'twentynineteen_setup' ) && 640 === (int) $content_width ) {
604
  $content_width = 932;
605
  }
606
  /**
611
  return (int) apply_filters( 'exactdn_content_width', $content_width );
612
  }
613
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
614
  /**
615
  * Get width within an ExactDN url.
616
  *
819
  $size = array_pop( $size );
820
 
821
  ewwwio_debug_message( "detected $size" );
822
+ if ( false === $width && false === $height && 'full' !== $size && array_key_exists( $size, $image_sizes ) ) {
823
  $width = (int) $image_sizes[ $size ]['width'];
824
  $height = (int) $image_sizes[ $size ]['height'];
825
  $transform = $image_sizes[ $size ]['crop'] ? 'resize' : 'fit';
854
  $attachment = get_post( $attachment_id );
855
 
856
  // Basic check on returned post object.
857
+ if ( is_object( $attachment ) && ! is_wp_error( $attachment ) && 'attachment' === $attachment->post_type ) {
858
  $src_per_wp = wp_get_attachment_image_src( $attachment_id, 'full' );
859
 
860
  if ( $src_per_wp && is_array( $src_per_wp ) ) {
876
 
877
  if ( $src_per_wp && $this->validate_image_url( $src_per_wp[0] ) ) {
878
  ewwwio_debug_message( "detected $width filenamew $filename_width" );
879
+ if ( $resize_existing || ( $width && (int) $filename_width !== (int) $width ) ) {
880
  ewwwio_debug_message( 'resizing existing or width does not match' );
881
  $src = $src_per_wp[0];
882
  }
951
  $args['h'] = $height;
952
  }
953
 
954
+ if ( ! $resize_existing && ( ! $width || (int) $filename_width === (int) $width ) ) {
955
  ewwwio_debug_message( 'preventing resize' );
956
  $args = array();
957
  } elseif ( ! $fullsize_url ) {
989
 
990
  // Modify image tag if ExactDN function provides a URL
991
  // Ensure changes are only applied to the current image by copying and modifying the matched tag, then replacing the entire tag with our modified version.
992
+ if ( $src !== $exactdn_url ) {
993
  $new_tag = $tag;
994
 
995
  // If present, replace the link href with an ExactDN URL for the full-size image.
998
  }
999
 
1000
  // Insert new image src into the srcset as well, if we have a width.
1001
+ if ( false !== $width && false === strpos( $width, '%' ) && $width ) {
1002
  ewwwio_debug_message( 'checking to see if srcset width already exists' );
1003
  $srcset_url = $exactdn_url . ' ' . (int) $width . 'w, ';
1004
  $new_srcset_attr = $this->get_attribute( $new_tag, $this->srcset_attr );
1005
+ if ( $new_srcset_attr && false === strpos( $new_srcset_attr, ' ' . (int) $width . 'w' ) && ! preg_match( '/\s(1|2|3)x/', $new_srcset_attr ) ) {
1006
  ewwwio_debug_message( 'src not in srcset, adding' );
1007
  $this->set_attribute( $new_tag, $this->srcset_attr, $srcset_url . $new_srcset_attr, true );
1008
  }
1009
  }
1010
 
1011
  // Check if content width pushed the respimg sizes attribute too far down.
1012
+ if ( ! empty( $constrain_width ) && (int) $constrain_width !== (int) $content_width ) {
1013
  $sizes_attr = $this->get_attribute( $new_tag, 'sizes' );
1014
  $new_sizes_attr = str_replace( ' ' . $content_width . 'px', ' ' . $constrain_width . 'px', $sizes_attr );
1015
+ if ( $sizes_attr !== $new_sizes_attr ) {
1016
  $new_tag = str_replace( $sizes_attr, $new_sizes_attr, $new_tag );
1017
  }
1018
  }
1027
  if ( isset( $placeholder_src ) && $this->validate_image_url( $placeholder_src ) ) {
1028
  $placeholder_src = $this->generate_url( $placeholder_src );
1029
 
1030
+ if ( $placeholder_src !== $placeholder_src_orig ) {
1031
  $new_tag = str_replace( $placeholder_src_orig, str_replace( '&#038;', '&', esc_url( $placeholder_src ) ), $new_tag );
1032
  }
1033
 
1072
  $new_tag = $tag;
1073
  // If Lazy Load is in use, pass placeholder image through ExactDN.
1074
  $placeholder_src = $this->generate_url( $placeholder_src );
1075
+ if ( $placeholder_src !== $placeholder_src_orig ) {
1076
  $new_tag = str_replace( $placeholder_src_orig, str_replace( '&#038;', '&', esc_url( $placeholder_src ) ), $new_tag );
1077
  // Replace original tag with modified version.
1078
  $content = str_replace( $tag, $new_tag, $content );
1200
  $args = array();
1201
  $div_class = $this->get_attribute( $div, 'class' );
1202
  if ( false !== strpos( $div_class, 'alignfull' ) && current_theme_supports( 'align-wide' ) ) {
1203
+ $args['w'] = apply_filters( 'exactdn_full_align_bgimage_width', 1920, $bg_image_url );
1204
  } elseif ( false !== strpos( $div_class, 'alignwide' ) && current_theme_supports( 'align-wide' ) ) {
1205
+ $args['w'] = apply_filters( 'exactdn_wide_align_bgimage_width', 1500, $bg_image_url );
1206
  } elseif ( $content_width ) {
1207
+ $args['w'] = apply_filters( 'exactdn_content_bgimage_width', $content_width, $bg_image_url );
1208
+ }
1209
+ if ( isset( $args['w'] ) && empty( $args['w'] ) ) {
1210
+ unset( $args['w'] );
1211
  }
1212
  $exactdn_bg_image_url = $this->generate_url( $bg_image_url, $args );
1213
  if ( $bg_image_url !== $exactdn_bg_image_url ) {
1237
  $prz_match = preg_match( '#productDetailsForPrz=[^<]+?thumbnailUrl:\'([^\']+?)\'[^<]+?</script>#', $content, $prz_detail_matches );
1238
  if ( $prz_match && ! empty( $prz_detail_matches[1] ) && $this->validate_image_url( $prz_detail_matches[1] ) ) {
1239
  $prz_thumb = $this->generate_url( $prz_detail_matches[1], apply_filters( 'exactdn_personalizationdotcom_thumb_args', '', $prz_detail_matches[1] ) );
1240
+ if ( $prz_thumb !== $prz_detail_matches ) {
1241
  $content = str_replace( "thumbnailUrl:'{$prz_detail_matches[1]}'", "thumbnailUrl:'$prz_thumb'", $content );
1242
  }
1243
  }
1255
  if ( ! wp_doing_ajax() ) {
1256
  return $allow;
1257
  }
1258
+ if ( ! empty( $_POST['action'] ) && 'eddvbugm_viewport_downloads' === $_POST['action'] ) {
1259
  return true;
1260
  }
1261
+ if ( ! empty( $_POST['action'] ) && 'vc_get_vc_grid_data' === $_POST['action'] ) {
1262
  return true;
1263
  }
1264
+ if ( ! empty( $_POST['action'] ) && 'Essential_Grid_Front_request_ajax' === $_POST['action'] ) {
1265
  return true;
1266
  }
1267
+ if ( ! empty( $_POST['action'] ) && 'mabel-rpn-getnew-purchased-products' === $_POST['action'] ) {
1268
  return true;
1269
  }
1270
  return $allow;
1398
  if ( is_string( $size ) && array_key_exists( $size, $this->image_sizes() ) ) {
1399
  $image_args = $this->image_sizes();
1400
  $image_args = $image_args[ $size ];
1401
+ ewwwio_debug_message( "image args for $size: " . ewwwio_implode( ',', $image_args ) );
1402
 
1403
  $exactdn_args = array();
1404
 
1430
  list( $image_args['width'], $image_args['height'] ) = image_constrain_size_for_editor( $image_args['width'], $image_args['height'], $size, 'display' );
1431
 
1432
  $has_size_meta = true;
1433
+ ewwwio_debug_message( 'image args constrained: ' . ewwwio_implode( ',', $image_args ) );
1434
  }
1435
 
1436
  $transform = $image_args['crop'] ? 'resize' : 'fit';
1437
 
1438
  // Check specified image dimensions and account for possible zero values; ExactDN fails to resize if a dimension is zero.
1439
+ if ( ! $image_args['width'] || ! $image_args['height'] ) {
1440
+ if ( ! $image_args['width'] && 0 < $image_args['height'] ) {
1441
  $exactdn_args['h'] = $image_args['height'];
1442
+ } elseif ( ! $image_args['height'] && 0 < $image_args['width'] ) {
1443
  $exactdn_args['w'] = $image_args['width'];
1444
  }
1445
  } else {
1462
 
1463
  if (
1464
  ! empty( $image_meta['sizes'] ) && ! empty( $image_meta['width'] ) && ! empty( $image_meta['height'] ) &&
1465
+ (int) $image_args['width'] === (int) $image_meta['width'] &&
1466
+ (int) $image_args['height'] === (int) $image_meta['height']
1467
  ) {
1468
  ewwwio_debug_message( 'image args match size of original, just use that' );
1469
  $size = 'full';
1639
  $url = $source['url'];
1640
 
1641
  list( $width, $height ) = $this->get_dimensions_from_filename( $url );
1642
+ if ( ! $resize_existing && 'w' === $source['descriptor'] && (int) $source['value'] === (int) $width ) {
1643
  ewwwio_debug_message( "preventing further processing for $url" );
1644
  $sources[ $i ]['url'] = $this->generate_url( $source['url'] );
1645
  continue;
1646
  }
1647
 
1648
  if ( $image_meta && ! empty( $image_meta['width'] ) ) {
1649
+ if ( ( $height && (int) $image_meta['height'] === (int) $height && $width && (int) $image_meta['width'] === (int) $width ) ||
1650
+ ( ! $height && ! $width && (int) $image_meta['width'] === (int) $source['value'] )
1651
  ) {
1652
  ewwwio_debug_message( "preventing further processing for (detected) full-size $url" );
1653
  $sources[ $i ]['url'] = $this->generate_url( $source['url'] );
1667
 
1668
  $args = array();
1669
  if ( 'w' === $source['descriptor'] ) {
1670
+ if ( $height && ( (int) $source['value'] === (int) $width ) ) {
1671
  $args['resize'] = $width . ',' . $height;
1672
  } else {
1673
  $args['w'] = $source['value'];
1734
  foreach ( $multipliers as $multiplier ) {
1735
 
1736
  $newwidth = intval( $base * $multiplier );
1737
+ if ( 1920 === (int) $multiplier ) {
1738
  $newwidth = 1920;
1739
  }
1740
  if ( $newwidth < 50 ) {
1749
 
1750
  if ( 1 === $multiplier && abs( $newwidth - $fullwidth ) < 5 ) {
1751
  $args = array();
1752
+ } elseif ( 'soft' === $crop ) {
1753
  $args = array(
1754
  'w' => $newwidth,
1755
  );
1860
 
1861
  foreach ( $multipliers as $multiplier ) {
1862
  $newwidth = intval( $width * $multiplier );
1863
+ if ( 1920 === (int) $multiplier ) {
1864
  $newwidth = 1920;
1865
  }
1866
  if ( $newwidth < 50 ) {
1980
  $s_y = floor( ( $meta['height'] - $crop_h ) * $focus_point[1] );
1981
  ewwwio_debug_message( "doing the math with size_ratio of $size_ratio" );
1982
 
1983
+ $args['crop'] = $s_x . ',' . $s_y . ',' . $crop_w . ',' . $crop_h;
1984
  ewwwio_debug_message( $args['crop'] );
1985
  return $args;
1986
  }
2060
 
2061
  // Bail if scheme isn't http or port is set that isn't port 80.
2062
  if (
2063
+ ( 'http' !== $url_info['scheme'] || ( 80 !== (int) $url_info['port'] && ! is_null( $url_info['port'] ) ) ) &&
2064
  /**
2065
  * Tells ExactDN to ignore images that are served via HTTPS.
2066
  *
2097
  }
2098
 
2099
  // Ensure image extension is acceptable, unless it's a dynamic NextGEN image.
2100
+ if ( ! in_array( strtolower( pathinfo( $url_info['path'], PATHINFO_EXTENSION ) ), $this->extensions, true ) && false === strpos( $url_info['path'], 'nextgen-image/' ) ) {
2101
  ewwwio_debug_message( 'invalid extension' );
2102
  return false;
2103
  }
2156
  */
2157
  protected function image_sizes() {
2158
  ewwwio_debug_message( '<b>' . __METHOD__ . '()</b>' );
2159
+ if ( is_null( self::$image_sizes ) ) {
2160
  global $_wp_additional_image_sizes;
2161
 
2162
  // Populate an array matching the data structure of $_wp_additional_image_sizes so we have a consistent structure for image sizes.
2408
 
2409
  global $wp_version;
2410
  // If a resource doesn't have a version string, we add one to help with cache-busting.
2411
+ if ( ( empty( $parsed_url['query'] ) || 'ver=' . $wp_version === $parsed_url['query'] ) && false !== strpos( $url, 'wp-content/' ) ) {
2412
  $modified = ewww_image_optimizer_function_exists( 'filemtime' ) ? filemtime( get_template_directory() ) : '';
2413
  if ( empty( $modified ) ) {
2414
  $modified = (int) EWWW_IMAGE_OPTIMIZER_VERSION;
2476
  if ( false === strpos( $image_url, 'lossy=' ) && ewww_image_optimizer_get_option( 'exactdn_lossy' ) ) {
2477
  $more_args['lossy'] = is_numeric( ewww_image_optimizer_get_option( 'exactdn_lossy' ) ) ? (int) ewww_image_optimizer_get_option( 'exactdn_lossy' ) : 80;
2478
  }
2479
+ if ( false === strpos( $image_url, 'quality=' ) && ! is_null( $jpg_quality ) && 82 !== (int) $jpg_quality ) {
2480
  $more_args['quality'] = $jpg_quality;
2481
  }
2482
  // Merge given args with the automatic (option-based) args, and also makes sure args is an array if it was previously a string.
2503
  return $image_url;
2504
  }
2505
 
2506
+ if ( isset( $image_url_parts['scheme'] ) && 'https' === $image_url_parts['scheme'] ) {
2507
  if ( is_array( $args ) ) {
2508
  $args['ssl'] = 1;
2509
  }
2551
  // However some source images are served via PHP so check the no-query-string extension.
2552
  // For future proofing, this is a blacklist of common issues rather than a whitelist.
2553
  $extension = pathinfo( $image_url_parts['path'], PATHINFO_EXTENSION );
2554
+ if ( ( empty( $extension ) && false === strpos( $image_url_parts['path'], 'nextgen-image/' ) ) || in_array( $extension, array( 'php', 'ashx' ), true ) ) {
2555
  ewwwio_debug_message( 'bad extension' );
2556
  return $image_url;
2557
  }
2601
  */
2602
  function url_scheme( $url, $scheme ) {
2603
  ewwwio_debug_message( '<b>' . __METHOD__ . '()</b>' );
2604
+ if ( ! in_array( $scheme, array( 'http', 'https' ), true ) ) {
2605
  ewwwio_debug_message( 'not a valid scheme' );
2606
  if ( preg_match( '#^(https?:)?//#', $url ) ) {
2607
  ewwwio_debug_message( 'url has a valid scheme already' );
2674
  */
2675
  function autoptimize_cdn_url( $domains ) {
2676
  ewwwio_debug_message( '<b>' . __METHOD__ . '()</b>' );
2677
+ if ( is_array( $domains ) && ! in_array( $this->exactdn_domain, $domains, true ) ) {
2678
  ewwwio_debug_message( 'adding to AO list: ' . $this->exactdn_domain );
2679
  $domains[] = $this->exactdn_domain;
2680
  }
common.php CHANGED
@@ -22,7 +22,7 @@ if ( ! defined( 'ABSPATH' ) ) {
22
  exit;
23
  }
24
 
25
- define( 'EWWW_IMAGE_OPTIMIZER_VERSION', '472.0' );
26
 
27
  // Initialize a couple globals.
28
  $ewww_debug = '';
@@ -463,7 +463,7 @@ function ewww_image_optimizer_function_exists( $function, $debug = false ) {
463
  $suhosin_disabled = explode( ',', $suhosin_disabled );
464
  $suhosin_disabled = array_map( 'trim', $suhosin_disabled );
465
  $suhosin_disabled = array_map( 'strtolower', $suhosin_disabled );
466
- if ( function_exists( $function ) && ! in_array( $function, $suhosin_disabled ) ) {
467
  return true;
468
  }
469
  return false;
@@ -828,10 +828,10 @@ function ewww_image_optimizer_admin_init() {
828
  add_action( 'admin_notices', 'ewww_image_optimizer_notice_reoptimization' );
829
  add_action( 'admin_notices', 'ewww_image_optimizer_notice_media_listmode' );
830
  if ( ! empty( $_GET['page'] ) ) {
831
- if ( 'regenerate-thumbnails' == $_GET['page']
832
- || 'force-regenerate-thumbnails' == $_GET['page']
833
- || 'ajax-thumbnail-rebuild' == $_GET['page']
834
- || 'regenerate_thumbnails_advanced' == $_GET['page']
835
  ) {
836
  // Add a notice for thumb regeneration.
837
  add_action( 'admin_notices', 'ewww_image_optimizer_thumbnail_regen_notice' );
@@ -865,10 +865,10 @@ function ewww_image_optimizer_admin_init() {
865
  function ewww_image_optimizer_cron_setup( $event ) {
866
  ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
867
  // Setup scheduled optimization if the user has enabled it, and it isn't already scheduled.
868
- if ( ewww_image_optimizer_get_option( $event ) == true && ! wp_next_scheduled( $event ) ) {
869
  ewwwio_debug_message( "scheduling $event" );
870
  wp_schedule_event( time(), apply_filters( 'ewww_image_optimizer_schedule', 'hourly', $event ), $event );
871
- } elseif ( ewww_image_optimizer_get_option( $event ) == true ) {
872
  ewwwio_debug_message( "$event already scheduled: " . wp_next_scheduled( $event ) );
873
  } elseif ( wp_next_scheduled( $event ) ) {
874
  ewwwio_debug_message( "un-scheduling $event" );
@@ -903,15 +903,15 @@ function ewww_image_optimizer_ajax_compat_check() {
903
  ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
904
  // Check for (Force) Regenerate Thumbnails action (includes MLP regenerate).
905
  if ( ! empty( $_REQUEST['action'] ) ) {
906
- if ( 'regeneratethumbnail' == $_REQUEST['action'] ||
907
- 'meauh_save_image' == $_REQUEST['action'] ||
908
- 'hotspot_save' == $_REQUEST['action']
909
  ) {
910
  ewwwio_debug_message( 'doing regeneratethumbnail' );
911
  ewww_image_optimizer_image_sizes( false );
912
  return;
913
  }
914
- if ( 'mic_crop_image' == $_REQUEST['action'] ) {
915
  ewwwio_debug_message( 'doing Manual Image Crop' );
916
  if ( ! defined( 'EWWWIO_EDITOR_OVERWRITE' ) ) {
917
  define( 'EWWWIO_EDITOR_OVERWRITE', true );
@@ -939,13 +939,13 @@ function ewww_image_optimizer_ajax_compat_check() {
939
  return;
940
  }
941
  // Check for other MLP actions, including multi-regen.
942
- if ( ! empty( $_REQUEST['action'] ) && class_exists( 'MaxGalleriaMediaLib' ) && ( 'regen_mlp_thumbnails' == $_REQUEST['action'] || 'move_media' == $_REQUEST['action'] || 'copy_media' == $_REQUEST['action'] || 'maxgalleria_rename_image' == $_REQUEST['action'] ) ) {
943
  ewwwio_debug_message( 'doing regen_mlp_thumbnails' );
944
  ewww_image_optimizer_image_sizes( false );
945
  return;
946
  }
947
  // Check for MLP upload.
948
- if ( ! empty( $_REQUEST['action'] ) && class_exists( 'MaxGalleriaMediaLib' ) && ! empty( $_REQUEST['nonce'] ) && 'upload_attachment' == $_REQUEST['action'] ) {
949
  ewwwio_debug_message( 'doing maxgalleria upload' );
950
  ewww_image_optimizer_image_sizes( false );
951
  return;
@@ -1012,11 +1012,11 @@ function ewww_image_optimizer_single_size_optimize( $id, $size ) {
1012
  'image/gif',
1013
  'application/pdf',
1014
  );
1015
- if ( ! in_array( $type, $supported_types ) ) {
1016
  ewwwio_debug_message( "mimetype not supported: $id" );
1017
  return;
1018
  }
1019
- if ( 'full' == $size ) {
1020
  $ewww_image = new EWWW_Image( $id, 'media', $file_path );
1021
  $ewww_image->resize = 'full';
1022
 
@@ -1036,7 +1036,7 @@ function ewww_image_optimizer_single_size_optimize( $id, $size ) {
1036
  if ( ! empty( $disabled_sizes[ $size ] ) ) {
1037
  return;
1038
  }
1039
- if ( ! empty( $disabled_sizes['pdf-full'] ) && 'full' == $size ) {
1040
  return;
1041
  }
1042
  if ( empty( $data['file'] ) ) {
@@ -1044,7 +1044,7 @@ function ewww_image_optimizer_single_size_optimize( $id, $size ) {
1044
  }
1045
  // If this is a unique size.
1046
  $resize_path = $base_dir . $data['file'];
1047
- if ( 'application/pdf' == $type && 'full' == $size ) {
1048
  $size = 'pdf-full';
1049
  ewwwio_debug_message( 'processing full size pdf preview' );
1050
  }
@@ -1209,7 +1209,7 @@ function ewww_image_optimizer_admin_background() {
1209
  * @return bool True if this is a 'large network'.
1210
  */
1211
  function ewww_image_optimizer_large_network( $large_network, $criteria, $count ) {
1212
- if ( 'sites' == $criteria && $count > 1000 ) {
1213
  return true;
1214
  }
1215
  return false;
@@ -1231,7 +1231,7 @@ function ewww_image_optimizer_install_table() {
1231
  ewwwio_debug_message( "current collation: $db_collation" );
1232
 
1233
  // See if the path column exists, and what collation it uses to determine the column index size.
1234
- if ( $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->ewwwio_images'" ) == $wpdb->ewwwio_images ) {
1235
  ewwwio_debug_message( 'upgrading table and checking collation for path, table exists' );
1236
  // Check if the old path_image_size index exists, and drop it.
1237
  if ( $wpdb->get_results( "SHOW INDEX FROM $wpdb->ewwwio_images WHERE Key_name = 'path_image_size'", ARRAY_A ) ) {
@@ -1445,12 +1445,12 @@ function ewww_image_optimizer_remove_obsolete_settings() {
1445
  * Display a success or failure message after PNGOUT installation.
1446
  */
1447
  function ewww_image_optimizer_pngout_installed() {
1448
- if ( 'success' == $_REQUEST['ewww_pngout'] ) {
1449
  echo "<div id='ewww-image-optimizer-pngout-success' class='updated fade'>\n" .
1450
  '<p>' . esc_html__( 'Pngout was successfully installed.', 'ewww-image-optimizer' ) . "</p>\n" .
1451
  "</div>\n";
1452
  }
1453
- if ( 'failed' == $_REQUEST['ewww_pngout'] ) {
1454
  echo "<div id='ewww-image-optimizer-pngout-failure' class='error'>\n" .
1455
  '<p>' . sprintf(
1456
  /* translators: 1: An error message 2: The folder where pngout should be installed */
@@ -1550,7 +1550,7 @@ function ewww_image_optimizer_notice_reoptimization() {
1550
  } else {
1551
  set_transient( 'ewww_image_optimizer_images_reoptimized', $reoptimized, HOUR_IN_SECONDS );
1552
  }
1553
- } elseif ( 'zero' == $reoptimized ) {
1554
  $reoptimized = 0;
1555
  }
1556
  // Do a check for 10+ optimizations on 5+ images.
@@ -1588,13 +1588,13 @@ function ewww_image_optimizer_load_editor( $editors ) {
1588
  require_once( plugin_dir_path( __FILE__ ) . '/classes/class-ewwwio-gmagick-editor.php' );
1589
  }
1590
  }
1591
- if ( ! in_array( 'EWWWIO_GD_Editor', $editors ) ) {
1592
  array_unshift( $editors, 'EWWWIO_GD_Editor' );
1593
  }
1594
- if ( ! in_array( 'EWWWIO_Imagick_Editor', $editors ) ) {
1595
  array_unshift( $editors, 'EWWWIO_Imagick_Editor' );
1596
  }
1597
- if ( ! in_array( 'EWWWIO_Gmagick_Editor', $editors ) && class_exists( 'WP_Image_Editor_Gmagick' ) ) {
1598
  array_unshift( $editors, 'EWWWIO_Gmagick_Editor' );
1599
  }
1600
  if ( is_array( $editors ) ) {
@@ -1690,7 +1690,7 @@ function ewww_image_optimizer_editor_save_pre( $image ) {
1690
  */
1691
  function ewww_image_optimizer_pte_check( $data ) {
1692
  if ( ! empty( $_GET['pte-action'] ) ) {
1693
- if ( 'confirm-images' == $_GET['pte-action'] ) {
1694
  add_filter( 'wp_update_attachment_metadata', 'ewww_image_optimizer_resize_from_meta_data', 15, 2 );
1695
  }
1696
  }
@@ -1863,13 +1863,13 @@ function ewww_image_optimizer_handle_upload( $params ) {
1863
  ewww_image_optimizer_autorotate( $file_path );
1864
  $new_image = ewww_image_optimizer_autoconvert( $file_path );
1865
  if ( $new_image ) {
1866
- if ( ! empty( $params['tmp_name'] ) && $params['tmp_name'] == $file_path ) {
1867
  $params['tmp_name'] = $new_image;
1868
  }
1869
- if ( ! empty( $params['file'] ) && $params['file'] == $file_path ) {
1870
  $params['file'] = $new_image;
1871
  }
1872
- if ( ! empty( $params['url'] ) && basename( $file_path ) == basename( $params['url'] ) ) {
1873
  $params['url'] = trailingslashit( dirname( $params['url'] ) ) . basename( $new_image );
1874
  }
1875
  $params['type'] = ewww_image_optimizer_mimetype( $new_image, 'i' );
@@ -1886,7 +1886,7 @@ function ewww_image_optimizer_handle_upload( $params ) {
1886
  } else {
1887
  $mime_type = $params['type'];
1888
  }
1889
- if ( ( ! is_wp_error( $params ) ) && is_file( $file_path ) && in_array( $mime_type, array( 'image/png', 'image/gif', 'image/jpeg' ) ) ) {
1890
  ewww_image_optimizer_resize_upload( $file_path );
1891
  }
1892
  }
@@ -1973,7 +1973,7 @@ function ewww_image_optimizer_auto() {
1973
  $ewww_defer = false;
1974
  require_once( EWWW_IMAGE_OPTIMIZER_PLUGIN_PATH . 'bulk.php' );
1975
  require_once( EWWW_IMAGE_OPTIMIZER_PLUGIN_PATH . 'aux-optimize.php' );
1976
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_auto' ) == true ) {
1977
  ewwwio_debug_message( 'running scheduled optimization' );
1978
  ewww_image_optimizer_aux_images_script( 'ewww-image-optimizer-auto' );
1979
  // Generate our own unique nonce value, because wp_create_nonce() will return the same value for 12-24 hours.
@@ -2166,9 +2166,9 @@ function ewww_image_optimizer_retina( $id, $retina_path ) {
2166
  $opt_size = ewww_image_optimizer_filesize( $retina_path );
2167
  ewwwio_debug_message( "retina size: $opt_size" );
2168
  $optimized_query = ewww_image_optimizer_find_already_optimized( $temp_path );
2169
- if ( is_array( $optimized_query ) && $optimized_query['image_size'] == $opt_size ) {
2170
  global $wpdb;
2171
- if ( strpos( $wpdb->charset, 'utf8' ) === false ) {
2172
  ewww_image_optimizer_db_init();
2173
  global $ewwwdb;
2174
  } else {
@@ -2280,7 +2280,7 @@ function ewww_image_optimizer_myarcade_thumbnail( $url ) {
2280
  * @param string $hook The unique hook of the page being loaded in the WP admin.
2281
  */
2282
  function ewww_image_optimizer_media_scripts( $hook ) {
2283
- if ( 'upload.php' == $hook || 'ims_gallery_page_ewww-ims-optimize' == $hook ) {
2284
  add_thickbox();
2285
  wp_enqueue_script( 'jquery-ui-tooltip' );
2286
  wp_enqueue_script( 'ewwwmediascript', plugins_url( '/includes/media.js', __FILE__ ), array( 'jquery' ), EWWW_IMAGE_OPTIMIZER_VERSION );
@@ -2356,7 +2356,7 @@ function ewww_image_optimizer_imagick_support() {
2356
  $imagick = new Imagick();
2357
  $formats = $imagick->queryFormats();
2358
  ewwwio_debug_message( implode( ',', $formats ) );
2359
- if ( in_array( 'PNG', $formats ) && in_array( 'JPG', $formats ) ) {
2360
  return true;
2361
  }
2362
  ewwwio_debug_message( 'imagick found, but PNG or JPG not supported' );
@@ -2375,7 +2375,7 @@ function ewww_image_optimizer_gmagick_support() {
2375
  $gmagick = new Gmagick();
2376
  $formats = $gmagick->queryFormats();
2377
  ewwwio_debug_message( implode( ',', $formats ) );
2378
- if ( in_array( 'PNG', $formats ) && in_array( 'JPG', $formats ) ) {
2379
  return true;
2380
  }
2381
  ewwwio_debug_message( 'gmagick found, but PNG or JPG not supported' );
@@ -2729,7 +2729,7 @@ function ewww_image_optimizer_manual() {
2729
  if ( ! $meta_saved ) {
2730
  ewwwio_debug_message( 'failed to save meta, or no changes' );
2731
  }
2732
- if ( get_transient( 'ewww_image_optimizer_cloud_status' ) == 'exceeded' || ewww_image_optimizer_get_option( 'ewww_image_optimizer_cloud_exceeded' ) > time() ) {
2733
  if ( ! wp_doing_ajax() ) {
2734
  wp_die( esc_html__( 'License exceeded', 'ewww-image-optimizer' ) );
2735
  }
@@ -2908,10 +2908,10 @@ function ewww_image_optimizer_cloud_restore_single_image( $image ) {
2908
  if ( is_file( $image['path'] ) ) {
2909
  $old_type = ewww_image_optimizer_mimetype( $image['path'], 'i' );
2910
  }
2911
- if ( ! in_array( $new_type, $enabled_types ) ) {
2912
  return false;
2913
  }
2914
- if ( empty( $old_type ) || $old_type == $new_type ) {
2915
  if ( rename( $image['path'] . '.tmp', $image['path'] ) ) {
2916
  if ( is_file( $image['path'] . '.webp' ) && is_writable( $image['path'] . '.webp' ) ) {
2917
  unlink( $image['path'] . '.webp' );
@@ -3124,7 +3124,7 @@ function ewww_image_optimizer_cloud_verify( $cache = true, $api_key = '' ) {
3124
  if ( ! empty( $api_key ) ) {
3125
  $sanitize = true;
3126
  }
3127
- if ( empty( $api_key ) && ! ( ! empty( $_REQUEST['option_page'] ) && 'ewww_image_optimizer_options' == $_REQUEST['option_page'] ) ) {
3128
  $api_key = ewww_image_optimizer_get_option( 'ewww_image_optimizer_cloud_key' );
3129
  } elseif ( empty( $api_key ) && ! empty( $_POST['ewww_image_optimizer_cloud_key'] ) ) {
3130
  $api_key = $_POST['ewww_image_optimizer_cloud_key'];
@@ -3134,7 +3134,7 @@ function ewww_image_optimizer_cloud_verify( $cache = true, $api_key = '' ) {
3134
  update_site_option( 'ewww_image_optimizer_jpg_level', 10 );
3135
  update_option( 'ewww_image_optimizer_jpg_level', 10 );
3136
  }
3137
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) > 10 && ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) != 40 ) {
3138
  update_site_option( 'ewww_image_optimizer_png_level', 10 );
3139
  update_option( 'ewww_image_optimizer_png_level', 10 );
3140
  }
@@ -3205,7 +3205,7 @@ function ewww_image_optimizer_cloud_verify( $cache = true, $api_key = '' ) {
3205
  return false;
3206
  } else {
3207
  set_transient( 'ewww_image_optimizer_cloud_status', $verified, 3600 );
3208
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) < 20 && ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) < 20 && ewww_image_optimizer_get_option( 'ewww_image_optimizer_gif_level' ) < 20 && ewww_image_optimizer_get_option( 'ewww_image_optimizer_pdf_level' ) == 0 ) {
3209
  ewww_image_optimizer_cloud_enable();
3210
  }
3211
  ewwwio_debug_message( "verification body contents: {$result['body']}" );
@@ -3283,7 +3283,7 @@ function ewww_image_optimizer_cloud_quota( $raw = false ) {
3283
  if ( $raw ) {
3284
  return $quota;
3285
  }
3286
- if ( 0 == $quota['licensed'] && $quota['consumed'] > 0 ) {
3287
  return esc_html(
3288
  sprintf(
3289
  /* translators: 1: Number of images 2: Number of days until renewal */
@@ -3292,7 +3292,7 @@ function ewww_image_optimizer_cloud_quota( $raw = false ) {
3292
  $quota['days']
3293
  )
3294
  );
3295
- } elseif ( 0 == $quota['licensed'] && $quota['consumed'] < 0 ) {
3296
  return esc_html(
3297
  sprintf(
3298
  /* translators: 1: Number of images */
@@ -3309,7 +3309,7 @@ function ewww_image_optimizer_cloud_quota( $raw = false ) {
3309
  $real_quota
3310
  )
3311
  );
3312
- } elseif ( 0 == $quota['licensed'] && 0 == $quota['consumed'] && 0 == $quota['days'] && 0 == $quota['metered'] ) {
3313
  return esc_html__( 'no credits remaining, please purchase more.', 'ewww-image-optimizer' );
3314
  } else {
3315
  return esc_html(
@@ -3392,17 +3392,17 @@ function ewww_image_optimizer_cloud_optimizer( $file, $type, $convert = false, $
3392
  $lossy_fast = 0;
3393
  if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_lossy_skip_full' ) && $fullsize ) {
3394
  $lossy = 0;
3395
- } elseif ( 'image/png' == $type && ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) >= 40 ) {
3396
  $lossy = 1;
3397
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) == 40 ) {
3398
  $lossy_fast = 1;
3399
  }
3400
- } elseif ( 'image/jpeg' == $type && ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) >= 30 ) {
3401
  $lossy = 1;
3402
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) == 30 ) {
3403
  $lossy_fast = 1;
3404
  }
3405
- } elseif ( 'application/pdf' == $type && ewww_image_optimizer_get_option( 'ewww_image_optimizer_pdf_level' ) == 20 ) {
3406
  $lossy = 1;
3407
  } else {
3408
  $lossy = 0;
@@ -3411,13 +3411,13 @@ function ewww_image_optimizer_cloud_optimizer( $file, $type, $convert = false, $
3411
  $lossy = 0;
3412
  $lossy_fast = 0;
3413
  }
3414
- if ( 'image/webp' == $newtype ) {
3415
  $webp = 1;
3416
  $jpg_quality = apply_filters( 'jpeg_quality', $jpg_quality, 'image/webp' );
3417
  } else {
3418
  $webp = 0;
3419
  }
3420
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) == 30 ) {
3421
  $png_compress = 1;
3422
  } else {
3423
  $png_compress = 0;
@@ -3431,7 +3431,7 @@ function ewww_image_optimizer_cloud_optimizer( $file, $type, $convert = false, $
3431
  && strpos( $file, '/dynamic/' ) === false // Nextgen dynamic images.
3432
  ) {
3433
  global $ewww_image;
3434
- if ( is_object( $ewww_image ) && $ewww_image->file == $file && ! empty( $ewww_image->backup ) ) {
3435
  $hash = $ewww_image->backup;
3436
  }
3437
  if ( empty( $hash ) && ! empty( $_REQUEST['ewww_force'] ) ) {
@@ -3540,15 +3540,15 @@ function ewww_image_optimizer_cloud_optimizer( $file, $type, $convert = false, $
3540
  set_transient( 'ewww_image_optimizer_cloud_status', 'exceeded', 3600 );
3541
  $msg = 'exceeded';
3542
  unlink( $tempfile );
3543
- } elseif ( ewww_image_optimizer_mimetype( $tempfile, 'i' ) == $type ) {
3544
  $newsize = filesize( $tempfile );
3545
  ewwwio_debug_message( "cloud results: $newsize (new) vs. $orig_size (original)" );
3546
  rename( $tempfile, $file );
3547
- } elseif ( ewww_image_optimizer_mimetype( $tempfile, 'i' ) == 'image/webp' ) {
3548
  $newsize = filesize( $tempfile );
3549
  ewwwio_debug_message( "cloud results: $newsize (new) vs. $orig_size (original)" );
3550
  rename( $tempfile, $newfile );
3551
- } elseif ( ! is_null( $newtype ) && ! is_null( $newfile ) && ewww_image_optimizer_mimetype( $tempfile, 'i' ) == $newtype ) {
3552
  $converted = true;
3553
  $newsize = filesize( $tempfile );
3554
  ewwwio_debug_message( "cloud results: $newsize (new) vs. $orig_size (original)" );
@@ -3668,7 +3668,7 @@ function ewww_image_optimizer_cloud_autorotate( $file, $type ) {
3668
  ewwwio_debug_message( 'License Exceeded' );
3669
  set_transient( 'ewww_image_optimizer_cloud_status', 'exceeded', 3600 );
3670
  unlink( $tempfile );
3671
- } elseif ( ewww_image_optimizer_mimetype( $tempfile, 'i' ) == $type ) {
3672
  $newsize = filesize( $tempfile );
3673
  ewwwio_debug_message( "cloud rotation success: $newsize (new) vs. $orig_size (original)" );
3674
  rename( $tempfile, $file );
@@ -3926,12 +3926,12 @@ function ewww_image_optimizer_check_table( $file, $orig_size ) {
3926
  ewwwio_debug_message( "checking for $file with size: $orig_size" );
3927
  global $s3_uploads_image;
3928
  global $ewww_image;
3929
- if ( class_exists( 'S3_Uploads' ) && ! empty( $s3_uploads_image ) && $s3_uploads_image != $file ) {
3930
  $file = $s3_uploads_image;
3931
  ewwwio_debug_message( "overriding check with: $file" );
3932
  }
3933
  $image = array();
3934
- if ( ! is_object( $ewww_image ) || ! $ewww_image instanceof EWWW_Image || $ewww_image->file != $file ) {
3935
  $ewww_image = new EWWW_Image( 0, '', $file );
3936
  }
3937
  if ( ! empty( $ewww_image->record ) ) {
@@ -3939,7 +3939,7 @@ function ewww_image_optimizer_check_table( $file, $orig_size ) {
3939
  } else {
3940
  $image = false;
3941
  }
3942
- if ( is_array( $image ) && $image['image_size'] == $orig_size ) {
3943
  $prev_string = ' - ' . __( 'Previously Optimized', 'ewww-image-optimizer' );
3944
  if ( preg_match( '/' . __( 'License exceeded', 'ewww-image-optimizer' ) . '/', $image['results'] ) ) {
3945
  return '';
@@ -3990,12 +3990,12 @@ function ewww_image_optimizer_update_table( $attachment, $opt_size, $orig_size,
3990
  }
3991
  global $ewww_image;
3992
  // First check if the image was converted, so we don't orphan records.
3993
- if ( $original && $original != $attachment ) {
3994
  $already_optimized = ewww_image_optimizer_find_already_optimized( $original );
3995
  $converted = $original;
3996
  } else {
3997
  global $s3_uploads_image;
3998
- if ( class_exists( 'S3_Uploads' ) && ! empty( $s3_uploads_image ) && $s3_uploads_image != $attachment ) {
3999
  $attachment = $s3_uploads_image;
4000
  ewwwio_debug_message( "overriding update with: $attachment" );
4001
  }
@@ -4411,7 +4411,7 @@ function ewww_image_optimizer_remote_fetch( $id, $meta ) {
4411
  // Check through all the sizes we've processed so far.
4412
  foreach ( $processed as $proc => $scan ) {
4413
  // If a previous resize had identical dimensions.
4414
- if ( $scan['height'] == $data['height'] && $scan['width'] == $data['width'] ) {
4415
  // Found a duplicate resize.
4416
  $dup_size = true;
4417
  }
@@ -4471,7 +4471,7 @@ function ewww_image_optimizer_remote_fetch( $id, $meta ) {
4471
  // Check through all the sizes we've processed so far.
4472
  foreach ( $processed as $proc => $scan ) {
4473
  // If a previous resize had identical dimensions.
4474
- if ( $scan['height'] == $data['height'] && $scan['width'] == $data['width'] ) {
4475
  // Found a duplicate resize.
4476
  $dup_size = true;
4477
  }
@@ -4625,7 +4625,7 @@ function ewww_image_optimizer_update_table_as3cf( $local_path, $s3_path ) {
4625
  * @return int|string The new amount of memory to allocate, if it was only 256M or lower.
4626
  */
4627
  function ewww_image_optimizer_raise_memory_limit( $memory_limit ) {
4628
- if ( ( is_string( $memory_limit ) && '256M' == $memory_limit ) || ( is_int( $memory_limit ) && 270000000 > $memory_limit ) ) {
4629
  ewwwio_debug_message( 'raising the roof' );
4630
  return '512M';
4631
  } else {
@@ -4633,52 +4633,6 @@ function ewww_image_optimizer_raise_memory_limit( $memory_limit ) {
4633
  }
4634
  }
4635
 
4636
- /**
4637
- * Determines scaling dimensions to be used for two phase cropping.
4638
- *
4639
- * @param int $current_width The width of the original image.
4640
- * @param int $current_height The height of the original image.
4641
- * @param int $max_width The maximum width of the final image.
4642
- * @param int $max_height The maximum height of the final image.
4643
- * @return array X coordinate, Y coordinate, width and height in pixels.
4644
- */
4645
- function ewwwio_crop_dimensions( $current_width, $current_height, $max_width = 0, $max_height = 0 ) {
4646
- if ( ! $max_width && ! $max_height ) {
4647
- return array( 0, 0, $current_width, $current_height );
4648
- }
4649
- if ( $max_width ) {
4650
- $max_width = min( $max_width, $current_width );
4651
- } else {
4652
- $max_width = $current_width;
4653
- }
4654
- if ( $max_height ) {
4655
- $max_height = min( $max_height, $current_height );
4656
- } else {
4657
- $max_height = $current_height;
4658
- }
4659
- $w = $current_width;
4660
- $h = $current_height;
4661
- $x = 0;
4662
- $y = 0;
4663
-
4664
- if ( $current_height > $current_width ) {
4665
- $h = round( $current_width * $max_height / $max_width );
4666
- $y = round( ( $current_height - $h ) / 2 );
4667
- } elseif ( $current_height == $current_width ) {
4668
- if ( $max_width > $max_height ) {
4669
- $h = round( $current_width * $max_height / $max_width );
4670
- $y = round( ( $current_height - $h ) / 2 );
4671
- } else {
4672
- $w = round( $current_height * $max_width / $max_height );
4673
- $x = round( ( $current_width - $w ) / 2 );
4674
- }
4675
- } else {
4676
- $w = round( $current_height * $max_width / $max_height );
4677
- $x = round( ( $current_width - $w ) / 2 );
4678
- }
4679
- return array( $x, $y, $w, $h );
4680
- }
4681
-
4682
  /**
4683
  * Uses gifsicle or the API to resize an image.
4684
  *
@@ -4707,7 +4661,7 @@ function ewww_image_optimizer_better_resize( $file, $dst_x, $dst_y, $src_x, $src
4707
  ewwwio_debug_message( 'not an image, no resizing possible' );
4708
  return new WP_Error( 'invalid_image', __( 'File is not an image.' ), $file );
4709
  }
4710
- if ( 'image/gif' == $type && ! ewww_image_optimizer_get_option( 'ewww_image_optimizer_cloud_key' ) && function_exists( 'ewww_image_optimizer_gifsicle_resize' ) ) {
4711
  return ewww_image_optimizer_gifsicle_resize( $file, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h );
4712
  }
4713
  return ewww_image_optimizer_cloud_resize( $file, $type, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h );
@@ -4727,12 +4681,12 @@ function ewww_image_optimizer_autorotate( $file ) {
4727
  wp_raise_memory_limit( 'image' );
4728
  }
4729
  $type = ewww_image_optimizer_mimetype( $file, 'i' );
4730
- if ( 'image/jpeg' != $type ) {
4731
  ewwwio_debug_message( 'not a JPG, no rotation needed' );
4732
  return;
4733
  }
4734
- $orientation = ewww_image_optimizer_get_orientation( $file, $type );
4735
- if ( ! $orientation || 1 == $orientation ) {
4736
  return;
4737
  }
4738
  if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) < 20 && function_exists( 'ewww_image_optimizer_jpegtran_autorotate' ) ) {
@@ -4760,7 +4714,7 @@ function ewww_image_optimizer_autorotate( $file ) {
4760
  $tiff = $exif->getTiff();
4761
  $ifd0 = $tiff->getIfd();
4762
  $orientation = $ifd0->getEntry( PelTag::ORIENTATION );
4763
- if ( null != $orientation ) {
4764
  ewwwio_debug_message( 'orientation being adjusted' );
4765
  $orientation->setValue( 1 );
4766
  }
@@ -4786,7 +4740,7 @@ function ewww_image_optimizer_autoconvert( $file ) {
4786
  wp_raise_memory_limit( 'image' );
4787
  }
4788
  $type = ewww_image_optimizer_mimetype( $file, 'i' );
4789
- if ( 'image/png' != $type ) {
4790
  ewwwio_debug_message( 'not a PNG, no conversion needed' );
4791
  return;
4792
  }
@@ -4880,8 +4834,10 @@ function ewww_image_optimizer_resize_upload( $file ) {
4880
  */
4881
  list( $maxwidth, $maxheight ) = apply_filters( 'ewww_image_optimizer_resize_dimensions', array( $maxwidth, $maxheight ), $file );
4882
 
 
 
4883
  // Check that options are not both set to zero.
4884
- if ( 0 == $maxwidth && 0 == $maxheight ) {
4885
  return false;
4886
  }
4887
  $maxwidth = $maxwidth ? $maxwidth : 999999;
@@ -5002,7 +4958,7 @@ function ewww_image_optimizer_resize_upload( $file ) {
5002
  $tiff = $old_exif->getTiff();
5003
  $ifd0 = $tiff->getIfd();
5004
  $orientation = $ifd0->getEntry( PelTag::ORIENTATION );
5005
- if ( null != $orientation ) {
5006
  $orientation->setValue( 1 );
5007
  }
5008
  }
@@ -5117,8 +5073,12 @@ function ewww_image_optimizer_find_already_optimized( $attachment ) {
5117
  }
5118
  if ( ewww_image_optimizer_iterable( $optimized_query ) ) {
5119
  foreach ( $optimized_query as $image ) {
5120
- $image['path'] = ewww_image_optimizer_absolutize_path( $image['path'] );
5121
- if ( $image['path'] != $attachment ) {
 
 
 
 
5122
  ewwwio_debug_message( "{$image['path']} does not match $attachment, continuing our search" );
5123
  } elseif ( ! $maybe_return_image ) {
5124
  ewwwio_debug_message( "found a match for $attachment" );
@@ -5174,7 +5134,7 @@ function ewww_image_optimizer_remove_duplicate_records( $duplicates ) {
5174
  $discard = array();
5175
  // First look for an image size match.
5176
  foreach ( $duplicates as $duplicate ) {
5177
- if ( empty( $keeper ) && ! empty( $duplicate['image_size'] ) && $image_size == $duplicate['image_size'] ) {
5178
  $keeper = $duplicate;
5179
  } else {
5180
  $discard[] = $duplicate;
@@ -5238,13 +5198,13 @@ function ewww_image_optimizer_test_background_opt( $type = '' ) {
5238
  if ( ewww_image_optimizer_detect_wpsf_location_lock() ) {
5239
  return false;
5240
  }
5241
- if ( 'image/type' == $type && ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_to_png' ) ) {
5242
  return apply_filters( 'ewww_image_optimizer_defer_conversion', false );
5243
  }
5244
- if ( 'image/png' == $type && ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_to_jpg' ) ) {
5245
  return apply_filters( 'ewww_image_optimizer_defer_conversion', false );
5246
  }
5247
- if ( 'image/gif' == $type && ewww_image_optimizer_get_option( 'ewww_image_optimizer_gif_to_png' ) ) {
5248
  return apply_filters( 'ewww_image_optimizer_defer_conversion', false );
5249
  }
5250
  global $ewww_defer;
@@ -5285,16 +5245,16 @@ function ewww_image_optimizer_test_parallel_opt( $type = '', $id = 0 ) {
5285
  if ( empty( $type ) ) {
5286
  $type = get_post_mime_type( $id );
5287
  }
5288
- if ( 'image/jpeg' == $type && ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_to_png' ) ) {
5289
  return false;
5290
  }
5291
- if ( 'image/png' == $type && ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_to_jpg' ) ) {
5292
  return false;
5293
  }
5294
- if ( 'image/gif' == $type && ewww_image_optimizer_get_option( 'ewww_image_optimizer_gif_to_png' ) ) {
5295
  return false;
5296
  }
5297
- if ( 'application/pdf' == $type ) {
5298
  return false;
5299
  }
5300
  return true;
@@ -5360,7 +5320,7 @@ function ewww_image_optimizer_resize_from_meta_data( $meta, $id = null, $log = t
5360
  if ( ! is_array( $meta ) && empty( $meta ) ) {
5361
  $meta = array();
5362
  } elseif ( ! is_array( $meta ) ) {
5363
- if ( is_string( $meta ) && is_numeric( $id ) && 'processing' == $meta ) {
5364
  ewwwio_debug_message( "attempting to rebuild attachment meta for $id" );
5365
  $new_meta = ewww_image_optimizer_rebuild_meta( $id );
5366
  if ( ! is_array( $new_meta ) ) {
@@ -5373,7 +5333,7 @@ function ewww_image_optimizer_resize_from_meta_data( $meta, $id = null, $log = t
5373
  ewwwio_debug_message( 'attachment meta is not a usable array' );
5374
  return $meta;
5375
  }
5376
- } elseif ( is_array( $meta ) && ! empty( $meta[0] ) && 'processing' == $meta[0] ) {
5377
  ewwwio_debug_message( "attempting to rebuild attachment meta for $id" );
5378
  $new_meta = ewww_image_optimizer_rebuild_meta( $id );
5379
  if ( ! is_array( $new_meta ) ) {
@@ -5406,7 +5366,7 @@ function ewww_image_optimizer_resize_from_meta_data( $meta, $id = null, $log = t
5406
  }
5407
  list( $file_path, $upload_path ) = ewww_image_optimizer_attachment_path( $meta, $id );
5408
  // If the attachment has been uploaded via the image store plugin.
5409
- if ( 'ims_image' == get_post_type( $id ) ) {
5410
  $gallery_type = 6;
5411
  }
5412
  if ( ! $new_image && class_exists( 'Amazon_S3_And_CloudFront' ) && ewww_image_optimizer_stream_wrapped( $file_path ) ) {
@@ -5428,7 +5388,7 @@ function ewww_image_optimizer_resize_from_meta_data( $meta, $id = null, $log = t
5428
  'image/gif',
5429
  'application/pdf',
5430
  );
5431
- if ( ! in_array( $type, $supported_types ) ) {
5432
  ewwwio_debug_message( "mimetype not supported: $id" );
5433
  return $meta;
5434
  }
@@ -5586,7 +5546,7 @@ function ewww_image_optimizer_resize_from_meta_data( $meta, $id = null, $log = t
5586
  if ( ! empty( $disabled_sizes[ $size ] ) ) {
5587
  continue;
5588
  }
5589
- if ( ! empty( $disabled_sizes['pdf-full'] ) && 'full' == $size ) {
5590
  continue;
5591
  }
5592
  if ( empty( $data['file'] ) ) {
@@ -5621,7 +5581,7 @@ function ewww_image_optimizer_resize_from_meta_data( $meta, $id = null, $log = t
5621
  // Check through all the sizes we've processed so far.
5622
  foreach ( $processed as $proc => $scan ) {
5623
  // If a previous resize had identical dimensions.
5624
- if ( $scan['height'] == $data['height'] && $scan['width'] == $data['width'] ) {
5625
  // We found a duplicate resize, so...
5626
  // Point this resize at the same image as the previous one.
5627
  $meta['sizes'][ $size ]['file'] = $meta['sizes'][ $proc ]['file'];
@@ -5630,7 +5590,7 @@ function ewww_image_optimizer_resize_from_meta_data( $meta, $id = null, $log = t
5630
  }
5631
  // If this is a unique size.
5632
  $resize_path = $base_dir . $data['file'];
5633
- if ( 'application/pdf' == $type && 'full' == $size ) {
5634
  $size = 'pdf-full';
5635
  ewwwio_debug_message( 'processing full size pdf preview' );
5636
  }
@@ -5885,7 +5845,7 @@ function ewww_image_optimizer_detect_wpsf_location_lock() {
5885
  if ( ewww_image_optimizer_function_exists( 'print_r' ) ) {
5886
  ewwwio_debug_message( print_r( $shield_user_man, true ) );
5887
  }
5888
- if ( ! empty( $shield_user_man['session_lock_location'] ) && 'Y' == $shield_user_man['session_lock_location'] ) {
5889
  return true;
5890
  }
5891
  }
@@ -5947,7 +5907,7 @@ function ewww_image_optimizer_update_attachment( $meta, $id ) {
5947
  // Construct the new guid based on the filename from the attachment metadata.
5948
  ewwwio_debug_message( "old guid: $old_guid" );
5949
  ewwwio_debug_message( "new guid: $guid" );
5950
- if ( substr( $old_guid, -1 ) == '/' || substr( $guid, -1 ) == '/' ) {
5951
  ewwwio_debug_message( 'could not obtain full url for current and previous image, bailing' );
5952
  return $meta;
5953
  }
@@ -5990,7 +5950,7 @@ function ewww_image_optimizer_update_attachment( $meta, $id ) {
5990
  // Generate the url for the new image.
5991
  $sguid = dirname( $old_guid ) . '/' . basename( $data['file'] );
5992
  ewwwio_debug_message( "new sguid: $sguid" );
5993
- if ( substr( $old_sguid, -1 ) == '/' || substr( $sguid, -1 ) == '/' ) {
5994
  ewwwio_debug_message( 'could not obtain full url for current and previous resized image, bailing' );
5995
  continue;
5996
  }
@@ -6085,7 +6045,7 @@ function ewww_image_optimizer_attachment_path( $meta, $id, $file = '', $refresh_
6085
  ) {
6086
  return array( str_replace( '//_imsgalleries/', '/_imsgalleries/', $file_path ), $upload_path );
6087
  }
6088
- if ( 'ims_image' == get_post_type( $id ) && is_array( $meta ) && ! empty( $meta['file'] ) ) {
6089
  ewwwio_debug_message( "finding path for IMS image: $id " );
6090
  if ( is_dir( $file_path ) && is_file( $file_path . $meta['file'] ) ) {
6091
  // Generate the absolute path.
@@ -6309,10 +6269,10 @@ function ewww_image_optimizer_png_alpha( $filename ) {
6309
  $color_type = ord( file_get_contents( $filename, null, null, 25, 1 ) );
6310
  ewwwio_debug_message( "color type: $color_type" );
6311
  // If it is set to RGB alpha or Grayscale alpha.
6312
- if ( 4 == $color_type || 6 == $color_type ) {
6313
  ewwwio_debug_message( 'transparency found' );
6314
  return true;
6315
- } elseif ( 3 == $color_type && ewww_image_optimizer_gd_support() ) {
6316
  $image = imagecreatefrompng( $filename );
6317
  if ( imagecolortransparent( $image ) >= 0 ) {
6318
  ewwwio_debug_message( 'transparency found' );
@@ -6387,7 +6347,7 @@ function ewww_image_optimizer_resize_count( $sizes ) {
6387
  // Check through all the sizes we've processed so far.
6388
  foreach ( $processed as $proc => $scan ) {
6389
  // If a previous resize had identical dimensions.
6390
- if ( $scan['height'] == $data['height'] && $scan['width'] == $data['width'] ) {
6391
  continue( 2 );
6392
  }
6393
  }
@@ -6427,9 +6387,9 @@ function ewww_image_optimizer_columns( $defaults ) {
6427
  function ewww_image_optimizer_custom_column( $column_name, $id, $meta = null, $return_output = false ) {
6428
  ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
6429
  // Once we get to the EWWW IO custom column.
6430
- if ( 'ewww-image-optimizer' == $column_name ) {
6431
  $output = '';
6432
- if ( null == $meta ) {
6433
  // Retrieve the metadata.
6434
  $meta = wp_get_attachment_metadata( $id );
6435
  }
@@ -6509,7 +6469,7 @@ function ewww_image_optimizer_custom_column( $column_name, $id, $meta = null, $r
6509
  esc_html__( '%s is missing', 'ewww-image-optimizer' ),
6510
  '<em>jpegtran</em>'
6511
  ) . '</div>';
6512
- } elseif ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) == 0 ) {
6513
  $msg = '<div>' . sprintf(
6514
  /* translators: %s: JPG, PNG, GIF, or PDF */
6515
  esc_html__( '%s compression disabled', 'ewww-image-optimizer' ),
@@ -6547,7 +6507,7 @@ function ewww_image_optimizer_custom_column( $column_name, $id, $meta = null, $r
6547
  }
6548
  break;
6549
  case 'application/pdf':
6550
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_pdf_level' ) == 0 ) {
6551
  $msg = '<div>' . sprintf(
6552
  /* translators: %s: JPG, PNG, GIF, or PDF */
6553
  esc_html__( '%s compression disabled', 'ewww-image-optimizer' ),
@@ -6678,7 +6638,7 @@ function ewww_image_optimizer_custom_column( $column_name, $id, $meta = null, $r
6678
  $id,
6679
  esc_html__( 'Re-optimize', 'ewww-image-optimizer' )
6680
  );
6681
- if ( ! ewww_image_optimizer_get_option( 'ewww_image_optimizer_disable_convert_links' ) && 'ims_image' != get_post_type( $id ) && ! empty( $convert_desc ) ) {
6682
  $output .= " | <a class='ewww-manual-convert' data-id='$id' data-nonce='$ewww_manual_nonce' title='$convert_desc' href='admin.php?action=ewww_image_optimizer_manual_optimize&amp;ewww_manual_nonce=$ewww_manual_nonce&amp;ewww_attachment_ID=$id&amp;ewww_convert=1&amp;ewww_force=1'>$convert_link</a>";
6683
  }
6684
  $output .= '</div>';
@@ -6725,7 +6685,7 @@ function ewww_image_optimizer_custom_column( $column_name, $id, $meta = null, $r
6725
  if ( empty( $msg ) && current_user_can( apply_filters( 'ewww_image_optimizer_manual_permissions', '' ) ) ) {
6726
  // Give the user the option to optimize the image right now.
6727
  $output .= sprintf( "<div><a class='ewww-manual-optimize' data-id='$id' data-nonce='$ewww_manual_nonce' href=\"admin.php?action=ewww_image_optimizer_manual_optimize&amp;ewww_manual_nonce=$ewww_manual_nonce&amp;ewww_attachment_ID=%d\">%s</a>", $id, esc_html__( 'Optimize now!', 'ewww-image-optimizer' ) );
6728
- if ( ! ewww_image_optimizer_get_option( 'ewww_image_optimizer_disable_convert_links' ) && 'ims_image' != get_post_type( $id ) && ! empty( $convert_desc ) ) {
6729
  $output .= " | <a class='ewww-manual-convert' data-id='$id' data-nonce='$ewww_manual_nonce' title='$convert_desc' href='admin.php?action=ewww_image_optimizer_manual_optimize&amp;ewww_manual_nonce=$ewww_manual_nonce&amp;ewww_attachment_ID=$id&amp;ewww_convert=1&amp;ewww_force=1'>$convert_link</a>";
6730
  }
6731
  $output .= '</div>';
@@ -6769,7 +6729,7 @@ function ewww_image_optimizer_count_unoptimized_sizes( $sizes ) {
6769
  if ( ! empty( $disabled_sizes[ $size ] ) ) {
6770
  continue;
6771
  }
6772
- if ( ! empty( $disabled_sizes['pdf-full'] ) && 'full' == $size ) {
6773
  continue;
6774
  }
6775
  if ( empty( $data['file'] ) ) {
@@ -6779,7 +6739,7 @@ function ewww_image_optimizer_count_unoptimized_sizes( $sizes ) {
6779
  // Check through all the sizes we've processed so far.
6780
  foreach ( $processed as $proc => $scan ) {
6781
  // If a previous resize had identical dimensions...
6782
- if ( $scan['height'] == $data['height'] && $scan['width'] == $data['width'] ) {
6783
  // Found a duplicate size, get outta here!
6784
  continue( 2 );
6785
  }
@@ -6823,7 +6783,7 @@ function ewww_image_optimizer_custom_column_results( $id, $optimized_images ) {
6823
  }
6824
  $orig_size += $optimized_image['orig_size'];
6825
  $opt_size += $optimized_image['image_size'];
6826
- if ( 'full' == $optimized_image['resize'] ) {
6827
  $level = $optimized_image['level'];
6828
  $updated_time = strtotime( $optimized_image['updated'] );
6829
  if ( DAY_IN_SECONDS * 30 + $updated_time > time() ) {
@@ -6994,7 +6954,7 @@ function ewww_image_optimizer_migrate_meta_to_db( $id, $meta, $bail_early = fals
6994
  // Resized versions, so we can continue.
6995
  if ( isset( $meta['sizes'] ) && ewww_image_optimizer_iterable( $meta['sizes'] ) ) {
6996
  // Meta sizes don't contain a path, so we calculate one.
6997
- if ( 'ims_image' == get_post_type( $id ) ) {
6998
  $base_dir = trailingslashit( dirname( $file_path ) ) . '_resized/';
6999
  } else {
7000
  $base_dir = trailingslashit( dirname( $file_path ) );
@@ -7007,9 +6967,9 @@ function ewww_image_optimizer_migrate_meta_to_db( $id, $meta, $bail_early = fals
7007
  if ( empty( $data ) || ! is_array( $data ) || empty( $data['file'] ) ) {
7008
  continue;
7009
  }
7010
- if ( 'full' == $size && 'application/pdf' == $type ) {
7011
  $size = 'pdf-full';
7012
- } elseif ( 'full' == $size ) {
7013
  continue;
7014
  }
7015
 
@@ -7117,7 +7077,7 @@ function ewww_image_optimizer_bulk_action_handler() {
7117
  // Borrowed from http://www.viper007bond.com/wordpress-plugins/regenerate-thumbnails/ .
7118
  ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
7119
  // If the requested action is blank, or not a bulk_optimize, do nothing.
7120
- if ( ( empty( $_REQUEST['action'] ) || 'bulk_optimize' != $_REQUEST['action'] ) && ( empty( $_REQUEST['action2'] ) || 'bulk_optimize' != $_REQUEST['action2'] ) ) {
7121
  return;
7122
  }
7123
  // If there is no media to optimize, do nothing.
@@ -7204,7 +7164,7 @@ function ewww_image_optimizer_set_option( $option_name, $option_value ) {
7204
  * }
7205
  */
7206
  function ewww_image_optimizer_get_bad_attachments() {
7207
- $bad_attachment = get_transient( 'ewww_image_optimizer_rebuilding_attachment' );
7208
  if ( $bad_attachment ) {
7209
  $bad_attachments = (array) ewww_image_optimizer_get_option( 'ewww_image_optimizer_bad_attachments' );
7210
  $bad_attachments[] = $bad_attachment;
@@ -7212,6 +7172,7 @@ function ewww_image_optimizer_get_bad_attachments() {
7212
  } else {
7213
  $bad_attachments = (array) ewww_image_optimizer_get_option( 'ewww_image_optimizer_bad_attachments' );
7214
  }
 
7215
  delete_transient( 'ewww_image_optimizer_rebuilding_attachment' );
7216
  return array( $bad_attachments, $bad_attachment );
7217
  }
@@ -7289,7 +7250,7 @@ function ewww_image_optimizer_savings() {
7289
  ewwwio_debug_message( "getting savings for site: $blog_id" );
7290
  $table_name = $wpdb->prefix . 'ewwwio_images';
7291
  ewwwio_debug_message( "table name is $table_name" );
7292
- if ( $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table_name ) ) != $table_name ) {
7293
  ewww_image_optimizer_install_table();
7294
  }
7295
  if ( $wpdb->ewwwio_images ) {
@@ -7308,7 +7269,7 @@ function ewww_image_optimizer_savings() {
7308
  ewwwio_debug_message( 'querying savings for single site' );
7309
  $table_name = $wpdb->ewwwio_images;
7310
  ewwwio_debug_message( "table name is $table_name" );
7311
- if ( $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table_name ) ) != $table_name ) {
7312
  ewww_image_optimizer_install_table();
7313
  }
7314
  $orig_size = $wpdb->get_var( "SELECT SUM(orig_size) FROM $wpdb->ewwwio_images WHERE image_size > 0" );
@@ -7449,7 +7410,7 @@ function ewww_image_optimizer_webp_rewrite_verify() {
7449
  function ewwwio_extract_from_markers( $filename, $marker ) {
7450
  // All because someone didn't test changes in core...
7451
  global $wp_version;
7452
- if ( '4.9' != $wp_version ) {
7453
  return extract_from_markers( $filename, $marker );
7454
  }
7455
  $result = array();
@@ -7526,13 +7487,13 @@ function ewww_image_optimizer_get_image_sizes() {
7526
  }
7527
  if ( ewww_image_optimizer_iterable( $image_sizes ) ) {
7528
  foreach ( $image_sizes as $_size ) {
7529
- if ( in_array( $_size, array( 'thumbnail', 'medium', 'medium_large', 'large' ) ) ) {
7530
  $sizes[ $_size ]['width'] = get_option( $_size . '_size_w' );
7531
  $sizes[ $_size ]['height'] = get_option( $_size . '_size_h' );
7532
- if ( 'medium_large' === $_size && 0 == $sizes[ $_size ]['width'] ) {
7533
  $sizes[ $_size ]['width'] = '768';
7534
  }
7535
- if ( 'medium_large' === $_size && 0 == $sizes[ $_size ]['height'] ) {
7536
  $sizes[ $_size ]['height'] = '9999';
7537
  }
7538
  } elseif ( isset( $_wp_additional_image_sizes[ $_size ] ) ) {
@@ -7638,7 +7599,7 @@ function ewww_image_optimizer_options( $network = 'singlesite' ) {
7638
  $output[] = "<div class='wrap'>\n";
7639
  $output[] = "<h1>EWWW Image Optimizer</h1>\n";
7640
  $output[] = "<!--<div id='ewww-container-left' style='float: left; margin-right: 225px;'>-->\n";
7641
- if ( 'network-multisite' == $network ) {
7642
  $bulk_link = esc_html__( 'Media Library', 'ewww-image-optimizer' ) . ' -> ' . esc_html__( 'Bulk Optimize', 'ewww-image-optimizer' );
7643
  } else {
7644
  $bulk_link = '<a href="upload.php?page=ewww-image-optimizer-bulk">' . esc_html__( 'Bulk Optimize', 'ewww-image-optimizer' ) . '</a>';
@@ -7856,7 +7817,7 @@ function ewww_image_optimizer_options( $network = 'singlesite' ) {
7856
  if ( ewww_image_optimizer_imagick_support() ) {
7857
  $toolkit_found = true;
7858
  }
7859
- if ( PHP_OS != 'WINNT' && ! ewww_image_optimizer_full_cloud() && ! EWWW_IMAGE_OPTIMIZER_NOEXEC ) {
7860
  ewww_image_optimizer_find_nix_binary( 'nice', 'n' );
7861
  }
7862
  $status_notices .= "<p>\n"; // This line encloses everything up to the end of the async stuff.
@@ -7879,7 +7840,7 @@ function ewww_image_optimizer_options( $network = 'singlesite' ) {
7879
  $status_notices .= "<p><a href='https://ewww.io/plans' target='_blank' class='button button-primary' style='background:#3eadc9'>" . esc_html__( 'Premium Upgrades', 'ewww-image-optimizer' ) . "</a></p>\n";
7880
  }
7881
 
7882
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_metadata_remove' ) == true ) {
7883
  $compress_score += 5;
7884
  } else {
7885
  $compress_recommendations[] = esc_html__( 'Remove metadata from JPG images.', 'ewww-image-optimizer' ) . ewwwio_help_link( 'https://docs.ewww.io/article/7-basic-configuration', '585373d5c697912ffd6c0bb2' );
@@ -7967,8 +7928,8 @@ function ewww_image_optimizer_options( $network = 'singlesite' ) {
7967
  // End status section.
7968
  $output[] = $status_output;
7969
 
7970
- if ( ( 'network-multisite' != $network || ! get_site_option( 'ewww_image_optimizer_allow_multisite_override' ) ) && // Display tabs so long as this isn't the network admin OR single-site override is disabled.
7971
- ! ( 'network-singlesite' == $network && ! get_site_option( 'ewww_image_optimizer_allow_multisite_override' ) ) ) { // Also make sure that this isn't single site without override mode.
7972
  $output[] = "<ul class='ewww-tab-nav'>\n" .
7973
  "<li class='ewww-tab ewww-general-nav'><span class='ewww-tab-hidden'>" . esc_html__( 'Basic', 'ewww-image-optimizer' ) . "</span></li>\n" .
7974
  "<li class='ewww-tab ewww-exactdn-nav'><span class='ewww-tab-hidden'>" . esc_html__( 'ExactDN', 'ewww-image-optimizer' ) . "</span></li>\n" .
@@ -7981,7 +7942,7 @@ function ewww_image_optimizer_options( $network = 'singlesite' ) {
7981
  "<li class='ewww-tab ewww-contribute-nav'><span class='ewww-tab-hidden'>" . esc_html__( 'Contribute', 'ewww-image-optimizer' ) . "</span></li>\n" .
7982
  "</ul>\n";
7983
  }
7984
- if ( 'network-multisite' == $network ) {
7985
  $output[] = "<form method='post' action=''>\n";
7986
  } else {
7987
  $output[] = "<form method='post' action='options.php'>\n";
@@ -8002,10 +7963,10 @@ function ewww_image_optimizer_options( $network = 'singlesite' ) {
8002
  $output[] = "<table class='form-table'>\n";
8003
  if ( is_multisite() ) {
8004
  if ( is_plugin_active_for_network( EWWW_IMAGE_OPTIMIZER_PLUGIN_FILE_REL ) ) {
8005
- $output[] = "<tr class='network-only'><th scope='row'><label for='ewww_image_optimizer_allow_multisite_override'>" . esc_html__( 'Allow Single-site Override', 'ewww-image-optimizer' ) . "</label></th><td><input type='checkbox' id='ewww_image_optimizer_allow_multisite_override' name='ewww_image_optimizer_allow_multisite_override' value='true' " . ( get_site_option( 'ewww_image_optimizer_allow_multisite_override' ) == true ? "checked='true'" : '' ) . ' /> ' . esc_html__( 'Allow individual sites to configure their own settings and override all network options.', 'ewww-image-optimizer' ) . "</td></tr>\n";
8006
  }
8007
- if ( 'network-multisite' == $network && get_site_option( 'ewww_image_optimizer_allow_multisite_override' ) ) {
8008
- $output[] = "<tr><th scope='row'><label for='ewww_image_optimizer_allow_tracking'>" . esc_html__( 'Allow Usage Tracking?', 'ewww-image-optimizer' ) . "</label></th><td><input type='checkbox' id='ewww_image_optimizer_allow_tracking' name='ewww_image_optimizer_allow_tracking' value='true' " . ( get_site_option( 'ewww_image_optimizer_allow_tracking' ) == true ? "checked='true'" : '' ) . ' /> ' .
8009
  esc_html__( 'Allow EWWW Image Optimizer to anonymously track how this plugin is used and help us make the plugin better. Opt-in to tracking and receive 500 API image credits free. No sensitive data is tracked.', 'ewww-image-optimizer' ) . "</td></tr>\n";
8010
  $output[] = "<input type='hidden' id='ewww_image_optimizer_allow_multisite_override_active' name='ewww_image_optimizer_allow_multisite_override_active' value='0'>";
8011
  if ( get_site_option( 'ewww_image_optimizer_cloud_key' ) ) {
@@ -8028,9 +7989,9 @@ function ewww_image_optimizer_options( $network = 'singlesite' ) {
8028
  $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_cloud_key'>" . esc_html__( 'Optimization API Key', 'ewww-image-optimizer' ) . '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/7-basic-configuration', '585373d5c697912ffd6c0bb2,5ad0c8e7042863075092650b,5a9efec62c7d3a7549516550' ) . "</th><td><input type='text' id='ewww_image_optimizer_cloud_key' name='ewww_image_optimizer_cloud_key' value='' size='32' /> " . esc_html__( 'API Key will be validated when you save your settings.', 'ewww-image-optimizer' ) . " <a href='https://ewww.io/plans/' target='_blank'>" . esc_html__( 'Purchase an API key.', 'ewww-image-optimizer' ) . "</a></td></tr>\n";
8029
  }
8030
  $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_metadata_remove'>" . esc_html__( 'Remove Metadata', 'ewww-image-optimizer' ) . '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/7-basic-configuration', '585373d5c697912ffd6c0bb2' ) . "</th>\n" .
8031
- "<td><input type='checkbox' id='ewww_image_optimizer_metadata_remove' name='ewww_image_optimizer_metadata_remove' value='true' " . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_metadata_remove' ) == true ? "checked='true'" : '' ) . ' /> ' . esc_html__( 'This will remove ALL metadata: EXIF, comments, color profiles, and anything else that is not pixel data.', 'ewww-image-optimizer' ) .
8032
  "<p class ='description'>" . esc_html__( 'Color profiles are preserved when using the API or ExactDN.', 'ewww-image-optimizer' ) . "</p></td></tr>\n";
8033
- ewwwio_debug_message( 'remove metadata: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_metadata_remove' ) == true ? 'on' : 'off' ) );
8034
 
8035
  $maybe_api_level = ewww_image_optimizer_get_option( 'ewww_image_optimizer_cloud_key' ) ? '*' : '';
8036
 
@@ -8081,8 +8042,8 @@ function ewww_image_optimizer_options( $network = 'singlesite' ) {
8081
  ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_backup_files' ) ? "checked='true'" : '' ) . " $disable_level > " . esc_html__( 'Store a copy of your original images on our secure server for 30 days. *Requires an active API key.', 'ewww-image-optimizer' ) . "</td></tr>\n";
8082
  ewwwio_debug_message( 'backup mode: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_backup_files' ) ? 'on' : 'off' ) );
8083
  if ( class_exists( 'Cloudinary' ) && Cloudinary::config_get( 'api_secret' ) ) {
8084
- $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_enable_cloudinary'>" . esc_html__( 'Automatic Cloudinary Upload', 'ewww-image-optimizer' ) . "</label></th><td><input type='checkbox' id='ewww_image_optimizer_enable_cloudinary' name='ewww_image_optimizer_enable_cloudinary' value='true' " . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_enable_cloudinary' ) == true ? "checked='true'" : '' ) . ' /> ' . esc_html__( 'When enabled, uploads to the Media Library will be transferred to Cloudinary after optimization. Cloudinary generates resizes, so only the full-size image is uploaded.', 'ewww-image-optimizer' ) . "</td></tr>\n";
8085
- ewwwio_debug_message( 'cloudinary upload: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_enable_cloudinary' ) == true ? 'on' : 'off' ) );
8086
  }
8087
  $output[] = "</table>\n</div>\n";
8088
  $output[] = "<div id='ewww-exactdn-settings'>\n";
@@ -8090,7 +8051,7 @@ function ewww_image_optimizer_options( $network = 'singlesite' ) {
8090
  $output[] = '<noscript><h2>' . esc_html__( 'ExactDN', 'ewww-image-optimizer' ) . '</h2></noscript>';
8091
  $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_exactdn'>" . esc_html__( 'ExactDN', 'ewww-image-optimizer' ) .
8092
  '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/44-introduction-to-exactdn', '59bc5ad6042863033a1ce370,59de6631042863379ddc953c,59c44349042863033a1d06d3,5ada43a12c7d3a0e93678b8c,5a3d278a2c7d3a1943677b52,5a9868eb04286374f7087795,59de68482c7d3a40f0ed6035,592dd69b2c7d3a074e8aed5b' ) . "</th><td><input type='checkbox' id='ewww_image_optimizer_exactdn' name='ewww_image_optimizer_exactdn' value='true' " .
8093
- ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_exactdn' ) == true ? "checked='true'" : '' ) . ' /> ' .
8094
  esc_html__( 'Enables CDN and automatic image resizing to fit your pages.', 'ewww-image-optimizer' ) .
8095
  ' <a href="https://ewww.io/resize/" target="_blank">' . esc_html__( 'Purchase a subscription for your site.', 'ewww-image-optimizer' ) . '</a>' .
8096
  '<p class="description">' .
@@ -8101,21 +8062,21 @@ function ewww_image_optimizer_options( $network = 'singlesite' ) {
8101
  esc_html__( 'JS/CSS Minification and Compression', 'ewww-image-optimizer' ) . '<br>' .
8102
  '<a href="https://docs.ewww.io/article/44-introduction-to-exactdn" target="_blank" data-beacon-article="59bc5ad6042863033a1ce370">' . esc_html__( 'Learn more about ExactDN', 'ewww-image-optimizer' ) . '</a>' .
8103
  "</p></td></tr>\n";
8104
- ewwwio_debug_message( 'ExactDN enabled: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_exactdn' ) == true ? 'on' : 'off' ) );
8105
  $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_backup_files'>" . esc_html__( 'Include All Resources', 'ewww-image-optimizer' ) . '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/47-getting-more-from-exactdn', '59de6631042863379ddc953c' ) . '</th>' .
8106
  "<td><input type='checkbox' id='exactdn_all_the_things' name='exactdn_all_the_things' value='true' " .
8107
  ( ewww_image_optimizer_get_option( 'exactdn_all_the_things' ) ? "checked='true'" : '' ) . '> ' . esc_html__( 'Use ExactDN for all resources in wp-includes/ and wp-content/, including JavaScript, CSS, fonts, etc.', 'ewww-image-optimizer' ) . "</td></tr>\n";
8108
- ewwwio_debug_message( 'ExactDN all the things: ' . ( ewww_image_optimizer_get_option( 'exactdn_all_the_things' ) == true ? 'on' : 'off' ) );
8109
  $output[] = "<tr class='$network_class'><th scope='row'><label for='exactdn_lossy'>" . esc_html__( 'Premium Compression', 'ewww-image-optimizer' ) . '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/47-getting-more-from-exactdn', '59de6631042863379ddc953c' ) . '</th>' .
8110
  "<td><input type='checkbox' id='exactdn_lossy' name='exactdn_lossy' value='true' " .
8111
  ( ewww_image_optimizer_get_option( 'exactdn_lossy' ) ? "checked='true'" : '' ) . '> ' . esc_html__( 'Enable high quality premium compression for all images. Disable to use Pixel Perfect mode instead.', 'ewww-image-optimizer' ) . "</td></tr>\n";
8112
  $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_lazy_load'>" . esc_html__( 'Lazy Load', 'ewww-image-optimizer' ) . '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/74-lazy-load', '5c6c36ed042863543ccd2d9b' ) .
8113
- "</th><td><input type='checkbox' id='ewww_image_optimizer_lazy_load' name='ewww_image_optimizer_lazy_load' value='true' " . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_lazy_load' ) == true ? "checked='true'" : '' ) . ' /> ' .
8114
  esc_html__( 'Improves actual and perceived loading time as images will be loaded only as they enter (or are about to enter) the viewport. When used with the ExactDN and WebP features, the plugin will load the best available image size and format for each device.', 'ewww-image-optimizer' ) . "</td></tr>\n";
8115
  ewwwio_debug_message( 'ExactDN lossy: ' . intval( ewww_image_optimizer_get_option( 'exactdn_lossy' ) ) );
8116
- ewwwio_debug_message( 'ExactDN resize existing: ' . ( ewww_image_optimizer_get_option( 'exactdn_resize_existing' ) == true ? 'on' : 'off' ) );
8117
- ewwwio_debug_message( 'ExactDN attachment queries: ' . ( ewww_image_optimizer_get_option( 'exactdn_prevent_db_queries' ) == true ? 'off' : 'on' ) );
8118
- ewwwio_debug_message( 'lazy load: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_lazy_load' ) == true ? 'on' : 'off' ) );
8119
  if ( defined( 'EXACTDN_EXCLUDE' ) && EXACTDN_EXCLUDE ) {
8120
  $exactdn_user_exclusions = EXACTDN_EXCLUDE;
8121
  if ( is_array( $exactdn_user_exclusions ) ) {
@@ -8132,13 +8093,13 @@ function ewww_image_optimizer_options( $network = 'singlesite' ) {
8132
  $output[] = "<table class='form-table'>\n";
8133
  if ( ! ewww_image_optimizer_full_cloud() ) {
8134
  ewwwio_debug_message( 'optipng level: ' . ewww_image_optimizer_get_option( 'ewww_image_optimizer_optipng_level' ) );
8135
- ewwwio_debug_message( 'pngout disabled: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_disable_pngout' ) == true ? 'yes' : 'no' ) );
8136
  ewwwio_debug_message( 'pngout level: ' . ewww_image_optimizer_get_option( 'ewww_image_optimizer_pngout_level' ) );
8137
  }
8138
  $output[] = "<tr class='$network_class'><th scope='row'><span><label for='ewww_image_optimizer_jpg_quality'>" . esc_html__( 'JPG Quality Level:', 'ewww-image-optimizer' ) . '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/11-advanced-configuration', '58542afac697912ffd6c18c0,58543c69c697912ffd6c19a7' ) . "</th><td><input type='text' id='ewww_image_optimizer_jpg_quality' name='ewww_image_optimizer_jpg_quality' class='small-text' value='" . ewww_image_optimizer_jpg_quality() . "' /> " . esc_html__( 'Valid values are 1-100.', 'ewww-image-optimizer' ) . "\n<p class='description'>" . esc_html__( 'Use this to override the default WordPress quality level of 82. Applies to image editing, resizing, PNG to JPG conversion, and JPG to WebP conversion. Does not affect the original uploaded image unless maximum dimensions are set and resizing occurs.', 'ewww-image-optimizer' ) . "</p></td></tr>\n";
8139
- $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_parallel_optimization'>" . esc_html__( 'Parallel Optimization', 'ewww-image-optimizer' ) . '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/11-advanced-configuration', '58542afac697912ffd6c18c0,598cb8be2c7d3a73488be237' ) . "</th><td><input type='checkbox' id='ewww_image_optimizer_parallel_optimization' name='ewww_image_optimizer_parallel_optimization' value='true' " . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_parallel_optimization' ) == true ? "checked='true'" : '' ) . ' /> ' . esc_html__( 'All resizes generated from a single upload are optimized in parallel for faster optimization. If this is causing performance issues, disable parallel optimization to reduce the load on your server.', 'ewww-image-optimizer' ) . "</td></tr>\n";
8140
- ewwwio_debug_message( 'parallel optimization: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_parallel_optimization' ) == true ? 'on' : 'off' ) );
8141
- ewwwio_debug_message( 'background optimization: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_background_optimization' ) == true ? 'on' : 'off' ) );
8142
  if ( ! ewww_image_optimizer_get_option( 'ewww_image_optimizer_background_optimization' ) ) {
8143
  $admin_ajax_url = admin_url( 'admin-ajax.php' );
8144
  if ( strpos( $admin_ajax_url, 'admin-ajax.php' ) ) {
@@ -8147,7 +8108,7 @@ function ewww_image_optimizer_options( $network = 'singlesite' ) {
8147
  ewwwio_debug_message( "admin ajax hostname: $admin_ajax_host" );
8148
  $resolved = gethostbyname( $admin_ajax_host . '.' );
8149
  ewwwio_debug_message( "resolved to $resolved" );
8150
- if ( $resolved == $admin_ajax_host . '.' ) {
8151
  ewwwio_debug_message( 'DNS lookup failed' );
8152
  } else {
8153
  $admin_ajax_url = add_query_arg(
@@ -8184,16 +8145,16 @@ function ewww_image_optimizer_options( $network = 'singlesite' ) {
8184
  ewwwio_debug_message( "invalid admin ajax url: $admin_ajax_url" );
8185
  }
8186
  }
8187
- $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_auto'>" . esc_html__( 'Scheduled Optimization', 'ewww-image-optimizer' ) . '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/11-advanced-configuration', '58542afac697912ffd6c18c0,5853713bc697912ffd6c0b98' ) . "</th><td><input type='checkbox' id='ewww_image_optimizer_auto' name='ewww_image_optimizer_auto' value='true' " . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_auto' ) == true ? "checked='true'" : '' ) . ' /> ' . esc_html__( 'This will enable scheduled optimization of unoptimized images for your theme, buddypress, and any additional folders you have configured below. Runs hourly: wp_cron only runs when your site is visited, so it may be even longer between optimizations.', 'ewww-image-optimizer' ) . "</td></tr>\n";
8188
- ewwwio_debug_message( 'scheduled optimization: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_auto' ) == true ? 'on' : 'off' ) );
8189
  $media_include_disable = '';
8190
  if ( get_option( 'ewww_image_optimizer_disable_resizes_opt' ) ) {
8191
  $media_include_disable = 'disabled="disabled"';
8192
  $output[] = "<tr class='$network_class'><th>&nbsp;</th><td>" .
8193
  '<p><span style="color: #3eadc9">' . esc_html__( '*Include Media Library Folders has been disabled because it will cause the scanner to ignore the disabled resizes.', 'ewww-image-optimizer' ) . "</span></p></td></tr>\n";
8194
  }
8195
- $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_include_media_paths'>" . esc_html__( 'Include Media Folders', 'ewww-image-optimizer' ) . '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/11-advanced-configuration', '58542afac697912ffd6c18c0,5853713bc697912ffd6c0b98' ) . "</th><td><input type='checkbox' id='ewww_image_optimizer_include_media_paths' name='ewww_image_optimizer_include_media_paths' $media_include_disable value='true' " . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_include_media_paths' ) == true && ! get_option( 'ewww_image_optimizer_disable_resizes_opt' ) ? "checked='true'" : '' ) . ' /> ' . esc_html__( 'Scan all images from the latest two folders of the Media Library during the Bulk Optimizer and Scheduled Optimization.', 'ewww-image-optimizer' ) . "</td></tr>\n";
8196
- ewwwio_debug_message( 'include media library: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_include_media_paths' ) == true ? 'on' : 'off' ) );
8197
  $aux_paths = ewww_image_optimizer_get_option( 'ewww_image_optimizer_aux_paths' ) ? esc_html( implode( "\n", ewww_image_optimizer_get_option( 'ewww_image_optimizer_aux_paths' ) ) ) : '';
8198
  $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_aux_paths'>" . esc_html__( 'Folders to Optimize', 'ewww-image-optimizer' ) . '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/11-advanced-configuration', '58542afac697912ffd6c18c0,5853713bc697912ffd6c0b98' ) . '</th><td>' .
8199
  /* translators: %s: the folder where WordPress is installed */
@@ -8211,27 +8172,37 @@ function ewww_image_optimizer_options( $network = 'singlesite' ) {
8211
  ewwwio_debug_message( $exclude_paths );
8212
  ewwwio_debug_message( 'skip images smaller than: ' . ewww_image_optimizer_get_option( 'ewww_image_optimizer_skip_size' ) . ' bytes' );
8213
  ewwwio_debug_message( 'skip PNG images larger than: ' . ewww_image_optimizer_get_option( 'ewww_image_optimizer_skip_png_size' ) . ' bytes' );
8214
- ewwwio_debug_message( 'exclude originals from lossy: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_lossy_skip_full' ) == true ? 'on' : 'off' ) );
8215
- ewwwio_debug_message( 'exclude originals from metadata removal: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_metadata_skip_full' ) == true ? 'on' : 'off' ) );
8216
- ewwwio_debug_message( 'use system binaries: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_skip_bundle' ) == true ? 'yes' : 'no' ) );
8217
  $output[] = "</table>\n</div>\n";
8218
 
8219
  $output[] = "<div id='ewww-resize-settings'>\n";
8220
  $output[] = '<noscript><h2>' . esc_html__( 'Resize', 'ewww-image-optimizer' ) . '</h2></noscript>';
8221
  $output[] = "<table class='form-table'>\n";
8222
- $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_resize_detection'>" . esc_html__( 'Resize Detection', 'ewww-image-optimizer' ) . '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/41-resize-settings', '59849911042863033a1ba5f9' ) . "</th><td><input type='checkbox' id='ewww_image_optimizer_resize_detection' name='ewww_image_optimizer_resize_detection' value='true' " . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_resize_detection' ) == true ? "checked='true'" : '' ) . ' /> ' . esc_html__( 'Highlight images that need to be resized because the browser is scaling them down. Only visible for Admin users and adds a button to the admin bar to detect scaled images that have been lazy loaded.', 'ewww-image-optimizer' ) . "</td></tr>\n";
8223
- ewwwio_debug_message( 'resize detection: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_resize_detection' ) == true ? 'on' : 'off' ) );
8224
  if ( function_exists( 'imsanity_get_max_width_height' ) ) {
8225
  $output[] = "<tr class='$network_class'><th>&nbsp;</th><td>" .
8226
  '<p><span style="color: #3eadc9">' . esc_html__( '*Imsanity settings override the EWWW resize dimensions.', 'ewww-image-optimizer' ) . "</span></p></td></tr>\n";
8227
  }
8228
- $output[] = "<tr class='$network_class'><th scope='row'>" . esc_html__( 'Resize Media Images', 'ewww-image-optimizer' ) . ewwwio_help_link( 'https://docs.ewww.io/article/41-resize-settings', '59849911042863033a1ba5f9' ) . "</th><td><label for='ewww_image_optimizer_maxmediawidth'>" . esc_html__( 'Max Width', 'ewww-image-optimizer' ) . "</label> <input type='number' step='1' min='0' class='small-text' id='ewww_image_optimizer_maxmediawidth' name='ewww_image_optimizer_maxmediawidth' value='" . ewww_image_optimizer_get_option( 'ewww_image_optimizer_maxmediawidth' ) . ( function_exists( 'imsanity_get_max_width_height' ) ? "' disabled='disabled" : '' ) . "' /> <label for='ewww_image_optimizer_maxmediaheight'>" . esc_html__( 'Max Height', 'ewww-image-optimizer' ) . "</label> <input type='number' step='1' min='0' class='small-text' id='ewww_image_optimizer_maxmediaheight' name='ewww_image_optimizer_maxmediaheight' value='" . ewww_image_optimizer_get_option( 'ewww_image_optimizer_maxmediaheight' ) . ( function_exists( 'imsanity_get_max_width_height' ) ? "' disabled='disabled" : '' ) . "' /> " . esc_html__( 'in pixels', 'ewww-image-optimizer' ) . "\n" .
8229
- "<p class='description'>" . esc_html__( 'Resizes images uploaded to the Media Library.', 'ewww-image-optimizer' ) .
 
 
 
 
 
 
8230
  "</td></tr>\n";
8231
  ewwwio_debug_message( 'max media dimensions: ' . ewww_image_optimizer_get_option( 'ewww_image_optimizer_maxmediawidth' ) . ' x ' . ewww_image_optimizer_get_option( 'ewww_image_optimizer_maxmediaheight' ) );
8232
  ewwwio_debug_message( 'max other dimensions: ' . ewww_image_optimizer_get_option( 'ewww_image_optimizer_maxotherwidth' ) . ' x ' . ewww_image_optimizer_get_option( 'ewww_image_optimizer_maxotherheight' ) );
8233
- $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_resize_existing'>" . esc_html__( 'Resize Existing Images', 'ewww-image-optimizer' ) . '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/41-resize-settings', '59849911042863033a1ba5f9' ) . "</th><td><input type='checkbox' id='ewww_image_optimizer_resize_existing' name='ewww_image_optimizer_resize_existing' value='true' " . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_resize_existing' ) == true ? "checked='true'" : '' ) . ' /> ' . esc_html__( 'Allow resizing of existing Media Library images.', 'ewww-image-optimizer' ) . "</td></tr>\n";
8234
- ewwwio_debug_message( 'resize existing images: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_resize_existing' ) == true ? 'on' : 'off' ) );
 
 
 
 
8235
 
8236
  $output[] = '<tr class="network-singlesite"><th scope="row">' . esc_html__( 'Disable Resizes', 'ewww-image-optimizer' ) .
8237
  ewwwio_help_link( 'https://docs.ewww.io/article/41-resize-settings', '59849911042863033a1ba5f9,58598744c697912ffd6c3eb4' ) . '</th><td><p>' .
@@ -8243,16 +8214,16 @@ function ewww_image_optimizer_options( $network = 'singlesite' ) {
8243
  $output[] = '<table><tr class="network-singlesite"><th scope="col">' . esc_html__( 'Disable Optimization', 'ewww-image-optimizer' ) . '</th><th scope="col">' . esc_html__( 'Disable Creation', 'ewww-image-optimizer' ) . "</th></tr>\n";
8244
  ewwwio_debug_message( 'disabled resizes:' );
8245
  foreach ( $image_sizes as $size => $dimensions ) {
8246
- if ( 'thumbnail' == $size ) {
8247
  $output[] = "<tr class='network-singlesite'><td><input type='checkbox' id='ewww_image_optimizer_disable_resizes_opt_$size' name='ewww_image_optimizer_disable_resizes_opt[$size]' value='true' " . ( ! empty( $disabled_sizes_opt[ $size ] ) ? "checked='true'" : '' ) . " /></td><td><input type='checkbox' id='ewww_image_optimizer_disable_resizes_$size' name='ewww_image_optimizer_disable_resizes[$size]' value='true' disabled /></td><td><label for='ewww_image_optimizer_disable_resizes_$size'>$size - {$dimensions['width']}x{$dimensions['height']}</label></td></tr>\n";
8248
- } elseif ( 'pdf-full' == $size ) {
8249
  $output[] = "<tr class='network-singlesite'><td><input type='checkbox' id='ewww_image_optimizer_disable_resizes_opt_$size' name='ewww_image_optimizer_disable_resizes_opt[$size]' value='true' " . ( ! empty( $disabled_sizes_opt[ $size ] ) ? "checked='true'" : '' ) . " /></td><td><input type='checkbox' id='ewww_image_optimizer_disable_resizes_$size' name='ewww_image_optimizer_disable_resizes[$size]' value='true' " . ( ! empty( $disabled_sizes[ $size ] ) ? "checked='true'" : '' ) . " /></td><td><label for='ewww_image_optimizer_disable_resizes_$size'>$size - <span class='description'>" . esc_html__( 'Disabling creation of the full-size preview for PDF files will disable all PDF preview sizes', 'ewww-image-optimizer' ) . "</span></label></td></tr>\n";
8250
  } else {
8251
  $output[] = "<tr class='network-singlesite'><td><input type='checkbox' id='ewww_image_optimizer_disable_resizes_opt_$size' name='ewww_image_optimizer_disable_resizes_opt[$size]' value='true' " . ( ! empty( $disabled_sizes_opt[ $size ] ) ? "checked='true'" : '' ) . " /></td><td><input type='checkbox' id='ewww_image_optimizer_disable_resizes_$size' name='ewww_image_optimizer_disable_resizes[$size]' value='true' " . ( ! empty( $disabled_sizes[ $size ] ) ? "checked='true'" : '' ) . " /></td><td><label for='ewww_image_optimizer_disable_resizes_$size'>$size - {$dimensions['width']}x{$dimensions['height']}</label></td></tr>\n";
8252
  }
8253
  ewwwio_debug_message( $size . ': ' . ( ! empty( $disabled_sizes_opt[ $size ] ) ? 'optimization=disabled ' : 'optimization=enabled ' ) . ( ! empty( $disabled_sizes[ $size ] ) ? 'creation=disabled' : 'creation=enabled' ) );
8254
  }
8255
- if ( 'network-multisite' != $network ) {
8256
  $output[] = "</table>\n";
8257
  $output[] = "</td></tr>\n";
8258
  } else {
@@ -8268,29 +8239,48 @@ function ewww_image_optimizer_options( $network = 'singlesite' ) {
8268
  "</p>\n";
8269
  $output[] = "<table class='form-table'>\n";
8270
  if ( $toolkit_found ) {
8271
- $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_disable_convert_links'>" . esc_html__( 'Hide Conversion Links', 'ewww-image-optimizer' ) . '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/14-converting-images', '58545a86c697912ffd6c1b53' ) . "</th><td><input type='checkbox' id='ewww_image_optimizer_disable_convert_links' name='ewww_image_optimizer_disable_convert_links' " . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_disable_convert_links' ) == true ? "checked='true'" : '' ) . ' /> ' . esc_html__( 'Site or Network admins can use this to prevent other users from using the conversion links in the Media Library which bypass the settings below.', 'ewww-image-optimizer' ) . "</td></tr>\n";
8272
- $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_delete_originals'>" . esc_html__( 'Delete Originals', 'ewww-image-optimizer' ) . '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/14-converting-images', '58545a86c697912ffd6c1b53' ) . "</th><td><input type='checkbox' id='ewww_image_optimizer_delete_originals' name='ewww_image_optimizer_delete_originals' " . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_delete_originals' ) == true ? "checked='true'" : '' ) . ' /> ' . esc_html__( 'This will remove the original image from the server after a successful conversion.', 'ewww-image-optimizer' ) . "</td></tr>\n";
8273
- ewwwio_debug_message( 'delete originals: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_delete_originals' ) == true ? 'on' : 'off' ) );
 
 
 
 
 
 
 
 
 
8274
  $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_jpg_to_png'>" .
8275
  /* translators: 1: JPG, GIF or PNG 2: JPG or PNG */
8276
  sprintf( esc_html__( '%1$s to %2$s Conversion', 'ewww-image-optimizer' ), 'JPG', 'PNG' ) .
8277
- '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/14-converting-images', '58545a86c697912ffd6c1b53' ) . "</th><td><span><input type='checkbox' id='ewww_image_optimizer_jpg_to_png' name='ewww_image_optimizer_jpg_to_png' " . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_to_png' ) == true ? "checked='true'" : '' ) . ' /> <b>' . esc_html__( 'WARNING:', 'ewww-image-optimizer' ) . '</b> ' . esc_html__( 'Removes metadata and increases cpu usage dramatically.', 'ewww-image-optimizer' ) . "</span>\n" .
8278
- "<p class='description'>" . esc_html__( 'PNG is generally much better than JPG for logos and other images with a limited range of colors. Checking this option will slow down JPG processing significantly, and you may want to enable it only temporarily.', 'ewww-image-optimizer' ) . "</p></td></tr>\n";
8279
- ewwwio_debug_message( 'jpg2png: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_to_png' ) == true ? 'on' : 'off' ) );
 
 
 
 
8280
  $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_png_to_jpg'>" .
8281
  /* translators: 1: JPG, GIF or PNG 2: JPG or PNG */
8282
  sprintf( esc_html__( '%1$s to %2$s Conversion', 'ewww-image-optimizer' ), 'PNG', 'JPG' ) .
8283
- '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/14-converting-images', '58545a86c697912ffd6c1b53,58543c69c697912ffd6c19a7,58542afac697912ffd6c18c0' ) . "</th><td><span><input type='checkbox' id='ewww_image_optimizer_png_to_jpg' name='ewww_image_optimizer_png_to_jpg' " . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_to_jpg' ) == true ? "checked='true'" : '' ) . ' /> <b>' . esc_html__( 'WARNING:', 'ewww-image-optimizer' ) . '</b> ' . esc_html__( 'This is not a lossless conversion.', 'ewww-image-optimizer' ) . "</span>\n" .
 
 
 
8284
  "<p class='description'>" . esc_html__( 'JPG is generally much better than PNG for photographic use because it compresses the image and discards data. PNGs with transparency are not converted by default.', 'ewww-image-optimizer' ) . "</p>\n" .
8285
  "<span><label for='ewww_image_optimizer_jpg_background'> " . esc_html__( 'JPG Background Color:', 'ewww-image-optimizer' ) . "</label> #<input type='text' id='ewww_image_optimizer_jpg_background' name='ewww_image_optimizer_jpg_background' size='6' value='" . ewww_image_optimizer_jpg_background() . "' /> <span style='padding-left: 12px; font-size: 12px; border: solid 1px #555555; background-color: #" . ewww_image_optimizer_jpg_background() . "'>&nbsp;</span> " . esc_html__( 'HEX format (#123def)', 'ewww-image-optimizer' ) . ".</span>\n" .
8286
  "<p class='description'>" . esc_html__( 'Background color is used only if the PNG has transparency. Leave this value blank to skip PNGs with transparency.', 'ewww-image-optimizer' ) . "</p></td></tr>\n";
8287
- ewwwio_debug_message( 'png2jpg: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_to_jpg' ) == true ? 'on' : 'off' ) );
8288
  $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_gif_to_png'>" .
8289
  /* translators: 1: JPG, GIF or PNG 2: JPG or PNG */
8290
  sprintf( esc_html__( '%1$s to %2$s Conversion', 'ewww-image-optimizer' ), 'GIF', 'PNG' ) .
8291
- '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/14-converting-images', '58545a86c697912ffd6c1b53' ) . "</th><td><span><input type='checkbox' id='ewww_image_optimizer_gif_to_png' name='ewww_image_optimizer_gif_to_png' " . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_gif_to_png' ) == true ? "checked='true'" : '' ) . ' /> ' . esc_html__( 'No warnings here, just do it.', 'ewww-image-optimizer' ) . "</span>\n" .
 
 
 
8292
  "<p class='description'> " . esc_html__( 'PNG is generally better than GIF, but animated images cannot be converted.', 'ewww-image-optimizer' ) . "</p></td></tr>\n";
8293
- ewwwio_debug_message( 'gif2png: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_gif_to_png' ) == true ? 'on' : 'off' ) );
8294
  } else {
8295
  $output[] = "<tr class='$network_class'><th>&nbsp;</th><td>" .
8296
  '<p><span style="color: #3eadc9">' . esc_html__( 'Image conversion requires one of the following PHP libraries: GD, Imagick, or GMagick.', 'ewww-image-optimizer' ) . "</span></p></td></tr>\n";
@@ -8304,17 +8294,17 @@ function ewww_image_optimizer_options( $network = 'singlesite' ) {
8304
  $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_webp'>" . esc_html__( 'JPG/PNG to WebP', 'ewww-image-optimizer' ) . '</label>' .
8305
  ewwwio_help_link( 'https://docs.ewww.io/article/16-ewww-io-and-webp-images', '5854745ac697912ffd6c1c89' ) .
8306
  "</th><td><span><input type='checkbox' id='ewww_image_optimizer_webp' name='ewww_image_optimizer_webp' value='true' " .
8307
- ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_webp' ) == true ? "checked='true'" : '' ) . ' /> <b>' .
8308
  esc_html__( 'WARNING:', 'ewww-image-optimizer' ) . '</b> ' . esc_html__( 'JPG to WebP conversion is lossy, but quality loss is minimal. PNG to WebP conversion is lossless.', 'ewww-image-optimizer' ) .
8309
  "</span>\n<p class='description'>" . esc_html__( 'Originals are never deleted, and WebP images should only be served to supported browsers.', 'ewww-image-optimizer' ) .
8310
  " <a href='#webp-rewrite'>" . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_webp' ) && ! ewww_image_optimizer_get_option( 'ewww_image_optimizer_webp_for_cdn' ) ? esc_html__( 'You can use the rewrite rules below to serve WebP images with Apache.', 'ewww-image-optimizer' ) : '' ) . "</a></td></tr>\n";
8311
- ewwwio_debug_message( 'webp conversion: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_webp' ) == true ? 'on' : 'off' ) );
8312
  $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_webp_force'>" . esc_html__( 'Force WebP', 'ewww-image-optimizer' ) . '</label>' .
8313
  ewwwio_help_link( 'https://docs.ewww.io/article/16-ewww-io-and-webp-images', '5854745ac697912ffd6c1c89' ) .
8314
  "</th><td><span><input type='checkbox' id='ewww_image_optimizer_webp_force' name='ewww_image_optimizer_webp_force' value='true' " .
8315
- ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_webp_force' ) == true ? "checked='true'" : '' ) . ' /> ' .
8316
  esc_html__( 'WebP images will be generated and saved for all JPG/PNG images regardless of their size. The JS WebP Rewriting will not check if a file exists, only that the domain matches the home url.', 'ewww-image-optimizer' ) . "</span></td></tr>\n";
8317
- ewwwio_debug_message( 'forced webp: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_webp_force' ) == true ? 'on' : 'off' ) );
8318
  }
8319
  if ( ! ewww_image_optimizer_ce_webp_enabled() && ! ewww_image_optimizer_get_option( 'ewww_image_optimizer_exactdn' ) ) {
8320
  $webp_paths = ewww_image_optimizer_get_option( 'ewww_image_optimizer_webp_paths' ) ? esc_html( implode( "\n", ewww_image_optimizer_get_option( 'ewww_image_optimizer_webp_paths' ) ) ) : '';
@@ -8327,11 +8317,11 @@ function ewww_image_optimizer_options( $network = 'singlesite' ) {
8327
  $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_webp_for_cdn'>" .
8328
  esc_html__( 'JS WebP Rewriting', 'ewww-image-optimizer' ) .
8329
  '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/16-ewww-io-and-webp-images', '5854745ac697912ffd6c1c89,59443d162c7d3a0747cdf9f0' ) . "</th><td><span><input type='checkbox' id='ewww_image_optimizer_webp_for_cdn' name='ewww_image_optimizer_webp_for_cdn' value='true' " .
8330
- ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_webp_for_cdn' ) == true ? "checked='true'" : '' ) . ' /> ' .
8331
  esc_html__( 'Use this if the Apache rewrite rules do not work, or if your images are served from a CDN.', 'ewww-image-optimizer' ) . ' ' .
8332
  /* translators: %s: Cache Enabler (link) */
8333
  sprintf( esc_html__( 'Sites using a CDN may also use the WebP option in the %s plugin.', 'ewww-image-optimizer' ), '<a href="https://wordpress.org/plugins/cache-enabler/">Cache Enabler</a>' ) . '</span></td></tr>';
8334
- ewwwio_debug_message( 'alt webp rewriting: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_webp_for_cdn' ) == true ? 'on' : 'off' ) );
8335
  } elseif ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_exactdn' ) ) {
8336
  $output[] = "<tr class='$network_class'><th>&nbsp;</th><td><p class='description'>" . esc_html__( 'WebP images are served automatically by ExactDN.', 'ewww-image-optimizer' ) . '</p></td></tr>';
8337
  }
@@ -8344,11 +8334,18 @@ function ewww_image_optimizer_options( $network = 'singlesite' ) {
8344
  "<a href='https://ewww.io/status/'>" . esc_html__( 'Server Status', 'ewww-image-optimizer' ) . '</a>' .
8345
  "</p>\n";
8346
  $output[] = "<table class='form-table'>\n";
8347
- $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_enable_help'>" . esc_html__( 'Enable Embedded Help', 'ewww-image-optimizer' ) . "</label></th><td><input type='checkbox' id='ewww_image_optimizer_enable_help' name='ewww_image_optimizer_enable_help' value='true' " . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_enable_help' ) == true ? "checked='true'" : '' ) . ' /> ' .
8348
- esc_html__( 'Enable the support beacon, which gives you access to documentation and our support team right from your WordPress dashboard. To assist you more efficiently, we may collect the current url, IP address, browser/device information, and debugging information.', 'ewww-image-optimizer' ) . "</td></tr>\n";
8349
- ewwwio_debug_message( 'enable help beacon: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_enable_help' ) == true ? 'yes' : 'no' ) );
8350
- $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_debug'>" . esc_html__( 'Debugging', 'ewww-image-optimizer' ) . '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/7-basic-configuration', '585373d5c697912ffd6c0bb2' ) . '</th>' .
8351
- "<td><input type='checkbox' id='ewww_image_optimizer_debug' name='ewww_image_optimizer_debug' value='true' " . ( ! $ewwwio_temp_debug && ewww_image_optimizer_get_option( 'ewww_image_optimizer_debug' ) == true ? "checked='true'" : '' ) . ' /> ' . esc_html__( 'Use this to provide information for support purposes, or if you feel comfortable digging around in the code to fix a problem you are experiencing.', 'ewww-image-optimizer' ) . "</td></tr>\n";
 
 
 
 
 
 
 
8352
  $output[] = "</table>\n";
8353
 
8354
  $output[] = 'DEBUG_PLACEHOLDER';
@@ -8362,8 +8359,12 @@ function ewww_image_optimizer_options( $network = 'singlesite' ) {
8362
  "<a href='https://wordpress.org/support/view/plugin-reviews/ewww-image-optimizer#postform'>" . esc_html__( 'Write a review', 'ewww-image-optimizer' ) . '</a> | ' .
8363
  "<a href='https://ewww.io/plans/'>" . esc_html__( 'Upgrade to premium image optimization', 'ewww-image-optimizer' ) . "</a></p>\n";
8364
  $output[] = "<table class='form-table'>\n";
8365
- $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_allow_tracking'>" . esc_html__( 'Allow Usage Tracking?', 'ewww-image-optimizer' ) . '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/23-usage-tracking', '591f3a8e2c7d3a057f893d91' ) . "</th><td><input type='checkbox' id='ewww_image_optimizer_allow_tracking' name='ewww_image_optimizer_allow_tracking' value='true' " . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_allow_tracking' ) == true ? "checked='true'" : '' ) . ' /> ' .
8366
- esc_html__( 'Allow EWWW Image Optimizer to anonymously track how this plugin is used and help us make the plugin better. Opt-in to tracking and receive 500 API image credits free. No sensitive data is tracked.', 'ewww-image-optimizer' ) . "</td></tr>\n";
 
 
 
 
8367
  $output[] = "</table>\n";
8368
  $output[] = "</div>\n";
8369
 
@@ -8600,7 +8601,7 @@ function ewww_image_optimizer_remove_cloud_key( $redirect = true ) {
8600
  if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) > 10 ) {
8601
  ewww_image_optimizer_set_option( 'ewww_image_optimizer_jpg_level', $default_level );
8602
  }
8603
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) > 10 && ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) != 40 ) {
8604
  ewww_image_optimizer_set_option( 'ewww_image_optimizer_png_level', $default_level );
8605
  }
8606
  if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_gif_level' ) > 0 ) {
@@ -8623,7 +8624,7 @@ function ewww_image_optimizer_remove_cloud_key( $redirect = true ) {
8623
  * Loads script to detect scaled images within the page, only enabled for admins.
8624
  */
8625
  function ewww_image_optimizer_resize_detection_script() {
8626
- if ( ! current_user_can( apply_filters( 'ewww_image_optimizer_admin_permissions', 'edit_others_posts' ) ) || 'wp-login.php' == basename( $_SERVER['SCRIPT_NAME'] ) ) {
8627
  return;
8628
  }
8629
  if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_resize_detection' ) ) {
@@ -8658,7 +8659,7 @@ function ewww_image_optimizer_autoptimize_js_exclude( $jsexcludes = '', $content
8658
  * Checks if admin bar is visible, and then adds the admin_bar_menu action.
8659
  */
8660
  function ewww_image_optimizer_admin_bar_init() {
8661
- if ( ! current_user_can( apply_filters( 'ewww_image_optimizer_admin_permissions', 'edit_others_posts' ) ) || ! is_admin_bar_showing() || 'wp-login.php' == basename( $_SERVER['SCRIPT_NAME'] ) || is_admin() ) {
8662
  return;
8663
  }
8664
  if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_resize_detection' ) ) {
@@ -8808,7 +8809,7 @@ function ewwwio_debug_version_info() {
8808
  if ( defined( 'LIBXML_VERSION' ) ) {
8809
  $ewww_debug .= 'libxml version: ' . LIBXML_VERSION . '<br>';
8810
  }
8811
- if ( ! empty( $_ENV['PANTHEON_ENVIRONMENT'] ) && in_array( $_ENV['PANTHEON_ENVIRONMENT'], array( 'test', 'live', 'dev' ) ) ) {
8812
  $ewww_debug .= "detected pantheon env: {$_ENV['PANTHEON_ENVIRONMENT']}<br>";
8813
  }
8814
  if ( defined( 'EWWW_IO_CLOUD_PLUGIN' ) && EWWW_IO_CLOUD_PLUGIN ) {
@@ -8851,10 +8852,10 @@ function ewww_image_optimizer_dynamic_image_debug() {
8851
  $ewwwdb = $wpdb;
8852
  }
8853
  $debug_images = $ewwwdb->get_results( "SELECT path,updates,updated,trace FROM $ewwwdb->ewwwio_images WHERE trace IS NOT NULL ORDER BY updates DESC LIMIT 100" );
8854
- if ( count( $debug_images ) != 0 ) {
8855
  foreach ( $debug_images as $image ) {
8856
  $trace = unserialize( $image->trace );
8857
- echo '<p><b>' . esc_html__( 'File path', 'ewww-image-optimizer' ) . ': ' . $image->path . '</b><br>';
8858
  echo esc_html__( 'Number of attempted optimizations', 'ewww-image-optimizer' ) . ': ' . $image->updates . '<br>';
8859
  echo esc_html__( 'Last attempted', 'ewww-image-optimizer' ) . ': ' . $image->updated . '<br>';
8860
  echo esc_html__( 'PHP trace', 'ewww-image-optimizer' ) . ':<br>';
@@ -9039,6 +9040,36 @@ function ewwwio_check_memory_available( $padding = 1050000 ) {
9039
  return true;
9040
  }
9041
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9042
  /**
9043
  * Logs memory usage stats. Disabled normally.
9044
  *
22
  exit;
23
  }
24
 
25
+ define( 'EWWW_IMAGE_OPTIMIZER_VERSION', '473.0' );
26
 
27
  // Initialize a couple globals.
28
  $ewww_debug = '';
463
  $suhosin_disabled = explode( ',', $suhosin_disabled );
464
  $suhosin_disabled = array_map( 'trim', $suhosin_disabled );
465
  $suhosin_disabled = array_map( 'strtolower', $suhosin_disabled );
466
+ if ( function_exists( $function ) && ! in_array( $function, $suhosin_disabled, true ) ) {
467
  return true;
468
  }
469
  return false;
828
  add_action( 'admin_notices', 'ewww_image_optimizer_notice_reoptimization' );
829
  add_action( 'admin_notices', 'ewww_image_optimizer_notice_media_listmode' );
830
  if ( ! empty( $_GET['page'] ) ) {
831
+ if ( 'regenerate-thumbnails' === $_GET['page']
832
+ || 'force-regenerate-thumbnails' === $_GET['page']
833
+ || 'ajax-thumbnail-rebuild' === $_GET['page']
834
+ || 'regenerate_thumbnails_advanced' === $_GET['page']
835
  ) {
836
  // Add a notice for thumb regeneration.
837
  add_action( 'admin_notices', 'ewww_image_optimizer_thumbnail_regen_notice' );
865
  function ewww_image_optimizer_cron_setup( $event ) {
866
  ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
867
  // Setup scheduled optimization if the user has enabled it, and it isn't already scheduled.
868
+ if ( ewww_image_optimizer_get_option( $event ) && ! wp_next_scheduled( $event ) ) {
869
  ewwwio_debug_message( "scheduling $event" );
870
  wp_schedule_event( time(), apply_filters( 'ewww_image_optimizer_schedule', 'hourly', $event ), $event );
871
+ } elseif ( ewww_image_optimizer_get_option( $event ) ) {
872
  ewwwio_debug_message( "$event already scheduled: " . wp_next_scheduled( $event ) );
873
  } elseif ( wp_next_scheduled( $event ) ) {
874
  ewwwio_debug_message( "un-scheduling $event" );
903
  ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
904
  // Check for (Force) Regenerate Thumbnails action (includes MLP regenerate).
905
  if ( ! empty( $_REQUEST['action'] ) ) {
906
+ if ( 'regeneratethumbnail' === $_REQUEST['action'] ||
907
+ 'meauh_save_image' === $_REQUEST['action'] ||
908
+ 'hotspot_save' === $_REQUEST['action']
909
  ) {
910
  ewwwio_debug_message( 'doing regeneratethumbnail' );
911
  ewww_image_optimizer_image_sizes( false );
912
  return;
913
  }
914
+ if ( 'mic_crop_image' === $_REQUEST['action'] ) {
915
  ewwwio_debug_message( 'doing Manual Image Crop' );
916
  if ( ! defined( 'EWWWIO_EDITOR_OVERWRITE' ) ) {
917
  define( 'EWWWIO_EDITOR_OVERWRITE', true );
939
  return;
940
  }
941
  // Check for other MLP actions, including multi-regen.
942
+ if ( ! empty( $_REQUEST['action'] ) && class_exists( 'MaxGalleriaMediaLib' ) && ( 'regen_mlp_thumbnails' === $_REQUEST['action'] || 'move_media' === $_REQUEST['action'] || 'copy_media' === $_REQUEST['action'] || 'maxgalleria_rename_image' === $_REQUEST['action'] ) ) {
943
  ewwwio_debug_message( 'doing regen_mlp_thumbnails' );
944
  ewww_image_optimizer_image_sizes( false );
945
  return;
946
  }
947
  // Check for MLP upload.
948
+ if ( ! empty( $_REQUEST['action'] ) && class_exists( 'MaxGalleriaMediaLib' ) && ! empty( $_REQUEST['nonce'] ) && 'upload_attachment' === $_REQUEST['action'] ) {
949
  ewwwio_debug_message( 'doing maxgalleria upload' );
950
  ewww_image_optimizer_image_sizes( false );
951
  return;
1012
  'image/gif',
1013
  'application/pdf',
1014
  );
1015
+ if ( ! in_array( $type, $supported_types, true ) ) {
1016
  ewwwio_debug_message( "mimetype not supported: $id" );
1017
  return;
1018
  }
1019
+ if ( 'full' === $size ) {
1020
  $ewww_image = new EWWW_Image( $id, 'media', $file_path );
1021
  $ewww_image->resize = 'full';
1022
 
1036
  if ( ! empty( $disabled_sizes[ $size ] ) ) {
1037
  return;
1038
  }
1039
+ if ( ! empty( $disabled_sizes['pdf-full'] ) && 'full' === $size ) {
1040
  return;
1041
  }
1042
  if ( empty( $data['file'] ) ) {
1044
  }
1045
  // If this is a unique size.
1046
  $resize_path = $base_dir . $data['file'];
1047
+ if ( 'application/pdf' === $type && 'full' === $size ) {
1048
  $size = 'pdf-full';
1049
  ewwwio_debug_message( 'processing full size pdf preview' );
1050
  }
1209
  * @return bool True if this is a 'large network'.
1210
  */
1211
  function ewww_image_optimizer_large_network( $large_network, $criteria, $count ) {
1212
+ if ( 'sites' === $criteria && $count > 1000 ) {
1213
  return true;
1214
  }
1215
  return false;
1231
  ewwwio_debug_message( "current collation: $db_collation" );
1232
 
1233
  // See if the path column exists, and what collation it uses to determine the column index size.
1234
+ if ( $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->ewwwio_images'" ) === $wpdb->ewwwio_images ) {
1235
  ewwwio_debug_message( 'upgrading table and checking collation for path, table exists' );
1236
  // Check if the old path_image_size index exists, and drop it.
1237
  if ( $wpdb->get_results( "SHOW INDEX FROM $wpdb->ewwwio_images WHERE Key_name = 'path_image_size'", ARRAY_A ) ) {
1445
  * Display a success or failure message after PNGOUT installation.
1446
  */
1447
  function ewww_image_optimizer_pngout_installed() {
1448
+ if ( 'success' === $_REQUEST['ewww_pngout'] ) {
1449
  echo "<div id='ewww-image-optimizer-pngout-success' class='updated fade'>\n" .
1450
  '<p>' . esc_html__( 'Pngout was successfully installed.', 'ewww-image-optimizer' ) . "</p>\n" .
1451
  "</div>\n";
1452
  }
1453
+ if ( 'failed' === $_REQUEST['ewww_pngout'] ) {
1454
  echo "<div id='ewww-image-optimizer-pngout-failure' class='error'>\n" .
1455
  '<p>' . sprintf(
1456
  /* translators: 1: An error message 2: The folder where pngout should be installed */
1550
  } else {
1551
  set_transient( 'ewww_image_optimizer_images_reoptimized', $reoptimized, HOUR_IN_SECONDS );
1552
  }
1553
+ } elseif ( 'zero' === $reoptimized ) {
1554
  $reoptimized = 0;
1555
  }
1556
  // Do a check for 10+ optimizations on 5+ images.
1588
  require_once( plugin_dir_path( __FILE__ ) . '/classes/class-ewwwio-gmagick-editor.php' );
1589
  }
1590
  }
1591
+ if ( ! in_array( 'EWWWIO_GD_Editor', $editors, true ) ) {
1592
  array_unshift( $editors, 'EWWWIO_GD_Editor' );
1593
  }
1594
+ if ( ! in_array( 'EWWWIO_Imagick_Editor', $editors, true ) ) {
1595
  array_unshift( $editors, 'EWWWIO_Imagick_Editor' );
1596
  }
1597
+ if ( ! in_array( 'EWWWIO_Gmagick_Editor', $editors, true ) && class_exists( 'WP_Image_Editor_Gmagick' ) ) {
1598
  array_unshift( $editors, 'EWWWIO_Gmagick_Editor' );
1599
  }
1600
  if ( is_array( $editors ) ) {
1690
  */
1691
  function ewww_image_optimizer_pte_check( $data ) {
1692
  if ( ! empty( $_GET['pte-action'] ) ) {
1693
+ if ( 'confirm-images' === $_GET['pte-action'] ) {
1694
  add_filter( 'wp_update_attachment_metadata', 'ewww_image_optimizer_resize_from_meta_data', 15, 2 );
1695
  }
1696
  }
1863
  ewww_image_optimizer_autorotate( $file_path );
1864
  $new_image = ewww_image_optimizer_autoconvert( $file_path );
1865
  if ( $new_image ) {
1866
+ if ( ! empty( $params['tmp_name'] ) && $params['tmp_name'] === $file_path ) {
1867
  $params['tmp_name'] = $new_image;
1868
  }
1869
+ if ( ! empty( $params['file'] ) && $params['file'] === $file_path ) {
1870
  $params['file'] = $new_image;
1871
  }
1872
+ if ( ! empty( $params['url'] ) && basename( $file_path ) === basename( $params['url'] ) ) {
1873
  $params['url'] = trailingslashit( dirname( $params['url'] ) ) . basename( $new_image );
1874
  }
1875
  $params['type'] = ewww_image_optimizer_mimetype( $new_image, 'i' );
1886
  } else {
1887
  $mime_type = $params['type'];
1888
  }
1889
+ if ( ( ! is_wp_error( $params ) ) && is_file( $file_path ) && in_array( $mime_type, array( 'image/png', 'image/gif', 'image/jpeg' ), true ) ) {
1890
  ewww_image_optimizer_resize_upload( $file_path );
1891
  }
1892
  }
1973
  $ewww_defer = false;
1974
  require_once( EWWW_IMAGE_OPTIMIZER_PLUGIN_PATH . 'bulk.php' );
1975
  require_once( EWWW_IMAGE_OPTIMIZER_PLUGIN_PATH . 'aux-optimize.php' );
1976
+ if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_auto' ) ) {
1977
  ewwwio_debug_message( 'running scheduled optimization' );
1978
  ewww_image_optimizer_aux_images_script( 'ewww-image-optimizer-auto' );
1979
  // Generate our own unique nonce value, because wp_create_nonce() will return the same value for 12-24 hours.
2166
  $opt_size = ewww_image_optimizer_filesize( $retina_path );
2167
  ewwwio_debug_message( "retina size: $opt_size" );
2168
  $optimized_query = ewww_image_optimizer_find_already_optimized( $temp_path );
2169
+ if ( is_array( $optimized_query ) && $optimized_query['image_size'] === $opt_size ) {
2170
  global $wpdb;
2171
+ if ( false === strpos( $wpdb->charset, 'utf8' ) ) {
2172
  ewww_image_optimizer_db_init();
2173
  global $ewwwdb;
2174
  } else {
2280
  * @param string $hook The unique hook of the page being loaded in the WP admin.
2281
  */
2282
  function ewww_image_optimizer_media_scripts( $hook ) {
2283
+ if ( 'upload.php' === $hook || 'ims_gallery_page_ewww-ims-optimize' === $hook ) {
2284
  add_thickbox();
2285
  wp_enqueue_script( 'jquery-ui-tooltip' );
2286
  wp_enqueue_script( 'ewwwmediascript', plugins_url( '/includes/media.js', __FILE__ ), array( 'jquery' ), EWWW_IMAGE_OPTIMIZER_VERSION );
2356
  $imagick = new Imagick();
2357
  $formats = $imagick->queryFormats();
2358
  ewwwio_debug_message( implode( ',', $formats ) );
2359
+ if ( in_array( 'PNG', $formats, true ) && in_array( 'JPG', $formats, true ) ) {
2360
  return true;
2361
  }
2362
  ewwwio_debug_message( 'imagick found, but PNG or JPG not supported' );
2375
  $gmagick = new Gmagick();
2376
  $formats = $gmagick->queryFormats();
2377
  ewwwio_debug_message( implode( ',', $formats ) );
2378
+ if ( in_array( 'PNG', $formats, true ) && in_array( 'JPG', $formats, true ) ) {
2379
  return true;
2380
  }
2381
  ewwwio_debug_message( 'gmagick found, but PNG or JPG not supported' );
2729
  if ( ! $meta_saved ) {
2730
  ewwwio_debug_message( 'failed to save meta, or no changes' );
2731
  }
2732
+ if ( get_transient( 'ewww_image_optimizer_cloud_status' ) === 'exceeded' || ewww_image_optimizer_get_option( 'ewww_image_optimizer_cloud_exceeded' ) > time() ) {
2733
  if ( ! wp_doing_ajax() ) {
2734
  wp_die( esc_html__( 'License exceeded', 'ewww-image-optimizer' ) );
2735
  }
2908
  if ( is_file( $image['path'] ) ) {
2909
  $old_type = ewww_image_optimizer_mimetype( $image['path'], 'i' );
2910
  }
2911
+ if ( ! in_array( $new_type, $enabled_types, true ) ) {
2912
  return false;
2913
  }
2914
+ if ( empty( $old_type ) || $old_type === $new_type ) {
2915
  if ( rename( $image['path'] . '.tmp', $image['path'] ) ) {
2916
  if ( is_file( $image['path'] . '.webp' ) && is_writable( $image['path'] . '.webp' ) ) {
2917
  unlink( $image['path'] . '.webp' );
3124
  if ( ! empty( $api_key ) ) {
3125
  $sanitize = true;
3126
  }
3127
+ if ( empty( $api_key ) && ! ( ! empty( $_REQUEST['option_page'] ) && 'ewww_image_optimizer_options' === $_REQUEST['option_page'] ) ) {
3128
  $api_key = ewww_image_optimizer_get_option( 'ewww_image_optimizer_cloud_key' );
3129
  } elseif ( empty( $api_key ) && ! empty( $_POST['ewww_image_optimizer_cloud_key'] ) ) {
3130
  $api_key = $_POST['ewww_image_optimizer_cloud_key'];
3134
  update_site_option( 'ewww_image_optimizer_jpg_level', 10 );
3135
  update_option( 'ewww_image_optimizer_jpg_level', 10 );
3136
  }
3137
+ if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) > 10 && 40 !== (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) ) {
3138
  update_site_option( 'ewww_image_optimizer_png_level', 10 );
3139
  update_option( 'ewww_image_optimizer_png_level', 10 );
3140
  }
3205
  return false;
3206
  } else {
3207
  set_transient( 'ewww_image_optimizer_cloud_status', $verified, 3600 );
3208
+ if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) < 20 && ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) < 20 && ewww_image_optimizer_get_option( 'ewww_image_optimizer_gif_level' ) < 20 && ! ewww_image_optimizer_get_option( 'ewww_image_optimizer_pdf_level' ) ) {
3209
  ewww_image_optimizer_cloud_enable();
3210
  }
3211
  ewwwio_debug_message( "verification body contents: {$result['body']}" );
3283
  if ( $raw ) {
3284
  return $quota;
3285
  }
3286
+ if ( ! $quota['licensed'] && $quota['consumed'] > 0 ) {
3287
  return esc_html(
3288
  sprintf(
3289
  /* translators: 1: Number of images 2: Number of days until renewal */
3292
  $quota['days']
3293
  )
3294
  );
3295
+ } elseif ( ! $quota['licensed'] && $quota['consumed'] < 0 ) {
3296
  return esc_html(
3297
  sprintf(
3298
  /* translators: 1: Number of images */
3309
  $real_quota
3310
  )
3311
  );
3312
+ } elseif ( ! $quota['licensed'] && ! $quota['consumed'] && ! $quota['days'] && ! $quota['metered'] ) {
3313
  return esc_html__( 'no credits remaining, please purchase more.', 'ewww-image-optimizer' );
3314
  } else {
3315
  return esc_html(
3392
  $lossy_fast = 0;
3393
  if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_lossy_skip_full' ) && $fullsize ) {
3394
  $lossy = 0;
3395
+ } elseif ( 'image/png' === $type && ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) >= 40 ) {
3396
  $lossy = 1;
3397
+ if ( 40 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) ) {
3398
  $lossy_fast = 1;
3399
  }
3400
+ } elseif ( 'image/jpeg' === $type && ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) >= 30 ) {
3401
  $lossy = 1;
3402
+ if ( 30 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) ) {
3403
  $lossy_fast = 1;
3404
  }
3405
+ } elseif ( 'application/pdf' === $type && 20 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_pdf_level' ) ) {
3406
  $lossy = 1;
3407
  } else {
3408
  $lossy = 0;
3411
  $lossy = 0;
3412
  $lossy_fast = 0;
3413
  }
3414
+ if ( 'image/webp' === $newtype ) {
3415
  $webp = 1;
3416
  $jpg_quality = apply_filters( 'jpeg_quality', $jpg_quality, 'image/webp' );
3417
  } else {
3418
  $webp = 0;
3419
  }
3420
+ if ( 30 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) ) {
3421
  $png_compress = 1;
3422
  } else {
3423
  $png_compress = 0;
3431
  && strpos( $file, '/dynamic/' ) === false // Nextgen dynamic images.
3432
  ) {
3433
  global $ewww_image;
3434
+ if ( is_object( $ewww_image ) && $ewww_image->file === $file && ! empty( $ewww_image->backup ) ) {
3435
  $hash = $ewww_image->backup;
3436
  }
3437
  if ( empty( $hash ) && ! empty( $_REQUEST['ewww_force'] ) ) {
3540
  set_transient( 'ewww_image_optimizer_cloud_status', 'exceeded', 3600 );
3541
  $msg = 'exceeded';
3542
  unlink( $tempfile );
3543
+ } elseif ( ewww_image_optimizer_mimetype( $tempfile, 'i' ) === $type ) {
3544
  $newsize = filesize( $tempfile );
3545
  ewwwio_debug_message( "cloud results: $newsize (new) vs. $orig_size (original)" );
3546
  rename( $tempfile, $file );
3547
+ } elseif ( ewww_image_optimizer_mimetype( $tempfile, 'i' ) === 'image/webp' ) {
3548
  $newsize = filesize( $tempfile );
3549
  ewwwio_debug_message( "cloud results: $newsize (new) vs. $orig_size (original)" );
3550
  rename( $tempfile, $newfile );
3551
+ } elseif ( ! is_null( $newtype ) && ! is_null( $newfile ) && ewww_image_optimizer_mimetype( $tempfile, 'i' ) === $newtype ) {
3552
  $converted = true;
3553
  $newsize = filesize( $tempfile );
3554
  ewwwio_debug_message( "cloud results: $newsize (new) vs. $orig_size (original)" );
3668
  ewwwio_debug_message( 'License Exceeded' );
3669
  set_transient( 'ewww_image_optimizer_cloud_status', 'exceeded', 3600 );
3670
  unlink( $tempfile );
3671
+ } elseif ( ewww_image_optimizer_mimetype( $tempfile, 'i' ) === $type ) {
3672
  $newsize = filesize( $tempfile );
3673
  ewwwio_debug_message( "cloud rotation success: $newsize (new) vs. $orig_size (original)" );
3674
  rename( $tempfile, $file );
3926
  ewwwio_debug_message( "checking for $file with size: $orig_size" );
3927
  global $s3_uploads_image;
3928
  global $ewww_image;
3929
+ if ( class_exists( 'S3_Uploads' ) && ! empty( $s3_uploads_image ) && $s3_uploads_image !== $file ) {
3930
  $file = $s3_uploads_image;
3931
  ewwwio_debug_message( "overriding check with: $file" );
3932
  }
3933
  $image = array();
3934
+ if ( ! is_object( $ewww_image ) || ! $ewww_image instanceof EWWW_Image || $ewww_image->file !== $file ) {
3935
  $ewww_image = new EWWW_Image( 0, '', $file );
3936
  }
3937
  if ( ! empty( $ewww_image->record ) ) {
3939
  } else {
3940
  $image = false;
3941
  }
3942
+ if ( is_array( $image ) && $image['image_size'] === $orig_size ) {
3943
  $prev_string = ' - ' . __( 'Previously Optimized', 'ewww-image-optimizer' );
3944
  if ( preg_match( '/' . __( 'License exceeded', 'ewww-image-optimizer' ) . '/', $image['results'] ) ) {
3945
  return '';
3990
  }
3991
  global $ewww_image;
3992
  // First check if the image was converted, so we don't orphan records.
3993
+ if ( $original && $original !== $attachment ) {
3994
  $already_optimized = ewww_image_optimizer_find_already_optimized( $original );
3995
  $converted = $original;
3996
  } else {
3997
  global $s3_uploads_image;
3998
+ if ( class_exists( 'S3_Uploads' ) && ! empty( $s3_uploads_image ) && $s3_uploads_image !== $attachment ) {
3999
  $attachment = $s3_uploads_image;
4000
  ewwwio_debug_message( "overriding update with: $attachment" );
4001
  }
4411
  // Check through all the sizes we've processed so far.
4412
  foreach ( $processed as $proc => $scan ) {
4413
  // If a previous resize had identical dimensions.
4414
+ if ( $scan['height'] === $data['height'] && $scan['width'] === $data['width'] ) {
4415
  // Found a duplicate resize.
4416
  $dup_size = true;
4417
  }
4471
  // Check through all the sizes we've processed so far.
4472
  foreach ( $processed as $proc => $scan ) {
4473
  // If a previous resize had identical dimensions.
4474
+ if ( $scan['height'] === $data['height'] && $scan['width'] === $data['width'] ) {
4475
  // Found a duplicate resize.
4476
  $dup_size = true;
4477
  }
4625
  * @return int|string The new amount of memory to allocate, if it was only 256M or lower.
4626
  */
4627
  function ewww_image_optimizer_raise_memory_limit( $memory_limit ) {
4628
+ if ( '256M' === $memory_limit || ( is_int( $memory_limit ) && 270000000 > $memory_limit ) ) {
4629
  ewwwio_debug_message( 'raising the roof' );
4630
  return '512M';
4631
  } else {
4633
  }
4634
  }
4635
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4636
  /**
4637
  * Uses gifsicle or the API to resize an image.
4638
  *
4661
  ewwwio_debug_message( 'not an image, no resizing possible' );
4662
  return new WP_Error( 'invalid_image', __( 'File is not an image.' ), $file );
4663
  }
4664
+ if ( 'image/gif' === $type && ! ewww_image_optimizer_get_option( 'ewww_image_optimizer_cloud_key' ) && function_exists( 'ewww_image_optimizer_gifsicle_resize' ) ) {
4665
  return ewww_image_optimizer_gifsicle_resize( $file, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h );
4666
  }
4667
  return ewww_image_optimizer_cloud_resize( $file, $type, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h );
4681
  wp_raise_memory_limit( 'image' );
4682
  }
4683
  $type = ewww_image_optimizer_mimetype( $file, 'i' );
4684
+ if ( 'image/jpeg' !== $type ) {
4685
  ewwwio_debug_message( 'not a JPG, no rotation needed' );
4686
  return;
4687
  }
4688
+ $orientation = (int) ewww_image_optimizer_get_orientation( $file, $type );
4689
+ if ( ! $orientation || 1 === $orientation ) {
4690
  return;
4691
  }
4692
  if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) < 20 && function_exists( 'ewww_image_optimizer_jpegtran_autorotate' ) ) {
4714
  $tiff = $exif->getTiff();
4715
  $ifd0 = $tiff->getIfd();
4716
  $orientation = $ifd0->getEntry( PelTag::ORIENTATION );
4717
+ if ( ! is_null( $orientation ) ) {
4718
  ewwwio_debug_message( 'orientation being adjusted' );
4719
  $orientation->setValue( 1 );
4720
  }
4740
  wp_raise_memory_limit( 'image' );
4741
  }
4742
  $type = ewww_image_optimizer_mimetype( $file, 'i' );
4743
+ if ( 'image/png' !== $type ) {
4744
  ewwwio_debug_message( 'not a PNG, no conversion needed' );
4745
  return;
4746
  }
4834
  */
4835
  list( $maxwidth, $maxheight ) = apply_filters( 'ewww_image_optimizer_resize_dimensions', array( $maxwidth, $maxheight ), $file );
4836
 
4837
+ $maxwidth = (int) $maxwidth;
4838
+ $maxheight = (int) $maxheight;
4839
  // Check that options are not both set to zero.
4840
+ if ( 0 === $maxwidth && 0 === $maxheight ) {
4841
  return false;
4842
  }
4843
  $maxwidth = $maxwidth ? $maxwidth : 999999;
4958
  $tiff = $old_exif->getTiff();
4959
  $ifd0 = $tiff->getIfd();
4960
  $orientation = $ifd0->getEntry( PelTag::ORIENTATION );
4961
+ if ( ! is_null( $orientation ) ) {
4962
  $orientation->setValue( 1 );
4963
  }
4964
  }
5073
  }
5074
  if ( ewww_image_optimizer_iterable( $optimized_query ) ) {
5075
  foreach ( $optimized_query as $image ) {
5076
+ $image['path'] = ewww_image_optimizer_absolutize_path( $image['path'] );
5077
+ $image['image_size'] = (int) $image['image_size'];
5078
+ $image['orig_size'] = (int) $image['orig_size'];
5079
+ $image['attachment_id'] = (int) $image['attachment_id'];
5080
+ $image['level'] = (int) $image['level'];
5081
+ if ( $image['path'] !== $attachment ) {
5082
  ewwwio_debug_message( "{$image['path']} does not match $attachment, continuing our search" );
5083
  } elseif ( ! $maybe_return_image ) {
5084
  ewwwio_debug_message( "found a match for $attachment" );
5134
  $discard = array();
5135
  // First look for an image size match.
5136
  foreach ( $duplicates as $duplicate ) {
5137
+ if ( empty( $keeper ) && ! empty( $duplicate['image_size'] ) && $image_size === $duplicate['image_size'] ) {
5138
  $keeper = $duplicate;
5139
  } else {
5140
  $discard[] = $duplicate;
5198
  if ( ewww_image_optimizer_detect_wpsf_location_lock() ) {
5199
  return false;
5200
  }
5201
+ if ( 'image/type' === $type && ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_to_png' ) ) {
5202
  return apply_filters( 'ewww_image_optimizer_defer_conversion', false );
5203
  }
5204
+ if ( 'image/png' === $type && ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_to_jpg' ) ) {
5205
  return apply_filters( 'ewww_image_optimizer_defer_conversion', false );
5206
  }
5207
+ if ( 'image/gif' === $type && ewww_image_optimizer_get_option( 'ewww_image_optimizer_gif_to_png' ) ) {
5208
  return apply_filters( 'ewww_image_optimizer_defer_conversion', false );
5209
  }
5210
  global $ewww_defer;
5245
  if ( empty( $type ) ) {
5246
  $type = get_post_mime_type( $id );
5247
  }
5248
+ if ( 'image/jpeg' === $type && ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_to_png' ) ) {
5249
  return false;
5250
  }
5251
+ if ( 'image/png' === $type && ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_to_jpg' ) ) {
5252
  return false;
5253
  }
5254
+ if ( 'image/gif' === $type && ewww_image_optimizer_get_option( 'ewww_image_optimizer_gif_to_png' ) ) {
5255
  return false;
5256
  }
5257
+ if ( 'application/pdf' === $type ) {
5258
  return false;
5259
  }
5260
  return true;
5320
  if ( ! is_array( $meta ) && empty( $meta ) ) {
5321
  $meta = array();
5322
  } elseif ( ! is_array( $meta ) ) {
5323
+ if ( is_string( $meta ) && is_numeric( $id ) && 'processing' === $meta ) {
5324
  ewwwio_debug_message( "attempting to rebuild attachment meta for $id" );
5325
  $new_meta = ewww_image_optimizer_rebuild_meta( $id );
5326
  if ( ! is_array( $new_meta ) ) {
5333
  ewwwio_debug_message( 'attachment meta is not a usable array' );
5334
  return $meta;
5335
  }
5336
+ } elseif ( is_array( $meta ) && ! empty( $meta[0] ) && 'processing' === $meta[0] ) {
5337
  ewwwio_debug_message( "attempting to rebuild attachment meta for $id" );
5338
  $new_meta = ewww_image_optimizer_rebuild_meta( $id );
5339
  if ( ! is_array( $new_meta ) ) {
5366
  }
5367
  list( $file_path, $upload_path ) = ewww_image_optimizer_attachment_path( $meta, $id );
5368
  // If the attachment has been uploaded via the image store plugin.
5369
+ if ( 'ims_image' === get_post_type( $id ) ) {
5370
  $gallery_type = 6;
5371
  }
5372
  if ( ! $new_image && class_exists( 'Amazon_S3_And_CloudFront' ) && ewww_image_optimizer_stream_wrapped( $file_path ) ) {
5388
  'image/gif',
5389
  'application/pdf',
5390
  );
5391
+ if ( ! in_array( $type, $supported_types, true ) ) {
5392
  ewwwio_debug_message( "mimetype not supported: $id" );
5393
  return $meta;
5394
  }
5546
  if ( ! empty( $disabled_sizes[ $size ] ) ) {
5547
  continue;
5548
  }
5549
+ if ( ! empty( $disabled_sizes['pdf-full'] ) && 'full' === $size ) {
5550
  continue;
5551
  }
5552
  if ( empty( $data['file'] ) ) {
5581
  // Check through all the sizes we've processed so far.
5582
  foreach ( $processed as $proc => $scan ) {
5583
  // If a previous resize had identical dimensions.
5584
+ if ( $scan['height'] === $data['height'] && $scan['width'] === $data['width'] ) {
5585
  // We found a duplicate resize, so...
5586
  // Point this resize at the same image as the previous one.
5587
  $meta['sizes'][ $size ]['file'] = $meta['sizes'][ $proc ]['file'];
5590
  }
5591
  // If this is a unique size.
5592
  $resize_path = $base_dir . $data['file'];
5593
+ if ( 'application/pdf' === $type && 'full' === $size ) {
5594
  $size = 'pdf-full';
5595
  ewwwio_debug_message( 'processing full size pdf preview' );
5596
  }
5845
  if ( ewww_image_optimizer_function_exists( 'print_r' ) ) {
5846
  ewwwio_debug_message( print_r( $shield_user_man, true ) );
5847
  }
5848
+ if ( ! empty( $shield_user_man['session_lock_location'] ) && 'Y' === $shield_user_man['session_lock_location'] ) {
5849
  return true;
5850
  }
5851
  }
5907
  // Construct the new guid based on the filename from the attachment metadata.
5908
  ewwwio_debug_message( "old guid: $old_guid" );
5909
  ewwwio_debug_message( "new guid: $guid" );
5910
+ if ( substr( $old_guid, -1 ) === '/' || substr( $guid, -1 ) === '/' ) {
5911
  ewwwio_debug_message( 'could not obtain full url for current and previous image, bailing' );
5912
  return $meta;
5913
  }
5950
  // Generate the url for the new image.
5951
  $sguid = dirname( $old_guid ) . '/' . basename( $data['file'] );
5952
  ewwwio_debug_message( "new sguid: $sguid" );
5953
+ if ( substr( $old_sguid, -1 ) === '/' || substr( $sguid, -1 ) === '/' ) {
5954
  ewwwio_debug_message( 'could not obtain full url for current and previous resized image, bailing' );
5955
  continue;
5956
  }
6045
  ) {
6046
  return array( str_replace( '//_imsgalleries/', '/_imsgalleries/', $file_path ), $upload_path );
6047
  }
6048
+ if ( 'ims_image' === get_post_type( $id ) && is_array( $meta ) && ! empty( $meta['file'] ) ) {
6049
  ewwwio_debug_message( "finding path for IMS image: $id " );
6050
  if ( is_dir( $file_path ) && is_file( $file_path . $meta['file'] ) ) {
6051
  // Generate the absolute path.
6269
  $color_type = ord( file_get_contents( $filename, null, null, 25, 1 ) );
6270
  ewwwio_debug_message( "color type: $color_type" );
6271
  // If it is set to RGB alpha or Grayscale alpha.
6272
+ if ( 4 === $color_type || 6 === $color_type ) {
6273
  ewwwio_debug_message( 'transparency found' );
6274
  return true;
6275
+ } elseif ( 3 === $color_type && ewww_image_optimizer_gd_support() ) {
6276
  $image = imagecreatefrompng( $filename );
6277
  if ( imagecolortransparent( $image ) >= 0 ) {
6278
  ewwwio_debug_message( 'transparency found' );
6347
  // Check through all the sizes we've processed so far.
6348
  foreach ( $processed as $proc => $scan ) {
6349
  // If a previous resize had identical dimensions.
6350
+ if ( $scan['height'] === $data['height'] && $scan['width'] === $data['width'] ) {
6351
  continue( 2 );
6352
  }
6353
  }
6387
  function ewww_image_optimizer_custom_column( $column_name, $id, $meta = null, $return_output = false ) {
6388
  ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
6389
  // Once we get to the EWWW IO custom column.
6390
+ if ( 'ewww-image-optimizer' === $column_name ) {
6391
  $output = '';
6392
+ if ( is_null( $meta ) ) {
6393
  // Retrieve the metadata.
6394
  $meta = wp_get_attachment_metadata( $id );
6395
  }
6469
  esc_html__( '%s is missing', 'ewww-image-optimizer' ),
6470
  '<em>jpegtran</em>'
6471
  ) . '</div>';
6472
+ } elseif ( ! ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) ) {
6473
  $msg = '<div>' . sprintf(
6474
  /* translators: %s: JPG, PNG, GIF, or PDF */
6475
  esc_html__( '%s compression disabled', 'ewww-image-optimizer' ),
6507
  }
6508
  break;
6509
  case 'application/pdf':
6510
+ if ( ! ewww_image_optimizer_get_option( 'ewww_image_optimizer_pdf_level' ) ) {
6511
  $msg = '<div>' . sprintf(
6512
  /* translators: %s: JPG, PNG, GIF, or PDF */
6513
  esc_html__( '%s compression disabled', 'ewww-image-optimizer' ),
6638
  $id,
6639
  esc_html__( 'Re-optimize', 'ewww-image-optimizer' )
6640
  );
6641
+ if ( ! ewww_image_optimizer_get_option( 'ewww_image_optimizer_disable_convert_links' ) && 'ims_image' !== get_post_type( $id ) && ! empty( $convert_desc ) ) {
6642
  $output .= " | <a class='ewww-manual-convert' data-id='$id' data-nonce='$ewww_manual_nonce' title='$convert_desc' href='admin.php?action=ewww_image_optimizer_manual_optimize&amp;ewww_manual_nonce=$ewww_manual_nonce&amp;ewww_attachment_ID=$id&amp;ewww_convert=1&amp;ewww_force=1'>$convert_link</a>";
6643
  }
6644
  $output .= '</div>';
6685
  if ( empty( $msg ) && current_user_can( apply_filters( 'ewww_image_optimizer_manual_permissions', '' ) ) ) {
6686
  // Give the user the option to optimize the image right now.
6687
  $output .= sprintf( "<div><a class='ewww-manual-optimize' data-id='$id' data-nonce='$ewww_manual_nonce' href=\"admin.php?action=ewww_image_optimizer_manual_optimize&amp;ewww_manual_nonce=$ewww_manual_nonce&amp;ewww_attachment_ID=%d\">%s</a>", $id, esc_html__( 'Optimize now!', 'ewww-image-optimizer' ) );
6688
+ if ( ! ewww_image_optimizer_get_option( 'ewww_image_optimizer_disable_convert_links' ) && 'ims_image' !== get_post_type( $id ) && ! empty( $convert_desc ) ) {
6689
  $output .= " | <a class='ewww-manual-convert' data-id='$id' data-nonce='$ewww_manual_nonce' title='$convert_desc' href='admin.php?action=ewww_image_optimizer_manual_optimize&amp;ewww_manual_nonce=$ewww_manual_nonce&amp;ewww_attachment_ID=$id&amp;ewww_convert=1&amp;ewww_force=1'>$convert_link</a>";
6690
  }
6691
  $output .= '</div>';
6729
  if ( ! empty( $disabled_sizes[ $size ] ) ) {
6730
  continue;
6731
  }
6732
+ if ( ! empty( $disabled_sizes['pdf-full'] ) && 'full' === $size ) {
6733
  continue;
6734
  }
6735
  if ( empty( $data['file'] ) ) {
6739
  // Check through all the sizes we've processed so far.
6740
  foreach ( $processed as $proc => $scan ) {
6741
  // If a previous resize had identical dimensions...
6742
+ if ( $scan['height'] === $data['height'] && $scan['width'] === $data['width'] ) {
6743
  // Found a duplicate size, get outta here!
6744
  continue( 2 );
6745
  }
6783
  }
6784
  $orig_size += $optimized_image['orig_size'];
6785
  $opt_size += $optimized_image['image_size'];
6786
+ if ( 'full' === $optimized_image['resize'] ) {
6787
  $level = $optimized_image['level'];
6788
  $updated_time = strtotime( $optimized_image['updated'] );
6789
  if ( DAY_IN_SECONDS * 30 + $updated_time > time() ) {
6954
  // Resized versions, so we can continue.
6955
  if ( isset( $meta['sizes'] ) && ewww_image_optimizer_iterable( $meta['sizes'] ) ) {
6956
  // Meta sizes don't contain a path, so we calculate one.
6957
+ if ( 'ims_image' === get_post_type( $id ) ) {
6958
  $base_dir = trailingslashit( dirname( $file_path ) ) . '_resized/';
6959
  } else {
6960
  $base_dir = trailingslashit( dirname( $file_path ) );
6967
  if ( empty( $data ) || ! is_array( $data ) || empty( $data['file'] ) ) {
6968
  continue;
6969
  }
6970
+ if ( 'full' === $size && 'application/pdf' === $type ) {
6971
  $size = 'pdf-full';
6972
+ } elseif ( 'full' === $size ) {
6973
  continue;
6974
  }
6975
 
7077
  // Borrowed from http://www.viper007bond.com/wordpress-plugins/regenerate-thumbnails/ .
7078
  ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
7079
  // If the requested action is blank, or not a bulk_optimize, do nothing.
7080
+ if ( ( empty( $_REQUEST['action'] ) || 'bulk_optimize' !== $_REQUEST['action'] ) && ( empty( $_REQUEST['action2'] ) || 'bulk_optimize' !== $_REQUEST['action2'] ) ) {
7081
  return;
7082
  }
7083
  // If there is no media to optimize, do nothing.
7164
  * }
7165
  */
7166
  function ewww_image_optimizer_get_bad_attachments() {
7167
+ $bad_attachment = (int) get_transient( 'ewww_image_optimizer_rebuilding_attachment' );
7168
  if ( $bad_attachment ) {
7169
  $bad_attachments = (array) ewww_image_optimizer_get_option( 'ewww_image_optimizer_bad_attachments' );
7170
  $bad_attachments[] = $bad_attachment;
7172
  } else {
7173
  $bad_attachments = (array) ewww_image_optimizer_get_option( 'ewww_image_optimizer_bad_attachments' );
7174
  }
7175
+ array_walk( $bad_attachments, 'intval' );
7176
  delete_transient( 'ewww_image_optimizer_rebuilding_attachment' );
7177
  return array( $bad_attachments, $bad_attachment );
7178
  }
7250
  ewwwio_debug_message( "getting savings for site: $blog_id" );
7251
  $table_name = $wpdb->prefix . 'ewwwio_images';
7252
  ewwwio_debug_message( "table name is $table_name" );
7253
+ if ( $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table_name ) ) !== $table_name ) {
7254
  ewww_image_optimizer_install_table();
7255
  }
7256
  if ( $wpdb->ewwwio_images ) {
7269
  ewwwio_debug_message( 'querying savings for single site' );
7270
  $table_name = $wpdb->ewwwio_images;
7271
  ewwwio_debug_message( "table name is $table_name" );
7272
+ if ( $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table_name ) ) !== $table_name ) {
7273
  ewww_image_optimizer_install_table();
7274
  }
7275
  $orig_size = $wpdb->get_var( "SELECT SUM(orig_size) FROM $wpdb->ewwwio_images WHERE image_size > 0" );
7410
  function ewwwio_extract_from_markers( $filename, $marker ) {
7411
  // All because someone didn't test changes in core...
7412
  global $wp_version;
7413
+ if ( '4.9' !== $wp_version ) {
7414
  return extract_from_markers( $filename, $marker );
7415
  }
7416
  $result = array();
7487
  }
7488
  if ( ewww_image_optimizer_iterable( $image_sizes ) ) {
7489
  foreach ( $image_sizes as $_size ) {
7490
+ if ( in_array( $_size, array( 'thumbnail', 'medium', 'medium_large', 'large' ), true ) ) {
7491
  $sizes[ $_size ]['width'] = get_option( $_size . '_size_w' );
7492
  $sizes[ $_size ]['height'] = get_option( $_size . '_size_h' );
7493
+ if ( 'medium_large' === $_size && 0 === intval( $sizes[ $_size ]['width'] ) ) {
7494
  $sizes[ $_size ]['width'] = '768';
7495
  }
7496
+ if ( 'medium_large' === $_size && 0 === intval( $sizes[ $_size ]['height'] ) ) {
7497
  $sizes[ $_size ]['height'] = '9999';
7498
  }
7499
  } elseif ( isset( $_wp_additional_image_sizes[ $_size ] ) ) {
7599
  $output[] = "<div class='wrap'>\n";
7600
  $output[] = "<h1>EWWW Image Optimizer</h1>\n";
7601
  $output[] = "<!--<div id='ewww-container-left' style='float: left; margin-right: 225px;'>-->\n";
7602
+ if ( 'network-multisite' === $network ) {
7603
  $bulk_link = esc_html__( 'Media Library', 'ewww-image-optimizer' ) . ' -> ' . esc_html__( 'Bulk Optimize', 'ewww-image-optimizer' );
7604
  } else {
7605
  $bulk_link = '<a href="upload.php?page=ewww-image-optimizer-bulk">' . esc_html__( 'Bulk Optimize', 'ewww-image-optimizer' ) . '</a>';
7817
  if ( ewww_image_optimizer_imagick_support() ) {
7818
  $toolkit_found = true;
7819
  }
7820
+ if ( PHP_OS !== 'WINNT' && ! ewww_image_optimizer_full_cloud() && ! EWWW_IMAGE_OPTIMIZER_NOEXEC ) {
7821
  ewww_image_optimizer_find_nix_binary( 'nice', 'n' );
7822
  }
7823
  $status_notices .= "<p>\n"; // This line encloses everything up to the end of the async stuff.
7840
  $status_notices .= "<p><a href='https://ewww.io/plans' target='_blank' class='button button-primary' style='background:#3eadc9'>" . esc_html__( 'Premium Upgrades', 'ewww-image-optimizer' ) . "</a></p>\n";
7841
  }
7842
 
7843
+ if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_metadata_remove' ) ) {
7844
  $compress_score += 5;
7845
  } else {
7846
  $compress_recommendations[] = esc_html__( 'Remove metadata from JPG images.', 'ewww-image-optimizer' ) . ewwwio_help_link( 'https://docs.ewww.io/article/7-basic-configuration', '585373d5c697912ffd6c0bb2' );
7928
  // End status section.
7929
  $output[] = $status_output;
7930
 
7931
+ if ( ( 'network-multisite' !== $network || ! get_site_option( 'ewww_image_optimizer_allow_multisite_override' ) ) && // Display tabs so long as this isn't the network admin OR single-site override is disabled.
7932
+ ! ( 'network-singlesite' === $network && ! get_site_option( 'ewww_image_optimizer_allow_multisite_override' ) ) ) { // Also make sure that this isn't single site without override mode.
7933
  $output[] = "<ul class='ewww-tab-nav'>\n" .
7934
  "<li class='ewww-tab ewww-general-nav'><span class='ewww-tab-hidden'>" . esc_html__( 'Basic', 'ewww-image-optimizer' ) . "</span></li>\n" .
7935
  "<li class='ewww-tab ewww-exactdn-nav'><span class='ewww-tab-hidden'>" . esc_html__( 'ExactDN', 'ewww-image-optimizer' ) . "</span></li>\n" .
7942
  "<li class='ewww-tab ewww-contribute-nav'><span class='ewww-tab-hidden'>" . esc_html__( 'Contribute', 'ewww-image-optimizer' ) . "</span></li>\n" .
7943
  "</ul>\n";
7944
  }
7945
+ if ( 'network-multisite' === $network ) {
7946
  $output[] = "<form method='post' action=''>\n";
7947
  } else {
7948
  $output[] = "<form method='post' action='options.php'>\n";
7963
  $output[] = "<table class='form-table'>\n";
7964
  if ( is_multisite() ) {
7965
  if ( is_plugin_active_for_network( EWWW_IMAGE_OPTIMIZER_PLUGIN_FILE_REL ) ) {
7966
+ $output[] = "<tr class='network-only'><th scope='row'><label for='ewww_image_optimizer_allow_multisite_override'>" . esc_html__( 'Allow Single-site Override', 'ewww-image-optimizer' ) . "</label></th><td><input type='checkbox' id='ewww_image_optimizer_allow_multisite_override' name='ewww_image_optimizer_allow_multisite_override' value='true' " . ( get_site_option( 'ewww_image_optimizer_allow_multisite_override' ) ? "checked='true'" : '' ) . ' /> ' . esc_html__( 'Allow individual sites to configure their own settings and override all network options.', 'ewww-image-optimizer' ) . "</td></tr>\n";
7967
  }
7968
+ if ( 'network-multisite' === $network && get_site_option( 'ewww_image_optimizer_allow_multisite_override' ) ) {
7969
+ $output[] = "<tr><th scope='row'><label for='ewww_image_optimizer_allow_tracking'>" . esc_html__( 'Allow Usage Tracking?', 'ewww-image-optimizer' ) . "</label></th><td><input type='checkbox' id='ewww_image_optimizer_allow_tracking' name='ewww_image_optimizer_allow_tracking' value='true' " . ( get_site_option( 'ewww_image_optimizer_allow_tracking' ) ? "checked='true'" : '' ) . ' /> ' .
7970
  esc_html__( 'Allow EWWW Image Optimizer to anonymously track how this plugin is used and help us make the plugin better. Opt-in to tracking and receive 500 API image credits free. No sensitive data is tracked.', 'ewww-image-optimizer' ) . "</td></tr>\n";
7971
  $output[] = "<input type='hidden' id='ewww_image_optimizer_allow_multisite_override_active' name='ewww_image_optimizer_allow_multisite_override_active' value='0'>";
7972
  if ( get_site_option( 'ewww_image_optimizer_cloud_key' ) ) {
7989
  $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_cloud_key'>" . esc_html__( 'Optimization API Key', 'ewww-image-optimizer' ) . '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/7-basic-configuration', '585373d5c697912ffd6c0bb2,5ad0c8e7042863075092650b,5a9efec62c7d3a7549516550' ) . "</th><td><input type='text' id='ewww_image_optimizer_cloud_key' name='ewww_image_optimizer_cloud_key' value='' size='32' /> " . esc_html__( 'API Key will be validated when you save your settings.', 'ewww-image-optimizer' ) . " <a href='https://ewww.io/plans/' target='_blank'>" . esc_html__( 'Purchase an API key.', 'ewww-image-optimizer' ) . "</a></td></tr>\n";
7990
  }
7991
  $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_metadata_remove'>" . esc_html__( 'Remove Metadata', 'ewww-image-optimizer' ) . '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/7-basic-configuration', '585373d5c697912ffd6c0bb2' ) . "</th>\n" .
7992
+ "<td><input type='checkbox' id='ewww_image_optimizer_metadata_remove' name='ewww_image_optimizer_metadata_remove' value='true' " . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_metadata_remove' ) ? "checked='true'" : '' ) . ' /> ' . esc_html__( 'This will remove ALL metadata: EXIF, comments, color profiles, and anything else that is not pixel data.', 'ewww-image-optimizer' ) .
7993
  "<p class ='description'>" . esc_html__( 'Color profiles are preserved when using the API or ExactDN.', 'ewww-image-optimizer' ) . "</p></td></tr>\n";
7994
+ ewwwio_debug_message( 'remove metadata: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_metadata_remove' ) ? 'on' : 'off' ) );
7995
 
7996
  $maybe_api_level = ewww_image_optimizer_get_option( 'ewww_image_optimizer_cloud_key' ) ? '*' : '';
7997
 
8042
  ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_backup_files' ) ? "checked='true'" : '' ) . " $disable_level > " . esc_html__( 'Store a copy of your original images on our secure server for 30 days. *Requires an active API key.', 'ewww-image-optimizer' ) . "</td></tr>\n";
8043
  ewwwio_debug_message( 'backup mode: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_backup_files' ) ? 'on' : 'off' ) );
8044
  if ( class_exists( 'Cloudinary' ) && Cloudinary::config_get( 'api_secret' ) ) {
8045
+ $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_enable_cloudinary'>" . esc_html__( 'Automatic Cloudinary Upload', 'ewww-image-optimizer' ) . "</label></th><td><input type='checkbox' id='ewww_image_optimizer_enable_cloudinary' name='ewww_image_optimizer_enable_cloudinary' value='true' " . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_enable_cloudinary' ) ? "checked='true'" : '' ) . ' /> ' . esc_html__( 'When enabled, uploads to the Media Library will be transferred to Cloudinary after optimization. Cloudinary generates resizes, so only the full-size image is uploaded.', 'ewww-image-optimizer' ) . "</td></tr>\n";
8046
+ ewwwio_debug_message( 'cloudinary upload: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_enable_cloudinary' ) ? 'on' : 'off' ) );
8047
  }
8048
  $output[] = "</table>\n</div>\n";
8049
  $output[] = "<div id='ewww-exactdn-settings'>\n";
8051
  $output[] = '<noscript><h2>' . esc_html__( 'ExactDN', 'ewww-image-optimizer' ) . '</h2></noscript>';
8052
  $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_exactdn'>" . esc_html__( 'ExactDN', 'ewww-image-optimizer' ) .
8053
  '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/44-introduction-to-exactdn', '59bc5ad6042863033a1ce370,59de6631042863379ddc953c,59c44349042863033a1d06d3,5ada43a12c7d3a0e93678b8c,5a3d278a2c7d3a1943677b52,5a9868eb04286374f7087795,59de68482c7d3a40f0ed6035,592dd69b2c7d3a074e8aed5b' ) . "</th><td><input type='checkbox' id='ewww_image_optimizer_exactdn' name='ewww_image_optimizer_exactdn' value='true' " .
8054
+ ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_exactdn' ) ? "checked='true'" : '' ) . ' /> ' .
8055
  esc_html__( 'Enables CDN and automatic image resizing to fit your pages.', 'ewww-image-optimizer' ) .
8056
  ' <a href="https://ewww.io/resize/" target="_blank">' . esc_html__( 'Purchase a subscription for your site.', 'ewww-image-optimizer' ) . '</a>' .
8057
  '<p class="description">' .
8062
  esc_html__( 'JS/CSS Minification and Compression', 'ewww-image-optimizer' ) . '<br>' .
8063
  '<a href="https://docs.ewww.io/article/44-introduction-to-exactdn" target="_blank" data-beacon-article="59bc5ad6042863033a1ce370">' . esc_html__( 'Learn more about ExactDN', 'ewww-image-optimizer' ) . '</a>' .
8064
  "</p></td></tr>\n";
8065
+ ewwwio_debug_message( 'ExactDN enabled: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_exactdn' ) ? 'on' : 'off' ) );
8066
  $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_backup_files'>" . esc_html__( 'Include All Resources', 'ewww-image-optimizer' ) . '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/47-getting-more-from-exactdn', '59de6631042863379ddc953c' ) . '</th>' .
8067
  "<td><input type='checkbox' id='exactdn_all_the_things' name='exactdn_all_the_things' value='true' " .
8068
  ( ewww_image_optimizer_get_option( 'exactdn_all_the_things' ) ? "checked='true'" : '' ) . '> ' . esc_html__( 'Use ExactDN for all resources in wp-includes/ and wp-content/, including JavaScript, CSS, fonts, etc.', 'ewww-image-optimizer' ) . "</td></tr>\n";
8069
+ ewwwio_debug_message( 'ExactDN all the things: ' . ( ewww_image_optimizer_get_option( 'exactdn_all_the_things' ) ? 'on' : 'off' ) );
8070
  $output[] = "<tr class='$network_class'><th scope='row'><label for='exactdn_lossy'>" . esc_html__( 'Premium Compression', 'ewww-image-optimizer' ) . '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/47-getting-more-from-exactdn', '59de6631042863379ddc953c' ) . '</th>' .
8071
  "<td><input type='checkbox' id='exactdn_lossy' name='exactdn_lossy' value='true' " .
8072
  ( ewww_image_optimizer_get_option( 'exactdn_lossy' ) ? "checked='true'" : '' ) . '> ' . esc_html__( 'Enable high quality premium compression for all images. Disable to use Pixel Perfect mode instead.', 'ewww-image-optimizer' ) . "</td></tr>\n";
8073
  $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_lazy_load'>" . esc_html__( 'Lazy Load', 'ewww-image-optimizer' ) . '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/74-lazy-load', '5c6c36ed042863543ccd2d9b' ) .
8074
+ "</th><td><input type='checkbox' id='ewww_image_optimizer_lazy_load' name='ewww_image_optimizer_lazy_load' value='true' " . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_lazy_load' ) ? "checked='true'" : '' ) . ' /> ' .
8075
  esc_html__( 'Improves actual and perceived loading time as images will be loaded only as they enter (or are about to enter) the viewport. When used with the ExactDN and WebP features, the plugin will load the best available image size and format for each device.', 'ewww-image-optimizer' ) . "</td></tr>\n";
8076
  ewwwio_debug_message( 'ExactDN lossy: ' . intval( ewww_image_optimizer_get_option( 'exactdn_lossy' ) ) );
8077
+ ewwwio_debug_message( 'ExactDN resize existing: ' . ( ewww_image_optimizer_get_option( 'exactdn_resize_existing' ) ? 'on' : 'off' ) );
8078
+ ewwwio_debug_message( 'ExactDN attachment queries: ' . ( ewww_image_optimizer_get_option( 'exactdn_prevent_db_queries' ) ? 'off' : 'on' ) );
8079
+ ewwwio_debug_message( 'lazy load: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_lazy_load' ) ? 'on' : 'off' ) );
8080
  if ( defined( 'EXACTDN_EXCLUDE' ) && EXACTDN_EXCLUDE ) {
8081
  $exactdn_user_exclusions = EXACTDN_EXCLUDE;
8082
  if ( is_array( $exactdn_user_exclusions ) ) {
8093
  $output[] = "<table class='form-table'>\n";
8094
  if ( ! ewww_image_optimizer_full_cloud() ) {
8095
  ewwwio_debug_message( 'optipng level: ' . ewww_image_optimizer_get_option( 'ewww_image_optimizer_optipng_level' ) );
8096
+ ewwwio_debug_message( 'pngout disabled: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_disable_pngout' ) ? 'yes' : 'no' ) );
8097
  ewwwio_debug_message( 'pngout level: ' . ewww_image_optimizer_get_option( 'ewww_image_optimizer_pngout_level' ) );
8098
  }
8099
  $output[] = "<tr class='$network_class'><th scope='row'><span><label for='ewww_image_optimizer_jpg_quality'>" . esc_html__( 'JPG Quality Level:', 'ewww-image-optimizer' ) . '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/11-advanced-configuration', '58542afac697912ffd6c18c0,58543c69c697912ffd6c19a7' ) . "</th><td><input type='text' id='ewww_image_optimizer_jpg_quality' name='ewww_image_optimizer_jpg_quality' class='small-text' value='" . ewww_image_optimizer_jpg_quality() . "' /> " . esc_html__( 'Valid values are 1-100.', 'ewww-image-optimizer' ) . "\n<p class='description'>" . esc_html__( 'Use this to override the default WordPress quality level of 82. Applies to image editing, resizing, PNG to JPG conversion, and JPG to WebP conversion. Does not affect the original uploaded image unless maximum dimensions are set and resizing occurs.', 'ewww-image-optimizer' ) . "</p></td></tr>\n";
8100
+ $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_parallel_optimization'>" . esc_html__( 'Parallel Optimization', 'ewww-image-optimizer' ) . '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/11-advanced-configuration', '58542afac697912ffd6c18c0,598cb8be2c7d3a73488be237' ) . "</th><td><input type='checkbox' id='ewww_image_optimizer_parallel_optimization' name='ewww_image_optimizer_parallel_optimization' value='true' " . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_parallel_optimization' ) ? "checked='true'" : '' ) . ' /> ' . esc_html__( 'All resizes generated from a single upload are optimized in parallel for faster optimization. If this is causing performance issues, disable parallel optimization to reduce the load on your server.', 'ewww-image-optimizer' ) . "</td></tr>\n";
8101
+ ewwwio_debug_message( 'parallel optimization: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_parallel_optimization' ) ? 'on' : 'off' ) );
8102
+ ewwwio_debug_message( 'background optimization: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_background_optimization' ) ? 'on' : 'off' ) );
8103
  if ( ! ewww_image_optimizer_get_option( 'ewww_image_optimizer_background_optimization' ) ) {
8104
  $admin_ajax_url = admin_url( 'admin-ajax.php' );
8105
  if ( strpos( $admin_ajax_url, 'admin-ajax.php' ) ) {
8108
  ewwwio_debug_message( "admin ajax hostname: $admin_ajax_host" );
8109
  $resolved = gethostbyname( $admin_ajax_host . '.' );
8110
  ewwwio_debug_message( "resolved to $resolved" );
8111
+ if ( $resolved === $admin_ajax_host . '.' ) {
8112
  ewwwio_debug_message( 'DNS lookup failed' );
8113
  } else {
8114
  $admin_ajax_url = add_query_arg(
8145
  ewwwio_debug_message( "invalid admin ajax url: $admin_ajax_url" );
8146
  }
8147
  }
8148
+ $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_auto'>" . esc_html__( 'Scheduled Optimization', 'ewww-image-optimizer' ) . '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/11-advanced-configuration', '58542afac697912ffd6c18c0,5853713bc697912ffd6c0b98' ) . "</th><td><input type='checkbox' id='ewww_image_optimizer_auto' name='ewww_image_optimizer_auto' value='true' " . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_auto' ) ? "checked='true'" : '' ) . ' /> ' . esc_html__( 'This will enable scheduled optimization of unoptimized images for your theme, buddypress, and any additional folders you have configured below. Runs hourly: wp_cron only runs when your site is visited, so it may be even longer between optimizations.', 'ewww-image-optimizer' ) . "</td></tr>\n";
8149
+ ewwwio_debug_message( 'scheduled optimization: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_auto' ) ? 'on' : 'off' ) );
8150
  $media_include_disable = '';
8151
  if ( get_option( 'ewww_image_optimizer_disable_resizes_opt' ) ) {
8152
  $media_include_disable = 'disabled="disabled"';
8153
  $output[] = "<tr class='$network_class'><th>&nbsp;</th><td>" .
8154
  '<p><span style="color: #3eadc9">' . esc_html__( '*Include Media Library Folders has been disabled because it will cause the scanner to ignore the disabled resizes.', 'ewww-image-optimizer' ) . "</span></p></td></tr>\n";
8155
  }
8156
+ $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_include_media_paths'>" . esc_html__( 'Include Media Folders', 'ewww-image-optimizer' ) . '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/11-advanced-configuration', '58542afac697912ffd6c18c0,5853713bc697912ffd6c0b98' ) . "</th><td><input type='checkbox' id='ewww_image_optimizer_include_media_paths' name='ewww_image_optimizer_include_media_paths' $media_include_disable value='true' " . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_include_media_paths' ) && ! get_option( 'ewww_image_optimizer_disable_resizes_opt' ) ? "checked='true'" : '' ) . ' /> ' . esc_html__( 'Scan all images from the latest two folders of the Media Library during the Bulk Optimizer and Scheduled Optimization.', 'ewww-image-optimizer' ) . "</td></tr>\n";
8157
+ ewwwio_debug_message( 'include media library: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_include_media_paths' ) ? 'on' : 'off' ) );
8158
  $aux_paths = ewww_image_optimizer_get_option( 'ewww_image_optimizer_aux_paths' ) ? esc_html( implode( "\n", ewww_image_optimizer_get_option( 'ewww_image_optimizer_aux_paths' ) ) ) : '';
8159
  $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_aux_paths'>" . esc_html__( 'Folders to Optimize', 'ewww-image-optimizer' ) . '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/11-advanced-configuration', '58542afac697912ffd6c18c0,5853713bc697912ffd6c0b98' ) . '</th><td>' .
8160
  /* translators: %s: the folder where WordPress is installed */
8172
  ewwwio_debug_message( $exclude_paths );
8173
  ewwwio_debug_message( 'skip images smaller than: ' . ewww_image_optimizer_get_option( 'ewww_image_optimizer_skip_size' ) . ' bytes' );
8174
  ewwwio_debug_message( 'skip PNG images larger than: ' . ewww_image_optimizer_get_option( 'ewww_image_optimizer_skip_png_size' ) . ' bytes' );
8175
+ ewwwio_debug_message( 'exclude originals from lossy: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_lossy_skip_full' ) ? 'on' : 'off' ) );
8176
+ ewwwio_debug_message( 'exclude originals from metadata removal: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_metadata_skip_full' ) ? 'on' : 'off' ) );
8177
+ ewwwio_debug_message( 'use system binaries: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_skip_bundle' ) ? 'yes' : 'no' ) );
8178
  $output[] = "</table>\n</div>\n";
8179
 
8180
  $output[] = "<div id='ewww-resize-settings'>\n";
8181
  $output[] = '<noscript><h2>' . esc_html__( 'Resize', 'ewww-image-optimizer' ) . '</h2></noscript>';
8182
  $output[] = "<table class='form-table'>\n";
8183
+ $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_resize_detection'>" . esc_html__( 'Resize Detection', 'ewww-image-optimizer' ) . '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/41-resize-settings', '59849911042863033a1ba5f9' ) . "</th><td><input type='checkbox' id='ewww_image_optimizer_resize_detection' name='ewww_image_optimizer_resize_detection' value='true' " . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_resize_detection' ) ? "checked='true'" : '' ) . ' /> ' . esc_html__( 'Highlight images that need to be resized because the browser is scaling them down. Only visible for Admin users and adds a button to the admin bar to detect scaled images that have been lazy loaded.', 'ewww-image-optimizer' ) . "</td></tr>\n";
8184
+ ewwwio_debug_message( 'resize detection: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_resize_detection' ) ? 'on' : 'off' ) );
8185
  if ( function_exists( 'imsanity_get_max_width_height' ) ) {
8186
  $output[] = "<tr class='$network_class'><th>&nbsp;</th><td>" .
8187
  '<p><span style="color: #3eadc9">' . esc_html__( '*Imsanity settings override the EWWW resize dimensions.', 'ewww-image-optimizer' ) . "</span></p></td></tr>\n";
8188
  }
8189
+ $output[] = "<tr class='$network_class'><th scope='row'>" . esc_html__( 'Resize Media Images', 'ewww-image-optimizer' ) . ewwwio_help_link( 'https://docs.ewww.io/article/41-resize-settings', '59849911042863033a1ba5f9' ) .
8190
+ "</th><td><label for='ewww_image_optimizer_maxmediawidth'>" . esc_html__( 'Max Width', 'ewww-image-optimizer' ) .
8191
+ "</label> <input type='number' step='1' min='0' class='small-text' id='ewww_image_optimizer_maxmediawidth' name='ewww_image_optimizer_maxmediawidth' value='" .
8192
+ ewww_image_optimizer_get_option( 'ewww_image_optimizer_maxmediawidth' ) . ( function_exists( 'imsanity_get_max_width_height' ) ? "' disabled='disabled" : '' ) .
8193
+ "' /> <label for='ewww_image_optimizer_maxmediaheight'>" . esc_html__( 'Max Height', 'ewww-image-optimizer' ) .
8194
+ "</label> <input type='number' step='1' min='0' class='small-text' id='ewww_image_optimizer_maxmediaheight' name='ewww_image_optimizer_maxmediaheight' value='" .
8195
+ ewww_image_optimizer_get_option( 'ewww_image_optimizer_maxmediaheight' ) . ( function_exists( 'imsanity_get_max_width_height' ) ? "' disabled='disabled" : '' ) . "' /> " .
8196
+ esc_html__( 'in pixels', 'ewww-image-optimizer' ) . "\n" . "<p class='description'>" . esc_html__( 'Resizes images uploaded to the Media Library.', 'ewww-image-optimizer' ) .
8197
  "</td></tr>\n";
8198
  ewwwio_debug_message( 'max media dimensions: ' . ewww_image_optimizer_get_option( 'ewww_image_optimizer_maxmediawidth' ) . ' x ' . ewww_image_optimizer_get_option( 'ewww_image_optimizer_maxmediaheight' ) );
8199
  ewwwio_debug_message( 'max other dimensions: ' . ewww_image_optimizer_get_option( 'ewww_image_optimizer_maxotherwidth' ) . ' x ' . ewww_image_optimizer_get_option( 'ewww_image_optimizer_maxotherheight' ) );
8200
+ $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_resize_existing'>" . esc_html__( 'Resize Existing Images', 'ewww-image-optimizer' ) . '</label>' .
8201
+ ewwwio_help_link( 'https://docs.ewww.io/article/41-resize-settings', '59849911042863033a1ba5f9' ) .
8202
+ "</th><td><input type='checkbox' id='ewww_image_optimizer_resize_existing' name='ewww_image_optimizer_resize_existing' value='true' " .
8203
+ ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_resize_existing' ) ? "checked='true'" : '' ) . ' /> ' .
8204
+ esc_html__( 'Allow resizing of existing Media Library images.', 'ewww-image-optimizer' ) . "</td></tr>\n";
8205
+ ewwwio_debug_message( 'resize existing images: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_resize_existing' ) ? 'on' : 'off' ) );
8206
 
8207
  $output[] = '<tr class="network-singlesite"><th scope="row">' . esc_html__( 'Disable Resizes', 'ewww-image-optimizer' ) .
8208
  ewwwio_help_link( 'https://docs.ewww.io/article/41-resize-settings', '59849911042863033a1ba5f9,58598744c697912ffd6c3eb4' ) . '</th><td><p>' .
8214
  $output[] = '<table><tr class="network-singlesite"><th scope="col">' . esc_html__( 'Disable Optimization', 'ewww-image-optimizer' ) . '</th><th scope="col">' . esc_html__( 'Disable Creation', 'ewww-image-optimizer' ) . "</th></tr>\n";
8215
  ewwwio_debug_message( 'disabled resizes:' );
8216
  foreach ( $image_sizes as $size => $dimensions ) {
8217
+ if ( 'thumbnail' === $size ) {
8218
  $output[] = "<tr class='network-singlesite'><td><input type='checkbox' id='ewww_image_optimizer_disable_resizes_opt_$size' name='ewww_image_optimizer_disable_resizes_opt[$size]' value='true' " . ( ! empty( $disabled_sizes_opt[ $size ] ) ? "checked='true'" : '' ) . " /></td><td><input type='checkbox' id='ewww_image_optimizer_disable_resizes_$size' name='ewww_image_optimizer_disable_resizes[$size]' value='true' disabled /></td><td><label for='ewww_image_optimizer_disable_resizes_$size'>$size - {$dimensions['width']}x{$dimensions['height']}</label></td></tr>\n";
8219
+ } elseif ( 'pdf-full' === $size ) {
8220
  $output[] = "<tr class='network-singlesite'><td><input type='checkbox' id='ewww_image_optimizer_disable_resizes_opt_$size' name='ewww_image_optimizer_disable_resizes_opt[$size]' value='true' " . ( ! empty( $disabled_sizes_opt[ $size ] ) ? "checked='true'" : '' ) . " /></td><td><input type='checkbox' id='ewww_image_optimizer_disable_resizes_$size' name='ewww_image_optimizer_disable_resizes[$size]' value='true' " . ( ! empty( $disabled_sizes[ $size ] ) ? "checked='true'" : '' ) . " /></td><td><label for='ewww_image_optimizer_disable_resizes_$size'>$size - <span class='description'>" . esc_html__( 'Disabling creation of the full-size preview for PDF files will disable all PDF preview sizes', 'ewww-image-optimizer' ) . "</span></label></td></tr>\n";
8221
  } else {
8222
  $output[] = "<tr class='network-singlesite'><td><input type='checkbox' id='ewww_image_optimizer_disable_resizes_opt_$size' name='ewww_image_optimizer_disable_resizes_opt[$size]' value='true' " . ( ! empty( $disabled_sizes_opt[ $size ] ) ? "checked='true'" : '' ) . " /></td><td><input type='checkbox' id='ewww_image_optimizer_disable_resizes_$size' name='ewww_image_optimizer_disable_resizes[$size]' value='true' " . ( ! empty( $disabled_sizes[ $size ] ) ? "checked='true'" : '' ) . " /></td><td><label for='ewww_image_optimizer_disable_resizes_$size'>$size - {$dimensions['width']}x{$dimensions['height']}</label></td></tr>\n";
8223
  }
8224
  ewwwio_debug_message( $size . ': ' . ( ! empty( $disabled_sizes_opt[ $size ] ) ? 'optimization=disabled ' : 'optimization=enabled ' ) . ( ! empty( $disabled_sizes[ $size ] ) ? 'creation=disabled' : 'creation=enabled' ) );
8225
  }
8226
+ if ( 'network-multisite' !== $network ) {
8227
  $output[] = "</table>\n";
8228
  $output[] = "</td></tr>\n";
8229
  } else {
8239
  "</p>\n";
8240
  $output[] = "<table class='form-table'>\n";
8241
  if ( $toolkit_found ) {
8242
+ $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_disable_convert_links'>" . esc_html__( 'Hide Conversion Links', 'ewww-image-optimizer' ) .
8243
+ '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/14-converting-images', '58545a86c697912ffd6c1b53' ) .
8244
+ "</th><td><input type='checkbox' id='ewww_image_optimizer_disable_convert_links' name='ewww_image_optimizer_disable_convert_links' " .
8245
+ ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_disable_convert_links' ) ? "checked='true'" : '' ) . ' /> ' .
8246
+ esc_html__( 'Site or Network admins can use this to prevent other users from using the conversion links in the Media Library which bypass the settings below.', 'ewww-image-optimizer' ) .
8247
+ "</td></tr>\n";
8248
+ $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_delete_originals'>" . esc_html__( 'Delete Originals', 'ewww-image-optimizer' ) . '</label>' .
8249
+ ewwwio_help_link( 'https://docs.ewww.io/article/14-converting-images', '58545a86c697912ffd6c1b53' ) .
8250
+ "</th><td><input type='checkbox' id='ewww_image_optimizer_delete_originals' name='ewww_image_optimizer_delete_originals' " .
8251
+ ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_delete_originals' ) ? "checked='true'" : '' ) . ' /> ' .
8252
+ esc_html__( 'This will remove the original image from the server after a successful conversion.', 'ewww-image-optimizer' ) . "</td></tr>\n";
8253
+ ewwwio_debug_message( 'delete originals: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_delete_originals' ) ? 'on' : 'off' ) );
8254
  $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_jpg_to_png'>" .
8255
  /* translators: 1: JPG, GIF or PNG 2: JPG or PNG */
8256
  sprintf( esc_html__( '%1$s to %2$s Conversion', 'ewww-image-optimizer' ), 'JPG', 'PNG' ) .
8257
+ '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/14-converting-images', '58545a86c697912ffd6c1b53' ) .
8258
+ "</th><td><span><input type='checkbox' id='ewww_image_optimizer_jpg_to_png' name='ewww_image_optimizer_jpg_to_png' " .
8259
+ ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_to_png' ) ? "checked='true'" : '' ) . ' /> <b>' . esc_html__( 'WARNING:', 'ewww-image-optimizer' ) . '</b> ' .
8260
+ esc_html__( 'Removes metadata and increases cpu usage dramatically.', 'ewww-image-optimizer' ) . "</span>\n" .
8261
+ "<p class='description'>" . esc_html__( 'PNG is generally much better than JPG for logos and other images with a limited range of colors. Checking this option will slow down JPG processing significantly, and you may want to enable it only temporarily.', 'ewww-image-optimizer' ) .
8262
+ "</p></td></tr>\n";
8263
+ ewwwio_debug_message( 'jpg2png: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_to_png' ) ? 'on' : 'off' ) );
8264
  $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_png_to_jpg'>" .
8265
  /* translators: 1: JPG, GIF or PNG 2: JPG or PNG */
8266
  sprintf( esc_html__( '%1$s to %2$s Conversion', 'ewww-image-optimizer' ), 'PNG', 'JPG' ) .
8267
+ '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/14-converting-images', '58545a86c697912ffd6c1b53,58543c69c697912ffd6c19a7,58542afac697912ffd6c18c0' ) .
8268
+ "</th><td><span><input type='checkbox' id='ewww_image_optimizer_png_to_jpg' name='ewww_image_optimizer_png_to_jpg' " .
8269
+ ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_to_jpg' ) ? "checked='true'" : '' ) . ' /> <b>' . esc_html__( 'WARNING:', 'ewww-image-optimizer' ) . '</b> ' .
8270
+ esc_html__( 'This is not a lossless conversion.', 'ewww-image-optimizer' ) . "</span>\n" .
8271
  "<p class='description'>" . esc_html__( 'JPG is generally much better than PNG for photographic use because it compresses the image and discards data. PNGs with transparency are not converted by default.', 'ewww-image-optimizer' ) . "</p>\n" .
8272
  "<span><label for='ewww_image_optimizer_jpg_background'> " . esc_html__( 'JPG Background Color:', 'ewww-image-optimizer' ) . "</label> #<input type='text' id='ewww_image_optimizer_jpg_background' name='ewww_image_optimizer_jpg_background' size='6' value='" . ewww_image_optimizer_jpg_background() . "' /> <span style='padding-left: 12px; font-size: 12px; border: solid 1px #555555; background-color: #" . ewww_image_optimizer_jpg_background() . "'>&nbsp;</span> " . esc_html__( 'HEX format (#123def)', 'ewww-image-optimizer' ) . ".</span>\n" .
8273
  "<p class='description'>" . esc_html__( 'Background color is used only if the PNG has transparency. Leave this value blank to skip PNGs with transparency.', 'ewww-image-optimizer' ) . "</p></td></tr>\n";
8274
+ ewwwio_debug_message( 'png2jpg: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_to_jpg' ) ? 'on' : 'off' ) );
8275
  $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_gif_to_png'>" .
8276
  /* translators: 1: JPG, GIF or PNG 2: JPG or PNG */
8277
  sprintf( esc_html__( '%1$s to %2$s Conversion', 'ewww-image-optimizer' ), 'GIF', 'PNG' ) .
8278
+ '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/14-converting-images', '58545a86c697912ffd6c1b53' ) .
8279
+ "</th><td><span><input type='checkbox' id='ewww_image_optimizer_gif_to_png' name='ewww_image_optimizer_gif_to_png' " .
8280
+ ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_gif_to_png' ) ? "checked='true'" : '' ) . ' /> ' .
8281
+ esc_html__( 'No warnings here, just do it.', 'ewww-image-optimizer' ) . "</span>\n" .
8282
  "<p class='description'> " . esc_html__( 'PNG is generally better than GIF, but animated images cannot be converted.', 'ewww-image-optimizer' ) . "</p></td></tr>\n";
8283
+ ewwwio_debug_message( 'gif2png: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_gif_to_png' ) ? 'on' : 'off' ) );
8284
  } else {
8285
  $output[] = "<tr class='$network_class'><th>&nbsp;</th><td>" .
8286
  '<p><span style="color: #3eadc9">' . esc_html__( 'Image conversion requires one of the following PHP libraries: GD, Imagick, or GMagick.', 'ewww-image-optimizer' ) . "</span></p></td></tr>\n";
8294
  $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_webp'>" . esc_html__( 'JPG/PNG to WebP', 'ewww-image-optimizer' ) . '</label>' .
8295
  ewwwio_help_link( 'https://docs.ewww.io/article/16-ewww-io-and-webp-images', '5854745ac697912ffd6c1c89' ) .
8296
  "</th><td><span><input type='checkbox' id='ewww_image_optimizer_webp' name='ewww_image_optimizer_webp' value='true' " .
8297
+ ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_webp' ) ? "checked='true'" : '' ) . ' /> <b>' .
8298
  esc_html__( 'WARNING:', 'ewww-image-optimizer' ) . '</b> ' . esc_html__( 'JPG to WebP conversion is lossy, but quality loss is minimal. PNG to WebP conversion is lossless.', 'ewww-image-optimizer' ) .
8299
  "</span>\n<p class='description'>" . esc_html__( 'Originals are never deleted, and WebP images should only be served to supported browsers.', 'ewww-image-optimizer' ) .
8300
  " <a href='#webp-rewrite'>" . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_webp' ) && ! ewww_image_optimizer_get_option( 'ewww_image_optimizer_webp_for_cdn' ) ? esc_html__( 'You can use the rewrite rules below to serve WebP images with Apache.', 'ewww-image-optimizer' ) : '' ) . "</a></td></tr>\n";
8301
+ ewwwio_debug_message( 'webp conversion: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_webp' ) ? 'on' : 'off' ) );
8302
  $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_webp_force'>" . esc_html__( 'Force WebP', 'ewww-image-optimizer' ) . '</label>' .
8303
  ewwwio_help_link( 'https://docs.ewww.io/article/16-ewww-io-and-webp-images', '5854745ac697912ffd6c1c89' ) .
8304
  "</th><td><span><input type='checkbox' id='ewww_image_optimizer_webp_force' name='ewww_image_optimizer_webp_force' value='true' " .
8305
+ ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_webp_force' ) ? "checked='true'" : '' ) . ' /> ' .
8306
  esc_html__( 'WebP images will be generated and saved for all JPG/PNG images regardless of their size. The JS WebP Rewriting will not check if a file exists, only that the domain matches the home url.', 'ewww-image-optimizer' ) . "</span></td></tr>\n";
8307
+ ewwwio_debug_message( 'forced webp: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_webp_force' ) ? 'on' : 'off' ) );
8308
  }
8309
  if ( ! ewww_image_optimizer_ce_webp_enabled() && ! ewww_image_optimizer_get_option( 'ewww_image_optimizer_exactdn' ) ) {
8310
  $webp_paths = ewww_image_optimizer_get_option( 'ewww_image_optimizer_webp_paths' ) ? esc_html( implode( "\n", ewww_image_optimizer_get_option( 'ewww_image_optimizer_webp_paths' ) ) ) : '';
8317
  $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_webp_for_cdn'>" .
8318
  esc_html__( 'JS WebP Rewriting', 'ewww-image-optimizer' ) .
8319
  '</label>' . ewwwio_help_link( 'https://docs.ewww.io/article/16-ewww-io-and-webp-images', '5854745ac697912ffd6c1c89,59443d162c7d3a0747cdf9f0' ) . "</th><td><span><input type='checkbox' id='ewww_image_optimizer_webp_for_cdn' name='ewww_image_optimizer_webp_for_cdn' value='true' " .
8320
+ ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_webp_for_cdn' ) ? "checked='true'" : '' ) . ' /> ' .
8321
  esc_html__( 'Use this if the Apache rewrite rules do not work, or if your images are served from a CDN.', 'ewww-image-optimizer' ) . ' ' .
8322
  /* translators: %s: Cache Enabler (link) */
8323
  sprintf( esc_html__( 'Sites using a CDN may also use the WebP option in the %s plugin.', 'ewww-image-optimizer' ), '<a href="https://wordpress.org/plugins/cache-enabler/">Cache Enabler</a>' ) . '</span></td></tr>';
8324
+ ewwwio_debug_message( 'alt webp rewriting: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_webp_for_cdn' ) ? 'on' : 'off' ) );
8325
  } elseif ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_exactdn' ) ) {
8326
  $output[] = "<tr class='$network_class'><th>&nbsp;</th><td><p class='description'>" . esc_html__( 'WebP images are served automatically by ExactDN.', 'ewww-image-optimizer' ) . '</p></td></tr>';
8327
  }
8334
  "<a href='https://ewww.io/status/'>" . esc_html__( 'Server Status', 'ewww-image-optimizer' ) . '</a>' .
8335
  "</p>\n";
8336
  $output[] = "<table class='form-table'>\n";
8337
+ $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_enable_help'>" . esc_html__( 'Enable Embedded Help', 'ewww-image-optimizer' ) .
8338
+ "</label></th><td><input type='checkbox' id='ewww_image_optimizer_enable_help' name='ewww_image_optimizer_enable_help' value='true' " .
8339
+ ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_enable_help' ) ? "checked='true'" : '' ) . ' /> ' .
8340
+ esc_html__( 'Enable the support beacon, which gives you access to documentation and our support team right from your WordPress dashboard. To assist you more efficiently, we may collect the current url, IP address, browser/device information, and debugging information.', 'ewww-image-optimizer' ) .
8341
+ "</td></tr>\n";
8342
+ ewwwio_debug_message( 'enable help beacon: ' . ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_enable_help' ) ? 'yes' : 'no' ) );
8343
+ $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_debug'>" . esc_html__( 'Debugging', 'ewww-image-optimizer' ) . '</label>' .
8344
+ ewwwio_help_link( 'https://docs.ewww.io/article/7-basic-configuration', '585373d5c697912ffd6c0bb2' ) . '</th>' .
8345
+ "<td><input type='checkbox' id='ewww_image_optimizer_debug' name='ewww_image_optimizer_debug' value='true' " .
8346
+ ( ! $ewwwio_temp_debug && ewww_image_optimizer_get_option( 'ewww_image_optimizer_debug' ) ? "checked='true'" : '' ) . ' /> ' .
8347
+ esc_html__( 'Use this to provide information for support purposes, or if you feel comfortable digging around in the code to fix a problem you are experiencing.', 'ewww-image-optimizer' ) .
8348
+ "</td></tr>\n";
8349
  $output[] = "</table>\n";
8350
 
8351
  $output[] = 'DEBUG_PLACEHOLDER';
8359
  "<a href='https://wordpress.org/support/view/plugin-reviews/ewww-image-optimizer#postform'>" . esc_html__( 'Write a review', 'ewww-image-optimizer' ) . '</a> | ' .
8360
  "<a href='https://ewww.io/plans/'>" . esc_html__( 'Upgrade to premium image optimization', 'ewww-image-optimizer' ) . "</a></p>\n";
8361
  $output[] = "<table class='form-table'>\n";
8362
+ $output[] = "<tr class='$network_class'><th scope='row'><label for='ewww_image_optimizer_allow_tracking'>" . esc_html__( 'Allow Usage Tracking?', 'ewww-image-optimizer' ) . '</label>' .
8363
+ ewwwio_help_link( 'https://docs.ewww.io/article/23-usage-tracking', '591f3a8e2c7d3a057f893d91' ) .
8364
+ "</th><td><input type='checkbox' id='ewww_image_optimizer_allow_tracking' name='ewww_image_optimizer_allow_tracking' value='true' " .
8365
+ ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_allow_tracking' ) ? "checked='true'" : '' ) . ' /> ' .
8366
+ esc_html__( 'Allow EWWW Image Optimizer to anonymously track how this plugin is used and help us make the plugin better. Opt-in to tracking and receive 500 API image credits free. No sensitive data is tracked.', 'ewww-image-optimizer' ) .
8367
+ "</td></tr>\n";
8368
  $output[] = "</table>\n";
8369
  $output[] = "</div>\n";
8370
 
8601
  if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) > 10 ) {
8602
  ewww_image_optimizer_set_option( 'ewww_image_optimizer_jpg_level', $default_level );
8603
  }
8604
+ if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) > 10 && 40 !== (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) ) {
8605
  ewww_image_optimizer_set_option( 'ewww_image_optimizer_png_level', $default_level );
8606
  }
8607
  if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_gif_level' ) > 0 ) {
8624
  * Loads script to detect scaled images within the page, only enabled for admins.
8625
  */
8626
  function ewww_image_optimizer_resize_detection_script() {
8627
+ if ( ! current_user_can( apply_filters( 'ewww_image_optimizer_admin_permissions', 'edit_others_posts' ) ) || 'wp-login.php' === basename( $_SERVER['SCRIPT_NAME'] ) ) {
8628
  return;
8629
  }
8630
  if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_resize_detection' ) ) {
8659
  * Checks if admin bar is visible, and then adds the admin_bar_menu action.
8660
  */
8661
  function ewww_image_optimizer_admin_bar_init() {
8662
+ if ( ! current_user_can( apply_filters( 'ewww_image_optimizer_admin_permissions', 'edit_others_posts' ) ) || ! is_admin_bar_showing() || 'wp-login.php' === basename( $_SERVER['SCRIPT_NAME'] ) || is_admin() ) {
8663
  return;
8664
  }
8665
  if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_resize_detection' ) ) {
8809
  if ( defined( 'LIBXML_VERSION' ) ) {
8810
  $ewww_debug .= 'libxml version: ' . LIBXML_VERSION . '<br>';
8811
  }
8812
+ if ( ! empty( $_ENV['PANTHEON_ENVIRONMENT'] ) && in_array( $_ENV['PANTHEON_ENVIRONMENT'], array( 'test', 'live', 'dev' ), true ) ) {
8813
  $ewww_debug .= "detected pantheon env: {$_ENV['PANTHEON_ENVIRONMENT']}<br>";
8814
  }
8815
  if ( defined( 'EWWW_IO_CLOUD_PLUGIN' ) && EWWW_IO_CLOUD_PLUGIN ) {
8852
  $ewwwdb = $wpdb;
8853
  }
8854
  $debug_images = $ewwwdb->get_results( "SELECT path,updates,updated,trace FROM $ewwwdb->ewwwio_images WHERE trace IS NOT NULL ORDER BY updates DESC LIMIT 100" );
8855
+ if ( ewww_image_optimizer_iterable( $debug_images ) ) {
8856
  foreach ( $debug_images as $image ) {
8857
  $trace = unserialize( $image->trace );
8858
+ echo '<p><b>' . esc_html__( 'File path', 'ewww-image-optimizer' ) . ': ' . ewww_image_optimizer_absolutize_path( $image->path ) . '</b><br>';
8859
  echo esc_html__( 'Number of attempted optimizations', 'ewww-image-optimizer' ) . ': ' . $image->updates . '<br>';
8860
  echo esc_html__( 'Last attempted', 'ewww-image-optimizer' ) . ': ' . $image->updated . '<br>';
8861
  echo esc_html__( 'PHP trace', 'ewww-image-optimizer' ) . ':<br>';
9040
  return true;
9041
  }
9042
 
9043
+ /**
9044
+ * Implode a multi-dimensional array without throwing errors. Arguments can be reverse order, same as implode().
9045
+ *
9046
+ * @param string $delimiter The character to put between the array items (the glue).
9047
+ * @param array $data The array to output with the glue.
9048
+ * @return string The array values, separated by the delimiter.
9049
+ */
9050
+ function ewwwio_implode( $delimiter, $data = '' ) {
9051
+ if ( is_array( $delimiter ) ) {
9052
+ $temp_data = $delimiter;
9053
+ $delimiter = $data;
9054
+ $data = $temp_data;
9055
+ }
9056
+ if ( is_array( $delimiter ) ) {
9057
+ return '';
9058
+ }
9059
+ $output = '';
9060
+ foreach ( $data as $value ) {
9061
+ if ( is_string( $value ) || is_numeric( $value ) ) {
9062
+ $output .= $value . $delimiter;
9063
+ } elseif ( is_bool( $value ) ) {
9064
+ $output .= ( $value ? 'true' : 'false' ) . $delimiter;
9065
+ } elseif ( is_array( $value ) ) {
9066
+ $output .= 'Array,';
9067
+ }
9068
+ }
9069
+ return rtrim( $output, ',' );
9070
+ }
9071
+
9072
+
9073
  /**
9074
  * Logs memory usage stats. Disabled normally.
9075
  *
ewww-image-optimizer.php CHANGED
@@ -13,7 +13,7 @@ Plugin Name: EWWW Image Optimizer
13
  Plugin URI: https://wordpress.org/plugins/ewww-image-optimizer/
14
  Description: Reduce file sizes for images within WordPress including NextGEN Gallery and GRAND FlAGallery. Uses jpegtran, optipng/pngout, and gifsicle.
15
  Author: Exactly WWW
16
- Version: 4.7.2
17
  Author URI: https://ewww.io/
18
  License: GPLv3
19
  */
13
  Plugin URI: https://wordpress.org/plugins/ewww-image-optimizer/
14
  Description: Reduce file sizes for images within WordPress including NextGEN Gallery and GRAND FlAGallery. Uses jpegtran, optipng/pngout, and gifsicle.
15
  Author: Exactly WWW
16
+ Version: 4.7.3
17
  Author URI: https://ewww.io/
18
  License: GPLv3
19
  */
includes/lazysizes-post.js CHANGED
@@ -33,7 +33,7 @@ document.addEventListener('lazybeforeunveil', function(e){
33
  var wrongSize = false;
34
  var srcset = target.getAttribute('data-srcset');
35
  if ( ! srcset && target.naturalWidth) {
36
- console.log('we have something');
37
  if ((target.naturalWidth > 1) && (target.naturalHeight > 1)) {
38
  // For each image with a natural width which isn't
39
  // a 1x1 image, check its size.
@@ -41,15 +41,15 @@ document.addEventListener('lazybeforeunveil', function(e){
41
  var wrongWidth = (target.clientWidth * 1.25 < target.naturalWidth);
42
  var wrongHeight = (target.clientHeight * 1.25 < target.naturalHeight);
43
  if (wrongWidth || wrongHeight) {
44
- console.log(Math.round(target.clientWidth * dPR) + "x" + Math.round(target.clientHeight * dPR) + ", natural is " +
45
- target.naturalWidth + "x" + target.naturalHeight + "!");
46
  var targetWidth = Math.round(target.offsetWidth * dPR);
47
  var targetHeight = Math.round(target.offsetHeight * dPR);
48
 
49
  var src = target.getAttribute('data-src');
50
  var webpsrc = target.getAttribute('data-src-webp');
51
  if(ewww_webp_supported && webpsrc && -1 == src.search('webp=1')){
52
- console.log('using data-src-webp');
53
  src = webpsrc;
54
  }
55
  var newSrc = constrainSrc(src,targetWidth,targetHeight);
33
  var wrongSize = false;
34
  var srcset = target.getAttribute('data-srcset');
35
  if ( ! srcset && target.naturalWidth) {
36
+ //console.log('we have something');
37
  if ((target.naturalWidth > 1) && (target.naturalHeight > 1)) {
38
  // For each image with a natural width which isn't
39
  // a 1x1 image, check its size.
41
  var wrongWidth = (target.clientWidth * 1.25 < target.naturalWidth);
42
  var wrongHeight = (target.clientHeight * 1.25 < target.naturalHeight);
43
  if (wrongWidth || wrongHeight) {
44
+ //console.log(Math.round(target.clientWidth * dPR) + "x" + Math.round(target.clientHeight * dPR) + ", natural is " +
45
+ // target.naturalWidth + "x" + target.naturalHeight + "!");
46
  var targetWidth = Math.round(target.offsetWidth * dPR);
47
  var targetHeight = Math.round(target.offsetHeight * dPR);
48
 
49
  var src = target.getAttribute('data-src');
50
  var webpsrc = target.getAttribute('data-src-webp');
51
  if(ewww_webp_supported && webpsrc && -1 == src.search('webp=1')){
52
+ //console.log('using data-src-webp');
53
  src = webpsrc;
54
  }
55
  var newSrc = constrainSrc(src,targetWidth,targetHeight);
includes/lazysizes.min.js CHANGED
@@ -1 +1 @@
1
- var ewww_webp_supported=!1;function lazysizesWebP(e,t){var a=new Image;a.onload=function(){ewww_webp_supported=0<a.width&&0<a.height,t()},a.onerror=function(){t()},a.src="data:image/webp;base64,"+{alpha:"UklGRkoAAABXRUJQVlA4WAoAAAAQAAAAAAAAAAAAQUxQSAwAAAARBxAR/Q9ERP8DAABWUDggGAAAABQBAJ0BKgEAAQAAAP4AAA3AAP7mtQAAAA==",animation:"UklGRlIAAABXRUJQVlA4WAoAAAASAAAAAAAAAAAAQU5JTQYAAAD/////AABBTk1GJgAAAAAAAAAAAAAAAAAAAGQAAABWUDhMDQAAAC8AAAAQBxAREYiI/gcA"}[e]}function constrainSrc(e,t,a){var i=/w=(\d+)/,n=/fit=(\d+),(\d+)/,r=/resize=(\d+),(\d+)/;if(0<e.search("\\?")&&0<e.search(ewww_lazy_vars.exactdn_domain)){var o=r.exec(e);if(o&&t<o[1])return e.replace(r,"resize="+t+","+a);var s=i.exec(e);if(s&&t<=s[1])return e.replace(i,"resize="+t+","+a);var l=n.exec(e);if(l&&t<l[1])return e.replace(n,"resize="+t+","+a);if(!s&&!l&&!o)return e+"&resize="+t+","+a}return-1==e.search("\\?")&&0<e.search(ewww_lazy_vars.exactdn_domain)?e+"?resize="+t+","+a:e}window.lazySizesConfig=window.lazySizesConfig||{},window.lazySizesConfig.init=!1,function(e,t){var a=function(i,A){"use strict";if(!A.getElementsByClassName)return;var g,z,h=A.documentElement,r=i.Date,n=i.HTMLPictureElement,o="addEventListener",v="getAttribute",t=i[o],u=i.setTimeout,a=i.requestAnimationFrame||u,s=i.requestIdleCallback,f=/^picture$/i,l=["load","error","lazyincluded","_lazyloaded"],d={},p=Array.prototype.forEach,c=function(e,t){return d[t]||(d[t]=new RegExp("(\\s|^)"+t+"(\\s|$)")),d[t].test(e[v]("class")||"")&&d[t]},m=function(e,t){c(e,t)||e.setAttribute("class",(e[v]("class")||"").trim()+" "+t)},y=function(e,t){var a;(a=c(e,t))&&e.setAttribute("class",(e[v]("class")||"").replace(a," "))},b=function(t,a,e){var i=e?o:"removeEventListener";e&&b(t,a),l.forEach(function(e){t[i](e,a)})},w=function(e,t,a,i,n){var r=A.createEvent("Event");return a||(a={}),a.instance=g,r.initEvent(t,!i,!n),r.detail=a,e.dispatchEvent(r),r},C=function(e,t){var a;!n&&(a=i.picturefill||z.pf)?(t&&t.src&&!e[v]("srcset")&&e.setAttribute("srcset",t.src),a({reevaluate:!0,elements:[e]})):t&&t.src&&(e.src=t.src)},_=function(e,t){return(getComputedStyle(e,null)||{})[t]},E=function(e,t,a){for(a=a||e.offsetWidth;a<z.minSize&&t&&!e._lazysizesWidth;)a=t.offsetWidth,t=t.parentNode;return a},W=(B=[],R=[],L=B,N=function(){var e=L;for(L=B.length?R:B,S=!(M=!0);e.length;)e.shift()();M=!1},Q=function(e,t){M&&!t?e.apply(this,arguments):(L.push(e),S||(S=!0,(A.hidden?u:a)(N)))},Q._lsFlush=N,Q),e=function(a,e){return e?function(){W(a)}:function(){var e=this,t=arguments;W(function(){a.apply(e,t)})}},x=function(e){var t,a,i=function(){t=null,e()},n=function(){var e=r.now()-a;e<99?u(n,99-e):(s||i)(i)};return function(){a=r.now(),t||(t=u(n,99))}};var M,S,B,R,L,N,Q;!function(){var e,t={lazyClass:"lazyload",loadedClass:"lazyloaded",loadingClass:"lazyloading",preloadClass:"lazypreload",errorClass:"lazyerror",autosizesClass:"lazyautosizes",srcAttr:"data-src",srcsetAttr:"data-srcset",sizesAttr:"data-sizes",minSize:40,customMedia:{},init:!0,expFactor:1.5,hFac:.8,loadMode:2,loadHidden:!0,ricTimeout:0,throttleDelay:125};for(e in z=i.lazySizesConfig||i.lazysizesConfig||{},t)e in z||(z[e]=t[e]);i.lazySizesConfig=z,u(function(){z.init&&k()})}();var P=(se=/^img$/i,le=/^iframe$/i,de="onscroll"in i&&!/(gle|ing)bot/.test(navigator.userAgent),ce=0,ue=0,fe=-1,Ae=function(e){ue--,(!e||ue<0||!e.target)&&(ue=0)},ge=function(e){return null==Z&&(Z="hidden"==_(A.body,"visibility")),Z||"hidden"!=_(e.parentNode,"visibility")&&"hidden"!=_(e,"visibility")},ze=function(e,t){var a,i=e,n=ge(e);for(V-=t,K+=t,X-=t,Y+=t;n&&(i=i.offsetParent)&&i!=A.body&&i!=h;)(n=0<(_(i,"opacity")||1))&&"visible"!=_(i,"overflow")&&(a=i.getBoundingClientRect(),n=Y>a.left&&X<a.right&&K>a.top-1&&V<a.bottom+1);return n},he=function(){var e,t,a,i,n,r,o,s,l,d,c,u,f=g.elements;if((G=z.loadMode)&&ue<8&&(e=f.length)){for(t=0,fe++,d=!z.expand||z.expand<1?500<h.clientHeight&&500<h.clientWidth?500:370:z.expand,g._defEx=d,c=d*z.expFactor,u=z.hFac,Z=null,ce<c&&ue<1&&2<fe&&2<G&&!A.hidden?(ce=c,fe=0):ce=1<G&&1<fe&&ue<6?d:0;t<e;t++)if(f[t]&&!f[t]._lazyRace)if(de)if((s=f[t][v]("data-expand"))&&(r=1*s)||(r=ce),l!==r&&(q=innerWidth+r*u,j=innerHeight+r,o=-1*r,l=r),a=f[t].getBoundingClientRect(),(K=a.bottom)>=o&&(V=a.top)<=j&&(Y=a.right)>=o*u&&(X=a.left)<=q&&(K||Y||X||V)&&(z.loadHidden||ge(f[t]))&&(J&&ue<3&&!s&&(G<3||fe<4)||ze(f[t],r))){if(Ce(f[t]),n=!0,9<ue)break}else!n&&J&&!i&&ue<4&&fe<4&&2<G&&(I[0]||z.preloadAfterLoad)&&(I[0]||!s&&(K||Y||X||V||"auto"!=f[t][v](z.sizesAttr)))&&(i=I[0]||f[t]);else Ce(f[t]);i&&!n&&Ce(i)}},ee=he,ae=0,ie=z.throttleDelay,ne=z.ricTimeout,re=function(){te=!1,ae=r.now(),ee()},oe=s&&49<ne?function(){s(re,{timeout:ne}),ne!==z.ricTimeout&&(ne=z.ricTimeout)}:e(function(){u(re)},!0),ve=function(e){var t;(e=!0===e)&&(ne=33),te||(te=!0,(t=ie-(r.now()-ae))<0&&(t=0),e||t<9?oe():u(oe,t))},pe=function(e){var t=e.target;t._lazyCache?delete t._lazyCache:(Ae(e),m(t,z.loadedClass),y(t,z.loadingClass),b(t,ye),w(t,"lazyloaded"))},me=e(pe),ye=function(e){me({target:e.target})},be=function(e){var t,a=e[v](z.srcsetAttr);(t=z.customMedia[e[v]("data-media")||e[v]("media")])&&e.setAttribute("media",t),a&&e.setAttribute("srcset",a)},we=e(function(e,t,a,i,n){var r,o,s,l,d,c;(d=w(e,"lazybeforeunveil",t)).defaultPrevented||(i&&(a?m(e,z.autosizesClass):e.setAttribute("sizes",i)),o=e[v](z.srcsetAttr),r=e[v](z.srcAttr),n&&(s=e.parentNode,l=s&&f.test(s.nodeName||"")),c=t.firesLoad||"src"in e&&(o||r||l),d={target:e},m(e,z.loadingClass),c&&(clearTimeout(O),O=u(Ae,2500),b(e,ye,!0)),l&&p.call(s.getElementsByTagName("source"),be),o?e.setAttribute("srcset",o):r&&!l&&(le.test(e.nodeName)?function(t,a){try{t.contentWindow.location.replace(a)}catch(e){t.src=a}}(e,r):e.src=r),n&&(o||l)&&C(e,{src:r})),e._lazyRace&&delete e._lazyRace,y(e,z.lazyClass),W(function(){(!c||e.complete&&1<e.naturalWidth)&&(pe(d),e._lazyCache=!0,u(function(){"_lazyCache"in e&&delete e._lazyCache},9))},!0)}),Ce=function(e){var t,a=se.test(e.nodeName),i=a&&(e[v](z.sizesAttr)||e[v]("sizes")),n="auto"==i;(!n&&J||!a||!e[v]("src")&&!e.srcset||e.complete||c(e,z.errorClass)||!c(e,z.lazyClass))&&(t=w(e,"lazyunveilread").detail,n&&H.updateElem(e,!0,e.offsetWidth),e._lazyRace=!0,ue++,we(e,t,n,i,a))},_e=function(){if(!J)if(r.now()-$<999)u(_e,999);else{var e=x(function(){z.loadMode=3,ve()});J=!0,z.loadMode=3,ve(),t("scroll",function(){3==z.loadMode&&(z.loadMode=2),e()},!0)}},{_:function(){$=r.now(),g.elements=A.getElementsByClassName(z.lazyClass),I=A.getElementsByClassName(z.lazyClass+" "+z.preloadClass),t("scroll",ve,!0),t("resize",ve,!0),i.MutationObserver?new MutationObserver(ve).observe(h,{childList:!0,subtree:!0,attributes:!0}):(h[o]("DOMNodeInserted",ve,!0),h[o]("DOMAttrModified",ve,!0),setInterval(ve,999)),t("hashchange",ve,!0),["focus","mouseover","click","load","transitionend","animationend","webkitAnimationEnd"].forEach(function(e){A[o](e,ve,!0)}),/d$|^c/.test(A.readyState)?_e():(t("load",_e),A[o]("DOMContentLoaded",ve),u(_e,2e4)),g.elements.length?(he(),W._lsFlush()):ve()},checkElems:ve,unveil:Ce}),H=(T=e(function(e,t,a,i){var n,r,o;if(e._lazysizesWidth=i,i+="px",e.setAttribute("sizes",i),f.test(t.nodeName||""))for(n=t.getElementsByTagName("source"),r=0,o=n.length;r<o;r++)n[r].setAttribute("sizes",i);a.detail.dataAttr||C(e,a.detail)}),F=function(e,t,a){var i,n=e.parentNode;n&&(a=E(e,n,a),(i=w(e,"lazybeforesizes",{width:a,dataAttr:!!t})).defaultPrevented||(a=i.detail.width)&&a!==e._lazysizesWidth&&T(e,n,i,a))},U=x(function(){var e,t=D.length;if(t)for(e=0;e<t;e++)F(D[e])}),{_:function(){D=A.getElementsByClassName(z.autosizesClass),t("resize",U)},checkElems:U,updateElem:F}),k=function(){k.i||(k.i=!0,H._(),P._())};var D,T,F,U;var I,J,O,G,$,q,j,V,X,Y,K,Z,ee,te,ae,ie,ne,re,oe,se,le,de,ce,ue,fe,Ae,ge,ze,he,ve,pe,me,ye,be,we,Ce,_e;return g={cfg:z,autoSizer:H,loader:P,init:k,uP:C,aC:m,rC:y,hC:c,fire:w,gW:E,rAF:W}}(e,e.document);e.lazySizes=a,"object"==typeof module&&module.exports&&(module.exports=a)}(window),lazysizesWebP("alpha",lazySizes.init),document.addEventListener("lazybeforeunveil",function(e){var t=e.target,a=t.getAttribute("data-srcset");if(!a&&t.naturalWidth&&(console.log("we have something"),1<t.naturalWidth&&1<t.naturalHeight)){var i=window.devicePixelRatio||1,n=1.25*t.clientWidth<t.naturalWidth,r=1.25*t.clientHeight<t.naturalHeight;if(n||r){console.log(Math.round(t.clientWidth*i)+"x"+Math.round(t.clientHeight*i)+", natural is "+t.naturalWidth+"x"+t.naturalHeight+"!");var o=Math.round(t.offsetWidth*i),s=Math.round(t.offsetHeight*i),l=t.getAttribute("data-src"),d=t.getAttribute("data-src-webp");ewww_webp_supported&&d&&-1==l.search("webp=1")&&(console.log("using data-src-webp"),l=d);var c=constrainSrc(l,o,s);c&&l!=c&&t.setAttribute("data-src",c)}}if(ewww_webp_supported){if(a&&-1<a.search("webp=1"))return;if(a){var u=t.getAttribute("data-srcset-webp");u&&t.setAttribute("data-srcset",u)}if((l=t.getAttribute("data-src"))&&-1<l.search("webp=1"))return;if(!(d=t.getAttribute("data-src-webp")))return;t.setAttribute("data-src",d)}}),function(e,t){var a=function(){t(e.lazySizes),e.removeEventListener("lazyunveilread",a,!0)};t=t.bind(null,e,e.document),"object"==typeof module&&module.exports?t(require("lazysizes")):e.lazySizes?a():e.addEventListener("lazyunveilread",a,!0)}(window,function(s,i,l){"use strict";var d,c;i.addEventListener&&(d=function(e,t){var a=i.createElement("img");a.onload=function(){a.onload=null,a.onerror=null,a=null,t()},a.onerror=a.onload,a.src=e,a&&a.complete&&a.onload&&a.onload()},addEventListener("lazybeforeunveil",function(e){var t,a,i;if(e.detail.instance==l&&!e.defaultPrevented){if("none"==e.target.preload&&(e.target.preload="auto"),t=e.target.getAttribute("data-bg")){ewww_webp_supported&&(a=e.target.getAttribute("data-bg-webp"))&&(t=a);var n=s.devicePixelRatio||1,r=Math.round(e.target.offsetWidth*n),o=Math.round(e.target.offsetHeight*n);t=constrainSrc(t,r,o),e.detail.firesLoad=!0,d(t,function(){e.target.style.backgroundImage="url("+(c.test(t)?JSON.stringify(t):t)+")",e.detail.firesLoad=!1,l.fire(e.target,"_lazyloaded",{},!0,!0)})}(i=e.target.getAttribute("data-poster"))&&(e.detail.firesLoad=!0,d(i,function(){e.target.poster=i,e.detail.firesLoad=!1,l.fire(e.target,"_lazyloaded",{},!0,!0)}))}},!(c=/\(|\)|\s|'/)))});
1
+ var ewww_webp_supported=!1;function lazysizesWebP(e,t){var a=new Image;a.onload=function(){ewww_webp_supported=0<a.width&&0<a.height,t()},a.onerror=function(){t()},a.src="data:image/webp;base64,"+{alpha:"UklGRkoAAABXRUJQVlA4WAoAAAAQAAAAAAAAAAAAQUxQSAwAAAARBxAR/Q9ERP8DAABWUDggGAAAABQBAJ0BKgEAAQAAAP4AAA3AAP7mtQAAAA==",animation:"UklGRlIAAABXRUJQVlA4WAoAAAASAAAAAAAAAAAAQU5JTQYAAAD/////AABBTk1GJgAAAAAAAAAAAAAAAAAAAGQAAABWUDhMDQAAAC8AAAAQBxAREYiI/gcA"}[e]}function constrainSrc(e,t,a){var i=/w=(\d+)/,n=/fit=(\d+),(\d+)/,r=/resize=(\d+),(\d+)/;if(0<e.search("\\?")&&0<e.search(ewww_lazy_vars.exactdn_domain)){var o=r.exec(e);if(o&&t<o[1])return e.replace(r,"resize="+t+","+a);var s=i.exec(e);if(s&&t<=s[1])return e.replace(i,"resize="+t+","+a);var l=n.exec(e);if(l&&t<l[1])return e.replace(n,"resize="+t+","+a);if(!s&&!l&&!o)return e+"&resize="+t+","+a}return-1==e.search("\\?")&&0<e.search(ewww_lazy_vars.exactdn_domain)?e+"?resize="+t+","+a:e}window.lazySizesConfig=window.lazySizesConfig||{},window.lazySizesConfig.init=!1,function(e,t){var a=function(i,A){"use strict";if(!A.getElementsByClassName)return;var z,g,h=A.documentElement,r=i.Date,n=i.HTMLPictureElement,o="addEventListener",v="getAttribute",t=i[o],u=i.setTimeout,a=i.requestAnimationFrame||u,s=i.requestIdleCallback,f=/^picture$/i,l=["load","error","lazyincluded","_lazyloaded"],d={},p=Array.prototype.forEach,c=function(e,t){return d[t]||(d[t]=new RegExp("(\\s|^)"+t+"(\\s|$)")),d[t].test(e[v]("class")||"")&&d[t]},y=function(e,t){c(e,t)||e.setAttribute("class",(e[v]("class")||"").trim()+" "+t)},m=function(e,t){var a;(a=c(e,t))&&e.setAttribute("class",(e[v]("class")||"").replace(a," "))},b=function(t,a,e){var i=e?o:"removeEventListener";e&&b(t,a),l.forEach(function(e){t[i](e,a)})},w=function(e,t,a,i,n){var r=A.createEvent("Event");return a||(a={}),a.instance=z,r.initEvent(t,!i,!n),r.detail=a,e.dispatchEvent(r),r},C=function(e,t){var a;!n&&(a=i.picturefill||g.pf)?(t&&t.src&&!e[v]("srcset")&&e.setAttribute("srcset",t.src),a({reevaluate:!0,elements:[e]})):t&&t.src&&(e.src=t.src)},_=function(e,t){return(getComputedStyle(e,null)||{})[t]},E=function(e,t,a){for(a=a||e.offsetWidth;a<g.minSize&&t&&!e._lazysizesWidth;)a=t.offsetWidth,t=t.parentNode;return a},W=(B=[],R=[],L=B,N=function(){var e=L;for(L=B.length?R:B,S=!(M=!0);e.length;)e.shift()();M=!1},Q=function(e,t){M&&!t?e.apply(this,arguments):(L.push(e),S||(S=!0,(A.hidden?u:a)(N)))},Q._lsFlush=N,Q),e=function(a,e){return e?function(){W(a)}:function(){var e=this,t=arguments;W(function(){a.apply(e,t)})}},x=function(e){var t,a,i=function(){t=null,e()},n=function(){var e=r.now()-a;e<99?u(n,99-e):(s||i)(i)};return function(){a=r.now(),t||(t=u(n,99))}};var M,S,B,R,L,N,Q;!function(){var e,t={lazyClass:"lazyload",loadedClass:"lazyloaded",loadingClass:"lazyloading",preloadClass:"lazypreload",errorClass:"lazyerror",autosizesClass:"lazyautosizes",srcAttr:"data-src",srcsetAttr:"data-srcset",sizesAttr:"data-sizes",minSize:40,customMedia:{},init:!0,expFactor:1.5,hFac:.8,loadMode:2,loadHidden:!0,ricTimeout:0,throttleDelay:125};for(e in g=i.lazySizesConfig||i.lazysizesConfig||{},t)e in g||(g[e]=t[e]);i.lazySizesConfig=g,u(function(){g.init&&D()})}();var P=(se=/^img$/i,le=/^iframe$/i,de="onscroll"in i&&!/(gle|ing)bot/.test(navigator.userAgent),ce=0,ue=0,fe=-1,Ae=function(e){ue--,(!e||ue<0||!e.target)&&(ue=0)},ze=function(e){return null==Z&&(Z="hidden"==_(A.body,"visibility")),Z||"hidden"!=_(e.parentNode,"visibility")&&"hidden"!=_(e,"visibility")},ge=function(e,t){var a,i=e,n=ze(e);for(V-=t,K+=t,X-=t,Y+=t;n&&(i=i.offsetParent)&&i!=A.body&&i!=h;)(n=0<(_(i,"opacity")||1))&&"visible"!=_(i,"overflow")&&(a=i.getBoundingClientRect(),n=Y>a.left&&X<a.right&&K>a.top-1&&V<a.bottom+1);return n},he=function(){var e,t,a,i,n,r,o,s,l,d,c,u,f=z.elements;if((G=g.loadMode)&&ue<8&&(e=f.length)){for(t=0,fe++,d=!g.expand||g.expand<1?500<h.clientHeight&&500<h.clientWidth?500:370:g.expand,z._defEx=d,c=d*g.expFactor,u=g.hFac,Z=null,ce<c&&ue<1&&2<fe&&2<G&&!A.hidden?(ce=c,fe=0):ce=1<G&&1<fe&&ue<6?d:0;t<e;t++)if(f[t]&&!f[t]._lazyRace)if(de)if((s=f[t][v]("data-expand"))&&(r=1*s)||(r=ce),l!==r&&(q=innerWidth+r*u,j=innerHeight+r,o=-1*r,l=r),a=f[t].getBoundingClientRect(),(K=a.bottom)>=o&&(V=a.top)<=j&&(Y=a.right)>=o*u&&(X=a.left)<=q&&(K||Y||X||V)&&(g.loadHidden||ze(f[t]))&&(J&&ue<3&&!s&&(G<3||fe<4)||ge(f[t],r))){if(Ce(f[t]),n=!0,9<ue)break}else!n&&J&&!i&&ue<4&&fe<4&&2<G&&(I[0]||g.preloadAfterLoad)&&(I[0]||!s&&(K||Y||X||V||"auto"!=f[t][v](g.sizesAttr)))&&(i=I[0]||f[t]);else Ce(f[t]);i&&!n&&Ce(i)}},ee=he,ae=0,ie=g.throttleDelay,ne=g.ricTimeout,re=function(){te=!1,ae=r.now(),ee()},oe=s&&49<ne?function(){s(re,{timeout:ne}),ne!==g.ricTimeout&&(ne=g.ricTimeout)}:e(function(){u(re)},!0),ve=function(e){var t;(e=!0===e)&&(ne=33),te||(te=!0,(t=ie-(r.now()-ae))<0&&(t=0),e||t<9?oe():u(oe,t))},pe=function(e){var t=e.target;t._lazyCache?delete t._lazyCache:(Ae(e),y(t,g.loadedClass),m(t,g.loadingClass),b(t,me),w(t,"lazyloaded"))},ye=e(pe),me=function(e){ye({target:e.target})},be=function(e){var t,a=e[v](g.srcsetAttr);(t=g.customMedia[e[v]("data-media")||e[v]("media")])&&e.setAttribute("media",t),a&&e.setAttribute("srcset",a)},we=e(function(e,t,a,i,n){var r,o,s,l,d,c;(d=w(e,"lazybeforeunveil",t)).defaultPrevented||(i&&(a?y(e,g.autosizesClass):e.setAttribute("sizes",i)),o=e[v](g.srcsetAttr),r=e[v](g.srcAttr),n&&(s=e.parentNode,l=s&&f.test(s.nodeName||"")),c=t.firesLoad||"src"in e&&(o||r||l),d={target:e},y(e,g.loadingClass),c&&(clearTimeout(O),O=u(Ae,2500),b(e,me,!0)),l&&p.call(s.getElementsByTagName("source"),be),o?e.setAttribute("srcset",o):r&&!l&&(le.test(e.nodeName)?function(t,a){try{t.contentWindow.location.replace(a)}catch(e){t.src=a}}(e,r):e.src=r),n&&(o||l)&&C(e,{src:r})),e._lazyRace&&delete e._lazyRace,m(e,g.lazyClass),W(function(){(!c||e.complete&&1<e.naturalWidth)&&(pe(d),e._lazyCache=!0,u(function(){"_lazyCache"in e&&delete e._lazyCache},9))},!0)}),Ce=function(e){var t,a=se.test(e.nodeName),i=a&&(e[v](g.sizesAttr)||e[v]("sizes")),n="auto"==i;(!n&&J||!a||!e[v]("src")&&!e.srcset||e.complete||c(e,g.errorClass)||!c(e,g.lazyClass))&&(t=w(e,"lazyunveilread").detail,n&&k.updateElem(e,!0,e.offsetWidth),e._lazyRace=!0,ue++,we(e,t,n,i,a))},_e=function(){if(!J)if(r.now()-$<999)u(_e,999);else{var e=x(function(){g.loadMode=3,ve()});J=!0,g.loadMode=3,ve(),t("scroll",function(){3==g.loadMode&&(g.loadMode=2),e()},!0)}},{_:function(){$=r.now(),z.elements=A.getElementsByClassName(g.lazyClass),I=A.getElementsByClassName(g.lazyClass+" "+g.preloadClass),t("scroll",ve,!0),t("resize",ve,!0),i.MutationObserver?new MutationObserver(ve).observe(h,{childList:!0,subtree:!0,attributes:!0}):(h[o]("DOMNodeInserted",ve,!0),h[o]("DOMAttrModified",ve,!0),setInterval(ve,999)),t("hashchange",ve,!0),["focus","mouseover","click","load","transitionend","animationend","webkitAnimationEnd"].forEach(function(e){A[o](e,ve,!0)}),/d$|^c/.test(A.readyState)?_e():(t("load",_e),A[o]("DOMContentLoaded",ve),u(_e,2e4)),z.elements.length?(he(),W._lsFlush()):ve()},checkElems:ve,unveil:Ce}),k=(H=e(function(e,t,a,i){var n,r,o;if(e._lazysizesWidth=i,i+="px",e.setAttribute("sizes",i),f.test(t.nodeName||""))for(n=t.getElementsByTagName("source"),r=0,o=n.length;r<o;r++)n[r].setAttribute("sizes",i);a.detail.dataAttr||C(e,a.detail)}),F=function(e,t,a){var i,n=e.parentNode;n&&(a=E(e,n,a),(i=w(e,"lazybeforesizes",{width:a,dataAttr:!!t})).defaultPrevented||(a=i.detail.width)&&a!==e._lazysizesWidth&&H(e,n,i,a))},U=x(function(){var e,t=T.length;if(t)for(e=0;e<t;e++)F(T[e])}),{_:function(){T=A.getElementsByClassName(g.autosizesClass),t("resize",U)},checkElems:U,updateElem:F}),D=function(){D.i||(D.i=!0,k._(),P._())};var T,H,F,U;var I,J,O,G,$,q,j,V,X,Y,K,Z,ee,te,ae,ie,ne,re,oe,se,le,de,ce,ue,fe,Ae,ze,ge,he,ve,pe,ye,me,be,we,Ce,_e;return z={cfg:g,autoSizer:k,loader:P,init:D,uP:C,aC:y,rC:m,hC:c,fire:w,gW:E,rAF:W}}(e,e.document);e.lazySizes=a,"object"==typeof module&&module.exports&&(module.exports=a)}(window),lazysizesWebP("alpha",lazySizes.init),document.addEventListener("lazybeforeunveil",function(e){var t=e.target,a=t.getAttribute("data-srcset");if(!a&&t.naturalWidth&&1<t.naturalWidth&&1<t.naturalHeight){var i=window.devicePixelRatio||1,n=1.25*t.clientWidth<t.naturalWidth,r=1.25*t.clientHeight<t.naturalHeight;if(n||r){var o=Math.round(t.offsetWidth*i),s=Math.round(t.offsetHeight*i),l=t.getAttribute("data-src"),d=t.getAttribute("data-src-webp");ewww_webp_supported&&d&&-1==l.search("webp=1")&&(l=d);var c=constrainSrc(l,o,s);c&&l!=c&&t.setAttribute("data-src",c)}}if(ewww_webp_supported){if(a&&-1<a.search("webp=1"))return;if(a){var u=t.getAttribute("data-srcset-webp");u&&t.setAttribute("data-srcset",u)}if((l=t.getAttribute("data-src"))&&-1<l.search("webp=1"))return;if(!(d=t.getAttribute("data-src-webp")))return;t.setAttribute("data-src",d)}}),function(e,t){var a=function(){t(e.lazySizes),e.removeEventListener("lazyunveilread",a,!0)};t=t.bind(null,e,e.document),"object"==typeof module&&module.exports?t(require("lazysizes")):e.lazySizes?a():e.addEventListener("lazyunveilread",a,!0)}(window,function(s,i,l){"use strict";var d,c;i.addEventListener&&(d=function(e,t){var a=i.createElement("img");a.onload=function(){a.onload=null,a.onerror=null,a=null,t()},a.onerror=a.onload,a.src=e,a&&a.complete&&a.onload&&a.onload()},addEventListener("lazybeforeunveil",function(e){var t,a,i;if(e.detail.instance==l&&!e.defaultPrevented){if("none"==e.target.preload&&(e.target.preload="auto"),t=e.target.getAttribute("data-bg")){ewww_webp_supported&&(a=e.target.getAttribute("data-bg-webp"))&&(t=a);var n=s.devicePixelRatio||1,r=Math.round(e.target.offsetWidth*n),o=Math.round(e.target.offsetHeight*n);t=constrainSrc(t,r,o),e.detail.firesLoad=!0,d(t,function(){e.target.style.backgroundImage="url("+(c.test(t)?JSON.stringify(t):t)+")",e.detail.firesLoad=!1,l.fire(e.target,"_lazyloaded",{},!0,!0)})}(i=e.target.getAttribute("data-poster"))&&(e.detail.firesLoad=!0,d(i,function(){e.target.poster=i,e.detail.firesLoad=!1,l.fire(e.target,"_lazyloaded",{},!0,!0)}))}},!(c=/\(|\)|\s|'/)))});
mwebp.php CHANGED
@@ -81,7 +81,7 @@ function ewww_image_optimizer_webp_scan() {
81
  function ewww_image_optimizer_webp_script( $hook ) {
82
  ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
83
  // Make sure we are being called from the migration page.
84
- if ( 'admin_page_ewww-image-optimizer-webp-migrate' != $hook ) {
85
  return;
86
  }
87
  $images = ewww_image_optimizer_webp_scan();
81
  function ewww_image_optimizer_webp_script( $hook ) {
82
  ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
83
  // Make sure we are being called from the migration page.
84
+ if ( 'admin_page_ewww-image-optimizer-webp-migrate' !== $hook ) {
85
  return;
86
  }
87
  $images = ewww_image_optimizer_webp_scan();
readme.txt CHANGED
@@ -3,9 +3,9 @@ Contributors: nosilver4u
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=MKMQKCBFFG3WW
4
  Tags: image, compress, resize, optimize, optimization, lossless, lossy, seo, webp, wp-cli, scale, tinypng, tinyjpg
5
  Requires at least: 4.9
6
- Tested up to: 5.1
7
  Requires PHP: 5.6
8
- Stable tag: 4.7.2
9
  License: GPLv3
10
 
11
  Speed up your website and improve your visitors' experience by automatically compressing and resizing images and PDFs. Boost SEO and improve sales.
@@ -174,6 +174,17 @@ http://developer.yahoo.com/performance/rules.html#opt_images
174
  * Feature requests can be viewed and submitted at https://github.com/nosilver4u/ewww-image-optimizer/labels/enhancement
175
  * If you would like to help translate this plugin in your language, get started here: https://translate.wordpress.org/projects/wp-plugins/ewww-image-optimizer/
176
 
 
 
 
 
 
 
 
 
 
 
 
177
  = 4.7.2 =
178
  * changed: JS WebP no longer necessary with ExactDN
179
  * fixed: fatal error from NextGEN get_image_sizes() method
@@ -216,35 +227,6 @@ http://developer.yahoo.com/performance/rules.html#opt_images
216
  * fixed: animated GIF resizing breaks the use of image_resize_dimensions filter in WP_Image_Editor_GD
217
  * fixed: NextGen bulk optimizer unable to decode meta_data
218
 
219
- = 4.6.3 =
220
- * changed: folders to ignore setting applies to resizing also
221
- * fixed: lazy load placeholders have inconsistent URLs with ExactDN
222
- * fixed: bulk resume indicator gets stuck
223
- * fixed: bulk scanning queue gets out of sync and skips images
224
- * fixed: async processing does not handle memory limit specified in G (gigabytes)
225
-
226
- = 4.6.2 =
227
- * changed: API key may be defined as EWWW_IMAGE_OPTIMIZER_CLOUD_KEY
228
- * fixed: if img tag is missing dimensions, ExactDN sometimes loads original rather than existing thumbnail
229
- * fixed: TinyPNG/TinyJPG images skipped when Force Re-optimize is checked
230
-
231
- = 4.6.1 =
232
- * added: automatic configuration for ExactDN + WP Offload Media
233
- * fixed: bulk action from media library skipping last attachment in selection
234
- * fixed: uninstall function throws fatal error preventing deletion
235
-
236
- = 4.6.0 =
237
- * added: preserve animations in GIF images during resize operations for sites using Imagick extension
238
- * changed: EXACTDN_EXCLUDE applies to all resources, including images, CSS, JS, fonts, etc.
239
- * changed: API/ExactDN preserves color profiles, even when removing image metadata
240
- * changed: new queue table for bulk optimizer to avoid exceeding max packet size for MySQL
241
- * changed: unit tests run on PHP 7.3 also
242
- * fixed: too many settings updates when trying to prevent slow queries
243
- * fixed: ExactDN rewrites urls to static HTML files
244
- * fixed: ExactDN skips 1x url in some cases, causing browser upscaling
245
- * fixed: PHP notice when EXACTDN_EXCLUDE is defined
246
- * fixed: race condition in Alt WebP prevents Webp derivatives from replacing the originals
247
-
248
  = Earlier versions =
249
  Please refer to the separate changelog.txt file.
250
 
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=MKMQKCBFFG3WW
4
  Tags: image, compress, resize, optimize, optimization, lossless, lossy, seo, webp, wp-cli, scale, tinypng, tinyjpg
5
  Requires at least: 4.9
6
+ Tested up to: 5.2
7
  Requires PHP: 5.6
8
+ Stable tag: 4.7.3
9
  License: GPLv3
10
 
11
  Speed up your website and improve your visitors' experience by automatically compressing and resizing images and PDFs. Boost SEO and improve sales.
174
  * Feature requests can be viewed and submitted at https://github.com/nosilver4u/ewww-image-optimizer/labels/enhancement
175
  * If you would like to help translate this plugin in your language, get started here: https://translate.wordpress.org/projects/wp-plugins/ewww-image-optimizer/
176
 
177
+ = 4.7.3 =
178
+ * added: disable WebP script block on certain pages by defining EWWW_IMAGE_OPTIMIZER_NO_JS as true
179
+ * changed: use SVG inline image placeholder if width and height are known when LQIP is disabled or ExactDN is not available
180
+ * changed: Lazy Load ignores images using browser-native loading attribute
181
+ * fixed: page parsers (ExactDN, Lazy, JS WebP) do not properly handle attributes that start on a new line
182
+ * fixed: page parsers do not recognize img elements with unquoted attributes
183
+ * fixed: uninstaller cannot clear queue table due to undefined table name
184
+ * fixed: implode throws notice when image sizes array is multi-dimensional
185
+ * fixed: srcset url replaced incorrectly when using pixel density descriptors
186
+ * fixed: srcset url added with 0 width when width attribute is empty
187
+
188
  = 4.7.2 =
189
  * changed: JS WebP no longer necessary with ExactDN
190
  * fixed: fatal error from NextGEN get_image_sizes() method
227
  * fixed: animated GIF resizing breaks the use of image_resize_dimensions filter in WP_Image_Editor_GD
228
  * fixed: NextGen bulk optimizer unable to decode meta_data
229
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
230
  = Earlier versions =
231
  Please refer to the separate changelog.txt file.
232
 
uninstall.php CHANGED
@@ -33,6 +33,7 @@ if ( current_user_can( 'delete_plugins' ) ) {
33
  insert_with_markers( ewww_image_optimizer_htaccess_path(), 'EWWWIO', '' );
34
  }
35
  global $wpdb;
 
36
  $wpdb->query( $wpdb->prepare( "DELETE from $wpdb->ewwwio_queue WHERE gallery = %s", 'media' ) );
37
  $wpdb->query( $wpdb->prepare( "DELETE from $wpdb->ewwwio_queue WHERE gallery = %s", 'flag' ) );
38
  $wpdb->query( $wpdb->prepare( "DELETE from $wpdb->ewwwio_queue WHERE gallery = %s", 'nextgen' ) );
33
  insert_with_markers( ewww_image_optimizer_htaccess_path(), 'EWWWIO', '' );
34
  }
35
  global $wpdb;
36
+ $wpdb->ewwwio_queue = $wpdb->prefix . 'ewwwio_queue';
37
  $wpdb->query( $wpdb->prepare( "DELETE from $wpdb->ewwwio_queue WHERE gallery = %s", 'media' ) );
38
  $wpdb->query( $wpdb->prepare( "DELETE from $wpdb->ewwwio_queue WHERE gallery = %s", 'flag' ) );
39
  $wpdb->query( $wpdb->prepare( "DELETE from $wpdb->ewwwio_queue WHERE gallery = %s", 'nextgen' ) );
unique.php CHANGED
@@ -71,7 +71,7 @@ function ewww_image_optimizer_exec_init() {
71
  ewwwio_debug_message( 'wp.com/pantheon site, disabling tools' );
72
  ewww_image_optimizer_disable_tools();
73
  // Check if this is an unsupported OS (not Linux or Mac OSX or FreeBSD or Windows or SunOS).
74
- } elseif ( 'Linux' != PHP_OS && 'Darwin' != PHP_OS && 'FreeBSD' != PHP_OS && 'WINNT' != PHP_OS && 'SunOS' != PHP_OS ) {
75
  // Call the function to display a notice.
76
  add_action( 'network_admin_notices', 'ewww_image_optimizer_notice_os' );
77
  add_action( 'admin_notices', 'ewww_image_optimizer_notice_os' );
@@ -191,7 +191,7 @@ function ewww_image_optimizer_notice_os() {
191
  function ewww_image_optimizer_install_paths() {
192
  ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
193
  $tool_path = trailingslashit( EWWW_IMAGE_OPTIMIZER_TOOL_PATH );
194
- if ( PHP_OS == 'WINNT' ) {
195
  $gifsicle_src = EWWW_IMAGE_OPTIMIZER_BINARY_PATH . 'gifsicle.exe';
196
  $optipng_src = EWWW_IMAGE_OPTIMIZER_BINARY_PATH . 'optipng.exe';
197
  $jpegtran_src = EWWW_IMAGE_OPTIMIZER_BINARY_PATH . 'jpegtran.exe';
@@ -203,7 +203,7 @@ function ewww_image_optimizer_install_paths() {
203
  $pngquant_dst = $tool_path . 'pngquant.exe';
204
  $webp_dst = $tool_path . 'cwebp.exe';
205
  }
206
- if ( PHP_OS == 'Darwin' ) {
207
  $gifsicle_src = EWWW_IMAGE_OPTIMIZER_BINARY_PATH . 'gifsicle-mac';
208
  $optipng_src = EWWW_IMAGE_OPTIMIZER_BINARY_PATH . 'optipng-mac';
209
  $jpegtran_src = EWWW_IMAGE_OPTIMIZER_BINARY_PATH . 'jpegtran-mac';
@@ -215,7 +215,7 @@ function ewww_image_optimizer_install_paths() {
215
  $pngquant_dst = $tool_path . 'pngquant';
216
  $webp_dst = $tool_path . 'cwebp';
217
  }
218
- if ( PHP_OS == 'SunOS' ) {
219
  $gifsicle_src = EWWW_IMAGE_OPTIMIZER_BINARY_PATH . 'gifsicle-sol';
220
  $optipng_src = EWWW_IMAGE_OPTIMIZER_BINARY_PATH . 'optipng-sol';
221
  $jpegtran_src = EWWW_IMAGE_OPTIMIZER_BINARY_PATH . 'jpegtran-sol';
@@ -227,7 +227,7 @@ function ewww_image_optimizer_install_paths() {
227
  $pngquant_dst = $tool_path . 'pngquant';
228
  $webp_dst = $tool_path . 'cwebp';
229
  }
230
- if ( PHP_OS == 'FreeBSD' ) {
231
  if ( ewww_image_optimizer_function_exists( 'php_uname' ) ) {
232
  $arch_type = php_uname( 'm' );
233
  ewwwio_debug_message( "CPU architecture: $arch_type" );
@@ -245,7 +245,7 @@ function ewww_image_optimizer_install_paths() {
245
  $pngquant_dst = $tool_path . 'pngquant';
246
  $webp_dst = $tool_path . 'cwebp';
247
  }
248
- if ( PHP_OS == 'Linux' ) {
249
  if ( ewww_image_optimizer_function_exists( 'php_uname' ) ) {
250
  $arch_type = php_uname( 'm' );
251
  ewwwio_debug_message( "CPU architecture: $arch_type" );
@@ -366,35 +366,35 @@ function ewww_image_optimizer_install_tools() {
366
  }
367
  list ( $jpegtran_src, $optipng_src, $gifsicle_src, $pngquant_src, $webp_src, $jpegtran_dst, $optipng_dst, $gifsicle_dst, $pngquant_dst, $webp_dst ) = ewww_image_optimizer_install_paths();
368
  $skip = ewww_image_optimizer_skip_tools();
369
- if ( ! $skip['jpegtran'] && ( ! file_exists( $jpegtran_dst ) || filesize( $jpegtran_dst ) != filesize( $jpegtran_src ) ) ) {
370
  ewwwio_debug_message( 'jpegtran not found or different size, installing' );
371
  if ( ! copy( $jpegtran_src, $jpegtran_dst ) ) {
372
  $toolfail = true;
373
  ewwwio_debug_message( 'could not copy jpegtran' );
374
  }
375
  }
376
- if ( ! $skip['gifsicle'] && ( ! file_exists( $gifsicle_dst ) || filesize( $gifsicle_dst ) != filesize( $gifsicle_src ) ) ) {
377
  ewwwio_debug_message( 'gifsicle not found or different size, installing' );
378
  if ( ! copy( $gifsicle_src, $gifsicle_dst ) ) {
379
  $toolfail = true;
380
  ewwwio_debug_message( 'could not copy gifsicle' );
381
  }
382
  }
383
- if ( ! $skip['optipng'] && ( ! file_exists( $optipng_dst ) || filesize( $optipng_dst ) != filesize( $optipng_src ) ) ) {
384
  ewwwio_debug_message( 'optipng not found or different size, installing' );
385
  if ( ! copy( $optipng_src, $optipng_dst ) ) {
386
  $toolfail = true;
387
  ewwwio_debug_message( 'could not copy optipng' );
388
  }
389
  }
390
- if ( ! $skip['pngquant'] && ( ! file_exists( $pngquant_dst ) || filesize( $pngquant_dst ) != filesize( $pngquant_src ) ) ) {
391
  ewwwio_debug_message( 'pngquant not found or different size, installing' );
392
  if ( ! copy( $pngquant_src, $pngquant_dst ) ) {
393
  $toolfail = true;
394
  ewwwio_debug_message( 'could not copy pngquant' );
395
  }
396
  }
397
- if ( ! $skip['webp'] && ( ! file_exists( $webp_dst ) || filesize( $webp_dst ) != filesize( $webp_src ) ) ) {
398
  ewwwio_debug_message( 'webp not found or different size, installing' );
399
  if ( ! copy( $webp_src, $webp_dst ) ) {
400
  $toolfail = true;
@@ -402,10 +402,10 @@ function ewww_image_optimizer_install_tools() {
402
  }
403
  }
404
  // Install special version of cwebp for Mac OSX 10.8 systems.
405
- if ( PHP_OS == 'Darwin' && ! $skip['webp'] ) {
406
  $webp8_dst = $webp_dst . '-alt';
407
  $webp8_src = str_replace( 'mac9', 'mac8', $webp_src );
408
- if ( ! file_exists( $webp8_dst ) || ( ewww_image_optimizer_md5check( $webp8_dst ) && filesize( $webp8_dst ) != filesize( $webp8_src ) ) ) {
409
  ewwwio_debug_message( "copying $webp8_src to $webp8_dst" );
410
  if ( ! copy( $webp8_src, $webp8_dst ) ) {
411
  // This isn't a fatal error, besides we'll see it in the debug if needed.
@@ -419,7 +419,7 @@ function ewww_image_optimizer_install_tools() {
419
  }
420
  }
421
 
422
- if ( PHP_OS != 'WINNT' && ! $toolfail ) {
423
  ewwwio_debug_message( 'Linux/UNIX style OS, checking permissions' );
424
  if ( ! $skip['jpegtran'] && ! ewww_image_optimizer_check_permissions( $jpegtran_dst, 'rwxr-xr-x' ) ) {
425
  if ( ! is_writable( $jpegtran_dst ) || ! chmod( $jpegtran_dst, 0755 ) ) {
@@ -483,19 +483,19 @@ function ewww_image_optimizer_skip_tools() {
483
  $skip['pngquant'] = true;
484
  $skip['webp'] = true;
485
  // If the user has disabled a tool, we aren't going to bother checking to see if it is there.
486
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) == 0 || ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) > 10 ) {
487
  $skip['jpegtran'] = true;
488
  }
489
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) == 0 || ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_cloud_key' ) && ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) > 10 ) ) {
490
  $skip['optipng'] = true;
491
  }
492
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_gif_level' ) == 0 || ewww_image_optimizer_get_option( 'ewww_image_optimizer_cloud_key' ) ) {
493
  $skip['gifsicle'] = true;
494
  }
495
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_disable_pngout' ) || ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) == 0 || ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_cloud_key' ) && ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) > 10 ) ) {
496
  $skip['pngout'] = true;
497
  }
498
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) == 40 && ! ewww_image_optimizer_get_option( 'ewww_image_optimizer_cloud_key' ) ) {
499
  $skip['pngquant'] = false;
500
  }
501
  if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_webp' ) && ! ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_cloud_key' ) && ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) > 10 && ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) > 10 ) ) {
@@ -553,7 +553,7 @@ function ewww_image_optimizer_notice_utils( $quiet = null ) {
553
  // Check if exec is disabled.
554
  if ( ewww_image_optimizer_exec_check() ) {
555
  $no_compression = false;
556
- if ( 0 == ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) && 0 == ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) && 0 == ewww_image_optimizer_get_option( 'ewww_image_optimizer_gif_level' ) ) {
557
  $no_compression = true;
558
  }
559
  // Need to be a little particular with the quiet parameter.
@@ -729,7 +729,7 @@ function ewww_image_optimizer_path_check( $j = true, $o = true, $g = true, $p =
729
  'CWEBP' => false,
730
  );
731
  }
732
- if ( 'WINNT' == PHP_OS ) {
733
  if ( $j ) {
734
  if ( ! defined( 'EWWW_IMAGE_OPTIMIZER_JPEGTRAN' ) ) {
735
  $jpegtran = ewww_image_optimizer_find_win_binary( 'jpegtran', 'j' );
@@ -1581,7 +1581,7 @@ function ewww_image_optimizer_gifsicle_resize( $file, $dst_x, $dst_y, $src_x, $s
1581
 
1582
  $outfile = "$file.tmp";
1583
  // Run gifsicle.
1584
- if ( $orig_w != $src_w || $orig_h != $src_h ) {
1585
  $dim_string = $dst_w . 'x' . $dst_h;
1586
  $crop_string = $src_x . ',' . $src_y . '+' . $src_w . 'x' . $src_h;
1587
  ewwwio_debug_message( "resize to $dim_string" );
@@ -1603,7 +1603,7 @@ function ewww_image_optimizer_gifsicle_resize( $file, $dst_x, $dst_y, $src_x, $s
1603
  return new WP_Error( 'image_resize_error', 'file does not exist' );
1604
  }
1605
 
1606
- if ( 0 == $new_size || 'image/gif' != $new_type ) {
1607
  unlink( $outfile );
1608
  return new WP_Error( 'image_resize_error', 'wrong type or zero bytes' );
1609
  }
@@ -1624,11 +1624,11 @@ function ewww_image_optimizer_gifsicle_resize( $file, $dst_x, $dst_y, $src_x, $s
1624
  */
1625
  function ewww_image_optimizer_jpegtran_autorotate( $file, $type, $orientation ) {
1626
  ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
1627
- if ( 'image/jpeg' != $type ) {
1628
  ewwwio_debug_message( 'not a JPG, go away!' );
1629
  return false;
1630
  }
1631
- if ( ! $orientation || 1 == $orientation ) {
1632
  return false;
1633
  }
1634
  if ( ! defined( 'EWWW_IMAGE_OPTIMIZER_CLOUD' ) || ! EWWW_IMAGE_OPTIMIZER_CLOUD ) {
@@ -1692,7 +1692,7 @@ function ewww_image_optimizer_jpegtran_autorotate( $file, $type, $orientation )
1692
  return false;
1693
  }
1694
 
1695
- if ( 0 == $new_size || 'image/jpeg' != $new_type ) {
1696
  unlink( $outfile );
1697
  return false;
1698
  }
@@ -1796,7 +1796,7 @@ function ewww_image_optimizer( $file, $gallery_type = 4, $converted = false, $ne
1796
  ewww_image_optimizer_s3_uploads_image_cleanup( $file );
1797
  return array( false, __( 'Unsupported file type', 'ewww-image-optimizer' ) . ": $type", $converted, $original );
1798
  }
1799
- if ( ! is_object( $ewww_image ) || ! $ewww_image instanceof EWWW_Image || $ewww_image->file != $file ) {
1800
  $ewww_image = new EWWW_Image( 0, '', $file );
1801
  }
1802
  if ( ! EWWW_IMAGE_OPTIMIZER_CLOUD ) {
@@ -1860,7 +1860,7 @@ function ewww_image_optimizer( $file, $gallery_type = 4, $converted = false, $ne
1860
  // Tell the user optimization was skipped.
1861
  return array( false, __( 'Optimization skipped', 'ewww-image-optimizer' ), $converted, $file );
1862
  }
1863
- if ( 'image/png' == $type && ewww_image_optimizer_get_option( 'ewww_image_optimizer_skip_png_size' ) && $orig_size > ewww_image_optimizer_get_option( 'ewww_image_optimizer_skip_png_size' ) ) {
1864
  ewwwio_debug_message( "optimization bypassed due to filesize: $file" );
1865
  ewww_image_optimizer_s3_uploads_image_cleanup( $file );
1866
  // Tell the user optimization was skipped.
@@ -1879,7 +1879,7 @@ function ewww_image_optimizer( $file, $gallery_type = 4, $converted = false, $ne
1879
  case 'image/jpeg':
1880
  $png_size = 0;
1881
  // If jpg2png conversion is enabled, and this image is in the WordPress media library.
1882
- if ( ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_to_png' ) && 1 == $gallery_type ) || ! empty( $_REQUEST['ewww_convert'] ) ) {
1883
  // Generate the filename for a PNG:
1884
  // If this is a resize version.
1885
  if ( $converted ) {
@@ -1908,14 +1908,14 @@ function ewww_image_optimizer( $file, $gallery_type = 4, $converted = false, $ne
1908
  list( $file, $converted, $result, $new_size, $backup_hash ) = ewww_image_optimizer_cloud_optimizer( $file, $type, $convert, $pngfile, 'image/png', $skip_lossy );
1909
  if ( $converted ) {
1910
  // Check to see if the user wants the originals deleted.
1911
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_delete_originals' ) == true ) {
1912
  // Delete the original JPG.
1913
  unlink( $original );
1914
  }
1915
  $converted = $filenum;
1916
- ewww_image_optimizer_webp_create( $file, $new_size, 'image/png', null, $orig_size != $new_size );
1917
  } else {
1918
- ewww_image_optimizer_webp_create( $file, $new_size, $type, null, $orig_size != $new_size );
1919
  }
1920
  break;
1921
  }
@@ -1943,7 +1943,7 @@ function ewww_image_optimizer( $file, $gallery_type = 4, $converted = false, $ne
1943
  );
1944
  }
1945
  // If jpegtran optimization is disabled.
1946
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) == 0 ) {
1947
  // Store an appropriate message in $result.
1948
  $result = __( 'JPG optimization is disabled', 'ewww-image-optimizer' );
1949
  // Otherwise, if we aren't skipping the utility verification and jpegtran doesn't exist.
@@ -1979,7 +1979,7 @@ function ewww_image_optimizer( $file, $gallery_type = 4, $converted = false, $ne
1979
  $new_size = ewww_image_optimizer_filesize( $progfile );
1980
  ewwwio_debug_message( "optimized JPG size: $new_size" );
1981
  // If the best-optimized is smaller than the original JPG, and we didn't create an empty JPG.
1982
- if ( $orig_size > $new_size && 0 != $new_size && ewww_image_optimizer_mimetype( $progfile, 'i' ) == $type ) {
1983
  // Replace the original with the optimized file.
1984
  rename( $progfile, $file );
1985
  // Store the results of the optimization.
@@ -2034,7 +2034,7 @@ function ewww_image_optimizer( $file, $gallery_type = 4, $converted = false, $ne
2034
  $png_size = ewww_image_optimizer_filesize( $pngfile );
2035
  }
2036
  // If lossy optimization is ON and full-size exclusion is not active.
2037
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) == 40 && $tools['PNGQUANT'] && ! $skip_lossy ) {
2038
  ewwwio_debug_message( 'attempting lossy reduction' );
2039
  exec( "$nice " . $tools['PNGQUANT'] . ' ' . ewww_image_optimizer_escapeshellarg( $pngfile ) );
2040
  $quantfile = preg_replace( '/\.\w+$/', '-fs8.png', $pngfile );
@@ -2078,12 +2078,12 @@ function ewww_image_optimizer( $file, $gallery_type = 4, $converted = false, $ne
2078
  $png_size = ewww_image_optimizer_filesize( $pngfile );
2079
  ewwwio_debug_message( "converted PNG size: $png_size" );
2080
  // If the PNG is smaller than the original JPG, and we didn't end up with an empty file.
2081
- if ( $new_size > $png_size && 0 != $png_size && ewww_image_optimizer_mimetype( $pngfile, 'i' ) == 'image/png' ) {
2082
  ewwwio_debug_message( "converted PNG is better: $png_size vs. $new_size" );
2083
  // Store the size of the converted PNG.
2084
  $new_size = $png_size;
2085
  // Check to see if the user wants the originals deleted.
2086
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_delete_originals' ) == true ) {
2087
  // Delete the original JPG.
2088
  unlink( $file );
2089
  }
@@ -2102,14 +2102,14 @@ function ewww_image_optimizer( $file, $gallery_type = 4, $converted = false, $ne
2102
  }
2103
  }
2104
  } // End if().
2105
- ewww_image_optimizer_webp_create( $file, $new_size, $type, $tools['CWEBP'], $orig_size != $new_size );
2106
  break;
2107
  case 'image/png':
2108
  $jpg_size = 0;
2109
  // Png2jpg conversion is turned on, and the image is in the WordPress media library.
2110
  // We check for transparency later, after optimization, because optipng might fix an empty alpha channel.
2111
  if ( ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_to_jpg' ) || ! empty( $_REQUEST['ewww_convert'] ) )
2112
- && 1 == $gallery_type && ! $skip_lossy ) {
2113
  ewwwio_debug_message( 'PNG to JPG conversion turned on' );
2114
  $cloud_background = '';
2115
  $r = '';
@@ -2170,14 +2170,14 @@ function ewww_image_optimizer( $file, $gallery_type = 4, $converted = false, $ne
2170
  );
2171
  if ( $converted ) {
2172
  // Check to see if the user wants the originals deleted.
2173
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_delete_originals' ) == true ) {
2174
  // Delete the original JPG.
2175
  unlink( $original );
2176
  }
2177
  $converted = $filenum;
2178
- ewww_image_optimizer_webp_create( $file, $new_size, 'image/jpeg', null, $orig_size != $new_size );
2179
  } else {
2180
- ewww_image_optimizer_webp_create( $file, $new_size, $type, null, $orig_size != $new_size );
2181
  }
2182
  break;
2183
  }
@@ -2201,7 +2201,7 @@ function ewww_image_optimizer( $file, $gallery_type = 4, $converted = false, $ne
2201
  );
2202
  }
2203
  // If png optimization is disabled.
2204
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) == 0 ) {
2205
  // Tell the user all PNG tools are disabled.
2206
  $result = __( 'PNG optimization is disabled', 'ewww-image-optimizer' );
2207
  // If the utility checking is on, optipng is enabled, but optipng cannot be found.
@@ -2219,11 +2219,11 @@ function ewww_image_optimizer( $file, $gallery_type = 4, $converted = false, $ne
2219
  // If optimization is turned on.
2220
  if ( $optimize ) {
2221
  // If lossy optimization is ON and full-size exclusion is not active.
2222
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) == 40 && $tools['PNGQUANT'] && ! $skip_lossy ) {
2223
  ewwwio_debug_message( 'attempting lossy reduction' );
2224
  exec( "$nice " . $tools['PNGQUANT'] . ' ' . ewww_image_optimizer_escapeshellarg( $file ) );
2225
  $quantfile = preg_replace( '/\.\w+$/', '-fs8.png', $file );
2226
- if ( is_file( $quantfile ) && filesize( $file ) > filesize( $quantfile ) && ewww_image_optimizer_mimetype( $quantfile, 'i' ) == $type ) {
2227
  ewwwio_debug_message( 'lossy reduction is better: original - ' . filesize( $file ) . ' vs. lossy - ' . filesize( $quantfile ) );
2228
  rename( $quantfile, $file );
2229
  } elseif ( is_file( $quantfile ) ) {
@@ -2257,7 +2257,7 @@ function ewww_image_optimizer( $file, $gallery_type = 4, $converted = false, $ne
2257
  // Retrieve the filesize of the temporary PNG.
2258
  $new_size = ewww_image_optimizer_filesize( $tempfile );
2259
  // If the new PNG is smaller.
2260
- if ( $orig_size > $new_size && 0 != $new_size && ewww_image_optimizer_mimetype( $tempfile, 'i' ) == $type ) {
2261
  // Replace the original with the optimized file.
2262
  rename( $tempfile, $file );
2263
  // Store the results of the optimization.
@@ -2358,7 +2358,7 @@ function ewww_image_optimizer( $file, $gallery_type = 4, $converted = false, $ne
2358
  ewwwio_debug_message( 'unable to convert to JPG' );
2359
  }
2360
  // Next we need to optimize that JPG if jpegtran is enabled.
2361
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) == 10 && file_exists( $jpgfile ) ) {
2362
  // Generate temporary file-name.
2363
  $progfile = $jpgfile . '.prog';
2364
  // Check to see if we are supposed to strip metadata.
@@ -2379,7 +2379,7 @@ function ewww_image_optimizer( $file, $gallery_type = 4, $converted = false, $ne
2379
  // Check the filesize of the new JPG.
2380
  $opt_jpg_size = ewww_image_optimizer_filesize( $progfile );
2381
  // If the best-optimized is smaller than the original JPG, and we didn't create an empty JPG.
2382
- if ( $jpg_size > $opt_jpg_size && 0 != $opt_jpg_size ) {
2383
  // Replace the original with the optimized file.
2384
  rename( $progfile, $jpgfile );
2385
  // Store the size of the optimized JPG.
@@ -2392,11 +2392,11 @@ function ewww_image_optimizer( $file, $gallery_type = 4, $converted = false, $ne
2392
  }
2393
  ewwwio_debug_message( "converted JPG size: $jpg_size" );
2394
  // If the new JPG is smaller than the original PNG.
2395
- if ( $new_size > $jpg_size && 0 != $jpg_size && ewww_image_optimizer_mimetype( $jpgfile, 'i' ) == 'image/jpeg' ) {
2396
  // Store the size of the JPG as the new filesize.
2397
  $new_size = $jpg_size;
2398
  // If the user wants originals delted after a conversion.
2399
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_delete_originals' ) == true ) {
2400
  // Delete the original PNG.
2401
  unlink( $file );
2402
  }
@@ -2414,12 +2414,12 @@ function ewww_image_optimizer( $file, $gallery_type = 4, $converted = false, $ne
2414
  }
2415
  }
2416
  } // End if().
2417
- ewww_image_optimizer_webp_create( $file, $new_size, $type, $tools['CWEBP'], $orig_size != $new_size );
2418
  break;
2419
  case 'image/gif':
2420
  // If gif2png is turned on, and the image is in the WordPress media library.
2421
  if ( ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_gif_to_png' ) || ! empty( $_REQUEST['ewww_convert'] ) )
2422
- && 1 == $gallery_type && ! ewww_image_optimizer_is_animated( $file ) ) {
2423
  // Generate the filename for a PNG:
2424
  // if this is a resize version...
2425
  if ( $converted ) {
@@ -2444,16 +2444,16 @@ function ewww_image_optimizer( $file, $gallery_type = 4, $converted = false, $ne
2444
  }
2445
  }
2446
  $ewww_image->level = (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_gif_level' );
2447
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_cloud_key' ) && ewww_image_optimizer_get_option( 'ewww_image_optimizer_gif_level' ) == 10 ) {
2448
  list( $file, $converted, $result, $new_size, $backup_hash ) = ewww_image_optimizer_cloud_optimizer( $file, $type, $convert, $pngfile, 'image/png', $skip_lossy );
2449
  if ( $converted ) {
2450
  // Check to see if the user wants the originals deleted.
2451
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_delete_originals' ) == true ) {
2452
  // Delete the original GIF.
2453
  unlink( $original );
2454
  }
2455
  $converted = $filenum;
2456
- ewww_image_optimizer_webp_create( $file, $new_size, 'image/png', null, $orig_size != $new_size );
2457
  }
2458
  break;
2459
  }
@@ -2477,7 +2477,7 @@ function ewww_image_optimizer( $file, $gallery_type = 4, $converted = false, $ne
2477
  );
2478
  }
2479
  // If gifsicle is disabled.
2480
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_gif_level' ) == 0 ) {
2481
  $result = __( 'GIF optimization is disabled', 'ewww-image-optimizer' );
2482
  // If utility checking is on, and gifsicle is not installed.
2483
  } elseif ( ! $skip['gifsicle'] && ! $tools['GIFSICLE'] ) {
@@ -2495,7 +2495,7 @@ function ewww_image_optimizer( $file, $gallery_type = 4, $converted = false, $ne
2495
  // Retrieve the filesize of the temporary GIF.
2496
  $new_size = ewww_image_optimizer_filesize( $tempfile );
2497
  // If the new GIF is smaller.
2498
- if ( $orig_size > $new_size && 0 != $new_size && ewww_image_optimizer_mimetype( $tempfile, 'i' ) == $type ) {
2499
  // Replace the original with the optimized file.
2500
  rename( $tempfile, $file );
2501
  // Store the results of the optimization.
@@ -2549,11 +2549,11 @@ function ewww_image_optimizer( $file, $gallery_type = 4, $converted = false, $ne
2549
  // Retrieve the filesize of the PNG.
2550
  $png_size = ewww_image_optimizer_filesize( $pngfile );
2551
  // If the new PNG is smaller than the original GIF.
2552
- if ( $new_size > $png_size && 0 != $png_size && ewww_image_optimizer_mimetype( $pngfile, 'i' ) == 'image/png' ) {
2553
  // Store the PNG size as the new filesize.
2554
  $new_size = $png_size;
2555
  // If the user wants original GIFs deleted after successful conversion.
2556
- if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_delete_originals' ) == true ) {
2557
  // Delete the original GIF.
2558
  unlink( $file );
2559
  }
@@ -2562,7 +2562,7 @@ function ewww_image_optimizer( $file, $gallery_type = 4, $converted = false, $ne
2562
  // Let webp know what we're dealing with now.
2563
  $type = 'image/png';
2564
  // Normally this would be at the end of the section, but we only want to do webp if the image was successfully converted to a png.
2565
- ewww_image_optimizer_webp_create( $file, $new_size, $type, $tools['CWEBP'], $orig_size != $new_size );
2566
  // Successful conversion, so we store the increment.
2567
  $converted = $filenum;
2568
  } else {
@@ -2595,7 +2595,7 @@ function ewww_image_optimizer( $file, $gallery_type = 4, $converted = false, $ne
2595
  // NOTE: it is recommended to do any image modifications prior to optimization, otherwise you risk un-optimizing your images here.
2596
  do_action( 'ewww_image_optimizer_post_optimization', $file, $type, $fullsize );
2597
  // If their cloud api license limit has been exceeded.
2598
- if ( 'exceeded' == $result ) {
2599
  ewww_image_optimizer_s3_uploads_image_cleanup( $file );
2600
  return array( false, __( 'License exceeded', 'ewww-image-optimizer' ), $converted, $original );
2601
  }
@@ -2706,16 +2706,16 @@ function ewww_image_optimizer_install_pngout() {
2706
  if ( ! extension_loaded( 'zlib' ) || ! class_exists( 'PharData' ) ) {
2707
  $pngout_error = __( 'zlib or phar extension missing from PHP', 'ewww-image-optimizer' );
2708
  }
2709
- if ( PHP_OS == 'Linux' ) {
2710
  $os_string = 'linux';
2711
  }
2712
- if ( PHP_OS == 'FreeBSD' ) {
2713
  $os_string = 'bsd';
2714
  }
2715
  $latest = '20150319';
2716
  $tool_path = trailingslashit( EWWW_IMAGE_OPTIMIZER_TOOL_PATH );
2717
  if ( empty( $pngout_error ) ) {
2718
- if ( PHP_OS == 'Linux' || PHP_OS == 'FreeBSD' ) {
2719
  $download_result = download_url( 'http://static.jonof.id.au/dl/kenutils/pngout-' . $latest . '-' . $os_string . '-static.tar.gz' );
2720
  if ( is_wp_error( $download_result ) ) {
2721
  $pngout_error = $download_result->get_error_message();
@@ -2760,7 +2760,7 @@ function ewww_image_optimizer_install_pngout() {
2760
  }
2761
  }
2762
  }
2763
- if ( PHP_OS == 'Darwin' ) {
2764
  $latest = '20150920';
2765
  $download_result = download_url( 'http://static.jonof.id.au/dl/kenutils/pngout-' . $latest . '-darwin.tar.gz' );
2766
  if ( is_wp_error( $download_result ) ) {
@@ -2801,7 +2801,7 @@ function ewww_image_optimizer_install_pngout() {
2801
  }
2802
  }
2803
  } // End if().
2804
- if ( PHP_OS == 'WINNT' ) {
2805
  $download_result = download_url( 'http://advsys.net/ken/util/pngout.exe' );
2806
  if ( is_wp_error( $download_result ) ) {
2807
  $pngout_error = $download_result->get_error_message();
71
  ewwwio_debug_message( 'wp.com/pantheon site, disabling tools' );
72
  ewww_image_optimizer_disable_tools();
73
  // Check if this is an unsupported OS (not Linux or Mac OSX or FreeBSD or Windows or SunOS).
74
+ } elseif ( 'Linux' !== PHP_OS && 'Darwin' !== PHP_OS && 'FreeBSD' !== PHP_OS && 'WINNT' !== PHP_OS && 'SunOS' !== PHP_OS ) {
75
  // Call the function to display a notice.
76
  add_action( 'network_admin_notices', 'ewww_image_optimizer_notice_os' );
77
  add_action( 'admin_notices', 'ewww_image_optimizer_notice_os' );
191
  function ewww_image_optimizer_install_paths() {
192
  ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
193
  $tool_path = trailingslashit( EWWW_IMAGE_OPTIMIZER_TOOL_PATH );
194
+ if ( PHP_OS === 'WINNT' ) {
195
  $gifsicle_src = EWWW_IMAGE_OPTIMIZER_BINARY_PATH . 'gifsicle.exe';
196
  $optipng_src = EWWW_IMAGE_OPTIMIZER_BINARY_PATH . 'optipng.exe';
197
  $jpegtran_src = EWWW_IMAGE_OPTIMIZER_BINARY_PATH . 'jpegtran.exe';
203
  $pngquant_dst = $tool_path . 'pngquant.exe';
204
  $webp_dst = $tool_path . 'cwebp.exe';
205
  }
206
+ if ( PHP_OS === 'Darwin' ) {
207
  $gifsicle_src = EWWW_IMAGE_OPTIMIZER_BINARY_PATH . 'gifsicle-mac';
208
  $optipng_src = EWWW_IMAGE_OPTIMIZER_BINARY_PATH . 'optipng-mac';
209
  $jpegtran_src = EWWW_IMAGE_OPTIMIZER_BINARY_PATH . 'jpegtran-mac';
215
  $pngquant_dst = $tool_path . 'pngquant';
216
  $webp_dst = $tool_path . 'cwebp';
217
  }
218
+ if ( PHP_OS === 'SunOS' ) {
219
  $gifsicle_src = EWWW_IMAGE_OPTIMIZER_BINARY_PATH . 'gifsicle-sol';
220
  $optipng_src = EWWW_IMAGE_OPTIMIZER_BINARY_PATH . 'optipng-sol';
221
  $jpegtran_src = EWWW_IMAGE_OPTIMIZER_BINARY_PATH . 'jpegtran-sol';
227
  $pngquant_dst = $tool_path . 'pngquant';
228
  $webp_dst = $tool_path . 'cwebp';
229
  }
230
+ if ( PHP_OS === 'FreeBSD' ) {
231
  if ( ewww_image_optimizer_function_exists( 'php_uname' ) ) {
232
  $arch_type = php_uname( 'm' );
233
  ewwwio_debug_message( "CPU architecture: $arch_type" );
245
  $pngquant_dst = $tool_path . 'pngquant';
246
  $webp_dst = $tool_path . 'cwebp';
247
  }
248
+ if ( PHP_OS === 'Linux' ) {
249
  if ( ewww_image_optimizer_function_exists( 'php_uname' ) ) {
250
  $arch_type = php_uname( 'm' );
251
  ewwwio_debug_message( "CPU architecture: $arch_type" );
366
  }
367
  list ( $jpegtran_src, $optipng_src, $gifsicle_src, $pngquant_src, $webp_src, $jpegtran_dst, $optipng_dst, $gifsicle_dst, $pngquant_dst, $webp_dst ) = ewww_image_optimizer_install_paths();
368
  $skip = ewww_image_optimizer_skip_tools();
369
+ if ( ! $skip['jpegtran'] && ( ! file_exists( $jpegtran_dst ) || filesize( $jpegtran_dst ) !== filesize( $jpegtran_src ) ) ) {
370
  ewwwio_debug_message( 'jpegtran not found or different size, installing' );
371
  if ( ! copy( $jpegtran_src, $jpegtran_dst ) ) {
372
  $toolfail = true;
373
  ewwwio_debug_message( 'could not copy jpegtran' );
374
  }
375
  }
376
+ if ( ! $skip['gifsicle'] && ( ! file_exists( $gifsicle_dst ) || filesize( $gifsicle_dst ) !== filesize( $gifsicle_src ) ) ) {
377
  ewwwio_debug_message( 'gifsicle not found or different size, installing' );
378
  if ( ! copy( $gifsicle_src, $gifsicle_dst ) ) {
379
  $toolfail = true;
380
  ewwwio_debug_message( 'could not copy gifsicle' );
381
  }
382
  }
383
+ if ( ! $skip['optipng'] && ( ! file_exists( $optipng_dst ) || filesize( $optipng_dst ) !== filesize( $optipng_src ) ) ) {
384
  ewwwio_debug_message( 'optipng not found or different size, installing' );
385
  if ( ! copy( $optipng_src, $optipng_dst ) ) {
386
  $toolfail = true;
387
  ewwwio_debug_message( 'could not copy optipng' );
388
  }
389
  }
390
+ if ( ! $skip['pngquant'] && ( ! file_exists( $pngquant_dst ) || filesize( $pngquant_dst ) !== filesize( $pngquant_src ) ) ) {
391
  ewwwio_debug_message( 'pngquant not found or different size, installing' );
392
  if ( ! copy( $pngquant_src, $pngquant_dst ) ) {
393
  $toolfail = true;
394
  ewwwio_debug_message( 'could not copy pngquant' );
395
  }
396
  }
397
+ if ( ! $skip['webp'] && ( ! file_exists( $webp_dst ) || filesize( $webp_dst ) !== filesize( $webp_src ) ) ) {
398
  ewwwio_debug_message( 'webp not found or different size, installing' );
399
  if ( ! copy( $webp_src, $webp_dst ) ) {
400
  $toolfail = true;
402
  }
403
  }
404
  // Install special version of cwebp for Mac OSX 10.8 systems.
405
+ if ( PHP_OS === 'Darwin' && ! $skip['webp'] ) {
406
  $webp8_dst = $webp_dst . '-alt';
407
  $webp8_src = str_replace( 'mac9', 'mac8', $webp_src );
408
+ if ( ! file_exists( $webp8_dst ) || ( ewww_image_optimizer_md5check( $webp8_dst ) && filesize( $webp8_dst ) !== filesize( $webp8_src ) ) ) {
409
  ewwwio_debug_message( "copying $webp8_src to $webp8_dst" );
410
  if ( ! copy( $webp8_src, $webp8_dst ) ) {
411
  // This isn't a fatal error, besides we'll see it in the debug if needed.
419
  }
420
  }
421
 
422
+ if ( PHP_OS !== 'WINNT' && ! $toolfail ) {
423
  ewwwio_debug_message( 'Linux/UNIX style OS, checking permissions' );
424
  if ( ! $skip['jpegtran'] && ! ewww_image_optimizer_check_permissions( $jpegtran_dst, 'rwxr-xr-x' ) ) {
425
  if ( ! is_writable( $jpegtran_dst ) || ! chmod( $jpegtran_dst, 0755 ) ) {
483
  $skip['pngquant'] = true;
484
  $skip['webp'] = true;
485
  // If the user has disabled a tool, we aren't going to bother checking to see if it is there.
486
+ if ( ! ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) || ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) > 10 ) {
487
  $skip['jpegtran'] = true;
488
  }
489
+ if ( ! ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) || ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_cloud_key' ) && ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) > 10 ) ) {
490
  $skip['optipng'] = true;
491
  }
492
+ if ( ! ewww_image_optimizer_get_option( 'ewww_image_optimizer_gif_level' ) || ewww_image_optimizer_get_option( 'ewww_image_optimizer_cloud_key' ) ) {
493
  $skip['gifsicle'] = true;
494
  }
495
+ if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_disable_pngout' ) || ! ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) || ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_cloud_key' ) && ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) > 10 ) ) {
496
  $skip['pngout'] = true;
497
  }
498
+ if ( 40 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) && ! ewww_image_optimizer_get_option( 'ewww_image_optimizer_cloud_key' ) ) {
499
  $skip['pngquant'] = false;
500
  }
501
  if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_webp' ) && ! ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_cloud_key' ) && ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) > 10 && ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) > 10 ) ) {
553
  // Check if exec is disabled.
554
  if ( ewww_image_optimizer_exec_check() ) {
555
  $no_compression = false;
556
+ if ( ! ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) && ! ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) && ! ewww_image_optimizer_get_option( 'ewww_image_optimizer_gif_level' ) ) {
557
  $no_compression = true;
558
  }
559
  // Need to be a little particular with the quiet parameter.
729
  'CWEBP' => false,
730
  );
731
  }
732
+ if ( 'WINNT' === PHP_OS ) {
733
  if ( $j ) {
734
  if ( ! defined( 'EWWW_IMAGE_OPTIMIZER_JPEGTRAN' ) ) {
735
  $jpegtran = ewww_image_optimizer_find_win_binary( 'jpegtran', 'j' );
1581
 
1582
  $outfile = "$file.tmp";
1583
  // Run gifsicle.
1584
+ if ( (int) $orig_w !== (int) $src_w || (int) $orig_h !== (int) $src_h ) {
1585
  $dim_string = $dst_w . 'x' . $dst_h;
1586
  $crop_string = $src_x . ',' . $src_y . '+' . $src_w . 'x' . $src_h;
1587
  ewwwio_debug_message( "resize to $dim_string" );
1603
  return new WP_Error( 'image_resize_error', 'file does not exist' );
1604
  }
1605
 
1606
+ if ( ! $new_size || 'image/gif' !== $new_type ) {
1607
  unlink( $outfile );
1608
  return new WP_Error( 'image_resize_error', 'wrong type or zero bytes' );
1609
  }
1624
  */
1625
  function ewww_image_optimizer_jpegtran_autorotate( $file, $type, $orientation ) {
1626
  ewwwio_debug_message( '<b>' . __FUNCTION__ . '()</b>' );
1627
+ if ( 'image/jpeg' !== $type ) {
1628
  ewwwio_debug_message( 'not a JPG, go away!' );
1629
  return false;
1630
  }
1631
+ if ( ! $orientation || 1 === (int) $orientation ) {
1632
  return false;
1633
  }
1634
  if ( ! defined( 'EWWW_IMAGE_OPTIMIZER_CLOUD' ) || ! EWWW_IMAGE_OPTIMIZER_CLOUD ) {
1692
  return false;
1693
  }
1694
 
1695
+ if ( ! $new_size || 'image/jpeg' !== $new_type ) {
1696
  unlink( $outfile );
1697
  return false;
1698
  }
1796
  ewww_image_optimizer_s3_uploads_image_cleanup( $file );
1797
  return array( false, __( 'Unsupported file type', 'ewww-image-optimizer' ) . ": $type", $converted, $original );
1798
  }
1799
+ if ( ! is_object( $ewww_image ) || ! $ewww_image instanceof EWWW_Image || $ewww_image->file !== $file ) {
1800
  $ewww_image = new EWWW_Image( 0, '', $file );
1801
  }
1802
  if ( ! EWWW_IMAGE_OPTIMIZER_CLOUD ) {
1860
  // Tell the user optimization was skipped.
1861
  return array( false, __( 'Optimization skipped', 'ewww-image-optimizer' ), $converted, $file );
1862
  }
1863
+ if ( 'image/png' === $type && ewww_image_optimizer_get_option( 'ewww_image_optimizer_skip_png_size' ) && $orig_size > ewww_image_optimizer_get_option( 'ewww_image_optimizer_skip_png_size' ) ) {
1864
  ewwwio_debug_message( "optimization bypassed due to filesize: $file" );
1865
  ewww_image_optimizer_s3_uploads_image_cleanup( $file );
1866
  // Tell the user optimization was skipped.
1879
  case 'image/jpeg':
1880
  $png_size = 0;
1881
  // If jpg2png conversion is enabled, and this image is in the WordPress media library.
1882
+ if ( ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_to_png' ) && 1 === (int) $gallery_type ) || ! empty( $_REQUEST['ewww_convert'] ) ) {
1883
  // Generate the filename for a PNG:
1884
  // If this is a resize version.
1885
  if ( $converted ) {
1908
  list( $file, $converted, $result, $new_size, $backup_hash ) = ewww_image_optimizer_cloud_optimizer( $file, $type, $convert, $pngfile, 'image/png', $skip_lossy );
1909
  if ( $converted ) {
1910
  // Check to see if the user wants the originals deleted.
1911
+ if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_delete_originals' ) ) {
1912
  // Delete the original JPG.
1913
  unlink( $original );
1914
  }
1915
  $converted = $filenum;
1916
+ ewww_image_optimizer_webp_create( $file, $new_size, 'image/png', null, $orig_size !== $new_size );
1917
  } else {
1918
+ ewww_image_optimizer_webp_create( $file, $new_size, $type, null, $orig_size !== $new_size );
1919
  }
1920
  break;
1921
  }
1943
  );
1944
  }
1945
  // If jpegtran optimization is disabled.
1946
+ if ( ! ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) ) {
1947
  // Store an appropriate message in $result.
1948
  $result = __( 'JPG optimization is disabled', 'ewww-image-optimizer' );
1949
  // Otherwise, if we aren't skipping the utility verification and jpegtran doesn't exist.
1979
  $new_size = ewww_image_optimizer_filesize( $progfile );
1980
  ewwwio_debug_message( "optimized JPG size: $new_size" );
1981
  // If the best-optimized is smaller than the original JPG, and we didn't create an empty JPG.
1982
+ if ( $new_size && $orig_size > $new_size && ewww_image_optimizer_mimetype( $progfile, 'i' ) === $type ) {
1983
  // Replace the original with the optimized file.
1984
  rename( $progfile, $file );
1985
  // Store the results of the optimization.
2034
  $png_size = ewww_image_optimizer_filesize( $pngfile );
2035
  }
2036
  // If lossy optimization is ON and full-size exclusion is not active.
2037
+ if ( 40 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) && $tools['PNGQUANT'] && ! $skip_lossy ) {
2038
  ewwwio_debug_message( 'attempting lossy reduction' );
2039
  exec( "$nice " . $tools['PNGQUANT'] . ' ' . ewww_image_optimizer_escapeshellarg( $pngfile ) );
2040
  $quantfile = preg_replace( '/\.\w+$/', '-fs8.png', $pngfile );
2078
  $png_size = ewww_image_optimizer_filesize( $pngfile );
2079
  ewwwio_debug_message( "converted PNG size: $png_size" );
2080
  // If the PNG is smaller than the original JPG, and we didn't end up with an empty file.
2081
+ if ( $png_size && $new_size > $png_size && ewww_image_optimizer_mimetype( $pngfile, 'i' ) === 'image/png' ) {
2082
  ewwwio_debug_message( "converted PNG is better: $png_size vs. $new_size" );
2083
  // Store the size of the converted PNG.
2084
  $new_size = $png_size;
2085
  // Check to see if the user wants the originals deleted.
2086
+ if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_delete_originals' ) ) {
2087
  // Delete the original JPG.
2088
  unlink( $file );
2089
  }
2102
  }
2103
  }
2104
  } // End if().
2105
+ ewww_image_optimizer_webp_create( $file, $new_size, $type, $tools['CWEBP'], $orig_size !== $new_size );
2106
  break;
2107
  case 'image/png':
2108
  $jpg_size = 0;
2109
  // Png2jpg conversion is turned on, and the image is in the WordPress media library.
2110
  // We check for transparency later, after optimization, because optipng might fix an empty alpha channel.
2111
  if ( ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_to_jpg' ) || ! empty( $_REQUEST['ewww_convert'] ) )
2112
+ && 1 === (int) $gallery_type && ! $skip_lossy ) {
2113
  ewwwio_debug_message( 'PNG to JPG conversion turned on' );
2114
  $cloud_background = '';
2115
  $r = '';
2170
  );
2171
  if ( $converted ) {
2172
  // Check to see if the user wants the originals deleted.
2173
+ if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_delete_originals' ) ) {
2174
  // Delete the original JPG.
2175
  unlink( $original );
2176
  }
2177
  $converted = $filenum;
2178
+ ewww_image_optimizer_webp_create( $file, $new_size, 'image/jpeg', null, $orig_size !== $new_size );
2179
  } else {
2180
+ ewww_image_optimizer_webp_create( $file, $new_size, $type, null, $orig_size !== $new_size );
2181
  }
2182
  break;
2183
  }
2201
  );
2202
  }
2203
  // If png optimization is disabled.
2204
+ if ( ! ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) ) {
2205
  // Tell the user all PNG tools are disabled.
2206
  $result = __( 'PNG optimization is disabled', 'ewww-image-optimizer' );
2207
  // If the utility checking is on, optipng is enabled, but optipng cannot be found.
2219
  // If optimization is turned on.
2220
  if ( $optimize ) {
2221
  // If lossy optimization is ON and full-size exclusion is not active.
2222
+ if ( 40 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_png_level' ) && $tools['PNGQUANT'] && ! $skip_lossy ) {
2223
  ewwwio_debug_message( 'attempting lossy reduction' );
2224
  exec( "$nice " . $tools['PNGQUANT'] . ' ' . ewww_image_optimizer_escapeshellarg( $file ) );
2225
  $quantfile = preg_replace( '/\.\w+$/', '-fs8.png', $file );
2226
+ if ( is_file( $quantfile ) && filesize( $file ) > filesize( $quantfile ) && ewww_image_optimizer_mimetype( $quantfile, 'i' ) === $type ) {
2227
  ewwwio_debug_message( 'lossy reduction is better: original - ' . filesize( $file ) . ' vs. lossy - ' . filesize( $quantfile ) );
2228
  rename( $quantfile, $file );
2229
  } elseif ( is_file( $quantfile ) ) {
2257
  // Retrieve the filesize of the temporary PNG.
2258
  $new_size = ewww_image_optimizer_filesize( $tempfile );
2259
  // If the new PNG is smaller.
2260
+ if ( $new_size && $orig_size > $new_size && ewww_image_optimizer_mimetype( $tempfile, 'i' ) === $type ) {
2261
  // Replace the original with the optimized file.
2262
  rename( $tempfile, $file );
2263
  // Store the results of the optimization.
2358
  ewwwio_debug_message( 'unable to convert to JPG' );
2359
  }
2360
  // Next we need to optimize that JPG if jpegtran is enabled.
2361
+ if ( 10 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_jpg_level' ) && file_exists( $jpgfile ) ) {
2362
  // Generate temporary file-name.
2363
  $progfile = $jpgfile . '.prog';
2364
  // Check to see if we are supposed to strip metadata.
2379
  // Check the filesize of the new JPG.
2380
  $opt_jpg_size = ewww_image_optimizer_filesize( $progfile );
2381
  // If the best-optimized is smaller than the original JPG, and we didn't create an empty JPG.
2382
+ if ( $opt_jpg_size && $jpg_size > $opt_jpg_size ) {
2383
  // Replace the original with the optimized file.
2384
  rename( $progfile, $jpgfile );
2385
  // Store the size of the optimized JPG.
2392
  }
2393
  ewwwio_debug_message( "converted JPG size: $jpg_size" );
2394
  // If the new JPG is smaller than the original PNG.
2395
+ if ( $jpg_size && $new_size > $jpg_size && ewww_image_optimizer_mimetype( $jpgfile, 'i' ) === 'image/jpeg' ) {
2396
  // Store the size of the JPG as the new filesize.
2397
  $new_size = $jpg_size;
2398
  // If the user wants originals delted after a conversion.
2399
+ if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_delete_originals' ) ) {
2400
  // Delete the original PNG.
2401
  unlink( $file );
2402
  }
2414
  }
2415
  }
2416
  } // End if().
2417
+ ewww_image_optimizer_webp_create( $file, $new_size, $type, $tools['CWEBP'], $orig_size !== $new_size );
2418
  break;
2419
  case 'image/gif':
2420
  // If gif2png is turned on, and the image is in the WordPress media library.
2421
  if ( ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_gif_to_png' ) || ! empty( $_REQUEST['ewww_convert'] ) )
2422
+ && 1 === (int) $gallery_type && ! ewww_image_optimizer_is_animated( $file ) ) {
2423
  // Generate the filename for a PNG:
2424
  // if this is a resize version...
2425
  if ( $converted ) {
2444
  }
2445
  }
2446
  $ewww_image->level = (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_gif_level' );
2447
+ if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_cloud_key' ) && 10 === (int) ewww_image_optimizer_get_option( 'ewww_image_optimizer_gif_level' ) ) {
2448
  list( $file, $converted, $result, $new_size, $backup_hash ) = ewww_image_optimizer_cloud_optimizer( $file, $type, $convert, $pngfile, 'image/png', $skip_lossy );
2449
  if ( $converted ) {
2450
  // Check to see if the user wants the originals deleted.
2451
+ if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_delete_originals' ) ) {
2452
  // Delete the original GIF.
2453
  unlink( $original );
2454
  }
2455
  $converted = $filenum;
2456
+ ewww_image_optimizer_webp_create( $file, $new_size, 'image/png', null, $orig_size !== $new_size );
2457
  }
2458
  break;
2459
  }
2477
  );
2478
  }
2479
  // If gifsicle is disabled.
2480
+ if ( ! ewww_image_optimizer_get_option( 'ewww_image_optimizer_gif_level' ) ) {
2481
  $result = __( 'GIF optimization is disabled', 'ewww-image-optimizer' );
2482
  // If utility checking is on, and gifsicle is not installed.
2483
  } elseif ( ! $skip['gifsicle'] && ! $tools['GIFSICLE'] ) {
2495
  // Retrieve the filesize of the temporary GIF.
2496
  $new_size = ewww_image_optimizer_filesize( $tempfile );
2497
  // If the new GIF is smaller.
2498
+ if ( $new_size && $orig_size > $new_size && ewww_image_optimizer_mimetype( $tempfile, 'i' ) === $type ) {
2499
  // Replace the original with the optimized file.
2500
  rename( $tempfile, $file );
2501
  // Store the results of the optimization.
2549
  // Retrieve the filesize of the PNG.
2550
  $png_size = ewww_image_optimizer_filesize( $pngfile );
2551
  // If the new PNG is smaller than the original GIF.
2552
+ if ( $png_size && $new_size > $png_size && ewww_image_optimizer_mimetype( $pngfile, 'i' ) === 'image/png' ) {
2553
  // Store the PNG size as the new filesize.
2554
  $new_size = $png_size;
2555
  // If the user wants original GIFs deleted after successful conversion.
2556
+ if ( ewww_image_optimizer_get_option( 'ewww_image_optimizer_delete_originals' ) ) {
2557
  // Delete the original GIF.
2558
  unlink( $file );
2559
  }
2562
  // Let webp know what we're dealing with now.
2563
  $type = 'image/png';
2564
  // Normally this would be at the end of the section, but we only want to do webp if the image was successfully converted to a png.
2565
+ ewww_image_optimizer_webp_create( $file, $new_size, $type, $tools['CWEBP'], $orig_size !== $new_size );
2566
  // Successful conversion, so we store the increment.
2567
  $converted = $filenum;
2568
  } else {
2595
  // NOTE: it is recommended to do any image modifications prior to optimization, otherwise you risk un-optimizing your images here.
2596
  do_action( 'ewww_image_optimizer_post_optimization', $file, $type, $fullsize );
2597
  // If their cloud api license limit has been exceeded.
2598
+ if ( 'exceeded' === $result ) {
2599
  ewww_image_optimizer_s3_uploads_image_cleanup( $file );
2600
  return array( false, __( 'License exceeded', 'ewww-image-optimizer' ), $converted, $original );
2601
  }
2706
  if ( ! extension_loaded( 'zlib' ) || ! class_exists( 'PharData' ) ) {
2707
  $pngout_error = __( 'zlib or phar extension missing from PHP', 'ewww-image-optimizer' );
2708
  }
2709
+ if ( PHP_OS === 'Linux' ) {
2710
  $os_string = 'linux';
2711
  }
2712
+ if ( PHP_OS === 'FreeBSD' ) {
2713
  $os_string = 'bsd';
2714
  }
2715
  $latest = '20150319';
2716
  $tool_path = trailingslashit( EWWW_IMAGE_OPTIMIZER_TOOL_PATH );
2717
  if ( empty( $pngout_error ) ) {
2718
+ if ( PHP_OS === 'Linux' || PHP_OS === 'FreeBSD' ) {
2719
  $download_result = download_url( 'http://static.jonof.id.au/dl/kenutils/pngout-' . $latest . '-' . $os_string . '-static.tar.gz' );
2720
  if ( is_wp_error( $download_result ) ) {
2721
  $pngout_error = $download_result->get_error_message();
2760
  }
2761
  }
2762
  }
2763
+ if ( PHP_OS === 'Darwin' ) {
2764
  $latest = '20150920';
2765
  $download_result = download_url( 'http://static.jonof.id.au/dl/kenutils/pngout-' . $latest . '-darwin.tar.gz' );
2766
  if ( is_wp_error( $download_result ) ) {
2801
  }
2802
  }
2803
  } // End if().
2804
+ if ( PHP_OS === 'WINNT' ) {
2805
  $download_result = download_url( 'http://advsys.net/ken/util/pngout.exe' );
2806
  if ( is_wp_error( $download_result ) ) {
2807
  $pngout_error = $download_result->get_error_message();