Skip to content

Commit

Permalink
Added logic to display the output
Browse files Browse the repository at this point in the history
  • Loading branch information
CrochetFeve0251 committed Oct 24, 2023
1 parent cfe6f77 commit 707a2b7
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions classes/Optimization/Data/AbstractData.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ abstract class AbstractData implements DataInterface {
*/
protected $default_optimization_data = [
'status' => '',
'message' => '',
'level' => false,
'sizes' => [],
'stats' => [
Expand Down
4 changes: 4 additions & 0 deletions classes/Optimization/Data/CustomFolders.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ public function update_size_optimization_data( $size, array $data ) {
$old_data['hash'] = md5_file( $file_path );
}

if ( key_exists( 'message', $data ) ) {
$old_data['message'] = $data['message'];
}

if ( ! $data['success'] ) {
/**
* Error.
Expand Down
5 changes: 5 additions & 0 deletions classes/Optimization/Data/WP.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,13 @@ public function update_size_optimization_data( $size, array $data ) {
'original_size' => 0,
'optimized_size' => 0,
'percent' => 0,
'message' => '',
], $old_data['stats'] );

if ( key_exists( 'message', $data ) ) {
$old_data['message'] = $data['message'];
}

if ( ! $data['success'] ) {
/**
* Error.
Expand Down
3 changes: 3 additions & 0 deletions classes/Optimization/Process/AbstractProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -1757,6 +1757,9 @@ public function update_size_optimization_data( $response, $size, $level ) {

// Size data.
$data['success'] = true;
if(property_exists($response, 'message')) {
$data['message'] = imagify_translate_api_message($response->message);
}
$data['original_size'] = $response->original_size;
$data['optimized_size'] = $response->new_size;
}
Expand Down
4 changes: 4 additions & 0 deletions inc/functions/admin-ui.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ function get_imagify_attachment_optimization_text( $process ) {
$output .= $output_before . '<span class="data">' . __( 'New Filesize:', 'imagify' ) . '</span> <strong class="big">' . $data->get_optimized_size() . '</strong>' . $output_after;
}

if ( key_exists('message', $data) ) {
$output .= $output_before . '<span class="data">' . $data['message'] . '</span>' . $output_after;
}

$chart = '';

if ( ! $is_media_page ) {
Expand Down
3 changes: 2 additions & 1 deletion inc/functions/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ function get_imagify_max_image_size() {
*/
function imagify_translate_api_message( $message ) {
if ( ! $message ) {
return imagify_translate_api_message( 'Unknown error occurred' );
$message = 'Unknown error occurred';
}

if ( is_wp_error( $message ) ) {
Expand Down Expand Up @@ -199,6 +199,7 @@ function imagify_translate_api_message( $message ) {
'</a>'
),
'Your image is too big to be uploaded on our server' => __( 'Your file is too big to be uploaded on our server.', 'imagify' ),
'Webp is less performant than original' => __( 'Webp is less performant than original', 'imagify' ),
'Our server returned an invalid response' => __( 'Our server returned an invalid response.', 'imagify' ),
'cURL isn\'t installed on the server' => __( 'cURL is not available on the server.', 'imagify' ),
// API messages.
Expand Down

0 comments on commit 707a2b7

Please sign in to comment.