PluginProbe
Imsanity / 2.9.0
Imsanity v2.9.0
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.0, at settings.php

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