| @@ -376,9 +376,9 @@ | ||
| 376 | 376 | * |
| 377 | 377 | * @return int|null |
| 378 | 378 | */ |
| 379 | 379 | public function customizer_background_image($post_id, $url) { |
| 380 | - if (!is_null($post_id)) { | |
| 380 | + if (!empty($post_id)) { | |
| 381 | 381 | return $post_id; |
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | // There seems to be a bug in the WP Customizer whereby sometimes it puts the attachment ID on the URL. |
| @@ -391,9 +391,9 @@ | ||
| 391 | 391 | } |
| 392 | 392 | } else { |
| 393 | 393 | $path = Utils::get_attachment_source_path($url); |
| 394 | 394 | if (!Utils::is_empty($path)) { |
| 395 | - $item = Item::instance()->get_items_by_paths($path); | |
| 395 | + $item = Item::instance()->get_items_by_paths( $path, true, true ); | |
| 396 | 396 | if (!Utils::is_empty($item)) { |
| 397 | 397 | // If we found an offloaded Media Library item for that path, job's a good'n'. |
| 398 | 398 | $post_id = $item['source_id']; |
| 399 | 399 | } |
| @@ -468,15 +468,21 @@ | ||
| 468 | 468 | * the attachment's file should be. |
| 469 | 469 | * |
| 470 | 470 | * @return string|bool File if downloaded, false on failure |
| 471 | 471 | */ |
| 472 | - private function copy_provider_file_to_server($attachment_id, $file) { | |
| 472 | + public function copy_provider_file_to_server($attachment_id, $file) { | |
| 473 | 473 | // Download files |
| 474 | 474 | if (!Item::instance()->moveToServerBySourcePath($attachment_id, $file, 'media_library')) { |
| 475 | 475 | return false; |
| 476 | - } | |
| 476 | + } | |
| 477 | 477 | |
| 478 | 478 | $this->restored_files[] = $file; |
| 479 | + | |
| 480 | + // Shared with woocommerce.php — feeds the same pre_update_item pipeline as | |
| 481 | + // below when a save happens this request, with a shutdown fallback for the | |
| 482 | + // other three callers here (image editor, legacy copy-back, Regenerate | |
| 483 | + // Thumbnails pre-v3), which otherwise have no cleanup at all. | |
| 484 | + Item::instance()->track_restored_for_cleanup( [ $file ] ); | |
| 479 | 485 | |
| 480 | 486 | return $file; |
| 481 | 487 | } |
| 482 | 488 | |