Imsanity - Version 2.4.3

Version Description

  • changed: default size from 2048 to 1920
  • fixed: WP Import plugin breaks during Media imports
  • fixed: setting a value to 0 causes errors on multi-site
  • fixed: conversion settings not displaying correctly on multi-site
Download this release

Release Info

Developer nosilver4u
Plugin Icon 128x128 Imsanity
Version 2.4.3
Comparing to
See all releases

Code changes from version 2.4.2 to 2.4.3

Files changed (10) hide show
  1. .travis.yml +26 -0
  2. ajax.php +3 -3
  3. changelog.txt +6 -0
  4. imsanity.php +12 -11
  5. libs/imagecreatefrombmp.php +10 -10
  6. libs/utils.php +1 -1
  7. phpcs.ruleset.xml +15 -0
  8. readme.txt +11 -5
  9. scripts/imsanity.js +2 -0
  10. settings.php +26 -35
.travis.yml ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ sudo: false
2
+
3
+ language: php
4
+
5
+ notifications:
6
+ email:
7
+ on_success: never
8
+ on_failure: change
9
+
10
+ branches:
11
+ only:
12
+ - master
13
+
14
+ php:
15
+ - 7.3
16
+
17
+ env:
18
+ - WP_VERSION=latest WP_MULTISITE=0
19
+
20
+ before_script:
21
+ - export PATH="$HOME/.config/composer/vendor/bin:$PATH"
22
+ - phpenv config-rm xdebug.ini
23
+ - composer global require wp-coding-standards/wpcs dealerdirect/phpcodesniffer-composer-installer
24
+
25
+ script:
26
+ - phpcs --standard=phpcs.ruleset.xml --extensions=php .
ajax.php CHANGED
@@ -60,7 +60,7 @@ function imsanity_get_images() {
60
  $imageh = false;
61
 
62
  $meta = unserialize( $image->file_meta );
63
-
64
  // If "noresize" is included in the filename then we will bypass imsanity scaling.
65
  if ( ! empty( $meta['file'] ) && strpos( $meta['file'], 'noresize' ) !== false ) {
66
  continue;
@@ -165,7 +165,7 @@ function imsanity_resize_image() {
165
  if ( $resizeresult && ! is_wp_error( $resizeresult ) ) {
166
  $newpath = $resizeresult;
167
 
168
- if ( $newpath != $oldpath && is_file( $newpath ) && filesize( $newpath ) < filesize( $oldpath ) ) {
169
  // we saved some file space. remove original and replace with resized image.
170
  unlink( $oldpath );
171
  rename( $newpath, $oldpath );
@@ -180,7 +180,7 @@ function imsanity_resize_image() {
180
  /* translators: %s: File-name of the image */
181
  'message' => sprintf( esc_html__( 'OK: %s', 'imsanity' ), $oldpath ),
182
  );
183
- } elseif ( $newpath != $oldpath ) {
184
  // the resized image is actually bigger in filesize (most likely due to jpg quality).
185
  // keep the old one and just get rid of the resized image.
186
  if ( is_file( $newpath ) ) {
60
  $imageh = false;
61
 
62
  $meta = unserialize( $image->file_meta );
63
+
64
  // If "noresize" is included in the filename then we will bypass imsanity scaling.
65
  if ( ! empty( $meta['file'] ) && strpos( $meta['file'], 'noresize' ) !== false ) {
66
  continue;
165
  if ( $resizeresult && ! is_wp_error( $resizeresult ) ) {
166
  $newpath = $resizeresult;
167
 
168
+ if ( $newpath !== $oldpath && is_file( $newpath ) && filesize( $newpath ) < filesize( $oldpath ) ) {
169
  // we saved some file space. remove original and replace with resized image.
170
  unlink( $oldpath );
171
  rename( $newpath, $oldpath );
180
  /* translators: %s: File-name of the image */
181
  'message' => sprintf( esc_html__( 'OK: %s', 'imsanity' ), $oldpath ),
182
  );
183
+ } elseif ( $newpath !== $oldpath ) {
184
  // the resized image is actually bigger in filesize (most likely due to jpg quality).
185
  // keep the old one and just get rid of the resized image.
186
  if ( is_file( $newpath ) ) {
changelog.txt CHANGED
@@ -1,3 +1,9 @@
 
 
 
 
 
 
1
  = 2.4.2 =
2
  * changed: noresize in filename also works in batch processing
3
  * fixed: error message does not contain filename when file is missing
1
+ = 2.4.3 =
2
+ * changed: default size from 2048 to 1920
3
+ * fixed: WP Import plugin breaks during Media imports
4
+ * fixed: setting a value to 0 causes errors on multi-site installs
5
+ * fixed: conversion settings not displaying correctly on multi-site
6
+
7
  = 2.4.2 =
8
  * changed: noresize in filename also works in batch processing
9
  * fixed: error message does not contain filename when file is missing
imsanity.php CHANGED
@@ -14,7 +14,7 @@ Plugin URI: https://wordpress.org/plugins/imsanity/
14
  Description: Imsanity stops insanely huge image uploads
15
  Author: Exactly WWW
16
  Text Domain: imsanity
17
- Version: 2.4.2
18
  Author URI: https://ewww.io/
19
  License: GPLv3
20
  */
@@ -23,11 +23,11 @@ if ( ! defined( 'ABSPATH' ) ) {
23
  exit;
24
  }
25
 
26
- define( 'IMSANITY_VERSION', '2.4.2' );
27
  define( 'IMSANITY_SCHEMA_VERSION', '1.1' );
28
 
29
- define( 'IMSANITY_DEFAULT_MAX_WIDTH', 2048 );
30
- define( 'IMSANITY_DEFAULT_MAX_HEIGHT', 2048 );
31
  define( 'IMSANITY_DEFAULT_BMP_TO_JPG', 1 );
32
  define( 'IMSANITY_DEFAULT_PNG_TO_JPG', 0 );
33
  define( 'IMSANITY_DEFAULT_QUALITY', 82 );
@@ -74,7 +74,7 @@ function imsanity_get_source() {
74
  }
75
 
76
  // Post_id of 0 is 3.x otherwise use the action parameter.
77
- if ( 0 === $id || 'upload-attachment' == $action ) {
78
  return IMSANITY_SOURCE_LIBRARY;
79
  }
80
 
@@ -122,18 +122,18 @@ function imsanity_handle_upload( $params ) {
122
  }
123
 
124
  // If preferences specify so then we can convert an original bmp or png file into jpg.
125
- if ( 'image/bmp' == $params['type'] && imsanity_get_option( 'imsanity_bmp_to_jpg', IMSANITY_DEFAULT_BMP_TO_JPG ) ) {
126
  $params = imsanity_convert_to_jpg( 'bmp', $params );
127
  }
128
 
129
- if ( 'image/png' == $params['type'] && imsanity_get_option( 'imsanity_png_to_jpg', IMSANITY_DEFAULT_PNG_TO_JPG ) ) {
130
  $params = imsanity_convert_to_jpg( 'png', $params );
131
  }
132
 
133
  // Make sure this is a type of image that we want to convert and that it exists.
134
  $oldpath = $params['file'];
135
 
136
- if ( ( ! is_wp_error( $params ) ) && is_file( $oldpath ) && is_readable( $oldpath ) && is_writable( $oldpath ) && filesize( $oldpath ) > 0 && in_array( $params['type'], array( 'image/png', 'image/gif', 'image/jpeg' ) ) ) {
137
 
138
  // figure out where the upload is coming from.
139
  $source = imsanity_get_source();
@@ -148,7 +148,7 @@ function imsanity_handle_upload( $params ) {
148
  $ftype = imsanity_quick_mimetype( $oldpath );
149
  $orientation = imsanity_get_orientation( $oldpath, $ftype );
150
  // If we are going to rotate the image 90 degrees during the resize, swap the existing image dimensions.
151
- if ( 6 == $orientation || 8 == $orientation ) {
152
  $old_oldw = $oldw;
153
  $oldw = $oldh;
154
  $oldh = $old_oldw;
@@ -200,6 +200,7 @@ function imsanity_handle_upload( $params ) {
200
  }
201
  }
202
  }
 
203
  return $params;
204
  }
205
 
@@ -217,10 +218,10 @@ function imsanity_convert_to_jpg( $type, $params ) {
217
 
218
  $img = null;
219
 
220
- if ( 'bmp' == $type ) {
221
  include_once( 'libs/imagecreatefrombmp.php' );
222
  $img = imagecreatefrombmp( $params['file'] );
223
- } elseif ( 'png' == $type ) {
224
  if ( ! function_exists( 'imagecreatefrompng' ) ) {
225
  return wp_handle_upload_error( $params['file'], esc_html__( 'Imsanity requires the GD library to convert PNG images to JPG', 'imsanity' ) );
226
  }
14
  Description: Imsanity stops insanely huge image uploads
15
  Author: Exactly WWW
16
  Text Domain: imsanity
17
+ Version: 2.4.3
18
  Author URI: https://ewww.io/
19
  License: GPLv3
20
  */
23
  exit;
24
  }
25
 
26
+ define( 'IMSANITY_VERSION', '2.4.3' );
27
  define( 'IMSANITY_SCHEMA_VERSION', '1.1' );
28
 
29
+ define( 'IMSANITY_DEFAULT_MAX_WIDTH', 1920 );
30
+ define( 'IMSANITY_DEFAULT_MAX_HEIGHT', 1920 );
31
  define( 'IMSANITY_DEFAULT_BMP_TO_JPG', 1 );
32
  define( 'IMSANITY_DEFAULT_PNG_TO_JPG', 0 );
33
  define( 'IMSANITY_DEFAULT_QUALITY', 82 );
74
  }
75
 
76
  // Post_id of 0 is 3.x otherwise use the action parameter.
77
+ if ( 0 === $id || 'upload-attachment' === $action ) {
78
  return IMSANITY_SOURCE_LIBRARY;
79
  }
80
 
122
  }
123
 
124
  // If preferences specify so then we can convert an original bmp or png file into jpg.
125
+ if ( 'image/bmp' === $params['type'] && imsanity_get_option( 'imsanity_bmp_to_jpg', IMSANITY_DEFAULT_BMP_TO_JPG ) ) {
126
  $params = imsanity_convert_to_jpg( 'bmp', $params );
127
  }
128
 
129
+ if ( 'image/png' === $params['type'] && imsanity_get_option( 'imsanity_png_to_jpg', IMSANITY_DEFAULT_PNG_TO_JPG ) ) {
130
  $params = imsanity_convert_to_jpg( 'png', $params );
131
  }
132
 
133
  // Make sure this is a type of image that we want to convert and that it exists.
134
  $oldpath = $params['file'];
135
 
136
+ if ( ( ! is_wp_error( $params ) ) && is_file( $oldpath ) && is_readable( $oldpath ) && is_writable( $oldpath ) && filesize( $oldpath ) > 0 && in_array( $params['type'], array( 'image/png', 'image/gif', 'image/jpeg' ), true ) ) {
137
 
138
  // figure out where the upload is coming from.
139
  $source = imsanity_get_source();
148
  $ftype = imsanity_quick_mimetype( $oldpath );
149
  $orientation = imsanity_get_orientation( $oldpath, $ftype );
150
  // If we are going to rotate the image 90 degrees during the resize, swap the existing image dimensions.
151
+ if ( 6 === (int) $orientation || 8 === (int) $orientation ) {
152
  $old_oldw = $oldw;
153
  $oldw = $oldh;
154
  $oldh = $old_oldw;
200
  }
201
  }
202
  }
203
+ clearstatcache();
204
  return $params;
205
  }
206
 
218
 
219
  $img = null;
220
 
221
+ if ( 'bmp' === $type ) {
222
  include_once( 'libs/imagecreatefrombmp.php' );
223
  $img = imagecreatefrombmp( $params['file'] );
224
+ } elseif ( 'png' === $type ) {
225
  if ( ! function_exists( 'imagecreatefrompng' ) ) {
226
  return wp_handle_upload_error( $params['file'], esc_html__( 'Imsanity requires the GD library to convert PNG images to JPG', 'imsanity' ) );
227
  }
libs/imagecreatefrombmp.php CHANGED
@@ -30,7 +30,7 @@ if ( ! function_exists( 'imagecreatefrombmp' ) ) {
30
  // read file header.
31
  $meta = unpack( 'vtype/Vfilesize/Vreserved/Voffset', fread( $fh, 14 ) );
32
  // check for bitmap.
33
- if ( 19778 != $meta['type'] ) {
34
  /* translators: %s: the image filename */
35
  trigger_error( sprintf( __( 'imagecreatefrombmp: %s is not a bitmap!', 'imsanity' ), $filename ), E_USER_WARNING );
36
  return false;
@@ -40,7 +40,7 @@ if ( ! function_exists( 'imagecreatefrombmp' ) ) {
40
  $bytes_read = 40;
41
 
42
  // read additional bitfield header.
43
- if ( 3 == $meta['compression'] ) {
44
  $meta += unpack( 'VrMask/VgMask/VbMask', fread( $fh, 12 ) );
45
  $bytes_read += 12;
46
  }
@@ -48,7 +48,7 @@ if ( ! function_exists( 'imagecreatefrombmp' ) ) {
48
  // set bytes and padding.
49
  $meta['bytes'] = $meta['bits'] / 8;
50
  $meta['decal'] = 4 - ( 4 * ( ( $meta['width'] * $meta['bytes'] / 4 ) - floor( $meta['width'] * $meta['bytes'] / 4 ) ) );
51
- if ( 4 == $meta['decal'] ) {
52
  $meta['decal'] = 0;
53
  }
54
 
@@ -126,7 +126,7 @@ if ( ! function_exists( 'imagecreatefrombmp' ) ) {
126
  return $im;
127
  }
128
  $color = unpack( 'v', $part );
129
- if ( empty( $meta['rMask'] ) || 0xf800 != $meta['rMask'] ) {
130
  $color[1] = ( ( $color[1] & 0x7c00 ) >> 7 ) * 65536 + ( ( $color[1] & 0x03e0 ) >> 2 ) * 256 + ( ( $color[1] & 0x001f ) << 3 ); // 555.
131
  } else {
132
  $color[1] = ( ( $color[1] & 0xf800 ) >> 8 ) * 65536 + ( ( $color[1] & 0x07e0 ) >> 3 ) * 256 + ( ( $color[1] & 0x001f ) << 3 ); // 565.
@@ -138,7 +138,7 @@ if ( ! function_exists( 'imagecreatefrombmp' ) ) {
138
  break;
139
  case 4:
140
  $color = unpack( 'n', $vide . substr( $data, floor( $p ), 1 ) );
141
- $color[1] = 0 == ( $p * 2 ) % 2 ? $color[1] >> 4 : $color[1] & 0x0F;
142
  $color[1] = $palette[ $color[1] + 1 ];
143
  break;
144
  case 1:
@@ -263,12 +263,12 @@ if ( ! function_exists( 'imagecreatefrombmp' ) ) {
263
  $i++;
264
  switch ( ord( $str[ $i ] ) ) {
265
  case 0: // NEW LINE.
266
- while ( 0 != count( $pixels ) % $linewidth ) {
267
  $pixels[] = 0;
268
  }
269
  break;
270
  case 1: // END OF FILE.
271
- while ( 0 != count( $pixels ) % $linewidth ) {
272
  $pixels[] = 0;
273
  }
274
  break 3;
@@ -278,7 +278,7 @@ if ( ! function_exists( 'imagecreatefrombmp' ) ) {
278
  default: // ABSOLUTE MODE.
279
  $num = ord( $str[ $i ] );
280
  for ( $j = 0; $j < $num; $j++ ) {
281
- if ( 0 == $j % 2 ) {
282
  $c = ord( $str[ ++$i ] );
283
  $pixels[] = ( $c & 240 ) >> 4;
284
  } else {
@@ -286,7 +286,7 @@ if ( ! function_exists( 'imagecreatefrombmp' ) ) {
286
  }
287
  }
288
 
289
- if ( 0 == $num % 2 ) {
290
  $i++;
291
  }
292
  }
@@ -294,7 +294,7 @@ if ( ! function_exists( 'imagecreatefrombmp' ) ) {
294
  default:
295
  $c = ord( $str[ ++$i ] );
296
  for ( $j = 0; $j < $o; $j++ ) {
297
- $pixels[] = ( 0 == $j % 2 ? ( $c & 240 ) >> 4 : $c & 15 );
298
  }
299
  }
300
  }
30
  // read file header.
31
  $meta = unpack( 'vtype/Vfilesize/Vreserved/Voffset', fread( $fh, 14 ) );
32
  // check for bitmap.
33
+ if ( 19778 !== (int) $meta['type'] ) {
34
  /* translators: %s: the image filename */
35
  trigger_error( sprintf( __( 'imagecreatefrombmp: %s is not a bitmap!', 'imsanity' ), $filename ), E_USER_WARNING );
36
  return false;
40
  $bytes_read = 40;
41
 
42
  // read additional bitfield header.
43
+ if ( 3 === (int) $meta['compression'] ) {
44
  $meta += unpack( 'VrMask/VgMask/VbMask', fread( $fh, 12 ) );
45
  $bytes_read += 12;
46
  }
48
  // set bytes and padding.
49
  $meta['bytes'] = $meta['bits'] / 8;
50
  $meta['decal'] = 4 - ( 4 * ( ( $meta['width'] * $meta['bytes'] / 4 ) - floor( $meta['width'] * $meta['bytes'] / 4 ) ) );
51
+ if ( 4 === (int) $meta['decal'] ) {
52
  $meta['decal'] = 0;
53
  }
54
 
126
  return $im;
127
  }
128
  $color = unpack( 'v', $part );
129
+ if ( empty( $meta['rMask'] ) || 0xf800 !== (int) $meta['rMask'] ) {
130
  $color[1] = ( ( $color[1] & 0x7c00 ) >> 7 ) * 65536 + ( ( $color[1] & 0x03e0 ) >> 2 ) * 256 + ( ( $color[1] & 0x001f ) << 3 ); // 555.
131
  } else {
132
  $color[1] = ( ( $color[1] & 0xf800 ) >> 8 ) * 65536 + ( ( $color[1] & 0x07e0 ) >> 3 ) * 256 + ( ( $color[1] & 0x001f ) << 3 ); // 565.
138
  break;
139
  case 4:
140
  $color = unpack( 'n', $vide . substr( $data, floor( $p ), 1 ) );
141
+ $color[1] = 0 === ( $p * 2 ) % 2 ? $color[1] >> 4 : $color[1] & 0x0F;
142
  $color[1] = $palette[ $color[1] + 1 ];
143
  break;
144
  case 1:
263
  $i++;
264
  switch ( ord( $str[ $i ] ) ) {
265
  case 0: // NEW LINE.
266
+ while ( 0 !== count( $pixels ) % $linewidth ) {
267
  $pixels[] = 0;
268
  }
269
  break;
270
  case 1: // END OF FILE.
271
+ while ( 0 !== count( $pixels ) % $linewidth ) {
272
  $pixels[] = 0;
273
  }
274
  break 3;
278
  default: // ABSOLUTE MODE.
279
  $num = ord( $str[ $i ] );
280
  for ( $j = 0; $j < $num; $j++ ) {
281
+ if ( 0 === $j % 2 ) {
282
  $c = ord( $str[ ++$i ] );
283
  $pixels[] = ( $c & 240 ) >> 4;
284
  } else {
286
  }
287
  }
288
 
289
+ if ( 0 === $num % 2 ) {
290
  $i++;
291
  }
292
  }
294
  default:
295
  $c = ord( $str[ ++$i ] );
296
  for ( $j = 0; $j < $o; $j++ ) {
297
+ $pixels[] = ( 0 === $j % 2 ? ( $c & 240 ) >> 4 : $c & 15 );
298
  }
299
  }
300
  }
libs/utils.php CHANGED
@@ -96,7 +96,7 @@ function imsanity_get_orientation( $file, $type ) {
96
  if ( function_exists( 'exif_read_data' ) && 'image/jpeg' === $type ) {
97
  $exif = @exif_read_data( $file );
98
  if ( is_array( $exif ) && array_key_exists( 'Orientation', $exif ) ) {
99
- return $exif['Orientation'];
100
  }
101
  }
102
  return false;
96
  if ( function_exists( 'exif_read_data' ) && 'image/jpeg' === $type ) {
97
  $exif = @exif_read_data( $file );
98
  if ( is_array( $exif ) && array_key_exists( 'Orientation', $exif ) ) {
99
+ return (int) $exif['Orientation'];
100
  }
101
  }
102
  return false;
phpcs.ruleset.xml ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <ruleset name="WordPress Coding Standards for Plugins">
3
+ <description>Generally-applicable sniffs for WordPress plugins</description>
4
+
5
+ <exclude-pattern>*/vendor/*</exclude-pattern>
6
+ <exclude-pattern>*/tests/*</exclude-pattern>
7
+
8
+ <rule ref="WordPress-Core" />
9
+ <rule ref="WordPress-Docs" />
10
+ <rule ref="WordPress.PHP.NoSilencedErrors">
11
+ <properties>
12
+ <property name="custom_whitelist" type="array" value="exif_read_data"/>
13
+ </properties>
14
+ </rule>
15
+ </ruleset>
readme.txt CHANGED
@@ -1,11 +1,11 @@
1
  === Imsanity ===
2
- Contributors: nosilver4u,verysimple
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=MKMQKCBFFG3WW
4
  Tags: image, scale, resize, space saver, quality
5
- Requires at least: 4.5
6
- Tested up to: 5.1
7
  Requires PHP: 5.6
8
- Stable tag: 2.4.2
9
  License: GPLv3
10
 
11
  Imsanity automatically resizes huge image uploads. Are contributors uploading huge photos? Tired of manually scaling? Imsanity to the rescue!
@@ -134,6 +134,12 @@ Questions may be posted on the support forum at https://wordpress.org/support/pl
134
 
135
  == Changelog ==
136
 
 
 
 
 
 
 
137
  = 2.4.2 =
138
  * changed: noresize in filename also works in batch processing
139
  * fixed: error message does not contain filename when file is missing
@@ -142,7 +148,7 @@ Questions may be posted on the support forum at https://wordpress.org/support/pl
142
  = 2.4.1 =
143
  * fixed: bulk resizer scan returning incorrect results
144
  * fixed: sprintf error during resizing and upload
145
-
146
  = 2.4.0 =
147
  * added: deep scanning option for when attachment metadata isn't updating properly
148
  * fixed: uploads from Gutenberg not detected properly
1
  === Imsanity ===
2
+ Contributors: nosilver4u
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=MKMQKCBFFG3WW
4
  Tags: image, scale, resize, space saver, quality
5
+ Requires at least: 4.9
6
+ Tested up to: 5.2
7
  Requires PHP: 5.6
8
+ Stable tag: 2.4.3
9
  License: GPLv3
10
 
11
  Imsanity automatically resizes huge image uploads. Are contributors uploading huge photos? Tired of manually scaling? Imsanity to the rescue!
134
 
135
  == Changelog ==
136
 
137
+ = 2.4.3 =
138
+ * changed: default size from 2048 to 1920
139
+ * fixed: WP Import plugin breaks during Media imports
140
+ * fixed: setting a value to 0 causes errors on multi-site
141
+ * fixed: conversion settings not displaying correctly on multi-site
142
+
143
  = 2.4.2 =
144
  * changed: noresize in filename also works in batch processing
145
  * fixed: error message does not contain filename when file is missing
148
  = 2.4.1 =
149
  * fixed: bulk resizer scan returning incorrect results
150
  * fixed: sprintf error during resizing and upload
151
+
152
  = 2.4.0 =
153
  * added: deep scanning option for when attachment metadata isn't updating properly
154
  * fixed: uploads from Gutenberg not detected properly
scripts/imsanity.js CHANGED
@@ -2,6 +2,8 @@
2
  * imsanity admin javascript functions
3
  */
4
 
 
 
5
  /**
6
  * Begin the process of re-sizing all of the checked images
7
  */
2
  * imsanity admin javascript functions
3
  */
4
 
5
+ jQuery(document).ready(function($) {$(".fade").fadeTo(5000,1).fadeOut(3000);});
6
+
7
  /**
8
  * Begin the process of re-sizing all of the checked images
9
  */
settings.php CHANGED
@@ -84,6 +84,7 @@ function imsanity_queue_script( $hook ) {
84
  'none_found' => esc_html__( 'There are no images that need to be resized.', 'imsanity' ),
85
  )
86
  );
 
87
  }
88
 
89
  /**
@@ -93,7 +94,7 @@ function imsanity_queue_script( $hook ) {
93
  */
94
  function imsanity_multisite_table_exists() {
95
  global $wpdb;
96
- return $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->imsanity_ms'" ) == $wpdb->imsanity_ms;
97
  }
98
 
99
  /**
@@ -156,7 +157,7 @@ function imsanity_maybe_created_custom_table() {
156
 
157
  $schema = imsanity_multisite_table_schema_version();
158
 
159
- if ( '0' == $schema ) {
160
  // This is an initial database setup.
161
  $sql = 'CREATE TABLE IF NOT EXISTS ' . $wpdb->imsanity_ms . ' (
162
  setting varchar(55),
@@ -185,9 +186,9 @@ function imsanity_maybe_created_custom_table() {
185
  );
186
  }
187
 
188
- if ( IMSANITY_SCHEMA_VERSION != $schema ) {
189
  // This is a schema update. for the moment there is only one schema update available, from 1.0 to 1.1.
190
- if ( '1.0' == $schema ) {
191
  // Update from version 1.0 to 1.1.
192
  $wpdb->insert(
193
  $wpdb->imsanity_ms,
@@ -212,18 +213,10 @@ function imsanity_maybe_created_custom_table() {
212
  * Display the form for the multi-site settings page.
213
  */
214
  function imsanity_network_settings() {
215
- imsanity_settings_css();
216
-
217
- echo '
218
- <div class="wrap">
219
- <h1>' . esc_html__( 'Imsanity Network Settings', 'imsanity' ) . '</h1>
220
- ';
221
 
222
- $settings = imsanity_get_multisite_settings();
223
- ?>
224
- <script type='text/javascript'>
225
- jQuery(document).ready(function($) {$(".fade").fadeTo(5000,1).fadeOut(3000);});
226
- </script>
227
  <form method="post" action="settings.php?page=imsanity_network">
228
  <input type="hidden" name="update_imsanity_settings" value="1" />
229
  <?php wp_nonce_field( 'imsanity_network_options' ); ?>
@@ -232,8 +225,8 @@ function imsanity_network_settings() {
232
  <th scope="row"><label for="imsanity_override_site"><?php esc_html_e( 'Global Settings Override', 'imsanity' ); ?></label></th>
233
  <td>
234
  <select name="imsanity_override_site">
235
- <option value="0" <?php echo ( '0' == $settings->imsanity_override_site ) ? "selected='selected'" : ''; ?> ><?php esc_html_e( 'Allow each site to configure Imsanity settings', 'imsanity' ); ?></option>
236
- <option value="1" <?php echo ( '1' == $settings->imsanity_override_site ) ? "selected='selected'" : ''; ?> ><?php esc_html_e( 'Use global Imsanity settings (below) for all sites', 'imsanity' ); ?></option>
237
  </select>
238
  </td>
239
  </tr>
@@ -265,16 +258,16 @@ function imsanity_network_settings() {
265
  <tr>
266
  <th scope="row"><label for"imsanity_bmp_to_jpg"><?php esc_html_e( 'Convert BMP to JPG', 'imsanity' ); ?></label></th>
267
  <td><select name="imsanity_bmp_to_jpg">
268
- <option value="1" <?php echo ( '1' == $settings->imsanity_bmp_to_jpg ) ? "selected='selected'" : ''; ?> ><?php esc_html_e( 'Yes', 'imsanity' ); ?></option>
269
- <option value="0" <?php echo ( '0' == $settings->imsanity_bmp_to_jpg ) ? "selected='selected'" : ''; ?> ><?php esc_html_e( 'No', 'imsanity' ); ?></option>
270
  </select></td>
271
  </tr>
272
 
273
  <tr>
274
  <th scope="row"><label for="imsanity_png_to_jpg"><?php esc_html_e( 'Convert PNG to JPG', 'imsanity' ); ?></label></th>
275
  <td><select name="imsanity_png_to_jpg">
276
- <option value="1" <?php echo ( '1' == $settings->imsanity_png_to_jpg ) ? "selected='selected'" : ''; ?> ><?php esc_html_e( 'Yes', 'imsanity' ); ?></option>
277
- <option value="0" <?php echo ( '0' == $settings->imsanity_png_to_jpg ) ? "selected='selected'" : ''; ?> ><?php esc_html_e( 'No', 'imsanity' ); ?></option>
278
  </select></td>
279
  </tr>
280
 
@@ -317,17 +310,17 @@ function imsanity_network_settings_update() {
317
 
318
  $data = new stdClass();
319
 
320
- $data->imsanity_override_site = 1 == $_POST['imsanity_override_site'];
321
  $data->imsanity_max_height = sanitize_text_field( $_POST['imsanity_max_height'] );
322
  $data->imsanity_max_width = sanitize_text_field( $_POST['imsanity_max_width'] );
323
  $data->imsanity_max_height_library = sanitize_text_field( $_POST['imsanity_max_height_library'] );
324
  $data->imsanity_max_width_library = sanitize_text_field( $_POST['imsanity_max_width_library'] );
325
  $data->imsanity_max_height_other = sanitize_text_field( $_POST['imsanity_max_height_other'] );
326
  $data->imsanity_max_width_other = sanitize_text_field( $_POST['imsanity_max_width_other'] );
327
- $data->imsanity_bmp_to_jpg = 1 == $_POST['imsanity_bmp_to_jpg'];
328
- $data->imsanity_png_to_jpg = 1 == $_POST['imsanity_png_to_jpg'];
329
  $data->imsanity_quality = imsanity_jpg_quality( $_POST['imsanity_quality'] );
330
- $data->imsanity_deep_scan = (bool) $_POST['imsanity_deep_scan'];
331
 
332
  $success = $wpdb->update(
333
  $wpdb->imsanity_ms,
@@ -371,12 +364,15 @@ function imsanity_get_multisite_settings() {
371
  : imsanity_get_default_multisite_settings();
372
 
373
  // this is for backwards compatibility.
374
- if ( empty( $_imsanity_multisite_settings->imsanity_max_height_library ) ) {
375
  $_imsanity_multisite_settings->imsanity_max_height_library = $_imsanity_multisite_settings->imsanity_max_height;
376
  $_imsanity_multisite_settings->imsanity_max_width_library = $_imsanity_multisite_settings->imsanity_max_width;
377
  $_imsanity_multisite_settings->imsanity_max_height_other = $_imsanity_multisite_settings->imsanity_max_height;
378
  $_imsanity_multisite_settings->imsanity_max_width_other = $_imsanity_multisite_settings->imsanity_max_width;
379
  }
 
 
 
380
  if ( ! property_exists( $_imsanity_multisite_settings, 'imsanity_deep_scan' ) ) {
381
  $_imsanity_multisite_settings->imsanity_deep_scan = false;
382
  }
@@ -474,12 +470,7 @@ function imsanity_settings_css() {
474
  * are not editable instead of the settings form
475
  */
476
  function imsanity_settings_page() {
477
- imsanity_settings_css();
478
-
479
  ?>
480
- <script type='text/javascript'>
481
- jQuery(document).ready(function($) {$(".fade").fadeTo(5000,1).fadeOut(3000);});
482
- </script>
483
  <div class="wrap">
484
  <h1><?php esc_html_e( 'Imsanity Settings', 'imsanity' ); ?></h1>
485
  <?php
@@ -581,16 +572,16 @@ function imsanity_settings_page_form() {
581
  <tr>
582
  <th scope="row"><label for="imsanity_bmp_to_jpg"><?php esc_html_e( 'Convert BMP To JPG', 'imsanity' ); ?></label></th>
583
  <td><select name="imsanity_bmp_to_jpg">
584
- <option <?php echo ( '1' == get_option( 'imsanity_bmp_to_jpg', IMSANITY_DEFAULT_BMP_TO_JPG ) ) ? "selected='selected'" : ''; ?> value="1"><?php esc_html_e( 'Yes', 'imsanity' ); ?></option>
585
- <option <?php echo ( '0' == get_option( 'imsanity_bmp_to_jpg', IMSANITY_DEFAULT_BMP_TO_JPG ) ) ? "selected='selected'" : ''; ?> value="0"><?php esc_html_e( 'No', 'imsanity' ); ?></option>
586
  </select></td>
587
  </tr>
588
 
589
  <tr>
590
  <th scope="row"><label for="imsanity_png_to_jpg"><?php esc_html_e( 'Convert PNG To JPG', 'imsanity' ); ?></label></th>
591
  <td><select name="imsanity_png_to_jpg">
592
- <option <?php echo ( '1' == get_option( 'imsanity_png_to_jpg', IMSANITY_DEFAULT_PNG_TO_JPG ) ) ? "selected='selected'" : ''; ?> value="1"><?php esc_html_e( 'Yes', 'imsanity' ); ?></option>
593
- <option <?php echo ( '0' == get_option( 'imsanity_png_to_jpg', IMSANITY_DEFAULT_PNG_TO_JPG ) ) ? "selected='selected'" : ''; ?> value="0"><?php esc_html_e( 'No', 'imsanity' ); ?></option>
594
  </select></td>
595
  </tr>
596
 
84
  'none_found' => esc_html__( 'There are no images that need to be resized.', 'imsanity' ),
85
  )
86
  );
87
+ add_action( 'admin_print_styles', 'imsanity_settings_css' );
88
  }
89
 
90
  /**
94
  */
95
  function imsanity_multisite_table_exists() {
96
  global $wpdb;
97
+ return $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->imsanity_ms'" ) === $wpdb->imsanity_ms;
98
  }
99
 
100
  /**
157
 
158
  $schema = imsanity_multisite_table_schema_version();
159
 
160
+ if ( '0' === $schema ) {
161
  // This is an initial database setup.
162
  $sql = 'CREATE TABLE IF NOT EXISTS ' . $wpdb->imsanity_ms . ' (
163
  setting varchar(55),
186
  );
187
  }
188
 
189
+ if ( IMSANITY_SCHEMA_VERSION !== $schema ) {
190
  // This is a schema update. for the moment there is only one schema update available, from 1.0 to 1.1.
191
+ if ( '1.0' === $schema ) {
192
  // Update from version 1.0 to 1.1.
193
  $wpdb->insert(
194
  $wpdb->imsanity_ms,
213
  * Display the form for the multi-site settings page.
214
  */
215
  function imsanity_network_settings() {
216
+ $settings = imsanity_get_multisite_settings(); ?>
217
+ <div class="wrap">
218
+ <h1><?php esc_html_e( 'Imsanity Network Settings', 'imsanity' ); ?></h1>
 
 
 
219
 
 
 
 
 
 
220
  <form method="post" action="settings.php?page=imsanity_network">
221
  <input type="hidden" name="update_imsanity_settings" value="1" />
222
  <?php wp_nonce_field( 'imsanity_network_options' ); ?>
225
  <th scope="row"><label for="imsanity_override_site"><?php esc_html_e( 'Global Settings Override', 'imsanity' ); ?></label></th>
226
  <td>
227
  <select name="imsanity_override_site">
228
+ <option value="0" <?php selected( $settings->imsanity_override_site, '0' ); ?> ><?php esc_html_e( 'Allow each site to configure Imsanity settings', 'imsanity' ); ?></option>
229
+ <option value="1" <?php selected( $settings->imsanity_override_site, '1' ); ?> ><?php esc_html_e( 'Use global Imsanity settings (below) for all sites', 'imsanity' ); ?></option>
230
  </select>
231
  </td>
232
  </tr>
258
  <tr>
259
  <th scope="row"><label for"imsanity_bmp_to_jpg"><?php esc_html_e( 'Convert BMP to JPG', 'imsanity' ); ?></label></th>
260
  <td><select name="imsanity_bmp_to_jpg">
261
+ <option value="1" <?php selected( $settings->imsanity_bmp_to_jpg, '1' ); ?> ><?php esc_html_e( 'Yes', 'imsanity' ); ?></option>
262
+ <option value="0" <?php selected( $settings->imsanity_bmp_to_jpg, '0' ); ?> ><?php esc_html_e( 'No', 'imsanity' ); ?></option>
263
  </select></td>
264
  </tr>
265
 
266
  <tr>
267
  <th scope="row"><label for="imsanity_png_to_jpg"><?php esc_html_e( 'Convert PNG to JPG', 'imsanity' ); ?></label></th>
268
  <td><select name="imsanity_png_to_jpg">
269
+ <option value="1" <?php selected( $settings->imsanity_png_to_jpg, '1' ); ?> ><?php esc_html_e( 'Yes', 'imsanity' ); ?></option>
270
+ <option value="0" <?php selected( $settings->imsanity_png_to_jpg, '0' ); ?> ><?php esc_html_e( 'No', 'imsanity' ); ?></option>
271
  </select></td>
272
  </tr>
273
 
310
 
311
  $data = new stdClass();
312
 
313
+ $data->imsanity_override_site = (bool) $_POST['imsanity_override_site'];
314
  $data->imsanity_max_height = sanitize_text_field( $_POST['imsanity_max_height'] );
315
  $data->imsanity_max_width = sanitize_text_field( $_POST['imsanity_max_width'] );
316
  $data->imsanity_max_height_library = sanitize_text_field( $_POST['imsanity_max_height_library'] );
317
  $data->imsanity_max_width_library = sanitize_text_field( $_POST['imsanity_max_width_library'] );
318
  $data->imsanity_max_height_other = sanitize_text_field( $_POST['imsanity_max_height_other'] );
319
  $data->imsanity_max_width_other = sanitize_text_field( $_POST['imsanity_max_width_other'] );
320
+ $data->imsanity_bmp_to_jpg = (bool) $_POST['imsanity_bmp_to_jpg'];
321
+ $data->imsanity_png_to_jpg = (bool) $_POST['imsanity_png_to_jpg'];
322
  $data->imsanity_quality = imsanity_jpg_quality( $_POST['imsanity_quality'] );
323
+ $data->imsanity_deep_scan = empty( $_POST['imsanity_deep_scan'] ) ? 0 : 1;
324
 
325
  $success = $wpdb->update(
326
  $wpdb->imsanity_ms,
364
  : imsanity_get_default_multisite_settings();
365
 
366
  // this is for backwards compatibility.
367
+ if ( ! isset( $_imsanity_multisite_settings->imsanity_max_height_library ) ) {
368
  $_imsanity_multisite_settings->imsanity_max_height_library = $_imsanity_multisite_settings->imsanity_max_height;
369
  $_imsanity_multisite_settings->imsanity_max_width_library = $_imsanity_multisite_settings->imsanity_max_width;
370
  $_imsanity_multisite_settings->imsanity_max_height_other = $_imsanity_multisite_settings->imsanity_max_height;
371
  $_imsanity_multisite_settings->imsanity_max_width_other = $_imsanity_multisite_settings->imsanity_max_width;
372
  }
373
+ $_imsanity_multisite_settings->imsanity_override_site = ! empty( $_imsanity_multisite_settings->imsanity_override_site ) ? '1' : '0';
374
+ $_imsanity_multisite_settings->imsanity_bmp_to_jpg = ! empty( $_imsanity_multisite_settings->imsanity_bmp_to_jpg ) ? '1' : '0';
375
+ $_imsanity_multisite_settings->imsanity_png_to_jpg = ! empty( $_imsanity_multisite_settings->imsanity_png_to_jpg ) ? '1' : '0';
376
  if ( ! property_exists( $_imsanity_multisite_settings, 'imsanity_deep_scan' ) ) {
377
  $_imsanity_multisite_settings->imsanity_deep_scan = false;
378
  }
470
  * are not editable instead of the settings form
471
  */
472
  function imsanity_settings_page() {
 
 
473
  ?>
 
 
 
474
  <div class="wrap">
475
  <h1><?php esc_html_e( 'Imsanity Settings', 'imsanity' ); ?></h1>
476
  <?php
572
  <tr>
573
  <th scope="row"><label for="imsanity_bmp_to_jpg"><?php esc_html_e( 'Convert BMP To JPG', 'imsanity' ); ?></label></th>
574
  <td><select name="imsanity_bmp_to_jpg">
575
+ <option <?php selected( get_option( 'imsanity_bmp_to_jpg', IMSANITY_DEFAULT_BMP_TO_JPG ), '1' ); ?> value="1"><?php esc_html_e( 'Yes', 'imsanity' ); ?></option>
576
+ <option <?php selected( get_option( 'imsanity_bmp_to_jpg', IMSANITY_DEFAULT_BMP_TO_JPG ), '0' ); ?> value="0"><?php esc_html_e( 'No', 'imsanity' ); ?></option>
577
  </select></td>
578
  </tr>
579
 
580
  <tr>
581
  <th scope="row"><label for="imsanity_png_to_jpg"><?php esc_html_e( 'Convert PNG To JPG', 'imsanity' ); ?></label></th>
582
  <td><select name="imsanity_png_to_jpg">
583
+ <option <?php selected( get_option( 'imsanity_png_to_jpg', IMSANITY_DEFAULT_PNG_TO_JPG ), '1' ); ?> value="1"><?php esc_html_e( 'Yes', 'imsanity' ); ?></option>
584
+ <option <?php selected( get_option( 'imsanity_png_to_jpg', IMSANITY_DEFAULT_PNG_TO_JPG ), '0' ); ?> value="0"><?php esc_html_e( 'No', 'imsanity' ); ?></option>
585
  </select></td>
586
  </tr>
587