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-backup.php +24 -16 1.6.31.7.7 View file →
@@ -43,15 +43,14 @@
43 43
44 44 try {
45 45 File_System::copy( $image_path, $backup_path, true );
46 46 } catch ( File_System_Operation_Error $e ) {
47 - Logger::log(
48 - Logger::LEVEL_ERROR,
47 + Logger::error(
49 48 "Error while creating a backup for image {$image_id} and size {$image_size}"
50 49 );
51 50
52 51 throw new Image_Backup_Creation_Error(
53 - "Error while creating a backup for image {$image_id} and size {$image_size}"
52 + esc_html( "Error while creating a backup for image $image_id and size $image_size" )
54 53 );
55 54 }
56 55
57 56 $meta = new Image_Meta( $image_id );
@@ -96,16 +95,9 @@
96 95 if ( ! key_exists( $image_size, $backups ) ) {
97 96 return false;
98 97 }
99 98
100 - try {
101 - File_System::delete( $backups[ $image_size ], false, 'f' );
102 - } catch ( File_System_Operation_Error $e ) {
103 - Logger::log(
104 - Logger::LEVEL_ERROR,
105 - "Error while removing a backup for image {$image_id} and size {$image_size}"
106 - );
107 - }
99 + self::delete_backup_file( $image_id, $image_size, $backups[ $image_size ] );
108 100
109 101 $meta->remove_image_backup_path( $image_size );
110 102 $meta->save();
111 103
@@ -112,13 +104,9 @@
112 104 return true;
113 105 }
114 106
115 107 foreach ( $backups as $image_size => $backup_path ) {
116 - try {
117 - File_System::delete( $backup_path, false, 'f' );
118 - } catch ( File_System_Operation_Error $e ) {
119 - Logger::log( Logger::LEVEL_ERROR, "Error while removing backups {$image_id}" );
120 - }
108 + self::delete_backup_file( $image_id, $image_size, $backup_path );
121 109
122 110 $meta->remove_image_backup_path( $image_size );
123 111 }
124 112
@@ -124,6 +112,26 @@
124 112
125 113 $meta->save();
126 114
127 115 return true;
116 + }
117 +
118 + private static function delete_backup_file( int $image_id, string $image_size, string $backup_path ): void {
119 + $resolved_path = Image_Backup_Path_Validator::resolve( $backup_path );
120 +
121 + if ( null === $resolved_path ) {
122 + Logger::warn(
123 + "Skipped removing invalid backup path for image {$image_id} and size {$image_size}"
124 + );
125 +
126 + return;
127 + }
128 +
129 + try {
130 + File_System::delete( $resolved_path, false, 'f' );
131 + } catch ( File_System_Operation_Error $fsoe ) {
132 + Logger::error(
133 + "Error while removing a backup for image {$image_id} and size {$image_size}"
134 + );
135 + }
128 136 }
129 137 }