PluginProbe ʕ •ᴥ•ʔ
Modern Image Formats / 1.1.1
Modern Image Formats v1.1.1
2.7.0 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.1.0 1.1.1 2.0.0 2.0.1 2.0.2 2.1.0 2.2.0 2.3.0 2.4.0 2.5.0 2.5.1 2.6.0 2.6.1
webp-uploads / settings.php
webp-uploads Last commit date
deprecated.php 2 years ago fallback.js 2 years ago helper.php 2 years ago hooks.php 2 years ago image-edit.php 2 years ago load.php 2 years ago readme.txt 2 years ago rest-api.php 2 years ago settings.php 2 years ago uninstall.php 2 years ago
settings.php
117 lines
1 <?php
2 /**
3 * Settings for the Modern Image Formats plugin.
4 *
5 * @package webp-uploads
6 *
7 * @since 1.0.0
8 */
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit; // Exit if accessed directly.
12 }
13
14 /**
15 * Registers setting for generating both JPEG and WebP versions for image uploads.
16 *
17 * @since 1.0.0
18 */
19 function webp_uploads_register_media_settings_field(): void {
20 register_setting(
21 'media',
22 'perflab_generate_webp_and_jpeg',
23 array(
24 'type' => 'boolean',
25 'default' => false,
26 'show_in_rest' => false,
27 )
28 );
29 }
30 add_action( 'init', 'webp_uploads_register_media_settings_field' );
31
32 /**
33 * Adds media settings field for the 'perflab_generate_webp_and_jpeg' setting.
34 *
35 * @since 1.0.0
36 */
37 function webp_uploads_add_media_settings_field(): void {
38 // Add settings field.
39 add_settings_field(
40 'perflab_generate_webp_and_jpeg',
41 __( 'WebP and JPEG', 'webp-uploads' ),
42 'webp_uploads_generate_webp_jpeg_setting_callback',
43 'media',
44 is_multisite() ? 'default' : 'uploads',
45 array( 'class' => 'perflab-generate-webp-and-jpeg' )
46 );
47 }
48 add_action( 'admin_init', 'webp_uploads_add_media_settings_field' );
49
50 /**
51 * Renders the settings field for the 'perflab_generate_webp_and_jpeg' setting.
52 *
53 * @since 1.0.0
54 */
55 function webp_uploads_generate_webp_jpeg_setting_callback(): void {
56 if ( ! is_multisite() ) {
57 ?>
58 </td>
59 <td class="td-full">
60 <?php
61 }
62 ?>
63 <label for="perflab_generate_webp_and_jpeg">
64 <input name="perflab_generate_webp_and_jpeg" type="checkbox" id="perflab_generate_webp_and_jpeg" aria-describedby="perflab_generate_webp_and_jpeg_description" value="1"<?php checked( '1', get_option( 'perflab_generate_webp_and_jpeg' ) ); ?> />
65 <?php esc_html_e( 'Generate JPEG files in addition to WebP', 'webp-uploads' ); ?>
66 </label>
67 <p class="description" id="perflab_generate_webp_and_jpeg_description"><?php esc_html_e( 'Enabling JPEG in addition to WebP can improve compatibility, but will effectively double the filesystem storage use of your images.', 'webp-uploads' ); ?></p>
68 <?php
69 }
70
71 /**
72 * Adds custom styles to hide specific elements in media settings.
73 *
74 * @since 1.0.0
75 */
76 function webp_uploads_media_setting_style(): void {
77 if ( is_multisite() ) {
78 return;
79 }
80 ?>
81 <style>
82 .form-table .perflab-generate-webp-and-jpeg th,
83 .form-table .perflab-generate-webp-and-jpeg td:not(.td-full) {
84 display: none;
85 }
86 </style>
87 <?php
88 }
89 add_action( 'admin_head-options-media.php', 'webp_uploads_media_setting_style' );
90
91 /**
92 * Adds a settings link to the plugin's action links.
93 *
94 * @since 1.1.0
95 * @since 1.1.1 Renamed from webp_uploads_settings_link() to webp_uploads_add_settings_action_link()
96 *
97 * @param string[]|mixed $links An array of plugin action links.
98 * @return string[]|mixed The modified list of actions.
99 */
100 function webp_uploads_add_settings_action_link( $links ) {
101 if ( ! is_array( $links ) ) {
102 return $links;
103 }
104
105 $settings_link = sprintf(
106 '<a href="%1$s">%2$s</a>',
107 esc_url( admin_url( 'options-media.php#perflab_generate_webp_and_jpeg' ) ),
108 esc_html__( 'Settings', 'webp-uploads' )
109 );
110
111 return array_merge(
112 array( 'settings' => $settings_link ),
113 $links
114 );
115 }
116 add_filter( 'plugin_action_links_' . WEBP_UPLOADS_MAIN_FILE, 'webp_uploads_add_settings_action_link' );
117