diff --git a/src/admin/class-meta-box.php b/src/admin/class-meta-box.php index ef40c66..67a3056 100644 --- a/src/admin/class-meta-box.php +++ b/src/admin/class-meta-box.php @@ -123,6 +123,12 @@ function cimo_get_media_type_label( $mimetype ) { $optimization_savings = number_format( 100 * ( $original_filesize - $converted_filesize ) / $original_filesize, 2 ); } + // If optimization savings is not a valid number or is negative, do not display it + if ( ! is_numeric( $optimization_savings ) || floatval( $optimization_savings ) < 0 ) { + echo '
' . esc_html__( 'Cimo did not optimize this attachment.', 'cimo-image-optimizer' ) . '
'; + return; + } + $kb_saved = cimo_format_filesize( $original_filesize - $converted_filesize, 1, true ); $optimization_savings_class = ( $optimization_savings > 0 ) ? 'cimo-optimization-savings-up' : 'cimo-optimization-savings-down'; @@ -132,6 +138,7 @@ function cimo_get_media_type_label( $mimetype ) { $converted_format_raw = isset( $cimo['convertedFormat'] ) ? $cimo['convertedFormat'] : ( isset( $post->post_mime_type ) ? $post->post_mime_type : '' ); $converted_format = $converted_format_raw ? cimo_convert_mimetype_to_format( $converted_format_raw ) : ''; $media_type_label = cimo_get_media_type_label( $converted_format_raw ); + $is_image_media = is_string( $converted_format_raw ) && strpos( strtolower( $converted_format_raw ), 'image/' ) === 0; $converttime = isset( $cimo['conversionTime'] ) ? floatval( $cimo['conversionTime'] ) : null; if ( $converttime !== null ) { if ( $converttime < 1000 ) { @@ -207,7 +214,9 @@ function cimo_get_media_type_label( $mimetype ) { echo '