PluginProbe
Imsanity / 2.9.1
Imsanity v2.9.1
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.1, at settings.php

996 lines 42.2 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 $data->imsanity_override_site = false;
177 $data->imsanity_max_height = IMSANITY_DEFAULT_MAX_HEIGHT;
178 $data->imsanity_max_width = IMSANITY_DEFAULT_MAX_WIDTH;
179 $data->imsanity_max_height_library = IMSANITY_DEFAULT_MAX_HEIGHT;
180 $data->imsanity_max_width_library = IMSANITY_DEFAULT_MAX_WIDTH;
181 $data->imsanity_max_height_other = IMSANITY_DEFAULT_MAX_HEIGHT;
182 $data->imsanity_max_width_other = IMSANITY_DEFAULT_MAX_WIDTH;
183 $data->imsanity_bmp_to_jpg = IMSANITY_DEFAULT_BMP_TO_JPG;
184 $data->imsanity_png_to_jpg = IMSANITY_DEFAULT_PNG_TO_JPG;
185 $data->imsanity_quality = IMSANITY_DEFAULT_QUALITY;
186 $data->imsanity_avif_quality = IMSANITY_DEFAULT_AVIF_QUALITY;
187 $data->imsanity_webp_quality = IMSANITY_DEFAULT_WEBP_QUALITY;
188 $data->imsanity_delete_originals = false;
189 return $data;
190 }
191
192
193 /**
194 * On activation create the multisite database table if necessary. this is
195 * called when the plugin is activated as well as when it is automatically
196 * updated.
197 */
198 function imsanity_maybe_created_custom_table() {
199 // If not a multi-site no need to do any custom table lookups.
200 if ( ! function_exists( 'is_multisite' ) || ( ! is_multisite() ) ) {
201 return;
202 }
203
204 global $wpdb;
205
206 $schema = imsanity_multisite_table_schema_version();
207
208 if ( '0' === $schema ) {
209 // This is an initial database setup.
210 $sql = 'CREATE TABLE IF NOT EXISTS ' . $wpdb->imsanity_ms . ' (
211 setting varchar(55),
212 data text NOT NULL,
213 PRIMARY KEY (setting)
214 );';
215
216 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
217 dbDelta( $sql );
218
219 // Add the rows to the database.
220 $data = imsanity_get_default_multisite_settings();
221 $wpdb->insert(
222 $wpdb->imsanity_ms,
223 array(
224 'setting' => 'multisite',
225 'data' => maybe_serialize( $data ),
226 )
227 );
228 $wpdb->insert(
229 $wpdb->imsanity_ms,
230 array(
231 'setting' => 'schema',
232 'data' => IMSANITY_SCHEMA_VERSION,
233 )
234 );
235 }
236
237 if ( IMSANITY_SCHEMA_VERSION !== $schema ) {
238 // This is a schema update. for the moment there is only one schema update available, from 1.0 to 1.1.
239 if ( '1.0' === $schema ) {
240 // Update from version 1.0 to 1.1.
241 $wpdb->insert(
242 $wpdb->imsanity_ms,
243 array(
244 'setting' => 'schema',
245 'data' => IMSANITY_SCHEMA_VERSION,
246 )
247 );
248 $wpdb->query( "ALTER TABLE $wpdb->imsanity_ms CHANGE COLUMN data data TEXT NOT NULL;" );
249 } else {
250 // @todo we don't have this yet
251 $wpdb->update(
252 $wpdb->imsanity_ms,
253 array( 'data' => IMSANITY_SCHEMA_VERSION ),
254 array( 'setting' => 'schema' )
255 );
256 }
257 }
258 }
259
260 /**
261 * Display the form for the multi-site settings page.
262 */
263 function imsanity_network_settings() {
264 $settings = imsanity_get_multisite_settings(); ?>
265 <div class="wrap">
266 <h1><?php esc_html_e( 'Imsanity Network Settings', 'imsanity' ); ?></h1>
267
268 <div id="ewwwio-promo">
269 <p>
270 <?php
271 printf(
272 /* translators: %s: link to install EWWW Image Optimizer plugin */
273 esc_html__( 'Get comprehensive image optimization with %s', 'imsanity' ),
274 '<br><a href="' . esc_url( admin_url( 'plugin-install.php?s=ewww+image+optimizer&tab=search&type=term' ) ) . '">EWWW Image Optimizer</a>'
275 );
276 ?>
277 <ul>
278 <li><?php esc_html_e( 'Full Compression', 'imsanity' ); ?></li>
279 <li><?php esc_html_e( 'Automatic Scaling', 'imsanity' ); ?></li>
280 <li><?php esc_html_e( 'Lazy Load', 'imsanity' ); ?></li>
281 <li><?php esc_html_e( 'WebP Conversion', 'imsanity' ); ?></li>
282 </ul>
283 </p>
284 </div>
285
286 <form method="post" action="">
287 <input type="hidden" name="update_imsanity_settings" value="1" />
288 <?php wp_nonce_field( 'imsanity_network_options' ); ?>
289 <table class="form-table">
290 <tr>
291 <th scope="row"><label for="imsanity_override_site"><?php esc_html_e( 'Global Settings Override', 'imsanity' ); ?></label></th>
292 <td>
293 <select name="imsanity_override_site">
294 <option value="0" <?php selected( $settings->imsanity_override_site, '0' ); ?> ><?php esc_html_e( 'Allow each site to configure Imsanity settings', 'imsanity' ); ?></option>
295 <option value="1" <?php selected( $settings->imsanity_override_site, '1' ); ?> ><?php esc_html_e( 'Use global Imsanity settings (below) for all sites', 'imsanity' ); ?></option>
296 </select>
297 <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>
298 </td>
299 </tr>
300 <tr>
301 <th scope="row"><?php esc_html_e( 'Images uploaded within a Page/Post', 'imsanity' ); ?></th>
302 <td>
303 <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; ?>" />
304 <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' ); ?>
305 <p class="description"><?php esc_html_e( 'These dimensions are used for Bulk Resizing also.', 'imsanity' ); ?></p>
306 </td>
307 </tr>
308 <tr>
309 <th scope="row"><?php esc_html_e( 'Images uploaded directly to the Media Library', 'imsanity' ); ?></th>
310 <td>
311 <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; ?>" />
312 <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' ); ?>
313 </td>
314 </tr>
315 <tr>
316 <th scope="row"><?php esc_html_e( 'Images uploaded elsewhere (Theme headers, backgrounds, logos, etc)', 'imsanity' ); ?></th>
317 <td>
318 <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; ?>" />
319 <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' ); ?>
320 </td>
321 </tr>
322 <tr>
323 <th scope="row">
324 <label for='imsanity_quality'><?php esc_html_e( 'JPG image quality', 'imsanity' ); ?>
325 </th>
326 <td>
327 <input type='text' id='imsanity_quality' name='imsanity_quality' class='small-text' value='<?php echo (int) $settings->imsanity_quality; ?>' />
328 <?php esc_html_e( 'Usable values are 1-92.', 'imsanity' ); ?>
329 <p class='description'><?php esc_html_e( 'Only used when resizing images, does not affect thumbnails.', 'imsanity' ); ?></p>
330 </td>
331 </tr>
332 <tr>
333 <th scope="row">
334 <label for='imsanity_avif_quality'><?php esc_html_e( 'AVIF image quality', 'imsanity' ); ?>
335 </th>
336 <td>
337 <input type='text' id='imsanity_avif_quality' name='imsanity_avif_quality' class='small-text' value='<?php echo (int) $settings->imsanity_avif_quality; ?>' />
338 <?php esc_html_e( 'Usable values are 1-92.', 'imsanity' ); ?>
339 <p class='description'><?php esc_html_e( 'Only used when resizing images, does not affect thumbnails.', 'imsanity' ); ?></p>
340 </td>
341 </tr>
342 <tr>
343 <th scope="row">
344 <label for='imsanity_webp_quality'><?php esc_html_e( 'WebP image quality', 'imsanity' ); ?>
345 </th>
346 <td>
347 <input type='text' id='imsanity_webp_quality' name='imsanity_webp_quality' class='small-text' value='<?php echo (int) $settings->imsanity_webp_quality; ?>' />
348 <?php esc_html_e( 'Usable values are 1-92.', 'imsanity' ); ?>
349 <p class='description'><?php esc_html_e( 'Only used when resizing images, does not affect thumbnails.', 'imsanity' ); ?></p>
350 </td>
351 </tr>
352 <tr>
353 <th scope="row">
354 <label for"imsanity_bmp_to_jpg"><?php esc_html_e( 'Convert BMP to JPG', 'imsanity' ); ?></label>
355 </th>
356 <td>
357 <input type="checkbox" id="imsanity_bmp_to_jpg" name="imsanity_bmp_to_jpg" value="true" <?php checked( $settings->imsanity_bmp_to_jpg ); ?> />
358 <?php
359 printf(
360 /* translators: %s: link to install EWWW Image Optimizer plugin */
361 esc_html__( 'Only applies to new image uploads, existing images may be converted with %s.', 'imsanity' ),
362 '<a href="' . esc_url( admin_url( 'plugin-install.php?s=ewww+image+optimizer&tab=search&type=term' ) ) . '">EWWW Image Optimizer</a>'
363 );
364 ?>
365 </td>
366 </tr>
367 <tr>
368 <th scope="row">
369 <label for="imsanity_png_to_jpg"><?php esc_html_e( 'Convert PNG to JPG', 'imsanity' ); ?></label>
370 </th>
371 <td>
372 <input type="checkbox" id="imsanity_png_to_jpg" name="imsanity_png_to_jpg" value="true" <?php checked( $settings->imsanity_png_to_jpg ); ?> />
373 <?php
374 printf(
375 /* translators: %s: link to install EWWW Image Optimizer plugin */
376 esc_html__( 'Only applies to new image uploads, existing images may be converted with %s.', 'imsanity' ),
377 '<a href="' . esc_url( admin_url( 'plugin-install.php?s=ewww+image+optimizer&tab=search&type=term' ) ) . '">EWWW Image Optimizer</a>'
378 );
379 ?>
380 </td>
381 </tr>
382 <tr>
383 <th scope="row">
384 <label for="imsanity_delete_originals"><?php esc_html_e( 'Delete Originals', 'imsanity' ); ?></label>
385 </th>
386 <td>
387 <input type="checkbox" id="imsanity_delete_originals" name="imsanity_delete_originals" value="true" <?php checked( $settings->imsanity_delete_originals ); ?> />
388 <?php esc_html_e( 'Remove the large pre-scaled originals that WordPress retains for thumbnail generation.', 'imsanity' ); ?>
389 </td>
390 </tr>
391 <?php if ( is_file( imsanity_debug_log_path() ) ) : ?>
392 <tr>
393 <th><?php esc_html_e( 'Debug Log', 'imsanity' ); ?></th>
394 <td>
395 <p>
396 <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> -
397 <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>
398 </p>
399 </td>
400 </tr>
401 <?php endif; ?>
402 </table>
403
404 <p class="submit"><input type="submit" class="button-primary" value="<?php esc_attr_e( 'Update Settings', 'imsanity' ); ?>" /></p>
405
406 </form>
407
408 </div>
409 <?php
410 }
411
412 /**
413 * Process the form, update the network settings
414 * and clear the cached settings
415 */
416 function imsanity_network_settings_update() {
417 if ( ! current_user_can( 'manage_options' ) || empty( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST['_wpnonce'] ), 'imsanity_network_options' ) ) {
418 return;
419 }
420 global $wpdb;
421 global $_imsanity_multisite_settings;
422
423 // ensure that the custom table is created when the user updates network settings
424 // this is not ideal but it's better than checking for this table existance
425 // on every page load.
426 imsanity_maybe_created_custom_table();
427
428 $data = new stdClass();
429
430 $data->imsanity_override_site = isset( $_POST['imsanity_override_site'] ) ? (bool) $_POST['imsanity_override_site'] : false;
431 $data->imsanity_max_height = isset( $_POST['imsanity_max_height'] ) ? (int) $_POST['imsanity_max_height'] : 0;
432 $data->imsanity_max_width = isset( $_POST['imsanity_max_width'] ) ? (int) $_POST['imsanity_max_width'] : 0;
433 $data->imsanity_max_height_library = isset( $_POST['imsanity_max_height_library'] ) ? (int) $_POST['imsanity_max_height_library'] : 0;
434 $data->imsanity_max_width_library = isset( $_POST['imsanity_max_width_library'] ) ? (int) $_POST['imsanity_max_width_library'] : 0;
435 $data->imsanity_max_height_other = isset( $_POST['imsanity_max_height_other'] ) ? (int) $_POST['imsanity_max_height_other'] : 0;
436 $data->imsanity_max_width_other = isset( $_POST['imsanity_max_width_other'] ) ? (int) $_POST['imsanity_max_width_other'] : 0;
437 $data->imsanity_bmp_to_jpg = ! empty( $_POST['imsanity_bmp_to_jpg'] );
438 $data->imsanity_png_to_jpg = ! empty( $_POST['imsanity_png_to_jpg'] );
439 $data->imsanity_quality = isset( $_POST['imsanity_quality'] ) ? imsanity_jpg_quality( intval( $_POST['imsanity_quality'] ) ) : 82;
440 $data->imsanity_avif_quality = isset( $_POST['imsanity_avif_quality'] ) ? imsanity_avif_quality( intval( $_POST['imsanity_avif_quality'] ) ) : 86;
441 $data->imsanity_webp_quality = isset( $_POST['imsanity_webp_quality'] ) ? imsanity_webp_quality( intval( $_POST['imsanity_webp_quality'] ) ) : 86;
442 $data->imsanity_delete_originals = ! empty( $_POST['imsanity_delete_originals'] );
443
444 $wpdb->update(
445 $wpdb->imsanity_ms,
446 array( 'data' => maybe_serialize( $data ) ),
447 array( 'setting' => 'multisite' )
448 );
449
450 // Clear the cache.
451 $_imsanity_multisite_settings = null;
452 add_action( 'network_admin_notices', 'imsanity_network_settings_saved' );
453 }
454
455 /**
456 * Display a message to inform the user the multi-site setting have been saved.
457 */
458 function imsanity_network_settings_saved() {
459 echo "<div id='imsanity-network-settings-saved' class='updated fade'><p><strong>" . esc_html__( 'Imsanity network settings saved.', 'imsanity' ) . '</strong></p></div>';
460 }
461
462 /**
463 * Return the multi-site settings as a standard class. If the settings are not
464 * defined in the database or multi-site is not enabled then the default settings
465 * are returned. This is cached so it only loads once per page load, unless
466 * imsanity_network_settings_update is called.
467 *
468 * @return stdClass
469 */
470 function imsanity_get_multisite_settings() {
471 global $_imsanity_multisite_settings;
472 $result = null;
473
474 if ( ! $_imsanity_multisite_settings ) {
475 if ( function_exists( 'is_multisite' ) && is_multisite() ) {
476 global $wpdb;
477 $result = $wpdb->get_var( "SELECT data FROM $wpdb->imsanity_ms WHERE setting = 'multisite'" );
478 }
479
480 // if there's no results, return the defaults instead.
481 $_imsanity_multisite_settings = $result
482 ? unserialize( $result )
483 : imsanity_get_default_multisite_settings();
484
485 // this is for backwards compatibility.
486 if ( ! isset( $_imsanity_multisite_settings->imsanity_max_height_library ) ) {
487 $_imsanity_multisite_settings->imsanity_max_height_library = $_imsanity_multisite_settings->imsanity_max_height;
488 $_imsanity_multisite_settings->imsanity_max_width_library = $_imsanity_multisite_settings->imsanity_max_width;
489 $_imsanity_multisite_settings->imsanity_max_height_other = $_imsanity_multisite_settings->imsanity_max_height;
490 $_imsanity_multisite_settings->imsanity_max_width_other = $_imsanity_multisite_settings->imsanity_max_width;
491 }
492 $_imsanity_multisite_settings->imsanity_override_site = ! empty( $_imsanity_multisite_settings->imsanity_override_site ) ? '1' : '0';
493 $_imsanity_multisite_settings->imsanity_bmp_to_jpg = ! empty( $_imsanity_multisite_settings->imsanity_bmp_to_jpg ) ? true : false;
494 $_imsanity_multisite_settings->imsanity_png_to_jpg = ! empty( $_imsanity_multisite_settings->imsanity_png_to_jpg ) ? true : false;
495 if ( ! property_exists( $_imsanity_multisite_settings, 'imsanity_delete_originals' ) ) {
496 $_imsanity_multisite_settings->imsanity_delete_originals = false;
497 }
498 if ( ! property_exists( $_imsanity_multisite_settings, 'imsanity_avif_quality' ) ) {
499 $_imsanity_multisite_settings->imsanity_avif_quality = IMSANITY_DEFAULT_AVIF_QUALITY;
500 }
501 if ( ! property_exists( $_imsanity_multisite_settings, 'imsanity_webp_quality' ) ) {
502 $_imsanity_multisite_settings->imsanity_webp_quality = IMSANITY_DEFAULT_WEBP_QUALITY;
503 }
504 }
505 return $_imsanity_multisite_settings;
506 }
507
508 /**
509 * Gets the option setting for the given key, first checking to see if it has been
510 * set globally for multi-site. Otherwise checking the site options.
511 *
512 * @param string $key The name of the option to retrieve.
513 * @param string $ifnull Value to use if the requested option returns null.
514 */
515 function imsanity_get_option( $key, $ifnull ) {
516 $result = null;
517
518 $settings = imsanity_get_multisite_settings();
519
520 if ( $settings->imsanity_override_site ) {
521 $result = $settings->$key;
522 if ( is_null( $result ) ) {
523 $result = $ifnull;
524 }
525 } else {
526 $result = get_option( $key, $ifnull );
527 }
528
529 return $result;
530 }
531
532 /**
533 * Run upgrade check for new version.
534 */
535 function imsanity_upgrade() {
536 if ( is_network_admin() ) {
537 return;
538 }
539 if ( -1 === version_compare( get_option( 'imsanity_version' ), IMSANITY_VERSION ) ) {
540 if ( wp_doing_ajax() ) {
541 return;
542 }
543 imsanity_set_defaults();
544 update_option( 'imsanity_version', IMSANITY_VERSION );
545 }
546 }
547
548 /**
549 * Set default options on multi-site.
550 */
551 function imsanity_set_defaults() {
552 $settings = imsanity_get_multisite_settings();
553 add_option( 'imsanity_max_width', $settings->imsanity_max_width, '', false );
554 add_option( 'imsanity_max_height', $settings->imsanity_max_height, '', false );
555 add_option( 'imsanity_max_width_library', $settings->imsanity_max_width_library, '', false );
556 add_option( 'imsanity_max_height_library', $settings->imsanity_max_height_library, '', false );
557 add_option( 'imsanity_max_width_other', $settings->imsanity_max_width_other, '', false );
558 add_option( 'imsanity_max_height_other', $settings->imsanity_max_height_other, '', false );
559 add_option( 'imsanity_bmp_to_jpg', $settings->imsanity_bmp_to_jpg, '', false );
560 add_option( 'imsanity_png_to_jpg', $settings->imsanity_png_to_jpg, '', false );
561 add_option( 'imsanity_quality', $settings->imsanity_quality, '', false );
562 add_option( 'imsanity_avif_quality', $settings->imsanity_avif_quality, '', false );
563 add_option( 'imsanity_webp_quality', $settings->imsanity_webp_quality, '', false );
564 add_option( 'imsanity_delete_originals', $settings->imsanity_delete_originals, '', false );
565 if ( ! get_option( 'imsanity_version' ) ) {
566 global $wpdb;
567 $wpdb->query( "UPDATE $wpdb->options SET autoload='no' WHERE option_name LIKE 'imsanity_%'" );
568 }
569 }
570
571 /**
572 * Register the configuration settings that the plugin will use
573 */
574 function imsanity_register_settings() {
575 imsanity_upgrade();
576 // We only want to update if the form has been submitted.
577 // Verification is done inside the imsanity_network_settings_update() function.
578 if ( isset( $_POST['update_imsanity_settings'] ) && is_multisite() && is_network_admin() ) { // phpcs:ignore WordPress.Security.NonceVerification
579 imsanity_network_settings_update();
580 }
581 // Register our settings.
582 register_setting( 'imsanity-settings-group', 'imsanity_max_height', 'intval' );
583 register_setting( 'imsanity-settings-group', 'imsanity_max_width', 'intval' );
584 register_setting( 'imsanity-settings-group', 'imsanity_max_height_library', 'intval' );
585 register_setting( 'imsanity-settings-group', 'imsanity_max_width_library', 'intval' );
586 register_setting( 'imsanity-settings-group', 'imsanity_max_height_other', 'intval' );
587 register_setting( 'imsanity-settings-group', 'imsanity_max_width_other', 'intval' );
588 register_setting( 'imsanity-settings-group', 'imsanity_bmp_to_jpg', 'boolval' );
589 register_setting( 'imsanity-settings-group', 'imsanity_png_to_jpg', 'boolval' );
590 register_setting( 'imsanity-settings-group', 'imsanity_quality', 'imsanity_jpg_quality' );
591 register_setting( 'imsanity-settings-group', 'imsanity_avif_quality', 'imsanity_avif_quality' );
592 register_setting( 'imsanity-settings-group', 'imsanity_webp_quality', 'imsanity_webp_quality' );
593 register_setting( 'imsanity-settings-group', 'imsanity_delete_originals', 'boolval' );
594 }
595
596 /**
597 * Set the quality based on the mime type of the image being resized.
598 *
599 * @param int $quality The quality currently set.
600 * @param string $mime_type The mime type of the image being resized.
601 * @return int The (potentially) adjusted quality level.
602 */
603 function imsanity_editor_quality( $quality, $mime_type = '' ) {
604 if ( 'image/avif' === $mime_type ) {
605 $new_quality = imsanity_avif_quality();
606 } elseif ( 'image/webp' === $mime_type ) {
607 $new_quality = imsanity_webp_quality();
608 } elseif ( 'image/jpeg' === $mime_type ) {
609 $new_quality = imsanity_jpg_quality();
610 }
611 if ( ! empty( $new_quality ) && $new_quality > 0 && $new_quality <= 92 ) {
612 return $new_quality;
613 }
614 return $quality;
615 }
616
617 /**
618 * Validate and return the JPG quality setting.
619 *
620 * @param int $quality The JPG quality currently set.
621 * @return int The (potentially) adjusted quality level.
622 */
623 function imsanity_jpg_quality( $quality = null ) {
624 if ( is_null( $quality ) ) {
625 $quality = get_option( 'imsanity_quality' );
626 }
627 if ( preg_match( '/^(100|[1-9][0-9]?)$/', $quality ) ) {
628 return (int) $quality;
629 } else {
630 return IMSANITY_DEFAULT_QUALITY;
631 }
632 }
633
634 /**
635 * Validate and return the AVIF quality setting.
636 *
637 * @param int $quality The AVIF quality currently set.
638 * @return int The (potentially) adjusted quality level.
639 */
640 function imsanity_avif_quality( $quality = null ) {
641 if ( is_null( $quality ) ) {
642 $quality = get_option( 'imsanity_avif_quality' );
643 }
644 if ( preg_match( '/^(100|[1-9][0-9]?)$/', $quality ) ) {
645 return (int) $quality;
646 } else {
647 return IMSANITY_DEFAULT_AVIF_QUALITY;
648 }
649 }
650
651 /**
652 * Validate and return the WebP quality setting.
653 *
654 * @param int $quality The WebP quality currently set.
655 * @return int The (potentially) adjusted quality level.
656 */
657 function imsanity_webp_quality( $quality = null ) {
658 if ( is_null( $quality ) ) {
659 $quality = get_option( 'imsanity_webp_quality' );
660 }
661 if ( preg_match( '/^(100|[1-9][0-9]?)$/', $quality ) ) {
662 return (int) $quality;
663 } else {
664 return IMSANITY_DEFAULT_WEBP_QUALITY;
665 }
666 }
667
668 /**
669 * Check default WP threshold and adjust to comply with normal Imsanity behavior.
670 *
671 * @param int $size The default WP scaling size, or whatever has been filtered by other plugins.
672 * @param array $imagesize {
673 * Indexed array of the image width and height in pixels.
674 *
675 * @type int $0 The image width.
676 * @type int $1 The image height.
677 * }
678 * @param string $file Full path to the uploaded image file.
679 * @return int The proper size to use for scaling originals.
680 */
681 function imsanity_adjust_default_threshold( $size, $imagesize = array(), $file = '' ) {
682 if ( false !== strpos( $file, 'noresize' ) ) {
683 return false;
684 }
685 $max_size = max(
686 imsanity_get_option( 'imsanity_max_width', IMSANITY_DEFAULT_MAX_WIDTH ),
687 imsanity_get_option( 'imsanity_max_height', IMSANITY_DEFAULT_MAX_HEIGHT ),
688 imsanity_get_option( 'imsanity_max_width_library', IMSANITY_DEFAULT_MAX_WIDTH ),
689 imsanity_get_option( 'imsanity_max_height_library', IMSANITY_DEFAULT_MAX_HEIGHT ),
690 imsanity_get_option( 'imsanity_max_width_other', IMSANITY_DEFAULT_MAX_WIDTH ),
691 imsanity_get_option( 'imsanity_max_height_other', IMSANITY_DEFAULT_MAX_HEIGHT ),
692 (int) $size
693 );
694 return $max_size;
695 }
696
697 /**
698 * Helper function to render css styles for the settings forms
699 * for both site and network settings page
700 */
701 function imsanity_settings_css() {
702 ?>
703 <style>
704 #imsanity_header {
705 border: solid 1px #c6c6c6;
706 margin: 10px 0px;
707 padding: 0px 10px;
708 background-color: #e1e1e1;
709 }
710 #imsanity_header p {
711 margin: .5em 0;
712 }
713 #ewwwio-promo {
714 display: none;
715 float: right;
716 }
717 #ewwwio-promo a, #ewwwio-promo a:visited {
718 color: #3eadc9;
719 }
720 #ewwwio-promo ul {
721 list-style: disc;
722 padding-left: 13px;
723 }
724 @media screen and (min-width: 850px) {
725 .form-table {
726 clear: left;
727 width: calc(100% - 210px);
728 }
729 #ewwwio-promo {
730 display: block;
731 border: 1px solid #7e8993;
732 padding: 13px;
733 margin: 13px;
734 width: 150px;
735 }
736 }
737 </style>
738 <?php
739 }
740
741 /**
742 * Render the settings page by writing directly to stdout. if multi-site is enabled
743 * and imsanity_override_site is true, then display a notice message that settings
744 * are not editable instead of the settings form
745 */
746 function imsanity_settings_page() {
747 ?>
748 <div class="wrap">
749 <h1><?php esc_html_e( 'Imsanity Settings', 'imsanity' ); ?></h1>
750 <p>
751 <a target="_blank" href="https://wordpress.org/plugins/imsanity/#faq-header"><?php esc_html_e( 'FAQ', 'imsanity' ); ?></a> |
752 <a target="_blank" href="https://wordpress.org/support/plugin/imsanity/"><?php esc_html_e( 'Support', 'imsanity' ); ?></a> |
753 <a target="_blank" href="https://wordpress.org/support/plugin/imsanity/reviews/#new-post"><?php esc_html_e( 'Leave a Review', 'imsanity' ); ?></a>
754 </p>
755
756 <div id="ewwwio-promo">
757 <p>
758 <?php
759 printf(
760 /* translators: %s: link to install EWWW Image Optimizer plugin */
761 esc_html__( 'Get comprehensive image optimization with %s', 'imsanity' ),
762 '<br><a href="' . esc_url( admin_url( 'plugin-install.php?s=ewww+image+optimizer&tab=search&type=term' ) ) . '">EWWW Image Optimizer</a>'
763 );
764 ?>
765 <ul>
766 <li><?php esc_html_e( 'Full Compression', 'imsanity' ); ?></li>
767 <li><?php esc_html_e( 'Automatic Scaling', 'imsanity' ); ?></li>
768 <li><?php esc_html_e( 'Lazy Load', 'imsanity' ); ?></li>
769 <li><?php esc_html_e( 'WebP Conversion', 'imsanity' ); ?></li>
770 </ul>
771 </p>
772 </div>
773
774 <?php
775
776 $settings = imsanity_get_multisite_settings();
777
778 if ( $settings->imsanity_override_site ) {
779 imsanity_settings_page_notice();
780 } else {
781 imsanity_settings_page_form();
782 }
783
784 ?>
785
786 <h2 style="margin-top: 0px;"><?php esc_html_e( 'Bulk Resize Images', 'imsanity' ); ?></h2>
787
788 <div id="imsanity_header">
789 <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>
790 <p>
791 <?php
792 printf(
793 /* translators: 1: List View in the Media Library 2: the WP-CLI command */
794 esc_html__( 'You may also use %1$s to selectively resize images or WP-CLI to resize your images in bulk: %2$s', 'imsanity' ),
795 '<a href="' . esc_url( admin_url( 'upload.php?mode=list' ) ) . '">' . esc_html__( 'List View in the Media Library', 'imsanity' ) . '</a>',
796 '<code>wp help imsanity resize</code>'
797 );
798 ?>
799 </p>
800 </div>
801
802 <div style="border: solid 1px #ff6666; background-color: #ffbbbb; padding: 0 10px;margin-bottom:1em;">
803 <h4><?php esc_html_e( 'WARNING: Bulk Resize will alter your original images and cannot be undone!', 'imsanity' ); ?></h4>
804 <p>
805 <?php esc_html_e( 'It is HIGHLY recommended that you backup your images before proceeding.', 'imsanity' ); ?><br>
806 <?php
807 printf(
808 /* translators: %s: List View in the Media Library */
809 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' ),
810 '<a href="' . esc_url( admin_url( 'upload.php?mode=list' ) ) . '">' . esc_html__( 'List View in the Media Library', 'imsanity' ) . '</a>'
811 );
812 ?>
813 </p>
814 </div>
815
816 <?php
817 $button_text = __( 'Start Resizing All Images', 'imsanity' );
818 if ( get_option( 'imsanity_resume_id' ) ) {
819 $button_text = __( 'Continue Resizing', 'imsanity' );
820 }
821 ?>
822
823 <p class="submit" id="imsanity-examine-button">
824 <button class="button-primary" onclick="imsanity_load_images();"><?php echo esc_html( $button_text ); ?></button>
825 </p>
826 <form id="imsanity-bulk-stop" style="display:none;margin:1em 0 1em;" method="post" action="">
827 <button type="submit" class="button-secondary action"><?php esc_html_e( 'Stop Resizing', 'imsanity' ); ?></button><br>
828 *<i><?php esc_html_e( 'You will be able to resume the process later.', 'imsanity' ); ?></i>
829 </form>
830 <?php if ( get_option( 'imsanity_resume_id' ) ) : ?>
831 <p class="imsanity-bulk-text" style="margin-top:1em;"><?php esc_html_e( 'Would you like to start back at the beginning?', 'imsanity' ); ?></p>
832 <form class="imsanity-bulk-form" method="post" action="">
833 <?php wp_nonce_field( 'imsanity-bulk-reset', 'imsanity_wpnonce' ); ?>
834 <input type="hidden" name="imsanity_reset" value="1">
835 <button id="imsanity-bulk-reset" type="submit" class="button-secondary action"><?php esc_html_e( 'Clear Queue', 'imsanity' ); ?></button>
836 </form>
837 <?php endif; ?>
838 <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;" />
839 <?php esc_html_e( 'Searching for images. This may take a moment.', 'imsanity' ); ?>
840 </div>
841 <div id="resize_results" style="display: none; border: solid 2px #666666; padding: 10px; height: 400px; overflow: auto;">
842 <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>
843 </div>
844
845 <?php
846
847 echo '</div>';
848 }
849
850 /**
851 * Multi-user config file exists so display a notice
852 */
853 function imsanity_settings_page_notice() {
854 ?>
855 <div class="updated settings-error">
856 <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>
857 </div>
858 <?php
859 }
860
861 /**
862 * Check to see if GD is missing, and alert the user.
863 */
864 function imsanity_missing_gd_admin_notice() {
865 if ( imsanity_gd_support() ) {
866 return;
867 }
868 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>';
869 }
870
871 /**
872 * Render the site settings form. This is processed by
873 * WordPress built-in options persistance mechanism
874 */
875 function imsanity_settings_page_form() {
876 ?>
877 <form method="post" action="options.php">
878 <?php settings_fields( 'imsanity-settings-group' ); ?>
879 <table class="form-table">
880
881 <tr>
882 <th scope="row"><?php esc_html_e( 'Images uploaded within a Page/Post', 'imsanity' ); ?></th>
883 <td>
884 <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 ); ?>" />
885 <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' ); ?>
886 <p class="description"><?php esc_html_e( 'These dimensions are used for Bulk Resizing also.', 'imsanity' ); ?></p>
887 </td>
888 </tr>
889
890 <tr>
891 <th scope="row"><?php esc_html_e( 'Images uploaded directly to the Media Library', 'imsanity' ); ?></th>
892 <td>
893 <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 ); ?>" />
894 <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' ); ?>
895 </td>
896 </tr>
897
898 <tr>
899 <th scope="row"><?php esc_html_e( 'Images uploaded elsewhere (Theme headers, backgrounds, logos, etc)', 'imsanity' ); ?></th>
900 <td>
901 <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 ); ?>" />
902 <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' ); ?>
903 </td>
904 </tr>
905
906 <tr>
907 <th scope="row">
908 <label for='imsanity_quality' ><?php esc_html_e( 'JPG image quality', 'imsanity' ); ?>
909 </th>
910 <td>
911 <input type='text' id='imsanity_quality' name='imsanity_quality' class='small-text' value='<?php echo (int) imsanity_jpg_quality(); ?>' />
912 <?php esc_html_e( 'Usable values are 1-92.', 'imsanity' ); ?>
913 <p class='description'><?php esc_html_e( 'Only used when resizing images, does not affect thumbnails.', 'imsanity' ); ?></p>
914 </td>
915 </tr>
916
917 <tr>
918 <th scope="row">
919 <label for='imsanity_avif_quality' ><?php esc_html_e( 'AVIF image quality', 'imsanity' ); ?>
920 </th>
921 <td>
922 <input type='text' id='imsanity_avif_quality' name='imsanity_avif_quality' class='small-text' value='<?php echo (int) imsanity_avif_quality(); ?>' />
923 <?php esc_html_e( 'Usable values are 1-92.', 'imsanity' ); ?>
924 <p class='description'><?php esc_html_e( 'Only used when resizing images, does not affect thumbnails.', 'imsanity' ); ?></p>
925 </td>
926 </tr>
927
928 <tr>
929 <th scope="row">
930 <label for='imsanity_webp_quality' ><?php esc_html_e( 'WebP image quality', 'imsanity' ); ?>
931 </th>
932 <td>
933 <input type='text' id='imsanity_webp_quality' name='imsanity_webp_quality' class='small-text' value='<?php echo (int) imsanity_webp_quality(); ?>' />
934 <?php esc_html_e( 'Usable values are 1-92.', 'imsanity' ); ?>
935 <p class='description'><?php esc_html_e( 'Only used when resizing images, does not affect thumbnails.', 'imsanity' ); ?></p>
936 </td>
937 </tr>
938
939 <tr>
940 <th scope="row">
941 <label for="imsanity_bmp_to_jpg"><?php esc_html_e( 'Convert BMP To JPG', 'imsanity' ); ?></label>
942 </th>
943 <td>
944 <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 ) ); ?> />
945 <?php
946 printf(
947 /* translators: %s: link to install EWWW Image Optimizer plugin */
948 esc_html__( 'Only applies to new image uploads, existing images may be converted with %s.', 'imsanity' ),
949 '<a href="' . esc_url( admin_url( 'plugin-install.php?s=ewww+image+optimizer&tab=search&type=term' ) ) . '">EWWW Image Optimizer</a>'
950 );
951 ?>
952 </td>
953 </tr>
954 <tr>
955 <th scope="row">
956 <label for="imsanity_png_to_jpg"><?php esc_html_e( 'Convert PNG To JPG', 'imsanity' ); ?></label>
957 </th>
958 <td>
959 <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 ) ); ?> />
960 <?php
961 printf(
962 /* translators: %s: link to install EWWW Image Optimizer plugin */
963 esc_html__( 'Only applies to new image uploads, existing images may be converted with %s.', 'imsanity' ),
964 '<a href="' . esc_url( admin_url( 'plugin-install.php?s=ewww+image+optimizer&tab=search&type=term' ) ) . '">EWWW Image Optimizer</a>'
965 );
966 ?>
967 </td>
968 </tr>
969 <tr>
970 <th scope="row">
971 <label for="imsanity_delete_originals"><?php esc_html_e( 'Delete Originals', 'imsanity' ); ?></label>
972 </th>
973 <td>
974 <input type="checkbox" id="imsanity_delete_originals" name="imsanity_delete_originals" value="true" <?php checked( get_option( 'imsanity_delete_originals' ) ); ?> />
975 <?php esc_html_e( 'Remove the large pre-scaled originals that WordPress retains for thumbnail generation.', 'imsanity' ); ?>
976 </td>
977 </tr>
978 <?php if ( is_file( imsanity_debug_log_path() ) ) : ?>
979 <tr>
980 <th><?php esc_html_e( 'Debug Log', 'imsanity' ); ?></th>
981 <td>
982 <p>
983 <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> -
984 <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>
985 </p>
986 </td>
987 </tr>
988 <?php endif; ?>
989 </table>
990
991 <p class="submit"><input type="submit" class="button-primary" value="<?php esc_attr_e( 'Save Changes', 'imsanity' ); ?>" /></p>
992
993 </form>
994 <?php
995 }
996