PluginProbe
Plus WebP or AVIF / 2.06
Plus WebP or AVIF v2.06
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-pluswebp.php +58 -70 2.022.06 View file →
@@ -108,10 +108,11 @@
108 108 $this->change_db( $url . $file_thumb, $url . $file_thumb_webp );
109 109 }
110 110 }
111 111 }
112 - if ( ! empty( $metadata['original_image'] ) ) {
113 - $org_img_file = wp_get_original_image_path( $attachment_id, false );
112 + $org_img_file = null;
113 + if ( array_key_exists( 'original_image', $metadata ) && ! empty( $metadata['original_image'] ) ) {
114 + $org_img_file = wp_normalize_path( wp_get_original_image_path( $attachment_id, false ) );
114 115 $org_webp_file = $this->change_ext( $org_img_file, 'webp', $pluswebp_settings['addext'] );
115 116 $ret = $this->create_webp( $org_img_file, $mime_type, $org_webp_file );
116 117 if ( $ret ) {
117 118 $metadata_webp['original_image'] = wp_basename( $org_webp_file );
@@ -131,8 +132,11 @@
131 132 /* for bulk generate */
132 133 update_post_meta( $attachment_id, '_wp_attachment_metadata', $metadata_webp );
133 134 /* delete org file */
134 135 unlink( $this->upload_dir . '/' . $metadata['file'] );
136 + if ( $org_img_file ) {
137 + unlink( $org_img_file );
138 + }
135 139 /* Replace */
136 140 $this->change_db( $this->upload_url . '/' . $metadata['file'], $this->upload_url . '/' . $file_webp );
137 141 /* for hook */
138 142 $metadata = $metadata_webp;
@@ -147,9 +151,15 @@
147 151 'post_title' => $title,
148 152 'post_content' => '',
149 153 'post_status' => 'inherit',
150 154 );
151 - $attach_id = wp_insert_attachment( $attachment, $this->upload_dir . '/' . $file_webp );
155 + $file = $this->upload_dir . '/' . $file_webp;
156 + $attach_id = wp_insert_attachment( $attachment, $file );
157 +
158 + /* for XAMPP [ get_attached_file( $attach_id ): Unable to get correct value ] */
159 + $metapath_name = str_replace( $this->upload_dir . '/', '', $file );
160 + update_post_meta( $attach_id, '_wp_attached_file', $metapath_name );
161 +
152 162 wp_update_attachment_metadata( $attach_id, $metadata_webp );
153 163
154 164 $author = get_userdata( $post->post_author );
155 165 $userid = $author->ID;
@@ -260,9 +270,9 @@
260 270
261 271 /* Thumbnail urls */
262 272 list( $image_thumbnail, $imagethumburls ) = $this->thumbnail_urls( $webp_id, $metadata, $this->upload_url );
263 273 /* Output datas*/
264 - list( $attachment_link, $attachment_url, $original_image_url, $mime_type, $stamptime, $file_size ) = $this->output_datas( $webp_id );
274 + list( $attachment_link, $attachment_url, $filename, $original_image_url, $original_filename, $mime_type, $stamptime, $file_size ) = $this->output_datas( $webp_id, $metadata );
265 275
266 276 $output_html = '<div style="border-bottom: 1px solid; padding-top: 5px; padding-bottom: 5px;">';
267 277 $output_html .= '<img width="40" height="40" src="' . $image_thumbnail . '" style="float: left; margin: 5px;">';
268 278 $output_html .= '<div style="overflow: hidden;">';
@@ -269,12 +279,12 @@
269 279 $output_html .= '<div>ID: ' . $webp_id . '</div>';
270 280 $output_html .= '<div>' . __( 'Title' ) . ': ' . get_the_title( $webp_id ) . '</div>';
271 281 $output_html .= '<div>' . __( 'Permalink:' ) . ' <a href="' . $attachment_link . '" target="_blank" rel="noopener noreferrer" style="text-decoration: none; word-break: break-all;">' . $attachment_link . '</a></div>';
272 282 $output_html .= '<div>URL: <a href="' . $attachment_url . '" target="_blank" rel="noopener noreferrer" style="text-decoration: none; word-break: break-all;">' . $attachment_url . '</a></div>';
273 - $output_html .= '<div>' . __( 'File name:' ) . ' ' . wp_basename( $attachment_url ) . '</div>';
274 - if ( ! empty( $metadata['original_image'] ) ) {
283 + $output_html .= '<div>' . __( 'File name:' ) . ' ' . $filename . '</div>';
284 + if ( ! empty( $original_image_url ) ) {
275 285 $output_html .= '<div>' . __( 'Original URL', 'plus-webp' ) . ': <a href="' . $original_image_url . '" target="_blank" rel="noopener noreferrer" style="text-decoration: none; word-break: break-all;">' . $original_image_url . '</a></div>';
276 - $output_html .= '<div>' . __( 'Original File name', 'plus-webp' ) . ': ' . wp_basename( $original_image_url ) . '</div>';
286 + $output_html .= '<div>' . __( 'Original File name', 'plus-webp' ) . ': ' . $original_filename . '</div>';
277 287 }
278 288 $output_html .= '<div>' . __( 'Date/Time' ) . ': ' . $stamptime . '</div>';
279 289 $output_html .= '<div>' . __( 'File type:' ) . ' ' . $mime_type . '</div>';
280 290 $output_html .= '<div>' . __( 'File size:' ) . ' ' . $file_size . '</div>';
@@ -308,15 +318,14 @@
308 318 $image_attr_thumbnail = wp_get_attachment_image_src( $attach_id, 'thumbnail', true );
309 319 $image_thumbnail = $image_attr_thumbnail[0];
310 320
311 321 $imagethumburls = array();
312 - $media_path = get_post_meta( $attach_id, '_wp_attached_file', true );
313 - $media_paths = explode( DIRECTORY_SEPARATOR, $media_path );
314 - $str_length = strlen( end( $media_paths ) );
315 - $media_path = substr( $media_path, 0, -$str_length );
316 - $media_url = $upload_url . '/' . $media_path;
317 - if ( ! empty( $metadata ) ) {
318 - $thumbnails = $metadata['sizes'];
322 + if ( ! empty( $metadata ) && array_key_exists( 'sizes', $metadata ) ) {
323 + $thumbnails = $metadata['sizes'];
324 + $path_file = get_post_meta( $attach_id, '_wp_attached_file', true );
325 + $filename = wp_basename( $path_file );
326 + $media_path = str_replace( $filename, '', $path_file );
327 + $media_url = $upload_url . '/' . $media_path;
319 328 foreach ( $thumbnails as $key => $key2 ) {
320 329 $imagethumburls[ $key ] = $media_url . $key2['file'];
321 330 }
322 331 }
@@ -327,33 +336,40 @@
327 336
328 337 /** ==================================================
329 338 * Output datas
330 339 *
331 - * @param int $attach_id attach_id.
332 - * @return array (string) $attachment_link, $attachment_url, $original_image_url, $mime_type(string), $stamptime, $file_size
340 + * @param int $attach_id attach_id.
341 + * @param array $metadata metadata.
342 + * @return array (string) $attachment_link, $attachment_url, $filename, $original_image_url, $original_filename, $mime_type(string), $stamptime, $file_size
333 343 * @since 2.00
334 344 */
335 - private function output_datas( $attach_id ) {
345 + private function output_datas( $attach_id, $metadata ) {
336 346
337 347 $attachment_link = get_attachment_link( $attach_id );
338 348 $attachment_url = wp_get_attachment_url( $attach_id );
339 - $original_image_url = wp_get_original_image_url( $attach_id );
340 - $filetype = wp_check_filetype( get_attached_file( $attach_id ) );
341 - $mime_type = $filetype['type'];
349 + $filename = wp_basename( $attachment_url );
350 + if ( ! empty( $metadata ) && array_key_exists( 'original_image', $metadata ) && ! empty( $metadata['original_image'] ) ) {
351 + $original_image_url = wp_get_original_image_url( $attach_id );
352 + $original_filename = wp_basename( $original_image_url );
353 + } else {
354 + $original_image_url = null;
355 + $original_filename = null;
356 + }
357 + $mime_type = get_post_mime_type( $attach_id );
342 358
343 359 $stamptime = get_the_time( 'Y-n-j ', $attach_id ) . get_the_time( 'G:i:s', $attach_id );
344 - if ( isset( $metadata['filesize'] ) ) {
360 + if ( ! empty( $metadata ) && array_key_exists( 'filesize', $metadata ) && ! empty( $metadata['filesize'] ) ) {
345 361 $file_size = $metadata['filesize'];
346 362 } else {
347 363 $file_size = @filesize( get_attached_file( $attach_id ) );
348 364 }
349 365 if ( ! $file_size ) {
350 - $file_size = '<font color="red">' . __( 'Could not retrieve.', 'plus-webp' ) . '</font>';
366 + $file_size = __( 'Could not retrieve.', 'plus-webp' );
351 367 } else {
352 368 $file_size = size_format( $file_size );
353 369 }
354 370
355 - return array( $attachment_link, $attachment_url, $original_image_url, $mime_type, $stamptime, $file_size );
371 + return array( $attachment_link, $attachment_url, $filename, $original_image_url, $original_filename, $mime_type, $stamptime, $file_size );
356 372
357 373 }
358 374
359 375 /** ==================================================
@@ -440,29 +456,27 @@
440 456 $pluswebp_mail_send['count'] = count( $post_ids );
441 457
442 458 $count = 0;
443 459 foreach ( $post_ids as $attach_id ) {
444 - $filename = get_attached_file( $attach_id );
445 460 $metadata = wp_get_attachment_metadata( $attach_id );
446 - /* OutputMetaData */
447 - list( $imagethumburls, $stamptime, $file_size ) = $this->output_metadata( $attach_id, $metadata, $this->upload_url );
461 +
462 + /* Thumbnail urls */
463 + list( $image_thumbnail, $imagethumburls ) = $this->thumbnail_urls( $attach_id, $metadata, $this->upload_url );
464 + /* Output datas*/
465 + list( $attachment_link, $attachment_url, $filename, $original_image_url, $original_filename, $mime_type, $stamptime, $file_size ) = $this->output_datas( $attach_id, $metadata );
466 +
448 467 $count++;
449 468 $message .= __( 'Count' ) . ': ' . $count . "\n";
450 469 $message .= 'ID: ' . $attach_id . "\n";
451 470 $message .= __( 'Title' ) . ': ' . get_the_title( $attach_id ) . "\n";
452 - $message .= __( 'Permalink:' ) . ' ' . get_attachment_link( $attach_id ) . "\n";
453 - $message .= 'URL: ' . wp_get_attachment_url( $attach_id ) . "\n";
454 - $message .= __( 'File name:' ) . ' ' . wp_basename( wp_get_attachment_url( $attach_id ) ) . "\n";
455 - if ( ! empty( $metadata['original_image'] ) ) {
456 - $message .= __( 'Original URL:', 'plus-webp' ) . ' ' . wp_get_original_image_url( $attach_id ) . "\n";
457 - $message .= __( 'Original File name:', 'plus-webp' ) . ' ' . wp_basename( wp_get_original_image_url( $attach_id ) ) . "\n";
471 + $message .= __( 'Permalink:' ) . ' ' . $attachment_link . "\n";
472 + $message .= 'URL: ' . $attachment_url . "\n";
473 + $message .= __( 'File name:' ) . ' ' . $filename . "\n";
474 + if ( ! empty( $original_image_url ) ) {
475 + $message .= __( 'Original URL:', 'plus-webp' ) . ' ' . $original_image_url . "\n";
476 + $message .= __( 'Original File name:', 'plus-webp' ) . ' ' . $original_filename . "\n";
458 477 }
459 478 $message .= __( 'Date/Time' ) . ': ' . $stamptime . "\n";
460 - if ( ! $file_size ) {
461 - $file_size = __( 'Could not retrieve.', 'plus-webp' );
462 - } else {
463 - $file_size = size_format( $file_size );
464 - }
465 479 $message .= __( 'File size:' ) . ' ' . $file_size . "\n";
466 480 if ( ! empty( $imagethumburls ) ) {
467 481 foreach ( $imagethumburls as $thumbsize => $imagethumburl ) {
468 482 $message .= $thumbsize . ': ' . $imagethumburl . "\n";
@@ -483,39 +497,8 @@
483 497
484 498 }
485 499
486 500 /** ==================================================
487 - * Output metadata
488 - *
489 - * @param int $attach_id attach_id.
490 - * @param array $metadata metadata.
491 - * @param string $upload_url upload_url.
492 - * @return array $imagethumburls(string), $stamptime(string), $file_size(string)
493 - * @since 1.09
494 - */
495 - private function output_metadata( $attach_id, $metadata, $upload_url ) {
496 -
497 - $imagethumburls = array();
498 - $wp_attached_file = get_post_meta( $attach_id, '_wp_attached_file', true );
499 - $imagethumburl_base = $upload_url . '/' . rtrim( $wp_attached_file, wp_basename( $wp_attached_file ) );
500 - if ( ! empty( $metadata ) ) {
501 - foreach ( $metadata as $key1 => $key2 ) {
502 - if ( 'sizes' === $key1 ) {
503 - foreach ( $metadata[ $key1 ] as $key2 => $key3 ) {
504 - $imagethumburls[ $key2 ] = $imagethumburl_base . $metadata['sizes'][ $key2 ]['file'];
505 - }
506 - }
507 - }
508 - }
509 -
510 - $stamptime = get_the_time( 'Y-n-j ', $attach_id ) . get_the_time( 'G:i:s', $attach_id );
511 - $file_size = @filesize( get_attached_file( $attach_id, false ) );
512 -
513 - return array( $imagethumburls, $stamptime, $file_size );
514 -
515 - }
516 -
517 - /** ==================================================
518 501 * Webp create
519 502 *
520 503 * @param string $filename input filename for pictures.
521 504 * @param string $mime_type mimetype.
@@ -533,8 +516,9 @@
533 516 }
534 517
535 518 $pluswebp_settings = get_option( 'pluswebp' );
536 519 @set_time_limit( 60 );
520 + @ini_set( 'memory_limit', '256M' );
537 521
538 522 $ret = false;
539 523 switch ( $mime_type ) {
540 524 case 'image/jpeg':
@@ -539,9 +523,10 @@
539 523 switch ( $mime_type ) {
540 524 case 'image/jpeg':
541 525 $src = imagecreatefromjpeg( $filename );
542 526 $img = imagecreatetruecolor( imagesx( $src ), imagesy( $src ) );
543 - imagefill( $img, 0, 0, imagecolorallocate( $img, 255, 255, 255 ) );
527 + $bgcolor = imagecolorallocate( $img, 255, 255, 255 );
528 + imagefill( $img, 0, 0, $bgcolor );
544 529 imagealphablending( $img, true );
545 530 break;
546 531 case 'image/png':
547 532 $src = imagecreatefrompng( $filename );
@@ -608,9 +593,12 @@
608 593
609 594 /* Replace */
610 595 $wpdb->query(
611 596 $wpdb->prepare(
612 - "UPDATE `$wpdb->posts` SET post_content = replace(post_content, %s, %s)",
597 + "
598 + UPDATE {$wpdb->prefix}posts
599 + SET post_content = replace( post_content, %s, %s )
600 + ",
613 601 $before_url,
614 602 $after_url
615 603 )
616 604 );