PluginProbe
Image Optimization – Compress Images and Convert to WebP or AVIF / 1.6.8
Image Optimization – Compress Images and Convert to WebP or AVIF v1.6.8
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 1.6.6 All 32 releases
image-optimization / modules / optimization / classes / optimization-error-message.php

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

40 lines 1.3 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( "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 ];
32
33 if ( isset( $messages[ $error_type ] ) ) {
34 return $messages[ $error_type ];
35 }
36
37 return $messages[ Image_Optimization_Error_Type::GENERIC ];
38 }
39 }
40