Solution for : Error while deleting an image
-
Hi,
If the plugin is activated, when deleting an image, an error appears: Error in deleting the attachment.
The plugin was registering adelete_attachmenthook that called a methodwebpc_remove_original()in the main class, but this method didn’t exist. This caused a 500 error when trying to delete an image.Solution
Add the missing
method webpc_remove_original($attachment_id)to the WEBPCbySheepFish class. This method simply calls the static method of the same name in the WebpC_Remover class.Add method in
webp-conversion.php(afterwebpc_remove_originals_selected) – Line 674 (just beforefunction webpc_convert_single) :<?php
/**
* Hook callback for when an attachment is deleted.
* Removes the backup/original file associated with the attachment.
*
* @param int $attachment_id The attachment ID being deleted.
* @return void
*/
public function webpc_remove_original($attachment_id): void
{
WebpC_Remover::webpc_remove_original($attachment_id);
}Root Cause
Line 91 in
webp-conversion.phpregisters the hook:add_action('delete_attachment', [$this, 'webpc_remove_original']);But the method
webpc_remove_original()was not defined in the class, causing a fatal error when WordPress tries to delete an attachment.Regards
You must be logged in to reply to this topic.