PluginProbe
QuickWebP – WebP & AVIF Image Optimizer, Compression & SEO for WordPress / 4.1.1
QuickWebP – WebP & AVIF Image Optimizer, Compression & SEO for WordPress v4.1.1
4.1.2 4.1.1 4.1.0 4.0.1 4.0.0 3.3.1 3.3.0 trunk 1.0.0 2.0.0 2.1.0 3.0.0 3.1.0 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8
← All changes | includes/global-functions.php +208 -14 3.2.14.1.1 View file →
@@ -1,5 +1,7 @@
1 1 <?php
2 +if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3 +
2 4 /**
3 5 * The global functions for this plugin
4 6 *
5 7 * @since 1.0.0
@@ -27,26 +29,218 @@
27 29 */
28 30 function quickwebp_settings_default( $id ) {
29 31
30 32 $settings_arr = array(
31 - 'quickwebp_settings_conversion' => '1',
32 - 'quickwebp_settings_conversion_quality' => 75,
33 - 'quickwebp_settings_conversion_sharpen' => 0,
34 - 'quickwebp_settings_conversion_ignore_webp' => array('checked'),
35 - 'quickwebp_settings_conversion_save_original' => array(),
36 - 'quickwebp_settings_conversion_display_webp_mode' => 'disabled',
37 - 'quickwebp_settings_resize' => '1',
38 - 'quickwebp_settings_resize_value' => 2000,
39 - 'quickwebp_settings_completion' => '1',
40 - 'quickwebp_settings_completion_options' => array(
33 + 'quickwebp_settings_conversion' => '1',
34 + 'quickwebp_settings_conversion_quality' => 'high',
35 + 'quickwebp_settings_conversion_ignore_webp' => array('checked'),
36 + 'quickwebp_settings_conversion_save_original' => array(),
37 + 'quickwebp_settings_conversion_display_webp_mode' => 'disabled',
38 + 'quickwebp_settings_resize' => '1',
39 + 'quickwebp_settings_resize_value' => 2000,
40 + 'quickwebp_settings_completion' => '1',
41 + 'quickwebp_settings_completion_options' => array(
41 42 'title',
42 43 'caption',
43 44 'alt',
44 45 'description'
45 46 ),
46 - 'quickwebp_settings_cleanup' => '1',
47 - 'quickwebp_settings_paste_image' => '0',
48 - 'quickwebp_settings_library' => 'gd'
47 + 'quickwebp_settings_cleanup' => '1',
48 + 'quickwebp_settings_paste_image' => '0',
49 + 'quickwebp_settings_debug_mode' => '0',
49 50 );
50 51
51 52 return isset($settings_arr[$id]) ? $settings_arr[$id] : '';
52 -}
53 +}
54 +
55 +/**
56 + * Get the QuickWebP debug log path.
57 + *
58 + * @return string
59 + */
60 +function quickwebp_get_debug_log_path() {
61 + $upload_dir = wp_upload_dir();
62 + $base_dir = trailingslashit( $upload_dir['basedir'] ) . 'quickwebp';
63 +
64 + if ( ! is_dir( $base_dir ) ) {
65 + wp_mkdir_p( $base_dir );
66 + }
67 +
68 + return trailingslashit( $base_dir ) . 'quickwebp-debug.log';
69 +}
70 +
71 +/**
72 + * Check whether QuickWebP debug mode is enabled.
73 + *
74 + * @return bool
75 + */
76 +function quickwebp_is_debug_mode_enabled() {
77 + return '1' === (string) get_option( 'quickwebp_settings_debug_mode', quickwebp_settings_default( 'quickwebp_settings_debug_mode' ) );
78 +}
79 +
80 +/**
81 + * Write a debug message to the QuickWebP custom log file.
82 + *
83 + * @param string $message Debug message.
84 + * @param array $context Optional contextual data.
85 + *
86 + * @return void
87 + */
88 +function quickwebp_debug_log( $message, $context = array() ) {
89 + if ( ! quickwebp_is_debug_mode_enabled() ) {
90 + return;
91 + }
92 +
93 + $formatted_message = '[' . gmdate( 'Y-m-d H:i:s' ) . '] ' . sanitize_text_field( $message );
94 +
95 + if ( ! empty( $context ) ) {
96 + $formatted_message .= ' ' . wp_json_encode( $context );
97 + }
98 +
99 + error_log( $formatted_message . PHP_EOL, 3, quickwebp_get_debug_log_path() );
100 +}
101 +
102 +/**
103 + * Allowed tags for SVG files
104 + */
105 +function quickwebp_allowed_tags_for_svg_files() {
106 + $allowedtags = array(
107 + 'svg' => array(
108 + 'class' => true,
109 + 'xmlns' => true,
110 + 'width' => true,
111 + 'height' => true,
112 + 'viewbox' => true,
113 + 'preserveaspectratio' => true,
114 + 'fill' => true,
115 + 'aria-hidden' => true,
116 + 'focusable' => true,
117 + 'role' => true,
118 + ),
119 + 'path' => array(
120 + 'fill' => true,
121 + 'fill-rule' => true,
122 + 'd' => true,
123 + 'transform' => true,
124 + 'stroke' => true,
125 + 'stroke-linecap' => true,
126 + 'stroke-linejoin' => true,
127 + ),
128 + 'polygon' => array(
129 + 'fill' => true,
130 + 'fill-rule' => true,
131 + 'points' => true,
132 + 'transform' => true,
133 + 'focusable' => true,
134 + ),
135 + 'rect' => array(
136 + 'fill' => true,
137 + 'fill-rule' => true,
138 + 'height' => true,
139 + 'width' => true,
140 + 'x' => true,
141 + 'y' => true,
142 + ),
143 + 'line' => array(
144 + 'fill' => true,
145 + 'fill-rule' => true,
146 + 'x1' => true,
147 + 'x2' => true,
148 + 'y1' => true,
149 + 'y2' => true,
150 + 'stroke' => true,
151 + 'stroke-width' => true,
152 + 'transform' => true,
153 + ),
154 + 'defs' => array(
155 + 'id' => true,
156 + ),
157 + 'clipPath' => array(
158 + 'id' => true,
159 + ),
160 + 'g' => array(
161 + 'clip-path' => true,
162 + 'mask' => true,
163 + ),
164 + 'circle' => array(
165 + 'cx' => true,
166 + 'cy' => true,
167 + 'r' => true,
168 + 'fill' => true,
169 + 'stroke' => true,
170 + 'stroke-width' => true,
171 + 'stroke-dasharray' => true,
172 + 'stroke-linecap' => true,
173 + ),
174 + 'mask' => array(
175 + 'id' => true,
176 + 'fill' => true,
177 + 'style' => true,
178 + 'maskUnits' => true,
179 + 'x' => true,
180 + 'y' => true,
181 + 'width' => true,
182 + 'height' => true,
183 + ),
184 + 'image' => array(
185 + 'id' => true,
186 + 'href' => true,
187 + 'x' => true,
188 + 'y' => true,
189 + 'width' => true,
190 + 'height' => true,
191 + 'clip' => true,
192 + 'mask' => true,
193 + 'opacity' => true,
194 + 'xlink:href' => true,
195 + ),
196 + 'defs' => array(
197 + 'id' => true,
198 + ),
199 + 'pattern' => array(
200 + 'id' => true,
201 + 'x' => true,
202 + 'y' => true,
203 + 'width' => true,
204 + 'height' => true,
205 + 'patternUnits' => true,
206 + 'patternContentUnits' => true,
207 + ),
208 + 'use' => array(
209 + 'id' => true,
210 + 'x' => true,
211 + 'y' => true,
212 + 'xlink:href' => true,
213 + 'transform' => true,
214 + ),
215 + );
216 + return $allowedtags;
217 +}
218 +
219 +/**
220 + * Build a QuickWebP Pro URL with tracking parameters.
221 + *
222 + * @param string $context Stable location identifier for the CTA.
223 + * @param array $additional_args Optional additional query args.
224 + *
225 + * @return string
226 + */
227 +function quickwebp_get_pro_url( $context, $additional_args = array() ) {
228 + $base_url = 'https://solutions.leyoweb.com/products/quickwebp/';
229 +
230 + if ( class_exists( 'Quickwebp_Settings' ) && defined( 'Quickwebp_Settings::QUICKWEBP_GET_LICENSE_URL' ) ) {
231 + $base_url = Quickwebp_Settings::QUICKWEBP_GET_LICENSE_URL;
232 + }
233 +
234 + return add_query_arg(
235 + array_merge(
236 + $additional_args,
237 + array(
238 + 'utm_source' => 'quickwebp-plugin',
239 + 'utm_medium' => 'plugin',
240 + 'utm_campaign' => 'upgrade-pro',
241 + 'utm_content' => sanitize_key( $context ),
242 + )
243 + ),
244 + $base_url
245 + );
246 +}