PluginProbe
Imsanity / 2.9.4
Imsanity v2.9.4
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.4, at settings.php

1,029 lines 43.1 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', '__return_false' );
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 ( ! defined( 'IMSANITY_DEFAULT_MAX_WIDTH' ) ) {
479 imsanity_init();
480 }
481 if ( function_exists( 'is_multisite' ) && is_multisite() ) {
482 global $wpdb;
483 $result = $wpdb->get_var( "SELECT data FROM $wpdb->imsanity_ms WHERE setting = 'multisite'" );
484 }
485
486 // if there's no results, return the defaults instead.
487 $_imsanity_multisite_settings = $result
488 ? unserialize( $result )
489 : imsanity_get_default_multisite_settings();
490
491 // this is for backwards compatibility.
492 if ( ! isset( $_imsanity_multisite_settings->imsanity_max_height_library ) ) {
493 $_imsanity_multisite_settings->imsanity_max_height_library = $_imsanity_multisite_settings->imsanity_max_height;
494 $_imsanity_multisite_settings->imsanity_max_width_library = $_imsanity_multisite_settings->imsanity_max_width;
495 $_imsanity_multisite_settings->imsanity_max_height_other = $_imsanity_multisite_settings->imsanity_max_height;
496 $_imsanity_multisite_settings->imsanity_max_width_other = $_imsanity_multisite_settings->imsanity_max_width;
497 }
498 $_imsanity_multisite_settings->imsanity_override_site = ! empty( $_imsanity_multisite_settings->imsanity_override_site ) ? '1' : '0';
499 $_imsanity_multisite_settings->imsanity_bmp_to_jpg = ! empty( $_imsanity_multisite_settings->imsanity_bmp_to_jpg ) ? true : false;
500 $_imsanity_multisite_settings->imsanity_png_to_jpg = ! empty( $_imsanity_multisite_settings->imsanity_png_to_jpg ) ? true : false;
501 if ( ! property_exists( $_imsanity_multisite_settings, 'imsanity_delete_originals' ) ) {
502 $_imsanity_multisite_settings->imsanity_delete_originals = false;
503 }
504 if ( ! property_exists( $_imsanity_multisite_settings, 'imsanity_avif_quality' ) ) {
505 $_imsanity_multisite_settings->imsanity_avif_quality = IMSANITY_DEFAULT_AVIF_QUALITY;
506 }
507 if ( ! property_exists( $_imsanity_multisite_settings, 'imsanity_webp_quality' ) ) {
508 $_imsanity_multisite_settings->imsanity_webp_quality = IMSANITY_DEFAULT_WEBP_QUALITY;
509 }
510 }
511 return $_imsanity_multisite_settings;
512 }
513
514 /**
515 * Gets the option setting for the given key, first checking to see if it has been
516 * set globally for multi-site. Otherwise checking the site options.
517 *
518 * @param string $key The name of the option to retrieve.
519 * @param string $ifnull Value to use if the requested option returns null.
520 */
521 function imsanity_get_option( $key, $ifnull ) {
522 $result = null;
523
524 $settings = imsanity_get_multisite_settings();
525
526 if ( $settings->imsanity_override_site ) {
527 $result = $settings->$key;
528 if ( is_null( $result ) ) {
529 $result = $ifnull;
530 }
531 } else {
532 $result = get_option( $key, $ifnull );
533 }
534
535 return $result;
536 }
537
538 /**
539 * Run upgrade check for new version.
540 */
541 function imsanity_upgrade() {
542 if ( is_network_admin() ) {
543 return;
544 }
545 if ( -1 === version_compare( get_option( 'imsanity_version' ), IMSANITY_VERSION ) ) {
546 if ( wp_doing_ajax() ) {
547 return;
548 }
549 imsanity_set_defaults();
550 update_option( 'imsanity_version', IMSANITY_VERSION );
551 }
552 }
553
554 /**
555 * Set default options on multi-site.
556 */
557 function imsanity_set_defaults() {
558 $settings = imsanity_get_multisite_settings();
559 add_option( 'imsanity_max_width', $settings->imsanity_max_width, '', false );
560 add_option( 'imsanity_max_height', $settings->imsanity_max_height, '', false );
561 add_option( 'imsanity_max_width_library', $settings->imsanity_max_width_library, '', false );
562 add_option( 'imsanity_max_height_library', $settings->imsanity_max_height_library, '', false );
563 add_option( 'imsanity_max_width_other', $settings->imsanity_max_width_other, '', false );
564 add_option( 'imsanity_max_height_other', $settings->imsanity_max_height_other, '', false );
565 add_option( 'imsanity_bmp_to_jpg', $settings->imsanity_bmp_to_jpg, '', false );
566 add_option( 'imsanity_png_to_jpg', $settings->imsanity_png_to_jpg, '', false );
567 add_option( 'imsanity_quality', $settings->imsanity_quality, '', false );
568 add_option( 'imsanity_avif_quality', $settings->imsanity_avif_quality, '', false );
569 add_option( 'imsanity_webp_quality', $settings->imsanity_webp_quality, '', false );
570 add_option( 'imsanity_delete_originals', $settings->imsanity_delete_originals, '', false );
571
572 $autoload_options = array(
573 'imsanity_version' => true,
574 'imsanity_max_width' => false,
575 'imsanity_max_height' => false,
576 'imsanity_max_width_library' => false,
577 'imsanity_max_height_library' => false,
578 'imsanity_max_width_other' => false,
579 'imsanity_max_height_other' => false,
580 'imsanity_bmp_to_jpg' => false,
581 'imsanity_png_to_jpg' => false,
582 'imsanity_quality' => false,
583 'imsanity_avif_quality' => false,
584 'imsanity_webp_quality' => false,
585 'imsanity_delete_originals' => false,
586 );
587 wp_set_option_autoload_values( $autoload_options );
588 }
589
590 /**
591 * Register the configuration settings that the plugin will use
592 */
593 function imsanity_register_settings() {
594 imsanity_upgrade();
595 // We only want to update if the form has been submitted.
596 // Verification is done inside the imsanity_network_settings_update() function.
597 if ( isset( $_POST['update_imsanity_settings'] ) && is_multisite() && is_network_admin() ) { // phpcs:ignore WordPress.Security.NonceVerification
598 imsanity_network_settings_update();
599 }
600 // Register our settings.
601 register_setting( 'imsanity-settings-group', 'imsanity_max_height', 'intval' );
602 register_setting( 'imsanity-settings-group', 'imsanity_max_width', 'intval' );
603 register_setting( 'imsanity-settings-group', 'imsanity_max_height_library', 'intval' );
604 register_setting( 'imsanity-settings-group', 'imsanity_max_width_library', 'intval' );
605 register_setting( 'imsanity-settings-group', 'imsanity_max_height_other', 'intval' );
606 register_setting( 'imsanity-settings-group', 'imsanity_max_width_other', 'intval' );
607 register_setting( 'imsanity-settings-group', 'imsanity_bmp_to_jpg', 'boolval' );
608 register_setting( 'imsanity-settings-group', 'imsanity_png_to_jpg', 'boolval' );
609 register_setting( 'imsanity-settings-group', 'imsanity_quality', 'imsanity_jpg_quality' );
610 register_setting( 'imsanity-settings-group', 'imsanity_avif_quality', 'imsanity_avif_quality' );
611 register_setting( 'imsanity-settings-group', 'imsanity_webp_quality', 'imsanity_webp_quality' );
612 register_setting( 'imsanity-settings-group', 'imsanity_delete_originals', 'boolval' );
613 }
614
615 /**
616 * Set the quality based on the mime type of the image being resized.
617 *
618 * @param int $quality The quality currently set.
619 * @param string $mime_type The mime type of the image being resized.
620 * @return int The (potentially) adjusted quality level.
621 */
622 function imsanity_editor_quality( $quality, $mime_type = '' ) {
623 if ( 'image/avif' === $mime_type ) {
624 $new_quality = imsanity_avif_quality();
625 } elseif ( 'image/webp' === $mime_type ) {
626 $new_quality = imsanity_webp_quality();
627 } elseif ( 'image/jpeg' === $mime_type ) {
628 $new_quality = imsanity_jpg_quality();
629 }
630 if ( ! empty( $new_quality ) && $new_quality > 0 && $new_quality <= 92 ) {
631 return $new_quality;
632 }
633 return $quality;
634 }
635
636 /**
637 * Validate and return the JPG quality setting.
638 *
639 * @param int $quality The JPG quality currently set.
640 * @return int The (potentially) adjusted quality level.
641 */
642 function imsanity_jpg_quality( $quality = null ) {
643 if ( is_null( $quality ) ) {
644 $quality = get_option( 'imsanity_quality' );
645 }
646 if ( preg_match( '/^(100|[1-9][0-9]?)$/', $quality ) ) {
647 return (int) $quality;
648 } else {
649 if ( ! defined( 'IMSANITY_DEFAULT_QUALITY' ) ) {
650 imsanity_init();
651 }
652 return IMSANITY_DEFAULT_QUALITY;
653 }
654 }
655
656 /**
657 * Validate and return the AVIF quality setting.
658 *
659 * @param int $quality The AVIF quality currently set.
660 * @return int The (potentially) adjusted quality level.
661 */
662 function imsanity_avif_quality( $quality = null ) {
663 if ( is_null( $quality ) ) {
664 $quality = get_option( 'imsanity_avif_quality' );
665 }
666 if ( preg_match( '/^(100|[1-9][0-9]?)$/', $quality ) ) {
667 return (int) $quality;
668 } else {
669 if ( ! defined( 'IMSANITY_DEFAULT_AVIF_QUALITY' ) ) {
670 imsanity_init();
671 }
672 return IMSANITY_DEFAULT_AVIF_QUALITY;
673 }
674 }
675
676 /**
677 * Validate and return the WebP quality setting.
678 *
679 * @param int $quality The WebP quality currently set.
680 * @return int The (potentially) adjusted quality level.
681 */
682 function imsanity_webp_quality( $quality = null ) {
683 if ( is_null( $quality ) ) {
684 $quality = get_option( 'imsanity_webp_quality' );
685 }
686 if ( preg_match( '/^(100|[1-9][0-9]?)$/', $quality ) ) {
687 return (int) $quality;
688 } else {
689 if ( ! defined( 'IMSANITY_DEFAULT_WEBP_QUALITY' ) ) {
690 imsanity_init();
691 }
692 return IMSANITY_DEFAULT_WEBP_QUALITY;
693 }
694 }
695
696 /**
697 * Check default WP threshold and adjust to comply with normal Imsanity behavior.
698 *
699 * @param int $size The default WP scaling size, or whatever has been filtered by other plugins.
700 * @param array $imagesize {
701 * Indexed array of the image width and height in pixels.
702 *
703 * @type int $0 The image width.
704 * @type int $1 The image height.
705 * }
706 * @param string $file Full path to the uploaded image file.
707 * @return int The proper size to use for scaling originals.
708 */
709 function imsanity_adjust_default_threshold( $size, $imagesize = array(), $file = '' ) {
710 if ( false !== strpos( $file, 'noresize' ) ) {
711 return false;
712 }
713 if ( ! defined( 'IMSANITY_DEFAULT_MAX_WIDTH' ) ) {
714 imsanity_init();
715 }
716 $max_size = max(
717 imsanity_get_option( 'imsanity_max_width', IMSANITY_DEFAULT_MAX_WIDTH ),
718 imsanity_get_option( 'imsanity_max_height', IMSANITY_DEFAULT_MAX_HEIGHT ),
719 imsanity_get_option( 'imsanity_max_width_library', IMSANITY_DEFAULT_MAX_WIDTH ),
720 imsanity_get_option( 'imsanity_max_height_library', IMSANITY_DEFAULT_MAX_HEIGHT ),
721 imsanity_get_option( 'imsanity_max_width_other', IMSANITY_DEFAULT_MAX_WIDTH ),
722 imsanity_get_option( 'imsanity_max_height_other', IMSANITY_DEFAULT_MAX_HEIGHT ),
723 (int) $size
724 );
725 return $max_size;
726 }
727
728 /**
729 * Helper function to render css styles for the settings forms
730 * for both site and network settings page
731 */
732 function imsanity_settings_css() {
733 ?>
734 <style>
735 #imsanity_header {
736 border: solid 1px #c6c6c6;
737 margin: 10px 0px;
738 padding: 0px 10px;
739 background-color: #e1e1e1;
740 }
741 #imsanity_header p {
742 margin: .5em 0;
743 }
744 #ewwwio-promo {
745 display: none;
746 float: right;
747 }
748 #ewwwio-promo a, #ewwwio-promo a:visited {
749 color: #3eadc9;
750 }
751 #ewwwio-promo ul {
752 list-style: disc;
753 padding-left: 13px;
754 }
755 @media screen and (min-width: 850px) {
756 .form-table {
757 clear: left;
758 width: calc(100% - 210px);
759 }
760 #ewwwio-promo {
761 display: block;
762 border: 1px solid #7e8993;
763 padding: 13px;
764 margin: 13px;
765 width: 150px;
766 }
767 }
768 </style>
769 <?php
770 }
771
772 /**
773 * Render the settings page by writing directly to stdout. if multi-site is enabled
774 * and imsanity_override_site is true, then display a notice message that settings
775 * are not editable instead of the settings form
776 */
777 function imsanity_settings_page() {
778 ?>
779 <div class="wrap">
780 <h1><?php esc_html_e( 'Imsanity Settings', 'imsanity' ); ?></h1>
781 <p>
782 <a target="_blank" href="https://wordpress.org/plugins/imsanity/#faq-header"><?php esc_html_e( 'FAQ', 'imsanity' ); ?></a> |
783 <a target="_blank" href="https://wordpress.org/support/plugin/imsanity/"><?php esc_html_e( 'Support', 'imsanity' ); ?></a> |
784 <a target="_blank" href="https://wordpress.org/support/plugin/imsanity/reviews/#new-post"><?php esc_html_e( 'Leave a Review', 'imsanity' ); ?></a>
785 </p>
786
787 <div id="ewwwio-promo">
788 <p>
789 <?php
790 printf(
791 /* translators: %s: link to install EWWW Image Optimizer plugin */
792 esc_html__( 'Get comprehensive image optimization with %s', 'imsanity' ),
793 '<br><a href="' . esc_url( admin_url( 'plugin-install.php?s=ewww+image+optimizer&tab=search&type=term' ) ) . '">EWWW Image Optimizer</a>'
794 );
795 ?>
796 <ul>
797 <li><?php esc_html_e( 'Full Compression', 'imsanity' ); ?></li>
798 <li><?php esc_html_e( 'Automatic Scaling', 'imsanity' ); ?></li>
799 <li><?php esc_html_e( 'Lazy Load', 'imsanity' ); ?></li>
800 <li><?php esc_html_e( 'WebP Conversion', 'imsanity' ); ?></li>
801 </ul>
802 </p>
803 </div>
804
805 <?php
806
807 $settings = imsanity_get_multisite_settings();
808
809 if ( $settings->imsanity_override_site ) {
810 imsanity_settings_page_notice();
811 } else {
812 imsanity_settings_page_form();
813 }
814
815 ?>
816
817 <h2 style="margin-top: 0px;"><?php esc_html_e( 'Bulk Resize Images', 'imsanity' ); ?></h2>
818
819 <div id="imsanity_header">
820 <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>
821 <p>
822 <?php
823 printf(
824 /* translators: 1: List View in the Media Library 2: the WP-CLI command */
825 esc_html__( 'You may also use %1$s to selectively resize images or WP-CLI to resize your images in bulk: %2$s', 'imsanity' ),
826 '<a href="' . esc_url( admin_url( 'upload.php?mode=list' ) ) . '">' . esc_html__( 'List View in the Media Library', 'imsanity' ) . '</a>',
827 '<code>wp help imsanity resize</code>'
828 );
829 ?>
830 </p>
831 </div>
832
833 <div style="border: solid 1px #ff6666; background-color: #ffbbbb; padding: 0 10px;margin-bottom:1em;">
834 <h4><?php esc_html_e( 'WARNING: Bulk Resize will alter your original images and cannot be undone!', 'imsanity' ); ?></h4>
835 <p>
836 <?php esc_html_e( 'It is HIGHLY recommended that you backup your images before proceeding.', 'imsanity' ); ?><br>
837 <?php
838 printf(
839 /* translators: %s: List View in the Media Library */
840 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' ),
841 '<a href="' . esc_url( admin_url( 'upload.php?mode=list' ) ) . '">' . esc_html__( 'List View in the Media Library', 'imsanity' ) . '</a>'
842 );
843 ?>
844 </p>
845 </div>
846
847 <?php
848 $button_text = __( 'Start Resizing All Images', 'imsanity' );
849 if ( get_option( 'imsanity_resume_id' ) ) {
850 $button_text = __( 'Continue Resizing', 'imsanity' );
851 }
852 ?>
853
854 <p class="submit" id="imsanity-examine-button">
855 <button class="button-primary" onclick="imsanity_load_images();"><?php echo esc_html( $button_text ); ?></button>
856 </p>
857 <form id="imsanity-bulk-stop" style="display:none;margin:1em 0 1em;" method="post" action="">
858 <button type="submit" class="button-secondary action"><?php esc_html_e( 'Stop Resizing', 'imsanity' ); ?></button><br>
859 *<i><?php esc_html_e( 'You will be able to resume the process later.', 'imsanity' ); ?></i>
860 </form>
861 <?php if ( get_option( 'imsanity_resume_id' ) ) : ?>
862 <p class="imsanity-bulk-text" style="margin-top:1em;"><?php esc_html_e( 'Would you like to start back at the beginning?', 'imsanity' ); ?></p>
863 <form class="imsanity-bulk-form" method="post" action="">
864 <?php wp_nonce_field( 'imsanity-bulk-reset', 'imsanity_wpnonce' ); ?>
865 <input type="hidden" name="imsanity_reset" value="1">
866 <button id="imsanity-bulk-reset" type="submit" class="button-secondary action"><?php esc_html_e( 'Clear Queue', 'imsanity' ); ?></button>
867 </form>
868 <?php endif; ?>
869 <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;" />
870 <?php esc_html_e( 'Searching for images. This may take a moment.', 'imsanity' ); ?>
871 </div>
872 <div id="resize_results" style="display: none; border: solid 2px #666666; padding: 10px; height: 400px; overflow: auto;">
873 <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>
874 </div>
875
876 <?php
877
878 echo '</div>';
879 }
880
881 /**
882 * Multi-user config file exists so display a notice
883 */
884 function imsanity_settings_page_notice() {
885 ?>
886 <div class="updated settings-error">
887 <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>
888 </div>
889 <?php
890 }
891
892 /**
893 * Check to see if GD is missing and alert the user.
894 */
895 function imsanity_missing_gd_admin_notice() {
896 if ( imsanity_gd_support() ) {
897 return;
898 }
899 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>';
900 }
901
902 /**
903 * Render the site settings form.
904 */
905 function imsanity_settings_page_form() {
906 if ( ! defined( 'IMSANITY_DEFAULT_MAX_WIDTH' ) ) {
907 imsanity_init();
908 }
909 ?>
910 <form method="post" action="options.php">
911 <?php settings_fields( 'imsanity-settings-group' ); ?>
912 <table class="form-table">
913
914 <tr>
915 <th scope="row"><?php esc_html_e( 'Images uploaded within a Page/Post', 'imsanity' ); ?></th>
916 <td>
917 <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 ); ?>" />
918 <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' ); ?>
919 <p class="description"><?php esc_html_e( 'These dimensions are used for Bulk Resizing also.', 'imsanity' ); ?></p>
920 </td>
921 </tr>
922
923 <tr>
924 <th scope="row"><?php esc_html_e( 'Images uploaded directly to the Media Library', 'imsanity' ); ?></th>
925 <td>
926 <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 ); ?>" />
927 <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' ); ?>
928 </td>
929 </tr>
930
931 <tr>
932 <th scope="row"><?php esc_html_e( 'Images uploaded elsewhere (Theme headers, backgrounds, logos, etc)', 'imsanity' ); ?></th>
933 <td>
934 <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 ); ?>" />
935 <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' ); ?>
936 </td>
937 </tr>
938
939 <tr>
940 <th scope="row">
941 <label for='imsanity_quality' ><?php esc_html_e( 'JPG image quality', 'imsanity' ); ?>
942 </th>
943 <td>
944 <input type='text' id='imsanity_quality' name='imsanity_quality' class='small-text' value='<?php echo (int) imsanity_jpg_quality(); ?>' />
945 <?php esc_html_e( 'Usable values are 1-92.', 'imsanity' ); ?>
946 <p class='description'><?php esc_html_e( 'Only used when resizing images, does not affect thumbnails.', 'imsanity' ); ?></p>
947 </td>
948 </tr>
949
950 <tr>
951 <th scope="row">
952 <label for='imsanity_avif_quality' ><?php esc_html_e( 'AVIF image quality', 'imsanity' ); ?>
953 </th>
954 <td>
955 <input type='text' id='imsanity_avif_quality' name='imsanity_avif_quality' class='small-text' value='<?php echo (int) imsanity_avif_quality(); ?>' />
956 <?php esc_html_e( 'Usable values are 1-92.', 'imsanity' ); ?>
957 <p class='description'><?php esc_html_e( 'Only used when resizing images, does not affect thumbnails.', 'imsanity' ); ?></p>
958 </td>
959 </tr>
960
961 <tr>
962 <th scope="row">
963 <label for='imsanity_webp_quality' ><?php esc_html_e( 'WebP image quality', 'imsanity' ); ?>
964 </th>
965 <td>
966 <input type='text' id='imsanity_webp_quality' name='imsanity_webp_quality' class='small-text' value='<?php echo (int) imsanity_webp_quality(); ?>' />
967 <?php esc_html_e( 'Usable values are 1-92.', 'imsanity' ); ?>
968 <p class='description'><?php esc_html_e( 'Only used when resizing images, does not affect thumbnails.', 'imsanity' ); ?></p>
969 </td>
970 </tr>
971
972 <tr>
973 <th scope="row">
974 <label for="imsanity_bmp_to_jpg"><?php esc_html_e( 'Convert BMP To JPG', 'imsanity' ); ?></label>
975 </th>
976 <td>
977 <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 ) ); ?> />
978 <?php
979 printf(
980 /* translators: %s: link to install EWWW Image Optimizer plugin */
981 esc_html__( 'Only applies to new image uploads, existing images may be converted with %s.', 'imsanity' ),
982 '<a href="' . esc_url( admin_url( 'plugin-install.php?s=ewww+image+optimizer&tab=search&type=term' ) ) . '">EWWW Image Optimizer</a>'
983 );
984 ?>
985 </td>
986 </tr>
987 <tr>
988 <th scope="row">
989 <label for="imsanity_png_to_jpg"><?php esc_html_e( 'Convert PNG To JPG', 'imsanity' ); ?></label>
990 </th>
991 <td>
992 <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 ) ); ?> />
993 <?php
994 printf(
995 /* translators: %s: link to install EWWW Image Optimizer plugin */
996 esc_html__( 'Only applies to new image uploads, existing images may be converted with %s.', 'imsanity' ),
997 '<a href="' . esc_url( admin_url( 'plugin-install.php?s=ewww+image+optimizer&tab=search&type=term' ) ) . '">EWWW Image Optimizer</a>'
998 );
999 ?>
1000 </td>
1001 </tr>
1002 <tr>
1003 <th scope="row">
1004 <label for="imsanity_delete_originals"><?php esc_html_e( 'Delete Originals', 'imsanity' ); ?></label>
1005 </th>
1006 <td>
1007 <input type="checkbox" id="imsanity_delete_originals" name="imsanity_delete_originals" value="true" <?php checked( get_option( 'imsanity_delete_originals' ) ); ?> />
1008 <?php esc_html_e( 'Remove the large pre-scaled originals that WordPress retains for thumbnail generation.', 'imsanity' ); ?>
1009 </td>
1010 </tr>
1011 <?php if ( is_file( imsanity_debug_log_path() ) ) : ?>
1012 <tr>
1013 <th><?php esc_html_e( 'Debug Log', 'imsanity' ); ?></th>
1014 <td>
1015 <p>
1016 <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> -
1017 <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>
1018 </p>
1019 </td>
1020 </tr>
1021 <?php endif; ?>
1022 </table>
1023
1024 <p class="submit"><input type="submit" class="button-primary" value="<?php esc_attr_e( 'Save Changes', 'imsanity' ); ?>" /></p>
1025
1026 </form>
1027 <?php
1028 }
1029