Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2.2.1 #867

Merged
merged 14 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/.git export-ignore
/.github export-ignore
/.wordpress-org export-ignore
/_dev export-ignore
/bin export-ignore
/Tests export-ignore

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fail-fast: false
matrix:
operating-system: [ubuntu-latest]
php-versions: ['7.3', '7.4']
php-versions: ['7.4']
wp-versions: ['latest']

name: WP ${{ matrix.wp-versions }} with PHP ${{ matrix.php-versions }} on ${{ matrix.operating-system }}.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_plugin_legacy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fail-fast: false
matrix:
operating-system: [ubuntu-latest]
php-versions: ['7.1', '7.2']
php-versions: ['7.3']
wp-versions: ['5.3']

name: WP ${{ matrix.wp-versions }} with PHP ${{ matrix.php-versions }} on ${{ matrix.operating-system }}.
Expand Down
13 changes: 8 additions & 5 deletions assets/css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -1445,11 +1445,6 @@ ul.imagify-datas-details.imagify-datas-details {
}

/* Attachments specifics */
.wp_attachment_image #imagify-visual-comparison .close-btn,
.imagify-visual-comparison .close-btn {
top: 0;
}

.wp_attachment_image #imagify-visual-comparison .imagify-modal-content,
.imagify-visual-comparison .imagify-modal-content {
padding-top: 40px;
Expand Down Expand Up @@ -1585,3 +1580,11 @@ ul.imagify-datas-details.imagify-datas-details {
.imagify-upsell .imagify-meteo-icon {
filter: invert(100%) sepia(100%) saturate(0%) hue-rotate(104deg) brightness(103%) contrast(103%);
}

.imagify-original-fize-size {
display: block !important;
}

.imagify-original-fize-size .value {
padding-left: 15px !important;
}
2 changes: 1 addition & 1 deletion assets/css/admin.min.css

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions assets/js/jquery.twentytwenty.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
modalHtml += '<img class="imagify-img-after" alt="" width="' + settings.width + '" height="' + settings.height + '">';
modalHtml += '</div>';
modalHtml += '<div class="imagify-comparison-levels">';
modalHtml += '<div class="imagify-c-level imagify-level-original go-left">';
modalHtml += '<div class="imagify-c-level imagify-level-original go-left imagify-original-fize-size">';
modalHtml += '<p class="imagify-c-level-row">';
modalHtml += '<span class="label">' + imagifyTTT.labels.filesize + '</span>';
modalHtml += '<span class="value level">' + settings.originalSize + '</span>';
Expand Down Expand Up @@ -515,7 +515,7 @@
// If shown image > 360, use twentytwenty.
if ( imagifyTTT.imageWidth > imagifyTTT.widthLimit && oriSource.src ) {

filesize = $( '.misc-pub-filesize strong' ).text();
filesize = $( '#imagify-full-optimized-size' ).val();
saving = $( '.imagify-data-item .imagify-chart-value' ).text();

// Create button to trigger.
Expand Down Expand Up @@ -574,7 +574,7 @@
originalUrl: $this.data( 'backup-src' ),
optimizedUrl: $this.data( 'full-src' ),
originalSize: $datas.find( '.original' ).text(),
optimizedSize: $datas.find( '.imagify-data-item .big' ).text(),
optimizedSize: $datas.find( '#imagify_data_sum .big' ).text(),
saving: $datas.find( '.imagify-chart-value' ).text(),
modalAppendTo: $this.closest( '.column-primary' ),
trigger: $this,
Expand Down Expand Up @@ -630,7 +630,7 @@
originalUrl: originalSrc,
optimizedUrl: $( '#imagify-full-src' ).val(),
originalSize: $( '#imagify-original-size' ).val(),
optimizedSize: $datas.find( '.imagify-data-item .big' ).text(),
optimizedSize: $datas.find( '#imagify_data_sum .big' ).text(),
saving: $datas.find( '.imagify-chart-value' ).text(),
modalAppendTo: $( '.media-frame-content .thumbnail-image' ),
trigger: $( '#imagify-media-frame-comparison-btn' ),
Expand Down
2 changes: 1 addition & 1 deletion assets/js/jquery.twentytwenty.min.js

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions classes/Avif/Display.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ public function maybe_add_rewrite_rules( $values ) {
}

$enabled = isset( $values['display_nextgen'] ) ? true : false;
$was_enabled = (bool) get_imagify_option( 'display_nextgen' );

$result = false;

if ( $enabled ) {
// Add the AVIF file type.
if ( $enabled && ! $was_enabled ) {
// Add the WebP file type.
$result = $this->get_server_conf()->add();
} elseif ( ! $enabled ) {
// Remove the AVIF file type.
} elseif ( ! $enabled && $was_enabled ) {
// Remove the WebP file type.
$result = $this->get_server_conf()->remove();
}

Expand Down
29 changes: 3 additions & 26 deletions classes/Bulk/Bulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,31 +173,17 @@ public function run_optimize( string $context, int $optimization_level ) {
'message' => 'over-quota',
];
}
$formats = imagify_nextgen_images_formats();
$media_ids = [
'ids' => [],
'errors' => [
'no_file_path' => [],
'no_backup' => [],
],
];
foreach ( $formats as $format ) {
$result = $this->get_bulk_instance( $context )->get_optimized_media_ids_without_format( $format );
$media_ids['ids'] = array_merge( $media_ids['ids'], $result['ids'] );
}
$get_unoptimized_media_ids = $this->get_bulk_instance( $context )->get_unoptimized_media_ids( $optimization_level );

$media_ids['ids'] = array_merge( $media_ids['ids'], $get_unoptimized_media_ids );
$media_ids = $this->get_bulk_instance( $context )->get_unoptimized_media_ids( $optimization_level );

if ( empty( $media_ids['ids'] ) ) {
if ( empty( $media_ids ) ) {
return [
'success' => false,
'message' => 'no-images',
];
}
$media_ids['ids'] = array_unique( $media_ids['ids'] );

foreach ( $media_ids['ids'] as $media_id ) {
foreach ( $media_ids as $media_id ) {
try {
as_enqueue_async_action(
'imagify_optimize_media',
Expand Down Expand Up @@ -597,10 +583,6 @@ public function bulk_get_stats_callback() {
* @param array $old_value The old option value.
* @param array $value The new option value.
*
* Please note that the convert_to_avif new value is a checkbox,
* so it equals 1 when it's set otherwise it's not set.
* That's why we need to use empty function when checking its value.
*
* @return void
*/
public function maybe_generate_missing_nextgen( $old_value, $value ) {
Expand All @@ -609,11 +591,6 @@ public function maybe_generate_missing_nextgen( $old_value, $value ) {
return;
}

if ( empty( $value['convert_to_avif'] ) ) {
// new value is disabled, do nothing.
return;
}

$contexts = $this->get_contexts();
$formats = imagify_nextgen_images_formats();

Expand Down
62 changes: 39 additions & 23 deletions classes/Optimization/Data/AbstractData.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,36 +281,44 @@ public function get_original_size( $human_format = true, $decimals = 2 ) {

/**
* Get the file size of the full size file.
* If the WebP size is available, it is used.
* If the Nextgen size is available, it is used.
*
* @since 1.9
* @access public
* @author Grégory Viguier
*
* @param bool $human_format True to display the image human format size (1Mb).
* @param int $decimals Precision of number of decimal places.
* @param bool $use_webp Use the WebP size if available.
* @param bool $use_nextgen Use the Nextgen size if available.
* @return string|int
*/
public function get_optimized_size( $human_format = true, $decimals = 2, $use_webp = true ) {
public function get_optimized_size( $human_format = true, $decimals = 2, $use_nextgen = true ) {
if ( ! $this->is_valid() ) {
return $human_format ? imagify_size_format( 0, $decimals ) : 0;
}

$data = $this->get_optimization_data();
$media = $this->get_media();

if ( $use_webp ) {
$process_class_name = imagify_get_optimization_process_class_name( $media->get_context() );
$webp_size_name = 'full' . constant( $process_class_name . '::WEBP_SUFFIX' );
}

if ( $use_webp && ! empty( $data['sizes'][ $webp_size_name ]['optimized_size'] ) ) {
$size = (int) $data['sizes'][ $webp_size_name ]['optimized_size'];
$data = $this->get_optimization_data();
$media = $this->get_media();
$format = 'webp';

$process_class_name = imagify_get_optimization_process_class_name( $media->get_context() );
$nextgen_avif_size_name = 'full' . constant( $process_class_name . '::AVIF_SUFFIX' );
$nextgen_webp_size_name = 'full' . constant( $process_class_name . '::WEBP_SUFFIX' );

$size = 0;

if ( $use_nextgen ) {
/**Checking for success status before size, some cases the response is false
* because the image is already compressed, or we have a connection timed out
* */
$size = ! empty( $data['sizes'][ $nextgen_webp_size_name ] ) && $data['sizes'][ $nextgen_webp_size_name ]['success'] ?
(int) $data['sizes'][ $nextgen_webp_size_name ]['optimized_size'] : 0;
if ( ! empty( $data['sizes'][ $nextgen_avif_size_name ]['optimized_size'] ) &&
$data['sizes'][ $nextgen_avif_size_name ] ) {
$size = (int) $data['sizes'][ $nextgen_avif_size_name ]['optimized_size'];
}
} elseif ( ! empty( $data['sizes']['full']['optimized_size'] ) ) {
$size = (int) $data['sizes']['full']['optimized_size'];
} else {
$size = 0;
}

if ( $size ) {
Expand All @@ -320,18 +328,21 @@ public function get_optimized_size( $human_format = true, $decimals = 2, $use_we
// If nothing in the database, try to get the info from the file.
$filepath = false;

if ( $use_webp && ! empty( $data['sizes'][ $webp_size_name ]['success'] ) ) {
// Try with the WebP file first.
if ( $use_nextgen ) {
if ( ! empty( $data['sizes'][ $nextgen_avif_size_name ]['success'] ) ) {
$format = 'avif';
}
// Try with the Nextgen file first.
$filepath = $media->get_raw_fullsize_path();
$filepath = $filepath ? imagify_path_to_webp( $filepath ) : false;
$filepath = $filepath ? imagify_path_to_nextgen( $filepath, $format ) : false;

if ( ! $filepath || ! $this->filesystem->exists( $filepath ) ) {
$filepath = false;
}
}

if ( ! $filepath ) {
// No WebP? The full size then.
// No Nextgen? The full size then.
$filepath = $media->get_fullsize_path();
}

Expand Down Expand Up @@ -418,15 +429,20 @@ public function get_saving_percent() {
}

$process_class_name = imagify_get_optimization_process_class_name( $this->get_media()->get_context() );
$webp_size_name = 'full' . constant( $process_class_name . '::WEBP_SUFFIX' );
$nextgen_webp_size_name = 'full' . constant( $process_class_name . '::WEBP_SUFFIX' );
$nextgen_avif_size_name = 'full' . constant( $process_class_name . '::AVIF_SUFFIX' );

$percent = $this->get_size_data( $webp_size_name, 'percent' );
$percent = $this->get_size_data( $nextgen_avif_size_name, 'percent' );

// Check for webp version if avif is not found.
if ( ! $percent ) {
$percent = $this->get_size_data( 'full', 'percent' );
$percent = $this->get_size_data( $nextgen_webp_size_name, 'percent' );
}

$percent = $percent ? $percent : 0;
if ( ! $percent ) {
$percent = $this->get_size_data( 'full', 'percent' );
}
$percent = $percent ?: 0;

return round( (float) $percent, 2 );
}
Expand Down
6 changes: 3 additions & 3 deletions classes/Optimization/Data/DataInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,18 +208,18 @@ public function get_original_size( $human_format = true, $decimals = 2 );

/**
* Get the file size of the full size file.
* If the WebP size is available, it is used.
* If the Nextgen size is available, it is used.
*
* @since 1.9
* @access public
* @author Grégory Viguier
*
* @param bool $human_format True to display the image human format size (1Mb).
* @param int $decimals Precision of number of decimal places.
* @param bool $use_webp Use the WebP size if available.
* @param bool $use_nextgen Use the Nextgen size if available.
* @return string|int
*/
public function get_optimized_size( $human_format = true, $decimals = 2, $use_webp = true );
public function get_optimized_size( $human_format = true, $decimals = 2, $use_nextgen = true );


/** ----------------------------------------------------------------------------------------- */
Expand Down
6 changes: 3 additions & 3 deletions classes/Optimization/Data/Noop.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,18 +208,18 @@ public function get_original_size( $human_format = true, $decimals = 2 ) {

/**
* Get the file size of the full size file.
* If the WebP size is available, it is used.
* If the Nextgen size is available, it is used.
*
* @since 1.9
* @access public
* @author Grégory Viguier
*
* @param bool $human_format True to display the image human format size (1Mb).
* @param int $decimals Precision of number of decimal places.
* @param bool $use_webp Use the WebP size if available.
* @param bool $use_nextgen Use the Nextgen size if available.
* @return string|int
*/
public function get_optimized_size( $human_format = true, $decimals = 2, $use_webp = true ) {
public function get_optimized_size( $human_format = true, $decimals = 2, $use_nextgen = true ) {
return $human_format ? imagify_size_format( 0, $decimals ) : 0;
}

Expand Down
4 changes: 2 additions & 2 deletions classes/Optimization/Process/AbstractProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ public function restore() {
$media->update_dimensions();

// Delete the WebP version.
$this->delete_nextgen_file( $original_path );
$this->delete_nextgen_file( $original_path, true );

// Restore the thumbnails.
$response = $this->restore_thumbnails();
Expand Down Expand Up @@ -989,7 +989,7 @@ protected function restore_thumbnails() {
* In that case we must also delete the next-gen file associated to the full size.
*/
$keep_full_next_gen = $media->get_raw_original_path() === $media->get_raw_fullsize_path();
$this->delete_nextgen_files( $keep_full_next_gen );
$this->delete_nextgen_files( $keep_full_next_gen, true );

// Generate new thumbnails.
return $media->generate_thumbnails();
Expand Down
6 changes: 4 additions & 2 deletions classes/Webp/Display.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@ public function maybe_add_rewrite_rules( $values ) {
}

$enabled = isset( $values['display_nextgen'] ) ? true : false;
$was_enabled = (bool) get_imagify_option( 'display_nextgen' );

$result = false;

if ( $enabled ) {
if ( $enabled && ! $was_enabled ) {
// Add the WebP file type.
$result = $this->get_server_conf()->add();
} elseif ( ! $enabled ) {
} elseif ( ! $enabled && $was_enabled ) {
// Remove the WebP file type.
$result = $this->get_server_conf()->remove();
}
Expand Down
6 changes: 3 additions & 3 deletions imagify.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* Plugin Name: Imagify
* Plugin URI: https://wordpress.org/plugins/imagify/
* Description: Dramatically reduce image file sizes without losing quality, make your website load faster, boost your SEO and save money on your bandwidth using Imagify, the new most advanced image optimization tool.
* Version: 2.2.0.1
* Version: 2.2.1
* Requires at least: 5.3
* Requires PHP: 7.0
* Requires PHP: 7.3
* Author: Imagify – Optimize Images & Convert WebP & Avif
* Author URI: https://imagify.io
* Licence: GPLv2
Expand All @@ -19,7 +19,7 @@
defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' );

// Imagify defines.
define( 'IMAGIFY_VERSION', '2.2.0.1' );
define( 'IMAGIFY_VERSION', '2.2.1' );
define( 'IMAGIFY_SLUG', 'imagify' );
define( 'IMAGIFY_FILE', __FILE__ );
define( 'IMAGIFY_PATH', realpath( plugin_dir_path( IMAGIFY_FILE ) ) . '/' );
Expand Down
6 changes: 3 additions & 3 deletions inc/3rd-party/WooCommerce/class-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ class WooCommerce {
* @return void
*/
public function init() {
add_action( 'woocommerce_single_product_summary', [ $this, 'variable_products_webp_compat' ] );
add_action( 'woocommerce_single_product_summary', [ $this, 'variable_products_nextgen_compat' ] );
}

/**
* Add Variable Products Webp Compatibility.
* Add Variable Products Next-gen images Compatibility.
*
* @since 1.10.0
*
* @return void
*/
public function variable_products_webp_compat() {
public function variable_products_nextgen_compat() {
global $product;

if ( ! isset( $product ) || ! $product->is_type( 'variable' ) ) {
Expand Down
Loading
Loading