PluginProbe
Plus WebP or AVIF / 4.11
Plus WebP or AVIF v4.11
5.21 5.20 5.12 5.11 trunk 1.00 1.01 1.02 1.03 1.04 1.05 1.06 1.07 1.08 1.09 1.10 1.11 1.12 1.13 2.00 2.01 2.02 2.03 2.04 2.05 All 47 releases
← All changes | lib/class-pluswebpadmin.php +75 -120 5.204.11 View file →
@@ -1,9 +1,9 @@
1 1 <?php
2 2 /**
3 - * Plus WebP or AVIF
3 + * Plus WebP
4 4 *
5 - * @package Plus WebP or AVIF
5 + * @package Plus WebP
6 6 * @subpackage PlusWebpAdmin Management screen
7 7 Copyright (c) 2019- Katsushi Kawamori (email : dodesyoswift312@gmail.com)
8 8 This program is free software; you can redistribute it and/or modify
9 9 it under the terms of the GNU General Public License as published by
@@ -18,12 +18,8 @@
18 18 along with this program; if not, write to the Free Software
19 19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 20 */
21 21
22 -if ( ! defined( 'ABSPATH' ) ) {
23 - exit;
24 -}
25 -
26 22 $pluswebpadmin = new PlusWebpAdmin();
27 23
28 24 /** ==================================================
29 25 * Management screen
@@ -59,9 +55,9 @@
59 55 if ( empty( $this_plugin ) ) {
60 56 $this_plugin = 'plus-webp/pluswebp.php';
61 57 }
62 58 if ( $file === $this_plugin ) {
63 - $links[] = '<a href="' . admin_url( 'upload.php?page=plus-webp' ) . '">' . esc_html__( 'Settings', 'plus-webp' ) . ' & ' . esc_html__( 'Bulk Generate', 'plus-webp' ) . '</a>';
59 + $links[] = '<a href="' . admin_url( 'upload.php?page=plus-webp' ) . '">' . esc_html__( 'Settings' ) . ' & ' . esc_html__( 'Bulk Generate', 'plus-webp' ) . '</a>';
64 60 }
65 61 return $links;
66 62 }
67 63
@@ -72,10 +68,10 @@
72 68 */
73 69 public function plugin_menu() {
74 70
75 71 add_media_page(
76 - 'Plus WebP or AVIF',
77 - 'Plus WebP or AVIF',
72 + 'Plus WebP',
73 + 'Plus WebP',
78 74 'manage_options',
79 75 'plus-webp',
80 76 array( $this, 'plus_webp_generate_setteings' )
81 77 );
@@ -87,21 +83,9 @@
87 83 * @since 4.00
88 84 */
89 85 public function plus_webp_generate_setteings() {
90 86
91 - if ( ! current_user_can( 'manage_options' ) ) {
92 - wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'plus-webp' ) );
93 - }
94 -
95 - global $wp_version;
96 - $requires = '6.6';
97 - if ( version_compare( $wp_version, $requires, '>=' ) ) {
98 - $admin_screen = esc_html__( 'Loading…', 'plus-webp' );
99 - } else {
100 - /* translators: WordPress requires version */
101 - $admin_screen = sprintf( esc_html__( 'WordPress %s or higher is required to view this screen.', 'plus-webp' ), $requires );
102 - }
103 - printf( '<div class="wrap" id="plus-webp-page">%s</div>', esc_html( $admin_screen ) );
87 + echo '<div id="plus-webp-page"></div>';
104 88 }
105 89
106 90 /** ==================================================
107 91 * Load script
@@ -114,19 +98,13 @@
114 98 if ( 'media_page_plus-webp' !== $hook_suffix ) {
115 99 return;
116 100 }
117 101
118 - $asset_file = plugin_dir_path( __DIR__ ) . 'guten/build/index.asset.php';
102 + $asset_file = include plugin_dir_path( __DIR__ ) . 'guten/dist/plus-webp.asset.php';
119 103
120 - if ( ! file_exists( $asset_file ) ) {
121 - return;
122 - }
123 -
124 - $asset = include $asset_file;
125 -
126 104 wp_enqueue_style(
127 105 'plus-webp-style',
128 - plugin_dir_url( __DIR__ ) . 'guten/build/index.css',
106 + plugin_dir_url( __DIR__ ) . 'guten/dist/plus-webp.css',
129 107 array( 'wp-components' ),
130 108 '1.0.0',
131 109 );
132 110
@@ -131,28 +109,71 @@
131 109 );
132 110
133 111 wp_enqueue_script(
134 112 'plus-webp',
135 - plugin_dir_url( __DIR__ ) . 'guten/build/index.js',
136 - $asset['dependencies'],
137 - $asset['version'],
113 + plugin_dir_url( __DIR__ ) . 'guten/dist/plus-webp.js',
114 + $asset_file['dependencies'],
115 + $asset_file['version'],
116 + true
117 + );
118 +
119 + $pluswebp_settings = get_option( 'pluswebp' );
120 +
121 + list( $post_ids, $no_file_ids ) = apply_filters( 'pluswebp_get_allimages', $pluswebp_settings['types'] );
122 +
123 + $non_generate_description = null;
124 + if ( ! empty( $no_file_ids ) ) {
125 + /* translators: Count of no file Media */
126 + $non_generate_description = sprintf( __( 'Found %1$d media(id: %2$s), exists in the database, but the file does not, so the conversion is not performed.', 'plus-webp' ), count( $no_file_ids ), implode( ',', $no_file_ids ) );
127 + }
128 +
129 + wp_localize_script(
130 + 'plus-webp',
131 + 'pluswebpgenerate_data',
138 132 array(
139 - 'in_footer' => true,
133 + 'bulk_label' => __( 'Bulk Generate', 'plus-webp' ),
134 + 'description_label' => __( 'To perform "Bulk Generate" after changing the following settings, press "Check" and then press "Generate".', 'plus-webp' ),
135 + 'wp_cli_label' => __( 'WP-CLI commands are available. If you have a large number of files, WP-CLI commands is more reliable. Command line options allow you to specify whether or not email is sent and the source media ID.', 'plus-webp' ),
136 + 'generate_label' => __( 'Generate', 'plus-webp' ),
137 + 'generate_description_label' => __( 'Notified by email with details of the generate results.', 'plus-webp' ),
138 + 'generate_end_label' => __( 'Generation has been completed.', 'plus-webp' ),
139 + 'stop_label' => __( 'Stop', 'plus-webp' ),
140 + 'check_label' => __( 'Check', 'plus-webp' ),
141 + /* translators: Count of Media */
142 + 'generate_description' => sprintf( __( 'Found %1$d media that can be generated.', 'plus-webp' ), count( $post_ids ) ),
143 + 'non_description' => __( 'Cannot find any media that can be generated.', 'plus-webp' ),
144 + 'non_generate_description' => $non_generate_description,
145 + 'title_label' => __( 'Title' ) . ': ',
146 + 'filename_label' => __( 'File name:' ) . ' ',
147 + 'datetime_label' => __( 'Date/Time' ) . ': ',
148 + 'filesize_label' => __( 'File size:' ) . ' ',
149 + 'post_ids' => wp_json_encode( $post_ids, JSON_UNESCAPED_SLASHES ),
140 150 )
141 151 );
142 152
143 - $pluswebp_settings = get_option( 'pluswebp' );
144 -
145 153 wp_localize_script(
146 154 'plus-webp',
147 155 'pluswebpsettings_data',
148 156 array(
149 - 'settings' => $pluswebp_settings,
157 + 'settings_label' => __( 'Settings' ),
158 + 'quality_label' => __( 'Quality', 'plus-webp' ),
159 + 'lowreso_label' => __( 'low resolution', 'plus-webp' ),
160 + 'highreso_label' => __( 'high resolution', 'plus-webp' ),
161 + 'quality_description_label' => __( 'Specifies the quality of WebP. The higher the number, the better the quality and the larger the file size.', 'plus-webp' ),
162 + 'type_label' => __( 'Type' ),
163 + 'type_description_label' => __( 'Check the images you want to convert to WebP.', 'plus-webp' ),
164 + 'append_label' => __( 'Append the webp extension to the original filename', 'plus-webp' ),
165 + 'apply_label' => __( 'Apply' ),
166 + 'append_description_label' => __( 'Checking this setting, the extension webp will be appended to the name of the file, including the extension. Not checking, only the extension is changed.', 'plus-webp' ),
167 + 'replace_label' => __( 'WebP replacement of images and contents', 'plus-webp' ),
168 + 'replace_description_label' => __( 'Checking this setting will replace image files with WebP when adding new media, and delete the original image file. Also, when generating all images, the original image file ID will be overwritten as WebP and the original image file will be deleted. All URLs in the content are also replaced.', 'plus-webp' ),
169 + 'replace_advanced_description_label' => __( 'If you want to replace other databases besides content, use the "plus_webp_advanced_change_db" filter hook.', 'plus-webp' ),
170 + 'replace_advanced_link' => __( 'https://wordpress.org/plugins/plus-webp/', 'plus-webp' ),
171 + 'replace_advanced_text' => __( '"plus_webp_advanced_change_db" filter hook', 'plus-webp' ),
172 + 'settings' => wp_json_encode( $pluswebp_settings, JSON_UNESCAPED_SLASHES ),
150 173 )
151 174 );
152 175
153 - wp_set_script_translations( 'plus-webp', 'plus-webp' );
154 -
155 176 $this->credit_gutenberg( 'plus-webp' );
156 177 }
157 178
158 179 /** ==================================================
@@ -162,18 +183,8 @@
162 183 */
163 184 public function register_rest() {
164 185
165 186 register_rest_route(
166 - 'rf/plus-webp-confirm_api',
167 - '/token',
168 - array(
169 - 'methods' => 'POST',
170 - 'callback' => array( $this, 'confirm_api_save' ),
171 - 'permission_callback' => array( $this, 'rest_permission' ),
172 - ),
173 - );
174 -
175 - register_rest_route(
176 187 'rf/plus-webp-generate_api',
177 188 '/token',
178 189 array(
179 190 'methods' => 'POST',
@@ -203,41 +214,8 @@
203 214 return current_user_can( 'manage_options' );
204 215 }
205 216
206 217 /** ==================================================
207 - * Rest API save for Confirm
208 - *
209 - * @param object $request changed data.
210 - * @since 5.20
211 - */
212 - public function confirm_api_save( $request ) {
213 -
214 - $args = $request->get_json_params();
215 -
216 - $args['post_ids'] = array();
217 - $args['ids_desc'] = null;
218 - $args['non_ids_desc'] = null;
219 - if ( $args['submit'] ) {
220 - $pluswebp_settings = get_option( 'pluswebp' );
221 - list( $post_ids, $no_file_ids ) = apply_filters( 'pluswebp_get_allimages', $pluswebp_settings['types'], $pluswebp_settings['output_mime'] );
222 - update_option( 'test', $post_ids );
223 - $args['post_ids'] = $post_ids;
224 - if ( ! empty( $post_ids ) ) {
225 - /* translators: Count of file Media */
226 - $args['ids_desc'] = sprintf( __( 'Found %1$d media that can be generated.', 'plus-webp' ), count( $post_ids ) );
227 - } else {
228 - $args['ids_desc'] = __( 'Cannot find any media that can be generated.', 'plus-webp' );
229 - }
230 - if ( ! empty( $no_file_ids ) ) {
231 - /* translators: Count of no file Media */
232 - $args['non_ids_desc'] = sprintf( __( 'Found %1$d media(id: %2$s), exists in the database, but the file does not, so the conversion is not performed.', 'plus-webp' ), count( $no_file_ids ), implode( ',', $no_file_ids ) );
233 - }
234 - }
235 -
236 - return new WP_REST_Response( $args, 200 );
237 - }
238 -
239 - /** ==================================================
240 218 * Rest API save for Generate
241 219 *
242 220 * @param object $request changed data.
243 221 * @since 4.00
@@ -243,18 +221,16 @@
243 221 * @since 4.00
244 222 */
245 223 public function generate_api_save( $request ) {
246 224
247 - $args = $request->get_json_params();
225 + $args = json_decode( $request->get_body(), true );
248 226
249 227 $count = absint( $args['count'] );
250 228 $max_count = absint( $args['max_count'] );
251 229 $attach_id = absint( $args['post_id'] );
252 230 $messages = get_option( 'pluswebp_messages', array() );
253 - $sent_mail = boolval( $args['sent_mail'] );
254 - $stop = boolval( $args['stop'] );
255 231
256 - if ( boolval( $args['generate'] ) ) {
232 + if ( $args['generate'] ) {
257 233 $metadata_org = wp_get_attachment_metadata( $attach_id );
258 234
259 235 delete_option( 'pluswebp_generate' );
260 236 do_action( 'wp_generate_attachment_metadata', $metadata_org, $attach_id );
@@ -265,17 +241,13 @@
265 241 list( $tmp, $messages ) = apply_filters( 'pluswebp_mail_messages', $messages, $webp_id );
266 242 update_option( 'pluswebp_messages', $messages );
267 243 }
268 244 if ( $count === $max_count ) {
269 - if ( $sent_mail && ! empty( get_option( 'pluswebp_messages' ) ) ) {
270 - do_action( 'pluswebp_mail_generate_message', get_option( 'pluswebp_messages' ), count( get_option( 'pluswebp_messages' ) ) );
271 - }
245 + do_action( 'pluswebp_mail_generate_message', $messages, $max_count );
272 246 delete_option( 'pluswebp_messages' );
273 247 }
274 - } else if ( ! boolval( $args['generate'] ) && $stop ) {
275 - if ( $sent_mail && ! empty( get_option( 'pluswebp_messages' ) ) ) {
276 - do_action( 'pluswebp_mail_generate_message', get_option( 'pluswebp_messages' ), count( get_option( 'pluswebp_messages' ) ) );
277 - }
248 + } else {
249 + do_action( 'pluswebp_mail_generate_message', $messages, count( $messages ) );
278 250 delete_option( 'pluswebp_messages' );
279 251 }
280 252
281 253 return new WP_REST_Response( $args, 200 );
@@ -288,25 +260,14 @@
288 260 * @since 4.00
289 261 */
290 262 public function settings_api_save( $request ) {
291 263
292 - $args = $request->get_json_params();
264 + $args = json_decode( $request->get_body(), true );
293 265
294 - if ( isset( $args['settings'] ) && is_array( $args['settings'] ) ) {
295 - $settings = $args['settings'];
296 - } else {
297 - return new WP_Error(
298 - 'invalid_settings',
299 - 'Invalid settings.',
300 - array( 'status' => 400 )
301 - );
302 - }
303 -
304 266 $options = array();
305 - $options['output_mime'] = sanitize_text_field( wp_unslash( $settings['output_mime'] ) );
306 - $options['quality'] = intval( $settings['quality'] );
267 + $options['quality'] = intval( $args['quality'] );
307 268 $options['types'] = filter_var(
308 - wp_unslash( $settings['types'] ),
269 + wp_unslash( $args['types'] ),
309 270 FILTER_CALLBACK,
310 271 array(
311 272 'options' => function ( $value ) {
312 273 return sanitize_text_field( $value );
@@ -312,10 +273,10 @@
312 273 return sanitize_text_field( $value );
313 274 },
314 275 )
315 276 );
316 - $options['addext'] = boolval( $settings['addext'] );
317 - $options['replace'] = boolval( $settings['replace'] );
277 + $options['addext'] = boolval( $args['addext'] );
278 + $options['replace'] = boolval( $args['replace'] );
318 279
319 280 update_option( 'pluswebp', $options );
320 281
321 282 return new WP_REST_Response( $args, 200 );
@@ -363,9 +324,9 @@
363 324 $handle,
364 325 'credit',
365 326 array(
366 327 'links' => __( 'Various links of this plugin', 'plus-webp' ),
367 - 'plugin_version' => __( 'Version:', 'plus-webp' ) . ' ' . $plugin_ver_num,
328 + 'plugin_version' => __( 'Version:' ) . ' ' . $plugin_ver_num,
368 329 /* translators: FAQ Link & Slug */
369 330 'faq' => sprintf( __( 'https://wordpress.org/plugins/%1$s/faq', 'plus-webp' ), $slug ),
370 331 'support' => 'https://wordpress.org/support/plugin/' . $slug,
371 332 'review' => 'https://wordpress.org/support/view/plugin-reviews/' . $slug,
@@ -370,15 +331,15 @@
370 331 'support' => 'https://wordpress.org/support/plugin/' . $slug,
371 332 'review' => 'https://wordpress.org/support/view/plugin-reviews/' . $slug,
372 333 'translate' => 'https://translate.wordpress.org/projects/wp-plugins/' . $slug,
373 334 /* translators: Plugin translation link */
374 - 'translate_text' => sprintf( __( 'Translations for %s', 'plus-webp' ), $plugin_name ),
335 + 'translate_text' => sprintf( __( 'Translations for %s' ), $plugin_name ),
375 336 'facebook' => 'https://www.facebook.com/katsushikawamori/',
376 337 'twitter' => 'https://twitter.com/dodesyo312',
377 338 'youtube' => 'https://www.youtube.com/channel/UC5zTLeyROkvZm86OgNRcb_w',
378 339 'donate' => __( 'https://shop.riverforest-wp.info/donate/', 'plus-webp' ),
379 340 'donate_text' => __( 'Please make a donation if you like my work or would like to further the development of this plugin.', 'plus-webp' ),
380 - 'donate_button' => __( 'Donate to this plugin &#187;', 'plus-webp' ),
341 + 'donate_button' => __( 'Donate to this plugin &#187;' ),
381 342 )
382 343 );
383 344 }
384 345
@@ -405,20 +366,14 @@
405 366 if ( ! array_key_exists( 'addext', $pluswebp_settings ) ) {
406 367 $pluswebp_settings['addext'] = false;
407 368 update_option( 'pluswebp', $pluswebp_settings );
408 369 }
409 - /* 'mime' from ver 5.00 */
410 - if ( ! array_key_exists( 'output_mime', $pluswebp_settings ) ) {
411 - $pluswebp_settings['output_mime'] = 'image/webp';
412 - update_option( 'pluswebp', $pluswebp_settings );
413 - }
414 370 } else {
415 371 $pswp_tbl = array(
416 - 'output_mime' => 'image/webp',
417 372 'quality' => 80,
418 373 'replace' => false,
419 - 'addext' => false,
420 - 'types' => array(
374 + 'addext' => false,
375 + 'types' => array(
421 376 'image/jpeg',
422 377 'image/png',
423 378 'image/bmp',
424 379 'image/gif',