diff --git a/includes/Classifai/Providers/Azure/ComputerVision.php b/includes/Classifai/Providers/Azure/ComputerVision.php index 96d6ce666..3631df70a 100644 --- a/includes/Classifai/Providers/Azure/ComputerVision.php +++ b/includes/Classifai/Providers/Azure/ComputerVision.php @@ -510,10 +510,13 @@ public function generate_alt_tags( string $image_url, int $attachment_id ) { $settings = $feature->get_settings( static::ID ); $threshold = $settings['descriptive_confidence_threshold']; - // Check the first caption to see if it passes the threshold. - if ( $caption['confidence'] * 100 > $threshold ) { - $rtn = $caption['text']; + // Check the caption to see if it passes the threshold. + if ( isset( $caption['confidence'] ) && $caption['confidence'] * 100 > $threshold ) { + $rtn = ucfirst( $caption['text'] ?? '' ); } else { + /* translators: 1: Confidence score, 2: Threshold setting */ + $rtn = new WP_Error( 'threshold', sprintf( esc_html__( 'Caption confidence score is %1$d%% which is lower than your threshold setting of %2$d%%', 'classifai' ), $caption['confidence'] * 100, $threshold ) ); + /** * Fires if there were no captions returned. *