post_mime_type, Image::get_supported_mime_types(), true ) ) { throw new Image_Validation_Error( self::prepare_supported_formats_list_error() ); } if ( ! file_exists( get_attached_file( $image_id ) ) ) { throw new Image_Validation_Error( esc_html__( 'File is missing. Verify the upload', 'image-optimizer' ) ); } $wp_meta = new WP_Image_Meta( $image_id ); $image_size = $wp_meta->get_file_size( Image::SIZE_FULL ); if ( $image_size > self::MAX_FILE_SIZE ) { throw new Image_Validation_Error( sprintf( __( 'File is too large. Max size is %s', 'image-optimizer' ), File_Utils::format_file_size( self::MAX_FILE_SIZE, 0 ), ) ); } return true; } /** * Prepares the error message for the unsupported file formats. * * @return string The error message. */ private static function prepare_supported_formats_list_error(): string { $formats = Image::get_supported_formats(); $last_item = strtoupper( array_pop( $formats ) ); $formats_list = join( ', ', array_map( 'strtoupper', $formats ) ); return sprintf( __( 'Wrong file format. Only %1$s, or %2$s are accepted', 'image-optimizer' ), $formats_list, $last_item ); } }