| @@ -38,8 +38,12 @@ | ||
| 38 | 38 | |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | public function init() { |
| 42 | + if(!Utils::is_service_enabled()) { | |
| 43 | + return; | |
| 44 | + } | |
| 45 | + | |
| 42 | 46 | /* |
| 43 | 47 | * Image Editor Handler |
| 44 | 48 | * /wp-admin/includes/image-edit.php |
| 45 | 49 | */ |
| @@ -46,8 +50,9 @@ | ||
| 46 | 50 | add_filter( 'wpmcs_get_attached_file_noop', array( $this, 'image_editor_download_file' ), 10, 4 ); |
| 47 | 51 | add_filter( 'wpmcs_get_attached_file', array( $this, 'image_editor_download_file' ), 10, 4 ); |
| 48 | 52 | add_filter( 'wpmcs_get_attached_file', array( $this, 'customizer_crop_download_file' ), 10, 4 ); |
| 49 | 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 ); | |
| 50 | 55 | |
| 51 | 56 | /* |
| 52 | 57 | * WP_Customize_Control |
| 53 | 58 | * /wp-includes/class-wp-customize_control.php |
| @@ -197,11 +202,32 @@ | ||
| 197 | 202 | |
| 198 | 203 | return $url; |
| 199 | 204 | } |
| 200 | 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 | + } | |
| 201 | 216 | |
| 217 | + $action = Utils::filter_input('action', INPUT_GET) ?: Utils::filter_input('action', INPUT_POST); | |
| 218 | + $do = Utils::filter_input('do', INPUT_POST); | |
| 202 | 219 | |
| 220 | + if (in_array($do, ['save', 'restore'], true) && in_array($action, ['image-editor', 'imgedit-preview'], true)) { | |
| 221 | + return true; | |
| 222 | + } | |
| 203 | 223 | |
| 224 | + return $do_reupload; | |
| 225 | + } | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 204 | 230 | /** |
| 205 | 231 | * Called after REST API callback, and removes server files from the server for routes that need it. |
| 206 | 232 | * |
| 207 | 233 | * @param WP_HTTP_Response $response The response object. |
| @@ -372,9 +398,9 @@ | ||
| 372 | 398 | * |
| 373 | 399 | * @return int|null |
| 374 | 400 | */ |
| 375 | 401 | public function customizer_background_image($post_id, $url) { |
| 376 | - if (!is_null($post_id)) { | |
| 402 | + if (!empty($post_id)) { | |
| 377 | 403 | return $post_id; |
| 378 | 404 | } |
| 379 | 405 | |
| 380 | 406 | // There seems to be a bug in the WP Customizer whereby sometimes it puts the attachment ID on the URL. |
| @@ -387,9 +413,9 @@ | ||
| 387 | 413 | } |
| 388 | 414 | } else { |
| 389 | 415 | $path = Utils::get_attachment_source_path($url); |
| 390 | 416 | if (!Utils::is_empty($path)) { |
| 391 | - $item = Item::instance()->get_items_by_paths($path); | |
| 417 | + $item = Item::instance()->get_items_by_paths( $path, true, true ); | |
| 392 | 418 | if (!Utils::is_empty($item)) { |
| 393 | 419 | // If we found an offloaded Media Library item for that path, job's a good'n'. |
| 394 | 420 | $post_id = $item['source_id']; |
| 395 | 421 | } |
| @@ -464,15 +490,21 @@ | ||
| 464 | 490 | * the attachment's file should be. |
| 465 | 491 | * |
| 466 | 492 | * @return string|bool File if downloaded, false on failure |
| 467 | 493 | */ |
| 468 | - private function copy_provider_file_to_server($attachment_id, $file) { | |
| 494 | + public function copy_provider_file_to_server($attachment_id, $file) { | |
| 469 | 495 | // Download files |
| 470 | 496 | if (!Item::instance()->moveToServerBySourcePath($attachment_id, $file, 'media_library')) { |
| 471 | 497 | return false; |
| 472 | - } | |
| 498 | + } | |
| 473 | 499 | |
| 474 | 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 ] ); | |
| 475 | 507 | |
| 476 | 508 | return $file; |
| 477 | 509 | } |
| 478 | 510 | |