cloudProvider = $cloudProvider; $this->cloudAttachmentUploader = new CloudAttachmentUploader($cloudProvider); } public function register(): void { add_filter('wp_update_attachment_metadata', [$this, 'run'], 99, 2); } public function run($metadata, $attachment_id) { // PHPCS ignore reason: Update the attachment's metadata by either restoring or editing it. // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 10); foreach ($trace as $element) { switch ($element['function']) { case 'wp_save_image': // Right after an image has been edited. // TODO : Offload the edited image to the cloud. error_log("Image has been edited."); break; case 'wp_restore_image': // When an image has been restored. // TODO : Offload the restored image to the cloud if needed and Delete edited image from the Cloud. error_log("Image has been restored to original state."); break; } } return $metadata; } }