| @@ -50,8 +50,9 @@ | ||
| 50 | 50 | add_filter( 'wpmcs_get_attached_file_noop', array( $this, 'image_editor_download_file' ), 10, 4 ); |
| 51 | 51 | add_filter( 'wpmcs_get_attached_file', array( $this, 'image_editor_download_file' ), 10, 4 ); |
| 52 | 52 | add_filter( 'wpmcs_get_attached_file', array( $this, 'customizer_crop_download_file' ), 10, 4 ); |
| 53 | 53 | add_filter( 'wpmcs_pre_update_item_additional_files_to_remove_from_server', [ $this, 'customizer_crop_remove_restored_files' ], 10, 5 ); |
| 54 | + add_filter( 'wpmcs_do_reupload_media', [ $this, 'force_reupload_on_image_editor_save' ], 10, 3 ); | |
| 54 | 55 | |
| 55 | 56 | /* |
| 56 | 57 | * WP_Customize_Control |
| 57 | 58 | * /wp-includes/class-wp-customize_control.php |
| @@ -201,11 +202,32 @@ | ||
| 201 | 202 | |
| 202 | 203 | return $url; |
| 203 | 204 | } |
| 204 | 205 | |
| 206 | + /** | |
| 207 | + * A flip or 180° rotation changes pixel content without changing any | |
| 208 | + * declared width/height, which shouldForceReupload() can't detect — | |
| 209 | + * force it explicitly for any image-editor commit (save or restore). | |
| 210 | + * @since 1.4.3 | |
| 211 | + */ | |
| 212 | + public function force_reupload_on_image_editor_save($do_reupload, $attachment_id, $source_type) { | |
| 213 | + if ($do_reupload) { | |
| 214 | + return $do_reupload; | |
| 215 | + } | |
| 205 | 216 | |
| 217 | + $action = Utils::filter_input('action', INPUT_GET) ?: Utils::filter_input('action', INPUT_POST); | |
| 218 | + $do = Utils::filter_input('do', INPUT_POST); | |
| 206 | 219 | |
| 220 | + if (in_array($do, ['save', 'restore'], true) && in_array($action, ['image-editor', 'imgedit-preview'], true)) { | |
| 221 | + return true; | |
| 222 | + } | |
| 207 | 223 | |
| 224 | + return $do_reupload; | |
| 225 | + } | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 208 | 230 | /** |
| 209 | 231 | * Called after REST API callback, and removes server files from the server for routes that need it. |
| 210 | 232 | * |
| 211 | 233 | * @param WP_HTTP_Response $response The response object. |
| @@ -376,9 +398,9 @@ | ||
| 376 | 398 | * |
| 377 | 399 | * @return int|null |
| 378 | 400 | */ |
| 379 | 401 | public function customizer_background_image($post_id, $url) { |
| 380 | - if (!is_null($post_id)) { | |
| 402 | + if (!empty($post_id)) { | |
| 381 | 403 | return $post_id; |
| 382 | 404 | } |
| 383 | 405 | |
| 384 | 406 | // There seems to be a bug in the WP Customizer whereby sometimes it puts the attachment ID on the URL. |
| @@ -391,9 +413,9 @@ | ||
| 391 | 413 | } |
| 392 | 414 | } else { |
| 393 | 415 | $path = Utils::get_attachment_source_path($url); |
| 394 | 416 | if (!Utils::is_empty($path)) { |
| 395 | - $item = Item::instance()->get_items_by_paths($path); | |
| 417 | + $item = Item::instance()->get_items_by_paths( $path, true, true ); | |
| 396 | 418 | if (!Utils::is_empty($item)) { |
| 397 | 419 | // If we found an offloaded Media Library item for that path, job's a good'n'. |
| 398 | 420 | $post_id = $item['source_id']; |
| 399 | 421 | } |
| @@ -468,15 +490,21 @@ | ||
| 468 | 490 | * the attachment's file should be. |
| 469 | 491 | * |
| 470 | 492 | * @return string|bool File if downloaded, false on failure |
| 471 | 493 | */ |
| 472 | - private function copy_provider_file_to_server($attachment_id, $file) { | |
| 494 | + public function copy_provider_file_to_server($attachment_id, $file) { | |
| 473 | 495 | // Download files |
| 474 | 496 | if (!Item::instance()->moveToServerBySourcePath($attachment_id, $file, 'media_library')) { |
| 475 | 497 | return false; |
| 476 | - } | |
| 498 | + } | |
| 477 | 499 | |
| 478 | 500 | $this->restored_files[] = $file; |
| 501 | + | |
| 502 | + // Shared with woocommerce.php — feeds the same pre_update_item pipeline as | |
| 503 | + // below when a save happens this request, with a shutdown fallback for the | |
| 504 | + // other three callers here (image editor, legacy copy-back, Regenerate | |
| 505 | + // Thumbnails pre-v3), which otherwise have no cleanup at all. | |
| 506 | + Item::instance()->track_restored_for_cleanup( [ $file ] ); | |
| 479 | 507 | |
| 480 | 508 | return $file; |
| 481 | 509 | } |
| 482 | 510 | |