PluginProbe
Image Optimizer – Compress Images and Convert to WebP or AVIF / 1.7.7
Image Optimizer – Compress Images and Convert to WebP or AVIF v1.7.7
1.7.7 1.7.6 1.7.5 1.7.4 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 All 33 releases
image-optimization / modules / optimization / classes / optimization-error-message.php

optimization-error-message.php in Image Optimizer – Compress Images and Convert to WebP or AVIF 1.7.7, at modules/optimization/classes/optimization-error-message.php

41 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ImageOptimization\Modules\Optimization\Classes;
4
5 use ImageOptimization\Classes\Image\Image_Optimization_Error_Type;
6
7 use TypeError;
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit; // Exit if accessed directly.
11 }
12
13 class Optimization_Error_Message {
14 public static function get_reoptimization_error_message( string $error_type ) {
15 if ( Image_Optimization_Error_Type::GENERIC === $error_type ) {
16 return esc_html__( 'Image reoptimizing failed', 'image-optimization' );
17 }
18
19 return self::get_optimization_error_message( $error_type );
20 }
21
22 public static function get_optimization_error_message( string $error_type ) {
23 if ( ! in_array( $error_type, Image_Optimization_Error_Type::get_values(), true ) ) {
24 throw new TypeError( esc_html( "Error type $error_type is not a part of Image_Optimization_Error_Type values" ) );
25 }
26
27 $messages = [
28 Image_Optimization_Error_Type::FILE_ALREADY_EXISTS => esc_html__( 'File with this name already exists', 'image-optimization' ),
29 Image_Optimization_Error_Type::QUOTA_EXCEEDED => esc_html__( 'Plan quota reached', 'image-optimization' ),
30 Image_Optimization_Error_Type::GENERIC => esc_html__( 'Optimization error', 'image-optimization' ),
31 Image_Optimization_Error_Type::CONNECTION_ERROR => esc_html__( 'Connection error', 'image-optimization' ),
32 ];
33
34 if ( isset( $messages[ $error_type ] ) ) {
35 return $messages[ $error_type ];
36 }
37
38 return $messages[ Image_Optimization_Error_Type::GENERIC ];
39 }
40 }
41