diff --git a/includes/Classifai/Features/DescriptiveTextGenerator.php b/includes/Classifai/Features/DescriptiveTextGenerator.php index dd88dd633..b21e04597 100644 --- a/includes/Classifai/Features/DescriptiveTextGenerator.php +++ b/includes/Classifai/Features/DescriptiveTextGenerator.php @@ -263,6 +263,8 @@ public function maybe_rescan_image( int $attachment_id ) { $result = $this->run( $attachment_id, 'descriptive_text' ); if ( $result && ! is_wp_error( $result ) ) { + // Ensure we don't re-run this when the attachment is updated. + remove_action( 'edit_attachment', [ $this, 'maybe_rescan_image' ] ); $this->save( $result, $attachment_id ); } } diff --git a/includes/Classifai/Features/ImageCropping.php b/includes/Classifai/Features/ImageCropping.php index 777e4d0cd..c50c3965e 100644 --- a/includes/Classifai/Features/ImageCropping.php +++ b/includes/Classifai/Features/ImageCropping.php @@ -295,10 +295,8 @@ public function attachment_data_meta_box_content() { * @param int $attachment_id Attachment ID. */ public function maybe_crop_image( int $attachment_id ) { - $metadata = wp_get_attachment_metadata( $attachment_id ); - if ( clean_input( 'rescan-smart-crop' ) ) { - $result = $this->run( $attachment_id, 'crop', $metadata ); + $result = $this->run( $attachment_id, 'crop' ); if ( ! empty( $result ) && ! is_wp_error( $result ) ) { $meta = $this->save( $result, $attachment_id ); diff --git a/includes/Classifai/Features/ImageTextExtraction.php b/includes/Classifai/Features/ImageTextExtraction.php index 90000ebc8..d8dafd3cd 100644 --- a/includes/Classifai/Features/ImageTextExtraction.php +++ b/includes/Classifai/Features/ImageTextExtraction.php @@ -301,6 +301,8 @@ public function maybe_rescan_image( int $attachment_id ) { $result = $this->run( $attachment_id, 'ocr' ); if ( $result && ! is_wp_error( $result ) ) { + // Ensure we don't re-run this when the attachment is updated. + remove_action( 'edit_attachment', [ $this, 'maybe_rescan_image' ] ); $this->save( $result, $attachment_id ); } } diff --git a/includes/Classifai/Features/PDFTextExtraction.php b/includes/Classifai/Features/PDFTextExtraction.php index 3baa6bccb..066b974f2 100644 --- a/includes/Classifai/Features/PDFTextExtraction.php +++ b/includes/Classifai/Features/PDFTextExtraction.php @@ -211,6 +211,9 @@ public function maybe_rescan_pdf( int $attachment_id ) { * @param int $attachment_id The attachment ID. */ public function save( string $result, int $attachment_id ) { + // Ensure we don't re-run this when the attachment is updated. + remove_action( 'edit_attachment', [ $this, 'maybe_rescan_pdf' ] ); + return wp_update_post( [ 'ID' => $attachment_id, diff --git a/includes/Classifai/Providers/Azure/ComputerVision.php b/includes/Classifai/Providers/Azure/ComputerVision.php index 8ae0c33ef..0c0775a16 100644 --- a/includes/Classifai/Providers/Azure/ComputerVision.php +++ b/includes/Classifai/Providers/Azure/ComputerVision.php @@ -723,7 +723,7 @@ public function rest_endpoint_callback( $attachment_id, string $route_to_call = $metadata = wp_get_attachment_metadata( $attachment_id ); - if ( ! $metadata ) { + if ( ! $metadata || ! is_array( $metadata ) ) { return new WP_Error( 'invalid', esc_html__( 'No valid metadata found.', 'classifai' ) ); }