Plugin Updates

This commit is contained in:
Tony Volpe
2024-04-02 20:23:21 +00:00
parent 96800520e8
commit 94170ec2c4
1514 changed files with 133309 additions and 105985 deletions

View File

@@ -47,13 +47,15 @@ class Display implements SubscriberInterface {
}
$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();
}

View File

@@ -173,31 +173,17 @@ class Bulk {
'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',
@@ -597,10 +583,6 @@ class Bulk {
* @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 ) {
@@ -609,11 +591,6 @@ class Bulk {
return;
}
if ( empty( $value['convert_to_avif'] ) ) {
// new value is disabled, do nothing.
return;
}
$contexts = $this->get_contexts();
$formats = imagify_nextgen_images_formats();

View File

@@ -281,7 +281,7 @@ abstract class AbstractData implements DataInterface {
/**
* 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
@@ -289,28 +289,36 @@ abstract class AbstractData implements DataInterface {
*
* @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();
$data = $this->get_optimization_data();
$media = $this->get_media();
$format = 'webp';
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' );
}
$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' );
if ( $use_webp && ! empty( $data['sizes'][ $webp_size_name ]['optimized_size'] ) ) {
$size = (int) $data['sizes'][ $webp_size_name ]['optimized_size'];
$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 ) {
@@ -320,10 +328,13 @@ abstract class AbstractData implements DataInterface {
// 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;
@@ -331,7 +342,7 @@ abstract class AbstractData implements DataInterface {
}
if ( ! $filepath ) {
// No WebP? The full size then.
// No Nextgen? The full size then.
$filepath = $media->get_fullsize_path();
}
@@ -418,15 +429,20 @@ abstract class AbstractData implements DataInterface {
}
$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( $nextgen_webp_size_name, 'percent' );
}
if ( ! $percent ) {
$percent = $this->get_size_data( 'full', 'percent' );
}
$percent = $percent ? $percent : 0;
$percent = $percent ?: 0;
return round( (float) $percent, 2 );
}

View File

@@ -208,7 +208,7 @@ interface DataInterface {
/**
* 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
@@ -216,10 +216,10 @@ interface DataInterface {
*
* @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 );
/** ----------------------------------------------------------------------------------------- */

View File

@@ -208,7 +208,7 @@ class Noop implements DataInterface {
/**
* 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
@@ -216,10 +216,10 @@ class Noop implements DataInterface {
*
* @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;
}

View File

@@ -948,7 +948,7 @@ abstract class AbstractProcess implements ProcessInterface {
$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();
@@ -989,7 +989,7 @@ abstract class AbstractProcess implements ProcessInterface {
* 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();

View File

@@ -53,12 +53,14 @@ class Display implements SubscriberInterface {
}
$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();
}