PluginProbe
Imsanity / 2.9.2
Imsanity v2.9.2
2.9.4 2.9.3 2.9.2 trunk 2.4.3 2.5.0 2.6.0 2.7.0 2.7.2 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.9.0 2.9.1
imsanity / settings.php

settings.php in Imsanity 2.9.2, at settings.php

1,015 lines 42.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Imsanity settings and admin UI.
4 *
5 * @package Imsanity
6 */
7
8 // Setup custom $wpdb attribute for our image-tracking table.
9 global $wpdb;
10 if ( ! isset( $wpdb->imsanity_ms ) ) {
11 $wpdb->imsanity_ms = $wpdb->get_blog_prefix( 0 ) . 'imsanity';
12 }
13
14 // Register the plugin settings menu.
15 add_action( 'admin_menu', 'imsanity_create_menu' );
16 add_action( 'network_admin_menu', 'imsanity_register_network' );
17 add_filter( 'plugin_action_links_' . IMSANITY_PLUGIN_FILE_REL, 'imsanity_settings_link' );
18 add_filter( 'network_admin_plugin_action_links_' . IMSANITY_PLUGIN_FILE_REL, 'imsanity_settings_link' );
19 add_action( 'admin_enqueue_scripts', 'imsanity_queue_script' );
20 add_action( 'admin_init', 'imsanity_register_settings' );
21 add_filter( 'big_image_size_threshold', 'imsanity_adjust_default_threshold', 10, 3 );
22
23 register_activation_hook( IMSANITY_PLUGIN_FILE_REL, 'imsanity_maybe_created_custom_table' );
24
25 // settings cache.
26 $_imsanity_multisite_settings = null;
27
28 /**
29 * Create the settings menu item in the WordPress admin navigation and
30 * link it to the plugin settings page
31 */
32 function imsanity_create_menu() {
33 $permissions = apply_filters( 'imsanity_admin_permissions', 'manage_options' );
34 // Create new menu for site configuration.
35 add_options_page(
36 esc_html__( 'Imsanity Plugin Settings', 'imsanity' ), // Page Title.
37 esc_html__( 'Imsanity', 'imsanity' ), // Menu Title.
38 $permissions, // Required permissions.
39 'imsanity-options', // Slug.
40 'imsanity_settings_page' // Function to call.
41 );
42 }
43
44 /**
45 * Register the network settings page
46 */
47 function imsanity_register_network() {
48 if ( ! function_exists( 'is_plugin_active_for_network' ) && is_multisite() ) {
49 // Need to include the plugin library for the is_plugin_active function.
50 require_once ABSPATH . 'wp-admin/includes/plugin.php';
51 }
52 if ( is_multisite() ) {
53 $permissions = apply_filters( 'imsanity_superadmin_permissions', 'manage_network_options' );
54 add_submenu_page(
55 'settings.php',
56 esc_html__( 'Imsanity Network Settings', 'imsanity' ),
57 esc_html__( 'Imsanity', 'imsanity' ),
58 $permissions,
59 'imsanity-options',
60 'imsanity_network_settings'
61 );
62 }
63 }
64
65 /**
66 * Get the settings link, based on whether we are in a multi-site network admin or not.
67 *
68 * @return string The URL for the settings page.
69 */
70 function imsanity_get_settings_link() {
71 if ( is_multisite() && is_network_admin() ) {
72 return network_admin_url( 'settings.php?page=imsanity-options' );
73 }
74 return admin_url( 'options-general.php?page=imsanity-options' );
75 }
76
77 /**
78 * Settings link that appears on the plugins overview page
79 *
80 * @param array $links The plugin action links.
81 * @return array The action links, with a settings link pre-pended.
82 */
83 function imsanity_settings_link( $links ) {
84 if ( ! is_array( $links ) ) {
85 $links = array();
86 }
87 if ( is_multisite() && is_network_admin() ) {
88 $settings_link = '<a href="' . imsanity_get_settings_link() . '">' . esc_html__( 'Settings', 'imsanity' ) . '</a>';
89 } else {
90 $settings_link = '<a href="' . imsanity_get_settings_link() . '">' . esc_html__( 'Settings', 'imsanity' ) . '</a>';
91 }
92 array_unshift( $links, $settings_link );
93 return $links;
94 }
95
96 /**
97 * Queues up the AJAX script and any localized JS vars we need.
98 *
99 * @param string $hook The hook name for the current page.
100 */
101 function imsanity_queue_script( $hook ) {
102 // Make sure we are being called from the settings page.
103 if ( strpos( $hook, 'settings_page_imsanity' ) !== 0 && 'upload.php' !== $hook ) {
104 return;
105 }
106 if ( ! empty( $_REQUEST['imsanity_reset'] ) && ! empty( $_REQUEST['imsanity_wpnonce'] ) && wp_verify_nonce( sanitize_key( $_REQUEST['imsanity_wpnonce'] ), 'imsanity-bulk-reset' ) ) {
107 update_option( 'imsanity_resume_id', 0, false );
108 }
109 $resume_id = (int) get_option( 'imsanity_resume_id' );
110 $loading_image = plugins_url( '/images/ajax-loader.gif', __FILE__ );
111 // Register the scripts that are used by the bulk resizer.
112 wp_enqueue_script( 'imsanity_script', plugins_url( '/scripts/imsanity.js', __FILE__ ), array( 'jquery' ), IMSANITY_VERSION );
113 wp_localize_script(
114 'imsanity_script',
115 'imsanity_vars',
116 array(
117 '_wpnonce' => wp_create_nonce( 'imsanity-bulk' ),
118 'resize_all_prompt' => esc_html__( 'You are about to resize all your existing images. Please be sure your site is backed up before proceeding. Do you wish to continue?', 'imsanity' ),
119 'resizing_complete' => esc_html__( 'Resizing Complete', 'imsanity' ) . ' - <a target="_blank" href="https://wordpress.org/support/plugin/imsanity/reviews/#new-post">' . esc_html__( 'Leave a Review', 'imsanity' ) . '</a>',
120 'resize_selected' => esc_html__( 'Resize Selected Images', 'imsanity' ),
121 'resizing' => '<p>' . esc_html__( 'Please wait...', 'imsanity' ) . "&nbsp;<img src='$loading_image' /></p>",
122 'removal_failed' => esc_html__( 'Removal Failed', 'imsanity' ),
123 'removal_succeeded' => esc_html__( 'Removal Complete', 'imsanity' ),
124 'operation_stopped' => esc_html__( 'Resizing stopped, reload page to resume.', 'imsanity' ),
125 'image' => esc_html__( 'Image', 'imsanity' ),
126 'invalid_response' => esc_html__( 'Received an invalid response, please check for errors in the Developer Tools console of your browser.', 'imsanity' ),
127 'none_found' => esc_html__( 'There are no images that need to be resized.', 'imsanity' ),
128 'resume_id' => $resume_id,
129 )
130 );
131 add_action( 'admin_notices', 'imsanity_missing_gd_admin_notice' );
132 add_action( 'network_admin_notices', 'imsanity_missing_gd_admin_notice' );
133 add_action( 'admin_print_scripts', 'imsanity_settings_css' );
134 }
135
136 /**
137 * Return true if the multi-site settings table exists
138 *
139 * @return bool True if the Imsanity table exists.
140 */
141 function imsanity_multisite_table_exists() {
142 global $wpdb;
143 return $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->imsanity_ms'" ) === $wpdb->imsanity_ms;
144 }
145
146 /**
147 * Checks the schema version for the Imsanity table.
148 *
149 * @return string The version identifier for the schema.
150 */
151 function imsanity_multisite_table_schema_version() {
152 // If the table doesn't exist then there is no schema to report.
153 if ( ! imsanity_multisite_table_exists() ) {
154 return '0';
155 }
156
157 global $wpdb;
158 $version = $wpdb->get_var( "SELECT data FROM $wpdb->imsanity_ms WHERE setting = 'schema'" );
159
160 if ( ! $version ) {
161 $version = '1.0'; // This is a legacy version 1.0 installation.
162 }
163
164 return $version;
165 }
166
167 /**
168 * Returns the default network settings in the case where they are not
169 * defined in the database, or multi-site is not enabled.
170 *
171 * @return stdClass
172 */
173 function imsanity_get_default_multisite_settings() {
174 $data = new stdClass();
175
176 if ( ! defined( 'IMSANITY_DEFAULT_MAX_WIDTH' ) ) {
177 imsanity_init();
178 }
179 $data->imsanity_override_site = false;
180 $data->imsanity_max_height = IMSANITY_DEFAULT_MAX_HEIGHT;
181 $data->imsanity_max_width = IMSANITY_DEFAULT_MAX_WIDTH;
182 $data->imsanity_max_height_library = IMSANITY_DEFAULT_MAX_HEIGHT;
183 $data->imsanity_max_width_library = IMSANITY_DEFAULT_MAX_WIDTH;
184 $data->imsanity_max_height_other = IMSANITY_DEFAULT_MAX_HEIGHT;
185 $data->imsanity_max_width_other = IMSANITY_DEFAULT_MAX_WIDTH;
186 $data->imsanity_bmp_to_jpg = IMSANITY_DEFAULT_BMP_TO_JPG;
187 $data->imsanity_png_to_jpg = IMSANITY_DEFAULT_PNG_TO_JPG;
188 $data->imsanity_quality = IMSANITY_DEFAULT_QUALITY;
189 $data->imsanity_avif_quality = IMSANITY_DEFAULT_AVIF_QUALITY;
190 $data->imsanity_webp_quality = IMSANITY_DEFAULT_WEBP_QUALITY;
191 $data->imsanity_delete_originals = false;
192 return $data;
193 }
194
195
196 /**
197 * On activation create the multisite database table if necessary. this is
198 * called when the plugin is activated as well as when it is automatically
199 * updated.
200 */
201 function imsanity_maybe_created_custom_table() {
202 // If not a multi-site no need to do any custom table lookups.
203 if ( ! function_exists( 'is_multisite' ) || ( ! is_multisite() ) ) {
204 return;
205 }
206
207 global $wpdb;
208
209 $schema = imsanity_multisite_table_schema_version();
210
211 if ( '0' === $schema ) {
212 // This is an initial database setup.
213 $sql = 'CREATE TABLE IF NOT EXISTS ' . $wpdb->imsanity_ms . ' (
214 setting varchar(55),
215 data text NOT NULL,
216 PRIMARY KEY (setting)
217 );';
218
219 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
220 dbDelta( $sql );
221
222 // Add the rows to the database.
223 $data = imsanity_get_default_multisite_settings();
224 $wpdb->insert(
225 $wpdb->imsanity_ms,
226 array(
227 'setting' => 'multisite',
228 'data' => maybe_serialize( $data ),
229 )
230 );
231 $wpdb->insert(
232 $wpdb->imsanity_ms,
233 array(
234 'setting' => 'schema',
235 'data' => IMSANITY_SCHEMA_VERSION,
236 )
237 );
238 }
239
240 if ( IMSANITY_SCHEMA_VERSION !== $schema ) {
241 // This is a schema update. for the moment there is only one schema update available, from 1.0 to 1.1.
242 if ( '1.0' === $schema ) {
243 // Update from version 1.0 to 1.1.
244 $wpdb->insert(
245 $wpdb->imsanity_ms,
246 array(
247 'setting' => 'schema',
248 'data' => IMSANITY_SCHEMA_VERSION,
249 )
250 );
251 $wpdb->query( "ALTER TABLE $wpdb->imsanity_ms CHANGE COLUMN data data TEXT NOT NULL;" );
252 } else {
253 // @todo we don't have this yet
254 $wpdb->update(
255 $wpdb->imsanity_ms,
256 array( 'data' => IMSANITY_SCHEMA_VERSION ),
257 array( 'setting' => 'schema' )
258 );
259 }
260 }
261 }
262
263 /**
264 * Display the form for the multi-site settings page.
265 */
266 function imsanity_network_settings() {
267 $settings = imsanity_get_multisite_settings(); ?>
268 <div class="wrap">
269 <h1><?php esc_html_e( 'Imsanity Network Settings', 'imsanity' ); ?></h1>
270
271 <div id="ewwwio-promo">
272 <p>
273 <?php
274 printf(
275 /* translators: %s: link to install EWWW Image Optimizer plugin */
276 esc_html__( 'Get comprehensive image optimization with %s', 'imsanity' ),
277 '<br><a href="' . esc_url( admin_url( 'plugin-install.php?s=ewww+image+optimizer&tab=search&type=term' ) ) . '">EWWW Image Optimizer</a>'
278 );
279 ?>
280 <ul>
281 <li><?php esc_html_e( 'Full Compression', 'imsanity' ); ?></li>
282 <li><?php esc_html_e( 'Automatic Scaling', 'imsanity' ); ?></li>
283 <li><?php esc_html_e( 'Lazy Load', 'imsanity' ); ?></li>
284 <li><?php esc_html_e( 'WebP Conversion', 'imsanity' ); ?></li>
285 </ul>
286 </p>
287 </div>
288
289 <form method="post" action="">
290 <input type="hidden" name="update_imsanity_settings" value="1" />
291 <?php wp_nonce_field( 'imsanity_network_options' ); ?>
292 <table class="form-table">
293 <tr>
294 <th scope="row"><label for="imsanity_override_site"><?php esc_html_e( 'Global Settings Override', 'imsanity' ); ?></label></th>
295 <td>
296 <select name="imsanity_override_site">
297 <option value="0" <?php selected( $settings->imsanity_override_site, '0' ); ?> ><?php esc_html_e( 'Allow each site to configure Imsanity settings', 'imsanity' ); ?></option>
298 <option value="1" <?php selected( $settings->imsanity_override_site, '1' ); ?> ><?php esc_html_e( 'Use global Imsanity settings (below) for all sites', 'imsanity' ); ?></option>
299 </select>
300 <p class="description"><?php esc_html_e( 'If you allow per-site configuration, the settings below will be used as the defaults. Single-site defaults will be set the first time you visit the site admin after activating Imsanity.', 'imsanity' ); ?></p>
301 </td>
302 </tr>
303 <tr>
304 <th scope="row"><?php esc_html_e( 'Images uploaded within a Page/Post', 'imsanity' ); ?></th>
305 <td>
306 <label for="imsanity_max_width"><?php esc_html_e( 'Max Width', 'imsanity' ); ?></label> <input type="number" step="1" min="0" class='small-text' name="imsanity_max_width" value="<?php echo (int) $settings->imsanity_max_width; ?>" />
307 <label for="imsanity_max_height"><?php esc_html_e( 'Max Height', 'imsanity' ); ?></label> <input type="number" step="1" min="0" class="small-text" name="imsanity_max_height" value="<?php echo (int) $settings->imsanity_max_height; ?>" /> <?php esc_html_e( 'in pixels, enter 0 to disable', 'imsanity' ); ?>
308 <p class="description"><?php esc_html_e( 'These dimensions are used for Bulk Resizing also.', 'imsanity' ); ?></p>
309 </td>
310 </tr>
311 <tr>
312 <th scope="row"><?php esc_html_e( 'Images uploaded directly to the Media Library', 'imsanity' ); ?></th>
313 <td>
314 <label for="imsanity_max_width_library"><?php esc_html_e( 'Max Width', 'imsanity' ); ?></label> <input type="number" step="1" min="0" class='small-text' name="imsanity_max_width_library" value="<?php echo (int) $settings->imsanity_max_width_library; ?>" />
315 <label for="imsanity_max_height_library"><?php esc_html_e( 'Max Height', 'imsanity' ); ?></label> <input type="number" step="1" min="0" class="small-text" name="imsanity_max_height_library" value="<?php echo (int) $settings->imsanity_max_height_library; ?>" /> <?php esc_html_e( 'in pixels, enter 0 to disable', 'imsanity' ); ?>
316 </td>
317 </tr>
318 <tr>
319 <th scope="row"><?php esc_html_e( 'Images uploaded elsewhere (Theme headers, backgrounds, logos, etc)', 'imsanity' ); ?></th>
320 <td>
321 <label for="imsanity_max_width_other"><?php esc_html_e( 'Max Width', 'imsanity' ); ?></label> <input type="number" step="1" min="0" class='small-text' name="imsanity_max_width_other" value="<?php echo (int) $settings->imsanity_max_width_other; ?>" />
322 <label for="imsanity_max_height_other"><?php esc_html_e( 'Max Height', 'imsanity' ); ?></label> <input type="number" step="1" min="0" class="small-text" name="imsanity_max_height_other" value="<?php echo (int) $settings->imsanity_max_height_other; ?>" /> <?php esc_html_e( 'in pixels, enter 0 to disable', 'imsanity' ); ?>
323 </td>
324 </tr>
325 <tr>
326 <th scope="row">
327 <label for='imsanity_quality'><?php esc_html_e( 'JPG image quality', 'imsanity' ); ?>
328 </th>
329 <td>
330 <input type='text' id='imsanity_quality' name='imsanity_quality' class='small-text' value='<?php echo (int) $settings->imsanity_quality; ?>' />
331 <?php esc_html_e( 'Usable values are 1-92.', 'imsanity' ); ?>
332 <p class='description'><?php esc_html_e( 'Only used when resizing images, does not affect thumbnails.', 'imsanity' ); ?></p>
333 </td>
334 </tr>
335 <tr>
336 <th scope="row">
337 <label for='imsanity_avif_quality'><?php esc_html_e( 'AVIF image quality', 'imsanity' ); ?>
338 </th>
339 <td>
340 <input type='text' id='imsanity_avif_quality' name='imsanity_avif_quality' class='small-text' value='<?php echo (int) $settings->imsanity_avif_quality; ?>' />
341 <?php esc_html_e( 'Usable values are 1-92.', 'imsanity' ); ?>
342 <p class='description'><?php esc_html_e( 'Only used when resizing images, does not affect thumbnails.', 'imsanity' ); ?></p>
343 </td>
344 </tr>
345 <tr>
346 <th scope="row">
347 <label for='imsanity_webp_quality'><?php esc_html_e( 'WebP image quality', 'imsanity' ); ?>
348 </th>
349 <td>
350 <input type='text' id='imsanity_webp_quality' name='imsanity_webp_quality' class='small-text' value='<?php echo (int) $settings->imsanity_webp_quality; ?>' />
351 <?php esc_html_e( 'Usable values are 1-92.', 'imsanity' ); ?>
352 <p class='description'><?php esc_html_e( 'Only used when resizing images, does not affect thumbnails.', 'imsanity' ); ?></p>
353 </td>
354 </tr>
355 <tr>
356 <th scope="row">
357 <label for"imsanity_bmp_to_jpg"><?php esc_html_e( 'Convert BMP to JPG', 'imsanity' ); ?></label>
358 </th>
359 <td>
360 <input type="checkbox" id="imsanity_bmp_to_jpg" name="imsanity_bmp_to_jpg" value="true" <?php checked( $settings->imsanity_bmp_to_jpg ); ?> />
361 <?php
362 printf(
363 /* translators: %s: link to install EWWW Image Optimizer plugin */
364 esc_html__( 'Only applies to new image uploads, existing images may be converted with %s.', 'imsanity' ),
365 '<a href="' . esc_url( admin_url( 'plugin-install.php?s=ewww+image+optimizer&tab=search&type=term' ) ) . '">EWWW Image Optimizer</a>'
366 );
367 ?>
368 </td>
369 </tr>
370 <tr>
371 <th scope="row">
372 <label for="imsanity_png_to_jpg"><?php esc_html_e( 'Convert PNG to JPG', 'imsanity' ); ?></label>
373 </th>
374 <td>
375 <input type="checkbox" id="imsanity_png_to_jpg" name="imsanity_png_to_jpg" value="true" <?php checked( $settings->imsanity_png_to_jpg ); ?> />
376 <?php
377 printf(
378 /* translators: %s: link to install EWWW Image Optimizer plugin */
379 esc_html__( 'Only applies to new image uploads, existing images may be converted with %s.', 'imsanity' ),
380 '<a href="' . esc_url( admin_url( 'plugin-install.php?s=ewww+image+optimizer&tab=search&type=term' ) ) . '">EWWW Image Optimizer</a>'
381 );
382 ?>
383 </td>
384 </tr>
385 <tr>
386 <th scope="row">
387 <label for="imsanity_delete_originals"><?php esc_html_e( 'Delete Originals', 'imsanity' ); ?></label>
388 </th>
389 <td>
390 <input type="checkbox" id="imsanity_delete_originals" name="imsanity_delete_originals" value="true" <?php checked( $settings->imsanity_delete_originals ); ?> />
391 <?php esc_html_e( 'Remove the large pre-scaled originals that WordPress retains for thumbnail generation.', 'imsanity' ); ?>
392 </td>
393 </tr>
394 <?php if ( is_file( imsanity_debug_log_path() ) ) : ?>
395 <tr>
396 <th><?php esc_html_e( 'Debug Log', 'imsanity' ); ?></th>
397 <td>
398 <p>
399 <a target='_blank' href='<?php echo esc_url( wp_nonce_url( admin_url( 'admin.php?action=imsanity_view_debug_log' ), 'imsanity-options' ) ); ?>'><?php esc_html_e( 'View Log', 'imsanity' ); ?></a> -
400 <a href='<?php echo esc_url( wp_nonce_url( admin_url( 'admin.php?action=imsanity_delete_debug_log' ), 'imsanity-options' ) ); ?>'><?php esc_html_e( 'Clear Log', 'imsanity' ); ?></a>
401 </p>
402 </td>
403 </tr>
404 <?php endif; ?>
405 </table>
406
407 <p class="submit"><input type="submit" class="button-primary" value="<?php esc_attr_e( 'Update Settings', 'imsanity' ); ?>" /></p>
408
409 </form>
410
411 </div>
412 <?php
413 }
414
415 /**
416 * Process the form, update the network settings
417 * and clear the cached settings
418 */
419 function imsanity_network_settings_update() {
420 if ( ! current_user_can( 'manage_options' ) || empty( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST['_wpnonce'] ), 'imsanity_network_options' ) ) {
421 return;
422 }
423 global $wpdb;
424 global $_imsanity_multisite_settings;
425
426 // ensure that the custom table is created when the user updates network settings
427 // this is not ideal but it's better than checking for this table existance
428 // on every page load.
429 imsanity_maybe_created_custom_table();
430
431 $data = new stdClass();
432
433 $data->imsanity_override_site = isset( $_POST['imsanity_override_site'] ) ? (bool) $_POST['imsanity_override_site'] : false;
434 $data->imsanity_max_height = isset( $_POST['imsanity_max_height'] ) ? (int) $_POST['imsanity_max_height'] : 0;
435 $data->imsanity_max_width = isset( $_POST['imsanity_max_width'] ) ? (int) $_POST['imsanity_max_width'] : 0;
436 $data->imsanity_max_height_library = isset( $_POST['imsanity_max_height_library'] ) ? (int) $_POST['imsanity_max_height_library'] : 0;
437 $data->imsanity_max_width_library = isset( $_POST['imsanity_max_width_library'] ) ? (int) $_POST['imsanity_max_width_library'] : 0;
438 $data->imsanity_max_height_other = isset( $_POST['imsanity_max_height_other'] ) ? (int) $_POST['imsanity_max_height_other'] : 0;
439 $data->imsanity_max_width_other = isset( $_POST['imsanity_max_width_other'] ) ? (int) $_POST['imsanity_max_width_other'] : 0;
440 $data->imsanity_bmp_to_jpg = ! empty( $_POST['imsanity_bmp_to_jpg'] );
441 $data->imsanity_png_to_jpg = ! empty( $_POST['imsanity_png_to_jpg'] );
442 $data->imsanity_quality = isset( $_POST['imsanity_quality'] ) ? imsanity_jpg_quality( intval( $_POST['imsanity_quality'] ) ) : 82;
443 $data->imsanity_avif_quality = isset( $_POST['imsanity_avif_quality'] ) ? imsanity_avif_quality( intval( $_POST['imsanity_avif_quality'] ) ) : 86;
444 $data->imsanity_webp_quality = isset( $_POST['imsanity_webp_quality'] ) ? imsanity_webp_quality( intval( $_POST['imsanity_webp_quality'] ) ) : 86;
445 $data->imsanity_delete_originals = ! empty( $_POST['imsanity_delete_originals'] );
446
447 $wpdb->update(
448 $wpdb->imsanity_ms,
449 array( 'data' => maybe_serialize( $data ) ),
450 array( 'setting' => 'multisite' )
451 );
452
453 // Clear the cache.
454 $_imsanity_multisite_settings = null;
455 add_action( 'network_admin_notices', 'imsanity_network_settings_saved' );
456 }
457
458 /**
459 * Display a message to inform the user the multi-site setting have been saved.
460 */
461 function imsanity_network_settings_saved() {
462 echo "<div id='imsanity-network-settings-saved' class='updated fade'><p><strong>" . esc_html__( 'Imsanity network settings saved.', 'imsanity' ) . '</strong></p></div>';
463 }
464
465 /**
466 * Return the multi-site settings as a standard class. If the settings are not
467 * defined in the database or multi-site is not enabled then the default settings
468 * are returned. This is cached so it only loads once per page load, unless
469 * imsanity_network_settings_update is called.
470 *
471 * @return stdClass
472 */
473 function imsanity_get_multisite_settings() {
474 global $_imsanity_multisite_settings;
475 $result = null;
476
477 if ( ! $_imsanity_multisite_settings ) {
478 if ( function_exists( 'is_multisite' ) && is_multisite() ) {
479 global $wpdb;
480 $result = $wpdb->get_var( "SELECT data FROM $wpdb->imsanity_ms WHERE setting = 'multisite'" );
481 }
482
483 // if there's no results, return the defaults instead.
484 $_imsanity_multisite_settings = $result
485 ? unserialize( $result )
486 : imsanity_get_default_multisite_settings();
487
488 // this is for backwards compatibility.
489 if ( ! isset( $_imsanity_multisite_settings->imsanity_max_height_library ) ) {
490 $_imsanity_multisite_settings->imsanity_max_height_library = $_imsanity_multisite_settings->imsanity_max_height;
491 $_imsanity_multisite_settings->imsanity_max_width_library = $_imsanity_multisite_settings->imsanity_max_width;
492 $_imsanity_multisite_settings->imsanity_max_height_other = $_imsanity_multisite_settings->imsanity_max_height;
493 $_imsanity_multisite_settings->imsanity_max_width_other = $_imsanity_multisite_settings->imsanity_max_width;
494 }
495 $_imsanity_multisite_settings->imsanity_override_site = ! empty( $_imsanity_multisite_settings->imsanity_override_site ) ? '1' : '0';
496 $_imsanity_multisite_settings->imsanity_bmp_to_jpg = ! empty( $_imsanity_multisite_settings->imsanity_bmp_to_jpg ) ? true : false;
497 $_imsanity_multisite_settings->imsanity_png_to_jpg = ! empty( $_imsanity_multisite_settings->imsanity_png_to_jpg ) ? true : false;
498 if ( ! property_exists( $_imsanity_multisite_settings, 'imsanity_delete_originals' ) ) {
499 $_imsanity_multisite_settings->imsanity_delete_originals = false;
500 }
501 if ( ! property_exists( $_imsanity_multisite_settings, 'imsanity_avif_quality' ) ) {
502 $_imsanity_multisite_settings->imsanity_avif_quality = IMSANITY_DEFAULT_AVIF_QUALITY;
503 }
504 if ( ! property_exists( $_imsanity_multisite_settings, 'imsanity_webp_quality' ) ) {
505 $_imsanity_multisite_settings->imsanity_webp_quality = IMSANITY_DEFAULT_WEBP_QUALITY;
506 }
507 }
508 return $_imsanity_multisite_settings;
509 }
510
511 /**
512 * Gets the option setting for the given key, first checking to see if it has been
513 * set globally for multi-site. Otherwise checking the site options.
514 *
515 * @param string $key The name of the option to retrieve.
516 * @param string $ifnull Value to use if the requested option returns null.
517 */
518 function imsanity_get_option( $key, $ifnull ) {
519 $result = null;
520
521 $settings = imsanity_get_multisite_settings();
522
523 if ( $settings->imsanity_override_site ) {
524 $result = $settings->$key;
525 if ( is_null( $result ) ) {
526 $result = $ifnull;
527 }
528 } else {
529 $result = get_option( $key, $ifnull );
530 }
531
532 return $result;
533 }
534
535 /**
536 * Run upgrade check for new version.
537 */
538 function imsanity_upgrade() {
539 if ( is_network_admin() ) {
540 return;
541 }
542 if ( -1 === version_compare( get_option( 'imsanity_version' ), IMSANITY_VERSION ) ) {
543 if ( wp_doing_ajax() ) {
544 return;
545 }
546 imsanity_set_defaults();
547 update_option( 'imsanity_version', IMSANITY_VERSION );
548 }
549 }
550
551 /**
552 * Set default options on multi-site.
553 */
554 function imsanity_set_defaults() {
555 $settings = imsanity_get_multisite_settings();
556 add_option( 'imsanity_max_width', $settings->imsanity_max_width, '', false );
557 add_option( 'imsanity_max_height', $settings->imsanity_max_height, '', false );
558 add_option( 'imsanity_max_width_library', $settings->imsanity_max_width_library, '', false );
559 add_option( 'imsanity_max_height_library', $settings->imsanity_max_height_library, '', false );
560 add_option( 'imsanity_max_width_other', $settings->imsanity_max_width_other, '', false );
561 add_option( 'imsanity_max_height_other', $settings->imsanity_max_height_other, '', false );
562 add_option( 'imsanity_bmp_to_jpg', $settings->imsanity_bmp_to_jpg, '', false );
563 add_option( 'imsanity_png_to_jpg', $settings->imsanity_png_to_jpg, '', false );
564 add_option( 'imsanity_quality', $settings->imsanity_quality, '', false );
565 add_option( 'imsanity_avif_quality', $settings->imsanity_avif_quality, '', false );
566 add_option( 'imsanity_webp_quality', $settings->imsanity_webp_quality, '', false );
567 add_option( 'imsanity_delete_originals', $settings->imsanity_delete_originals, '', false );
568
569 $autoload_options = array(
570 'imsanity_version' => true,
571 'imsanity_max_width' => false,
572 'imsanity_max_height' => false,
573 'imsanity_max_width_library' => false,
574 'imsanity_max_height_library' => false,
575 'imsanity_max_width_other' => false,
576 'imsanity_max_height_other' => false,
577 'imsanity_bmp_to_jpg' => false,
578 'imsanity_png_to_jpg' => false,
579 'imsanity_quality' => false,
580 'imsanity_avif_quality' => false,
581 'imsanity_webp_quality' => false,
582 'imsanity_delete_originals' => false,
583 );
584 wp_set_option_autoload_values( $autoload_options );
585 }
586
587 /**
588 * Register the configuration settings that the plugin will use
589 */
590 function imsanity_register_settings() {
591 imsanity_upgrade();
592 // We only want to update if the form has been submitted.
593 // Verification is done inside the imsanity_network_settings_update() function.
594 if ( isset( $_POST['update_imsanity_settings'] ) && is_multisite() && is_network_admin() ) { // phpcs:ignore WordPress.Security.NonceVerification
595 imsanity_network_settings_update();
596 }
597 // Register our settings.
598 register_setting( 'imsanity-settings-group', 'imsanity_max_height', 'intval' );
599 register_setting( 'imsanity-settings-group', 'imsanity_max_width', 'intval' );
600 register_setting( 'imsanity-settings-group', 'imsanity_max_height_library', 'intval' );
601 register_setting( 'imsanity-settings-group', 'imsanity_max_width_library', 'intval' );
602 register_setting( 'imsanity-settings-group', 'imsanity_max_height_other', 'intval' );
603 register_setting( 'imsanity-settings-group', 'imsanity_max_width_other', 'intval' );
604 register_setting( 'imsanity-settings-group', 'imsanity_bmp_to_jpg', 'boolval' );
605 register_setting( 'imsanity-settings-group', 'imsanity_png_to_jpg', 'boolval' );
606 register_setting( 'imsanity-settings-group', 'imsanity_quality', 'imsanity_jpg_quality' );
607 register_setting( 'imsanity-settings-group', 'imsanity_avif_quality', 'imsanity_avif_quality' );
608 register_setting( 'imsanity-settings-group', 'imsanity_webp_quality', 'imsanity_webp_quality' );
609 register_setting( 'imsanity-settings-group', 'imsanity_delete_originals', 'boolval' );
610 }
611
612 /**
613 * Set the quality based on the mime type of the image being resized.
614 *
615 * @param int $quality The quality currently set.
616 * @param string $mime_type The mime type of the image being resized.
617 * @return int The (potentially) adjusted quality level.
618 */
619 function imsanity_editor_quality( $quality, $mime_type = '' ) {
620 if ( 'image/avif' === $mime_type ) {
621 $new_quality = imsanity_avif_quality();
622 } elseif ( 'image/webp' === $mime_type ) {
623 $new_quality = imsanity_webp_quality();
624 } elseif ( 'image/jpeg' === $mime_type ) {
625 $new_quality = imsanity_jpg_quality();
626 }
627 if ( ! empty( $new_quality ) && $new_quality > 0 && $new_quality <= 92 ) {
628 return $new_quality;
629 }
630 return $quality;
631 }
632
633 /**
634 * Validate and return the JPG quality setting.
635 *
636 * @param int $quality The JPG quality currently set.
637 * @return int The (potentially) adjusted quality level.
638 */
639 function imsanity_jpg_quality( $quality = null ) {
640 if ( is_null( $quality ) ) {
641 $quality = get_option( 'imsanity_quality' );
642 }
643 if ( preg_match( '/^(100|[1-9][0-9]?)$/', $quality ) ) {
644 return (int) $quality;
645 } else {
646 return IMSANITY_DEFAULT_QUALITY;
647 }
648 }
649
650 /**
651 * Validate and return the AVIF quality setting.
652 *
653 * @param int $quality The AVIF quality currently set.
654 * @return int The (potentially) adjusted quality level.
655 */
656 function imsanity_avif_quality( $quality = null ) {
657 if ( is_null( $quality ) ) {
658 $quality = get_option( 'imsanity_avif_quality' );
659 }
660 if ( preg_match( '/^(100|[1-9][0-9]?)$/', $quality ) ) {
661 return (int) $quality;
662 } else {
663 return IMSANITY_DEFAULT_AVIF_QUALITY;
664 }
665 }
666
667 /**
668 * Validate and return the WebP quality setting.
669 *
670 * @param int $quality The WebP quality currently set.
671 * @return int The (potentially) adjusted quality level.
672 */
673 function imsanity_webp_quality( $quality = null ) {
674 if ( is_null( $quality ) ) {
675 $quality = get_option( 'imsanity_webp_quality' );
676 }
677 if ( preg_match( '/^(100|[1-9][0-9]?)$/', $quality ) ) {
678 return (int) $quality;
679 } else {
680 return IMSANITY_DEFAULT_WEBP_QUALITY;
681 }
682 }
683
684 /**
685 * Check default WP threshold and adjust to comply with normal Imsanity behavior.
686 *
687 * @param int $size The default WP scaling size, or whatever has been filtered by other plugins.
688 * @param array $imagesize {
689 * Indexed array of the image width and height in pixels.
690 *
691 * @type int $0 The image width.
692 * @type int $1 The image height.
693 * }
694 * @param string $file Full path to the uploaded image file.
695 * @return int The proper size to use for scaling originals.
696 */
697 function imsanity_adjust_default_threshold( $size, $imagesize = array(), $file = '' ) {
698 if ( false !== strpos( $file, 'noresize' ) ) {
699 return false;
700 }
701 if ( ! defined( 'IMSANITY_DEFAULT_MAX_WIDTH' ) ) {
702 imsanity_init();
703 }
704 $max_size = max(
705 imsanity_get_option( 'imsanity_max_width', IMSANITY_DEFAULT_MAX_WIDTH ),
706 imsanity_get_option( 'imsanity_max_height', IMSANITY_DEFAULT_MAX_HEIGHT ),
707 imsanity_get_option( 'imsanity_max_width_library', IMSANITY_DEFAULT_MAX_WIDTH ),
708 imsanity_get_option( 'imsanity_max_height_library', IMSANITY_DEFAULT_MAX_HEIGHT ),
709 imsanity_get_option( 'imsanity_max_width_other', IMSANITY_DEFAULT_MAX_WIDTH ),
710 imsanity_get_option( 'imsanity_max_height_other', IMSANITY_DEFAULT_MAX_HEIGHT ),
711 (int) $size
712 );
713 return $max_size;
714 }
715
716 /**
717 * Helper function to render css styles for the settings forms
718 * for both site and network settings page
719 */
720 function imsanity_settings_css() {
721 ?>
722 <style>
723 #imsanity_header {
724 border: solid 1px #c6c6c6;
725 margin: 10px 0px;
726 padding: 0px 10px;
727 background-color: #e1e1e1;
728 }
729 #imsanity_header p {
730 margin: .5em 0;
731 }
732 #ewwwio-promo {
733 display: none;
734 float: right;
735 }
736 #ewwwio-promo a, #ewwwio-promo a:visited {
737 color: #3eadc9;
738 }
739 #ewwwio-promo ul {
740 list-style: disc;
741 padding-left: 13px;
742 }
743 @media screen and (min-width: 850px) {
744 .form-table {
745 clear: left;
746 width: calc(100% - 210px);
747 }
748 #ewwwio-promo {
749 display: block;
750 border: 1px solid #7e8993;
751 padding: 13px;
752 margin: 13px;
753 width: 150px;
754 }
755 }
756 </style>
757 <?php
758 }
759
760 /**
761 * Render the settings page by writing directly to stdout. if multi-site is enabled
762 * and imsanity_override_site is true, then display a notice message that settings
763 * are not editable instead of the settings form
764 */
765 function imsanity_settings_page() {
766 ?>
767 <div class="wrap">
768 <h1><?php esc_html_e( 'Imsanity Settings', 'imsanity' ); ?></h1>
769 <p>
770 <a target="_blank" href="https://wordpress.org/plugins/imsanity/#faq-header"><?php esc_html_e( 'FAQ', 'imsanity' ); ?></a> |
771 <a target="_blank" href="https://wordpress.org/support/plugin/imsanity/"><?php esc_html_e( 'Support', 'imsanity' ); ?></a> |
772 <a target="_blank" href="https://wordpress.org/support/plugin/imsanity/reviews/#new-post"><?php esc_html_e( 'Leave a Review', 'imsanity' ); ?></a>
773 </p>
774
775 <div id="ewwwio-promo">
776 <p>
777 <?php
778 printf(
779 /* translators: %s: link to install EWWW Image Optimizer plugin */
780 esc_html__( 'Get comprehensive image optimization with %s', 'imsanity' ),
781 '<br><a href="' . esc_url( admin_url( 'plugin-install.php?s=ewww+image+optimizer&tab=search&type=term' ) ) . '">EWWW Image Optimizer</a>'
782 );
783 ?>
784 <ul>
785 <li><?php esc_html_e( 'Full Compression', 'imsanity' ); ?></li>
786 <li><?php esc_html_e( 'Automatic Scaling', 'imsanity' ); ?></li>
787 <li><?php esc_html_e( 'Lazy Load', 'imsanity' ); ?></li>
788 <li><?php esc_html_e( 'WebP Conversion', 'imsanity' ); ?></li>
789 </ul>
790 </p>
791 </div>
792
793 <?php
794
795 $settings = imsanity_get_multisite_settings();
796
797 if ( $settings->imsanity_override_site ) {
798 imsanity_settings_page_notice();
799 } else {
800 imsanity_settings_page_form();
801 }
802
803 ?>
804
805 <h2 style="margin-top: 0px;"><?php esc_html_e( 'Bulk Resize Images', 'imsanity' ); ?></h2>
806
807 <div id="imsanity_header">
808 <p><?php esc_html_e( 'If you have existing images that were uploaded prior to installing Imsanity, you may resize them all in bulk to recover disk space (below).', 'imsanity' ); ?></p>
809 <p>
810 <?php
811 printf(
812 /* translators: 1: List View in the Media Library 2: the WP-CLI command */
813 esc_html__( 'You may also use %1$s to selectively resize images or WP-CLI to resize your images in bulk: %2$s', 'imsanity' ),
814 '<a href="' . esc_url( admin_url( 'upload.php?mode=list' ) ) . '">' . esc_html__( 'List View in the Media Library', 'imsanity' ) . '</a>',
815 '<code>wp help imsanity resize</code>'
816 );
817 ?>
818 </p>
819 </div>
820
821 <div style="border: solid 1px #ff6666; background-color: #ffbbbb; padding: 0 10px;margin-bottom:1em;">
822 <h4><?php esc_html_e( 'WARNING: Bulk Resize will alter your original images and cannot be undone!', 'imsanity' ); ?></h4>
823 <p>
824 <?php esc_html_e( 'It is HIGHLY recommended that you backup your images before proceeding.', 'imsanity' ); ?><br>
825 <?php
826 printf(
827 /* translators: %s: List View in the Media Library */
828 esc_html__( 'You may also resize 1 or 2 images using %s to verify that everything is working properly before processing your entire library.', 'imsanity' ),
829 '<a href="' . esc_url( admin_url( 'upload.php?mode=list' ) ) . '">' . esc_html__( 'List View in the Media Library', 'imsanity' ) . '</a>'
830 );
831 ?>
832 </p>
833 </div>
834
835 <?php
836 $button_text = __( 'Start Resizing All Images', 'imsanity' );
837 if ( get_option( 'imsanity_resume_id' ) ) {
838 $button_text = __( 'Continue Resizing', 'imsanity' );
839 }
840 ?>
841
842 <p class="submit" id="imsanity-examine-button">
843 <button class="button-primary" onclick="imsanity_load_images();"><?php echo esc_html( $button_text ); ?></button>
844 </p>
845 <form id="imsanity-bulk-stop" style="display:none;margin:1em 0 1em;" method="post" action="">
846 <button type="submit" class="button-secondary action"><?php esc_html_e( 'Stop Resizing', 'imsanity' ); ?></button><br>
847 *<i><?php esc_html_e( 'You will be able to resume the process later.', 'imsanity' ); ?></i>
848 </form>
849 <?php if ( get_option( 'imsanity_resume_id' ) ) : ?>
850 <p class="imsanity-bulk-text" style="margin-top:1em;"><?php esc_html_e( 'Would you like to start back at the beginning?', 'imsanity' ); ?></p>
851 <form class="imsanity-bulk-form" method="post" action="">
852 <?php wp_nonce_field( 'imsanity-bulk-reset', 'imsanity_wpnonce' ); ?>
853 <input type="hidden" name="imsanity_reset" value="1">
854 <button id="imsanity-bulk-reset" type="submit" class="button-secondary action"><?php esc_html_e( 'Clear Queue', 'imsanity' ); ?></button>
855 </form>
856 <?php endif; ?>
857 <div id="imsanity_loading" style="display: none;margin:1em 0 1em;"><img src="<?php echo esc_url( plugins_url( 'images/ajax-loader.gif', __FILE__ ) ); ?>" style="margin-bottom: .25em; vertical-align:middle;" />
858 <?php esc_html_e( 'Searching for images. This may take a moment.', 'imsanity' ); ?>
859 </div>
860 <div id="resize_results" style="display: none; border: solid 2px #666666; padding: 10px; height: 400px; overflow: auto;">
861 <div id="bulk-resize-beginning"><?php esc_html_e( 'Resizing...', 'imsanity' ); ?> <img src="<?php echo esc_url( plugins_url( 'images/ajax-loader.gif', __FILE__ ) ); ?>" style="margin-bottom: .25em; vertical-align:middle;" /></div>
862 </div>
863
864 <?php
865
866 echo '</div>';
867 }
868
869 /**
870 * Multi-user config file exists so display a notice
871 */
872 function imsanity_settings_page_notice() {
873 ?>
874 <div class="updated settings-error">
875 <p><strong><?php esc_html_e( 'Imsanity settings have been configured by the server administrator. There are no site-specific settings available.', 'imsanity' ); ?></strong></p>
876 </div>
877 <?php
878 }
879
880 /**
881 * Check to see if GD is missing, and alert the user.
882 */
883 function imsanity_missing_gd_admin_notice() {
884 if ( imsanity_gd_support() ) {
885 return;
886 }
887 echo "<div id='imsanity-missing-gd' class='notice notice-warning'><p>" . esc_html__( 'The GD extension is not enabled in PHP, Imsanity may not function correctly. Enable GD or contact your web host for assistance.', 'imsanity' ) . '</p></div>';
888 }
889
890 /**
891 * Render the site settings form. This is processed by
892 * WordPress built-in options persistance mechanism
893 */
894 function imsanity_settings_page_form() {
895 ?>
896 <form method="post" action="options.php">
897 <?php settings_fields( 'imsanity-settings-group' ); ?>
898 <table class="form-table">
899
900 <tr>
901 <th scope="row"><?php esc_html_e( 'Images uploaded within a Page/Post', 'imsanity' ); ?></th>
902 <td>
903 <label for="imsanity_max_width"><?php esc_html_e( 'Max Width', 'imsanity' ); ?></label> <input type="number" step="1" min="0" class="small-text" name="imsanity_max_width" value="<?php echo (int) get_option( 'imsanity_max_width', IMSANITY_DEFAULT_MAX_WIDTH ); ?>" />
904 <label for="imsanity_max_height"><?php esc_html_e( 'Max Height', 'imsanity' ); ?></label> <input type="number" step="1" min="0" class="small-text" name="imsanity_max_height" value="<?php echo (int) get_option( 'imsanity_max_height', IMSANITY_DEFAULT_MAX_HEIGHT ); ?>" /> <?php esc_html_e( 'in pixels, enter 0 to disable', 'imsanity' ); ?>
905 <p class="description"><?php esc_html_e( 'These dimensions are used for Bulk Resizing also.', 'imsanity' ); ?></p>
906 </td>
907 </tr>
908
909 <tr>
910 <th scope="row"><?php esc_html_e( 'Images uploaded directly to the Media Library', 'imsanity' ); ?></th>
911 <td>
912 <label for="imsanity_max_width_library"><?php esc_html_e( 'Max Width', 'imsanity' ); ?></label> <input type="number" step="1" min="0" class="small-text" name="imsanity_max_width_library" value="<?php echo (int) get_option( 'imsanity_max_width_library', IMSANITY_DEFAULT_MAX_WIDTH ); ?>" />
913 <label for="imsanity_max_height_library"><?php esc_html_e( 'Max Height', 'imsanity' ); ?></label> <input type="number" step="1" min="0" class="small-text" name="imsanity_max_height_library" value="<?php echo (int) get_option( 'imsanity_max_height_library', IMSANITY_DEFAULT_MAX_HEIGHT ); ?>" /> <?php esc_html_e( 'in pixels, enter 0 to disable', 'imsanity' ); ?>
914 </td>
915 </tr>
916
917 <tr>
918 <th scope="row"><?php esc_html_e( 'Images uploaded elsewhere (Theme headers, backgrounds, logos, etc)', 'imsanity' ); ?></th>
919 <td>
920 <label for="imsanity_max_width_other"><?php esc_html_e( 'Max Width', 'imsanity' ); ?></label> <input type="number" step="1" min="0" class="small-text" name="imsanity_max_width_other" value="<?php echo (int) get_option( 'imsanity_max_width_other', IMSANITY_DEFAULT_MAX_WIDTH ); ?>" />
921 <label for="imsanity_max_height_other"><?php esc_html_e( 'Max Height', 'imsanity' ); ?></label> <input type="number" step="1" min="0" class="small-text" name="imsanity_max_height_other" value="<?php echo (int) get_option( 'imsanity_max_height_other', IMSANITY_DEFAULT_MAX_HEIGHT ); ?>" /> <?php esc_html_e( 'in pixels, enter 0 to disable', 'imsanity' ); ?>
922 </td>
923 </tr>
924
925 <tr>
926 <th scope="row">
927 <label for='imsanity_quality' ><?php esc_html_e( 'JPG image quality', 'imsanity' ); ?>
928 </th>
929 <td>
930 <input type='text' id='imsanity_quality' name='imsanity_quality' class='small-text' value='<?php echo (int) imsanity_jpg_quality(); ?>' />
931 <?php esc_html_e( 'Usable values are 1-92.', 'imsanity' ); ?>
932 <p class='description'><?php esc_html_e( 'Only used when resizing images, does not affect thumbnails.', 'imsanity' ); ?></p>
933 </td>
934 </tr>
935
936 <tr>
937 <th scope="row">
938 <label for='imsanity_avif_quality' ><?php esc_html_e( 'AVIF image quality', 'imsanity' ); ?>
939 </th>
940 <td>
941 <input type='text' id='imsanity_avif_quality' name='imsanity_avif_quality' class='small-text' value='<?php echo (int) imsanity_avif_quality(); ?>' />
942 <?php esc_html_e( 'Usable values are 1-92.', 'imsanity' ); ?>
943 <p class='description'><?php esc_html_e( 'Only used when resizing images, does not affect thumbnails.', 'imsanity' ); ?></p>
944 </td>
945 </tr>
946
947 <tr>
948 <th scope="row">
949 <label for='imsanity_webp_quality' ><?php esc_html_e( 'WebP image quality', 'imsanity' ); ?>
950 </th>
951 <td>
952 <input type='text' id='imsanity_webp_quality' name='imsanity_webp_quality' class='small-text' value='<?php echo (int) imsanity_webp_quality(); ?>' />
953 <?php esc_html_e( 'Usable values are 1-92.', 'imsanity' ); ?>
954 <p class='description'><?php esc_html_e( 'Only used when resizing images, does not affect thumbnails.', 'imsanity' ); ?></p>
955 </td>
956 </tr>
957
958 <tr>
959 <th scope="row">
960 <label for="imsanity_bmp_to_jpg"><?php esc_html_e( 'Convert BMP To JPG', 'imsanity' ); ?></label>
961 </th>
962 <td>
963 <input type="checkbox" id="imsanity_bmp_to_jpg" name="imsanity_bmp_to_jpg" value="true" <?php checked( (bool) get_option( 'imsanity_bmp_to_jpg', IMSANITY_DEFAULT_BMP_TO_JPG ) ); ?> />
964 <?php
965 printf(
966 /* translators: %s: link to install EWWW Image Optimizer plugin */
967 esc_html__( 'Only applies to new image uploads, existing images may be converted with %s.', 'imsanity' ),
968 '<a href="' . esc_url( admin_url( 'plugin-install.php?s=ewww+image+optimizer&tab=search&type=term' ) ) . '">EWWW Image Optimizer</a>'
969 );
970 ?>
971 </td>
972 </tr>
973 <tr>
974 <th scope="row">
975 <label for="imsanity_png_to_jpg"><?php esc_html_e( 'Convert PNG To JPG', 'imsanity' ); ?></label>
976 </th>
977 <td>
978 <input type="checkbox" id="imsanity_png_to_jpg" name="imsanity_png_to_jpg" value="true" <?php checked( (bool) get_option( 'imsanity_png_to_jpg', IMSANITY_DEFAULT_PNG_TO_JPG ) ); ?> />
979 <?php
980 printf(
981 /* translators: %s: link to install EWWW Image Optimizer plugin */
982 esc_html__( 'Only applies to new image uploads, existing images may be converted with %s.', 'imsanity' ),
983 '<a href="' . esc_url( admin_url( 'plugin-install.php?s=ewww+image+optimizer&tab=search&type=term' ) ) . '">EWWW Image Optimizer</a>'
984 );
985 ?>
986 </td>
987 </tr>
988 <tr>
989 <th scope="row">
990 <label for="imsanity_delete_originals"><?php esc_html_e( 'Delete Originals', 'imsanity' ); ?></label>
991 </th>
992 <td>
993 <input type="checkbox" id="imsanity_delete_originals" name="imsanity_delete_originals" value="true" <?php checked( get_option( 'imsanity_delete_originals' ) ); ?> />
994 <?php esc_html_e( 'Remove the large pre-scaled originals that WordPress retains for thumbnail generation.', 'imsanity' ); ?>
995 </td>
996 </tr>
997 <?php if ( is_file( imsanity_debug_log_path() ) ) : ?>
998 <tr>
999 <th><?php esc_html_e( 'Debug Log', 'imsanity' ); ?></th>
1000 <td>
1001 <p>
1002 <a target='_blank' href='<?php echo esc_url( wp_nonce_url( admin_url( 'admin.php?action=imsanity_view_debug_log' ), 'imsanity-options' ) ); ?>'><?php esc_html_e( 'View Log', 'imsanity' ); ?></a> -
1003 <a href='<?php echo esc_url( wp_nonce_url( admin_url( 'admin.php?action=imsanity_delete_debug_log' ), 'imsanity-options' ) ); ?>'><?php esc_html_e( 'Clear Log', 'imsanity' ); ?></a>
1004 </p>
1005 </td>
1006 </tr>
1007 <?php endif; ?>
1008 </table>
1009
1010 <p class="submit"><input type="submit" class="button-primary" value="<?php esc_attr_e( 'Save Changes', 'imsanity' ); ?>" /></p>
1011
1012 </form>
1013 <?php
1014 }
1015