PluginProbe
Image Optimizer – Compress Images and Convert to WebP or AVIF / 1.7.7
Image Optimizer – Compress Images and Convert to WebP or AVIF v1.7.7
1.7.7 1.7.6 1.7.5 1.7.4 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 All 33 releases
← All changes | classes/image/image-restore.php +19 -6 1.2.0 → 1.7.7 View file →
@@ -23,9 +23,9 @@
23 23 foreach ( $image_ids as $image_id ) {
24 24 try {
25 25 self::restore( $image_id, $keep_image_meta );
26 26 } catch ( Throwable $t ) {
27 - Logger::log( Logger::LEVEL_ERROR, 'Bulk images restoring error: ' . $t->getMessage() );
27 + Logger::error( 'Bulk images restoring error: ' . $t->getMessage() );
28 28
29 29 ( new Image_Meta( $image_id ) )
30 30 ->set_status( Image_Status::RESTORING_FAILED )
31 31 ->save();
@@ -41,9 +41,9 @@
41 41 public static function restore( int $image_id, bool $keep_image_meta = false ): void {
42 42 $image = new Image( $image_id );
43 43
44 44 if ( ! $image->can_be_restored() ) {
45 - throw new Image_Restoring_Exception( "Image $image_id cannot be restored" );
45 + throw new Image_Restoring_Exception( esc_html( "Image $image_id cannot be restored" ) );
46 46 }
47 47
48 48 $meta = new Image_Meta( $image_id );
49 49 $wp_meta = new WP_Image_Meta( $image_id );
@@ -52,16 +52,27 @@
52 52 $backup_path = $meta->get_image_backup_path( $image_size );
53 53 $current_path = $image->get_file_path( $image_size );
54 54
55 55 if ( $backup_path && $current_path ) {
56 - $original_path = self::get_path_from_backup_path( $backup_path );
56 + $resolved_backup_path = Image_Backup_Path_Validator::resolve( $backup_path );
57 57
58 - if ( $original_path === $backup_path ) {
58 + if ( null === $resolved_backup_path ) {
59 + Logger::warn(
60 + "Skipped restoring invalid backup path for image {$image_id} and size {$image_size}"
61 + );
62 +
63 + continue;
64 + }
65 +
66 + $original_path = self::get_path_from_backup_path( $resolved_backup_path );
67 +
68 + if ( $original_path === $resolved_backup_path ) {
69 +
59 70 File_System::delete( $current_path, false, 'f' );
60 71
61 72 self::update_posts( $current_path, $original_path );
62 73 } else {
63 - File_System::move( $backup_path, $original_path, $original_path === $current_path );
74 + File_System::move( $resolved_backup_path, $original_path, $original_path === $current_path );
64 75
65 76 if ( $original_path !== $current_path ) {
66 77 File_System::delete( $current_path, false, 'f' );
67 78
@@ -68,14 +79,16 @@
68 79 self::update_posts( $current_path, $original_path );
69 80 }
70 81 }
71 82
83 + $file_size = $meta->get_original_file_size( $image_size ) ?? File_System::size( $original_path );
84 +
72 85 $wp_meta
73 86 ->set_file_path( $image_size, $original_path )
74 87 ->set_mime_type( $image_size, $meta->get_original_mime_type( $image_size ) )
75 88 ->set_width( $image_size, $meta->get_original_width( $image_size ) )
76 89 ->set_height( $image_size, $meta->get_original_height( $image_size ) )
77 - ->set_file_size( $image_size, $meta->get_original_file_size( $image_size ) );
90 + ->set_file_size( $image_size, $file_size );
78 91
79 92 if ( Image::SIZE_FULL === $image_size ) {
80 93 self::update_image_post(
81 94 $image,