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 +212 -375 2.05 → 4.11 View file →
@@ -36,12 +36,11 @@
36 36 add_action( 'admin_init', array( $this, 'register_settings' ) );
37 37
38 38 add_action( 'admin_menu', array( $this, 'plugin_menu' ) );
39 39 add_filter( 'plugin_action_links', array( $this, 'settings_link' ), 10, 2 );
40 - add_action( 'admin_notices', array( $this, 'generate_notice' ) );
41 40
42 - add_action( 'AllImagesRegenerateHook', array( $this, 'allimages_regenerate' ), 10, 1 );
43 -
41 + add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ), 10, 1 );
42 + add_action( 'rest_api_init', array( $this, 'register_rest' ) );
44 43 }
45 44
46 45 /** ==================================================
47 46 * Add a "Settings" link to the plugins page
@@ -56,9 +55,9 @@
56 55 if ( empty( $this_plugin ) ) {
57 56 $this_plugin = 'plus-webp/pluswebp.php';
58 57 }
59 58 if ( $file === $this_plugin ) {
60 - $links[] = '<a href="' . admin_url( 'tools.php?page=pluswebp' ) . '">' . esc_html__( 'Settings' ) . ' & ' . 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>';
61 60 }
62 61 return $links;
63 62 }
64 63
@@ -67,226 +66,230 @@
67 66 *
68 67 * @since 1.00
69 68 */
70 69 public function plugin_menu() {
71 - add_management_page( 'Plus WebP', 'Plus WebP', 'manage_options', 'pluswebp', array( $this, 'plugin_options' ) );
70 +
71 + add_media_page(
72 + 'Plus WebP',
73 + 'Plus WebP',
74 + 'manage_options',
75 + 'plus-webp',
76 + array( $this, 'plus_webp_generate_setteings' )
77 + );
72 78 }
73 79
74 80 /** ==================================================
75 - * Settings page
81 + * Generate and Settings page
76 82 *
77 - * @since 1.00
83 + * @since 4.00
78 84 */
79 - public function plugin_options() {
85 + public function plus_webp_generate_setteings() {
80 86
81 - if ( ! current_user_can( 'manage_options' ) ) {
82 - wp_die( esc_html__( 'You do not have sufficient permissions to access this page.' ) );
87 + echo '<div id="plus-webp-page"></div>';
88 + }
89 +
90 + /** ==================================================
91 + * Load script
92 + *
93 + * @param string $hook_suffix hook_suffix.
94 + * @since 4.00
95 + */
96 + public function admin_scripts( $hook_suffix ) {
97 +
98 + if ( 'media_page_plus-webp' !== $hook_suffix ) {
99 + return;
83 100 }
84 101
85 - $this->options_updated();
102 + $asset_file = include plugin_dir_path( __DIR__ ) . 'guten/dist/plus-webp.asset.php';
103 +
104 + wp_enqueue_style(
105 + 'plus-webp-style',
106 + plugin_dir_url( __DIR__ ) . 'guten/dist/plus-webp.css',
107 + array( 'wp-components' ),
108 + '1.0.0',
109 + );
110 +
111 + wp_enqueue_script(
112 + 'plus-webp',
113 + plugin_dir_url( __DIR__ ) . 'guten/dist/plus-webp.js',
114 + $asset_file['dependencies'],
115 + $asset_file['version'],
116 + true
117 + );
118 +
86 119 $pluswebp_settings = get_option( 'pluswebp' );
87 120
88 - if ( isset( $_POST['Generatewebp'] ) && ! empty( $_POST['Generatewebp'] ) ) {
89 - if ( check_admin_referer( 'pwp_gnt', 'pluswebp_gnt' ) ) {
90 - if ( ! empty( $pluswebp_settings['types'] ) ) {
91 - $user = wp_get_current_user();
92 - $to = $user->user_email;
93 - $userid = $user->ID;
94 - if ( ! wp_next_scheduled( 'AllImagesRegenerateHook', array( $to ) ) ) {
95 - wp_schedule_single_event( time(), 'AllImagesRegenerateHook', array( $to ) );
96 - echo '<div class="notice notice-success is-dismissible"><ul><li>' . esc_html__( 'Background generation starts.', 'plus-webp' ) . '</li></ul></div>';
97 - } else {
98 - echo '<div class="notice notice-error is-dismissible"><ul><li>' . esc_html__( 'Currently, there is a process that is being bulk generated.', 'plus-webp' ) . '</li></ul></div>';
99 - }
100 - } else {
101 - echo '<div class="notice notice-error is-dismissible"><ul><li>' . esc_html__( 'The image type for creating WebP is not specified.', 'plus-webp' ) . '</li></ul></div>';
102 - }
103 - }
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 ) );
104 127 }
105 128
106 - $scriptname = admin_url( 'tools.php?page=pluswebp' );
129 + wp_localize_script(
130 + 'plus-webp',
131 + 'pluswebpgenerate_data',
132 + array(
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 ),
150 + )
151 + );
107 152
108 - ?>
109 - <div class="wrap">
110 - <h2>Plus WebP</h2>
153 + wp_localize_script(
154 + 'plus-webp',
155 + 'pluswebpsettings_data',
156 + array(
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 ),
173 + )
174 + );
111 175
112 - <div id="bulkgeneratewebp-loading-container">
176 + $this->credit_gutenberg( 'plus-webp' );
177 + }
113 178
114 - <details>
115 - <summary><strong><?php esc_html_e( 'Various links of this plugin', 'plus-webp' ); ?></strong></summary>
116 - <?php $this->credit(); ?>
117 - </details>
179 + /** ==================================================
180 + * Register Rest API
181 + *
182 + * @since 4.00
183 + */
184 + public function register_rest() {
118 185
119 - <div class="wrap">
120 - <h2><?php esc_html_e( 'Bulk Generate', 'plus-webp' ); ?></h2>
121 - <details style="margin-bottom: 5px;">
122 - <summary style="cursor: pointer; padding: 10px; border: 1px solid #ddd; background: #f4f4f4; color: #000;"><strong><?php esc_html_e( 'Generate', 'plus-webp' ); ?></strong></summary>
123 - <?php
124 - $post_ids = $this->get_allimages();
125 - if ( ! empty( $post_ids ) ) {
126 - ?>
127 - <div style="margin: 5px; padding: 5px;">
128 - <p class="description">
129 - <?php esc_html_e( 'Press the following button to start WebP generation with Ajax.', 'plus-webp' ); ?>
130 - </p>
131 - </div>
132 - <?php
133 - /* for Ajax */
134 - $handle = 'bulkgeneratewebp-js';
135 - $action1 = 'bulkgeneratewebp-ajax-action';
136 - $action2 = 'bulkgeneratewebp_message';
137 - wp_enqueue_script( 'jquery' );
138 - wp_enqueue_script( $handle, plugin_dir_url( __DIR__ ) . 'js/jquery.bulkgeneratewebp.js', array( 'jquery' ), '1.00', false );
186 + register_rest_route(
187 + 'rf/plus-webp-generate_api',
188 + '/token',
189 + array(
190 + 'methods' => 'POST',
191 + 'callback' => array( $this, 'generate_api_save' ),
192 + 'permission_callback' => array( $this, 'rest_permission' ),
193 + ),
194 + );
139 195
140 - wp_localize_script(
141 - $handle,
142 - 'bulkgeneratewebp',
143 - array(
144 - 'ajax_url' => admin_url( 'admin-ajax.php' ),
145 - 'action' => $action1,
146 - 'nonce' => wp_create_nonce( $action1 ),
147 - )
148 - );
149 - wp_localize_script(
150 - $handle,
151 - 'bulkgeneratewebp_mes',
152 - array(
153 - 'ajax_url' => admin_url( 'admin-ajax.php' ),
154 - 'action' => $action2,
155 - 'nonce' => wp_create_nonce( $action2 ),
156 - )
157 - );
158 - wp_localize_script(
159 - $handle,
160 - 'bulkgeneratewebp_data',
161 - array(
162 - 'count' => count( $post_ids ),
163 - 'id' => json_encode( $post_ids, JSON_UNESCAPED_SLASHES ),
164 - )
165 - );
196 + register_rest_route(
197 + 'rf/plus-webp-settings_api',
198 + '/token',
199 + array(
200 + 'methods' => 'POST',
201 + 'callback' => array( $this, 'settings_api_save' ),
202 + 'permission_callback' => array( $this, 'rest_permission' ),
203 + ),
204 + );
205 + }
166 206
167 - wp_localize_script(
168 - $handle,
169 - 'bulkgeneratewebp_text',
170 - array(
171 - 'stop_button' => __( 'Stop', 'plus-webp' ),
172 - 'stop_message' => __( 'Stopping now..', 'plus-webp' ),
173 - )
174 - );
175 - submit_button( __( 'Generate', 'plus-webp' ), 'primary', 'bulkgeneratewebp_ajax_update', false );
176 - } else {
177 - ?>
178 - <div style="margin: 5px; padding: 5px;">
179 - <p class="description">
180 - <?php esc_html_e( 'There is no media in the media library that can generate WebP.', 'plus-webp' ); ?>
181 - </p>
182 - </div>
183 - <?php
184 - }
185 - ?>
186 - </details>
187 - <details style="margin-bottom: 5px;">
188 - <summary style="cursor: pointer; padding: 10px; border: 1px solid #ddd; background: #f4f4f4; color: #000;"><strong><?php esc_html_e( 'Generate Background', 'plus-webp' ); ?></strong></summary>
189 - <div style="margin: 5px; padding: 5px;">
190 - <p class="description">
191 - <?php esc_html_e( 'Press the following button to start WebP generation in the background. When finished, you will receive an email.', 'plus-webp' ); ?>
192 - </p>
193 - </div>
194 - <form method="post" action="<?php echo esc_url( $scriptname ); ?>">
195 - <?php wp_nonce_field( 'pwp_gnt', 'pluswebp_gnt' ); ?>
196 - <?php submit_button( __( 'Generate Background', 'plus-webp' ), 'primary', 'Generatewebp', false ); ?>
197 - </form>
198 - </details>
207 + /** ==================================================
208 + * Rest Permission
209 + *
210 + * @since 4.00
211 + */
212 + public function rest_permission() {
199 213
200 - </div>
214 + return current_user_can( 'manage_options' );
215 + }
201 216
202 - <div class="wrap">
203 - <h2><?php esc_html_e( 'Settings' ); ?></h2>
217 + /** ==================================================
218 + * Rest API save for Generate
219 + *
220 + * @param object $request changed data.
221 + * @since 4.00
222 + */
223 + public function generate_api_save( $request ) {
204 224
205 - <form method="post" action="<?php echo esc_url( $scriptname ); ?>">
206 - <?php wp_nonce_field( 'pwp_set', 'pluswebp_set' ); ?>
225 + $args = json_decode( $request->get_body(), true );
207 226
208 - <details style="margin-bottom: 5px;">
209 - <summary style="cursor: pointer; padding: 10px; border: 1px solid #ddd; background: #f4f4f4; color: #000;"><strong><?php esc_html_e( 'Quality', 'plus-webp' ); ?></strong></summary>
210 - <div style="margin: 5px; padding: 5px;">
211 - <?php esc_html_e( 'low resolution', 'plus-webp' ); ?>
212 - <input type="range" style="vertical-align:middle;" name="quality" value="<?php echo esc_attr( $pluswebp_settings['quality'] ); ?>" min="0" max="100" step="1">
213 - <?php esc_html_e( 'high resolution', 'plus-webp' ); ?>
214 - <div style="margin: 5px; padding: 5px;">
215 - <p class="description">
216 - <?php esc_html_e( 'Specifies the quality of WebP. The higher the resolution, the larger the file size.', 'plus-webp' ); ?>
217 - </p>
218 - </div>
219 - </div>
220 - </details>
227 + $count = absint( $args['count'] );
228 + $max_count = absint( $args['max_count'] );
229 + $attach_id = absint( $args['post_id'] );
230 + $messages = get_option( 'pluswebp_messages', array() );
221 231
222 - <details style="margin-bottom: 5px;">
223 - <summary style="cursor: pointer; padding: 10px; border: 1px solid #ddd; background: #f4f4f4; color: #000;"><strong><?php esc_html_e( 'Type' ); ?></strong></summary>
224 - <?php
225 - $list_types = array(
226 - 'image/jpeg',
227 - 'image/png',
228 - 'image/bmp',
229 - 'image/gif',
230 - );
231 - foreach ( $list_types as $value ) {
232 - if ( in_array( $value, $pluswebp_settings['types'] ) ) {
233 - $check = 1;
234 - } else {
235 - $check = 0;
236 - }
237 - ?>
238 - <div style="display: block;padding:5px 5px"><input type="checkbox" name="list_types[<?php echo esc_attr( $value ); ?>]" value="1" <?php checked( '1', $check ); ?> /><?php echo esc_html( $value ); ?></div>
239 - <?php
240 - }
241 - ?>
242 - <div style="margin: 5px; padding: 5px;">
243 - <p class="description">
244 - <?php esc_html_e( 'Check the images you want to convert to WebP.', 'plus-webp' ); ?>
245 - </p>
246 - </div>
247 - </details>
232 + if ( $args['generate'] ) {
233 + $metadata_org = wp_get_attachment_metadata( $attach_id );
248 234
249 - <details style="margin-bottom: 5px;">
250 - <summary style="cursor: pointer; padding: 10px; border: 1px solid #ddd; background: #f4f4f4; color: #000;"><strong><?php esc_html_e( 'Append the webp extension to the original filename', 'plus-webp' ); ?></strong></summary>
251 - <div style="margin: 5px; padding: 5px;">
252 - <input type="checkbox" name="addext" value="1" <?php checked( $pluswebp_settings['addext'], true ); ?>><?php esc_html_e( 'Apply' ); ?>
253 - <div style="margin: 5px; padding: 5px;">
254 - <p class="description">
255 - <?php esc_html_e( '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' ); ?>
256 - </p>
257 - </div>
258 - </div>
259 - </details>
235 + delete_option( 'pluswebp_generate' );
236 + do_action( 'wp_generate_attachment_metadata', $metadata_org, $attach_id );
237 + $webp_id = get_option( 'pluswebp_generate' );
238 + delete_option( 'pluswebp_generate' );
260 239
261 - <details style="margin-bottom: 5px;">
262 - <summary style="cursor: pointer; padding: 10px; border: 1px solid #ddd; background: #f4f4f4; color: #000;"><strong><?php esc_html_e( 'WebP replacement of images and contents', 'plus-webp' ); ?></strong></summary>
263 - <div style="margin: 5px; padding: 5px;">
264 - <input type="checkbox" name="replace" value="1" <?php checked( $pluswebp_settings['replace'], true ); ?>><?php esc_html_e( 'Apply' ); ?>
265 - <div style="margin: 5px; padding: 5px;">
266 - <p class="description">
267 - <?php esc_html_e( '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' ); ?>
268 - </p>
269 - </div>
270 - </div>
271 - </details>
240 + if ( $webp_id ) {
241 + list( $tmp, $messages ) = apply_filters( 'pluswebp_mail_messages', $messages, $webp_id );
242 + update_option( 'pluswebp_messages', $messages );
243 + }
244 + if ( $count === $max_count ) {
245 + do_action( 'pluswebp_mail_generate_message', $messages, $max_count );
246 + delete_option( 'pluswebp_messages' );
247 + }
248 + } else {
249 + do_action( 'pluswebp_mail_generate_message', $messages, count( $messages ) );
250 + delete_option( 'pluswebp_messages' );
251 + }
272 252
273 - <?php submit_button( __( 'Save Changes' ), 'large', 'Manageset', false ); ?>
274 - </form>
275 - </div>
253 + return new WP_REST_Response( $args, 200 );
254 + }
276 255
277 - </div>
256 + /** ==================================================
257 + * Rest API save for Settings
258 + *
259 + * @param object $request changed data.
260 + * @since 4.00
261 + */
262 + public function settings_api_save( $request ) {
278 263
279 - </div>
280 - <?php
264 + $args = json_decode( $request->get_body(), true );
265 +
266 + $options = array();
267 + $options['quality'] = intval( $args['quality'] );
268 + $options['types'] = filter_var(
269 + wp_unslash( $args['types'] ),
270 + FILTER_CALLBACK,
271 + array(
272 + 'options' => function ( $value ) {
273 + return sanitize_text_field( $value );
274 + },
275 + )
276 + );
277 + $options['addext'] = boolval( $args['addext'] );
278 + $options['replace'] = boolval( $args['replace'] );
279 +
280 + update_option( 'pluswebp', $options );
281 +
282 + return new WP_REST_Response( $args, 200 );
281 283 }
282 284
283 285 /** ==================================================
284 - * Credit
286 + * Credit for Gutenberg
285 287 *
286 - * @since 1.00
288 + * @param string $handle handle.
289 + * @since 4.00
287 290 */
288 - private function credit() {
291 + private function credit_gutenberg( $handle ) {
289 292
290 293 $plugin_name = null;
291 294 $plugin_ver_num = null;
292 295 $plugin_path = plugin_dir_path( __DIR__ );
@@ -315,162 +318,33 @@
315 318 }
316 319 }
317 320 }
318 321 }
319 - $plugin_version = __( 'Version:' ) . ' ' . $plugin_ver_num;
320 - /* translators: FAQ Link & Slug */
321 - $faq = sprintf( __( 'https://wordpress.org/plugins/%s/faq', 'plus-webp' ), $slug );
322 - $support = 'https://wordpress.org/support/plugin/' . $slug;
323 - $review = 'https://wordpress.org/support/view/plugin-reviews/' . $slug;
324 - $translate = 'https://translate.wordpress.org/projects/wp-plugins/' . $slug;
325 - $facebook = 'https://www.facebook.com/katsushikawamori/';
326 - $twitter = 'https://twitter.com/dodesyo312';
327 - $youtube = 'https://www.youtube.com/channel/UC5zTLeyROkvZm86OgNRcb_w';
328 - $donate = __( 'https://shop.riverforest-wp.info/donate/', 'plus-webp' );
329 322
330 - ?>
331 - <span style="font-weight: bold;">
332 - <div>
333 - <?php echo esc_html( $plugin_version ); ?> |
334 - <a style="text-decoration: none;" href="<?php echo esc_url( $faq ); ?>" target="_blank" rel="noopener noreferrer">FAQ</a> | <a style="text-decoration: none;" href="<?php echo esc_url( $support ); ?>" target="_blank" rel="noopener noreferrer">Support Forums</a> | <a style="text-decoration: none;" href="<?php echo esc_url( $review ); ?>" target="_blank" rel="noopener noreferrer">Reviews</a>
335 - </div>
336 - <div>
337 - <a style="text-decoration: none;" href="<?php echo esc_url( $translate ); ?>" target="_blank" rel="noopener noreferrer">
338 - <?php
339 - /* translators: Plugin translation link */
340 - echo esc_html( sprintf( __( 'Translations for %s' ), $plugin_name ) );
341 - ?>
342 - </a> | <a style="text-decoration: none;" href="<?php echo esc_url( $facebook ); ?>" target="_blank" rel="noopener noreferrer"><span class="dashicons dashicons-facebook"></span></a> | <a style="text-decoration: none;" href="<?php echo esc_url( $twitter ); ?>" target="_blank" rel="noopener noreferrer"><span class="dashicons dashicons-twitter"></span></a> | <a style="text-decoration: none;" href="<?php echo esc_url( $youtube ); ?>" target="_blank" rel="noopener noreferrer"><span class="dashicons dashicons-video-alt3"></span></a>
343 - </div>
344 - </span>
345 -
346 - <div style="width: 250px; height: 180px; margin: 5px; padding: 5px; border: #CCC 2px solid;">
347 - <h3><?php esc_html_e( 'Please make a donation if you like my work or would like to further the development of this plugin.', 'plus-webp' ); ?></h3>
348 - <div style="text-align: right; margin: 5px; padding: 5px;"><span style="padding: 3px; color: #ffffff; background-color: #008000">Plugin Author</span> <span style="font-weight: bold;">Katsushi Kawamori</span></div>
349 - <button type="button" style="margin: 5px; padding: 5px;" onclick="window.open('<?php echo esc_url( $donate ); ?>')"><?php esc_html_e( 'Donate to this plugin &#187;' ); ?></button>
350 - </div>
351 -
352 - <?php
353 -
354 - }
355 -
356 - /** ==================================================
357 - * Get All Images
358 - *
359 - * @since 2.00
360 - */
361 - private function get_allimages() {
362 -
363 - $pluswebp_settings = get_option( 'pluswebp' );
364 - $args = array(
365 - 'post_type' => 'attachment',
366 - 'post_status' => 'inherit',
367 - 'post_mime_type' => $pluswebp_settings['types'],
368 - 'posts_per_page' => -1,
369 - 'orderby' => 'date',
370 - 'order' => 'DESC',
323 + wp_localize_script(
324 + $handle,
325 + 'credit',
326 + array(
327 + 'links' => __( 'Various links of this plugin', 'plus-webp' ),
328 + 'plugin_version' => __( 'Version:' ) . ' ' . $plugin_ver_num,
329 + /* translators: FAQ Link & Slug */
330 + 'faq' => sprintf( __( 'https://wordpress.org/plugins/%1$s/faq', 'plus-webp' ), $slug ),
331 + 'support' => 'https://wordpress.org/support/plugin/' . $slug,
332 + 'review' => 'https://wordpress.org/support/view/plugin-reviews/' . $slug,
333 + 'translate' => 'https://translate.wordpress.org/projects/wp-plugins/' . $slug,
334 + /* translators: Plugin translation link */
335 + 'translate_text' => sprintf( __( 'Translations for %s' ), $plugin_name ),
336 + 'facebook' => 'https://www.facebook.com/katsushikawamori/',
337 + 'twitter' => 'https://twitter.com/dodesyo312',
338 + 'youtube' => 'https://www.youtube.com/channel/UC5zTLeyROkvZm86OgNRcb_w',
339 + 'donate' => __( 'https://shop.riverforest-wp.info/donate/', 'plus-webp' ),
340 + 'donate_text' => __( 'Please make a donation if you like my work or would like to further the development of this plugin.', 'plus-webp' ),
341 + 'donate_button' => __( 'Donate to this plugin &#187;' ),
342 + )
371 343 );
372 - $posts = get_posts( $args );
373 -
374 - global $wpdb;
375 - $webp_titles = $wpdb->get_col(
376 - "
377 - SELECT post_title
378 - FROM {$wpdb->prefix}posts
379 - WHERE post_type = 'attachment'
380 - AND post_mime_type IN ( 'image/webp' )
381 - AND post_status = 'inherit'
382 - "
383 - );
384 -
385 - $post_ids = array();
386 - foreach ( $posts as $post ) {
387 - if ( ! in_array( $post->post_title, $webp_titles ) ) {
388 - $post_ids[] = $post->ID;
389 - }
390 - }
391 -
392 - return $post_ids;
393 -
394 344 }
395 345
396 346 /** ==================================================
397 - * Regenerate All Images
398 - *
399 - * @param string $to mail address.
400 - * @since 1.00
401 - */
402 - public function allimages_regenerate( $to ) {
403 -
404 - $post_ids = $this->get_allimages();
405 -
406 - if ( ! empty( $post_ids ) ) {
407 - delete_option( 'pluswebp_generate' );
408 - include_once ABSPATH . 'wp-admin/includes/image.php';
409 - /* Generate WebP */
410 - foreach ( $post_ids as $attach_id ) {
411 - $metadata = wp_get_attachment_metadata( $attach_id );
412 - do_action( 'wp_generate_attachment_metadata', $metadata, $attach_id );
413 - }
414 - /* Mail send */
415 - do_action( 'pluswebp_mail_send', $to );
416 - } else {
417 - ?>
418 - <div class="notice notice-error is-dismissible"><ul><li><?php esc_html_e( 'There are no images to convert. Generation stopped.', 'plus-webp' ); ?></li></ul></div>';
419 - <?php
420 - }
421 -
422 - }
423 -
424 - /** ==================================================
425 - * Update wp_options table.
426 - *
427 - * @since 1.02
428 - */
429 - private function options_updated() {
430 -
431 - if ( isset( $_POST['Manageset'] ) && ! empty( $_POST['Manageset'] ) ) {
432 - if ( check_admin_referer( 'pwp_set', 'pluswebp_set' ) ) {
433 - $pluswebp_settings = get_option( 'pluswebp' );
434 - $list_types = array();
435 - if ( isset( $_POST['list_types'] ) && ! empty( $_POST['list_types'] ) ) {
436 - $tmps = filter_var(
437 - wp_unslash( $_POST['list_types'] ),
438 - FILTER_CALLBACK,
439 - array(
440 - 'options' => function( $value ) {
441 - return sanitize_text_field( $value );
442 - },
443 - )
444 - );
445 - foreach ( $tmps as $key => $value ) {
446 - $list_types[] = $key;
447 - }
448 - $pluswebp_settings['types'] = $list_types;
449 - } else {
450 - $pluswebp_settings['types'] = $list_types;
451 - }
452 - if ( isset( $_POST['addext'] ) && ! empty( $_POST['addext'] ) ) {
453 - $pluswebp_settings['addext'] = true;
454 - } else {
455 - $pluswebp_settings['addext'] = false;
456 - }
457 - if ( isset( $_POST['replace'] ) && ! empty( $_POST['replace'] ) ) {
458 - $pluswebp_settings['replace'] = true;
459 - } else {
460 - $pluswebp_settings['replace'] = false;
461 - }
462 - if ( isset( $_POST['quality'] ) ) {
463 - $pluswebp_settings['quality'] = intval( $_POST['quality'] );
464 - }
465 - update_option( 'pluswebp', $pluswebp_settings );
466 - echo '<div class="notice notice-success is-dismissible"><ul><li>' . esc_html__( 'Settings' ) . ' --> ' . esc_html__( 'Settings saved.' ) . '</li></ul></div>';
467 - }
468 - }
469 -
470 - }
471 -
472 - /** ==================================================
473 347 * Settings register
474 348 *
475 349 * @since 1.00
476 350 */
@@ -506,43 +380,6 @@
506 380 ),
507 381 );
508 382 update_option( 'pluswebp', $pswp_tbl );
509 383 }
510 -
511 384 }
512 -
513 - /** ==================================================
514 - * Generate notice
515 - *
516 - * @since 1.09
517 - */
518 - public function generate_notice() {
519 -
520 - if ( get_option( 'pluswebp_generate_mail' ) ) {
521 - $pluswebp_mail_send = get_option( 'pluswebp_generate_mail' );
522 - if ( 0 < $pluswebp_mail_send['count'] ) {
523 - ?>
524 - <div class="notice notice-success is-dismissible"><ul><li><strong>Plus WebP</strong>
525 - <?php
526 - /* translators: %1$s Date Time, %2$d File Count */
527 - echo wp_kses_post( sprintf( __( ' : %1$s : %2$d WebP files and their thumbnails have been generated. Details have been sent by e-mail.', 'plus-webp' ), $pluswebp_mail_send['datetime'], $pluswebp_mail_send['count'] ) );
528 - ?>
529 - </li></ul></div>
530 - <?php
531 - } else {
532 - ?>
533 - <div class="notice notice-error is-dismissible"><ul><li><strong>Plus WebP</strong>
534 - <?php
535 - /* translators: %1$s Date Time %2$s error message */
536 - echo wp_kses_post( sprintf( __( ' : %1$s : %2$s', 'plus-webp' ), $pluswebp_mail_send['datetime'], __( 'WebP was not generated. A file with the same name already exists.', 'plus-webp' ) ) );
537 - ?>
538 - </li></ul></div>
539 - <?php
540 - }
541 - delete_option( 'pluswebp_generate_mail' );
542 - }
543 -
544 - }
545 -
546 385 }
547 -
548 -