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

@@ -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' ) ) {

View File

@@ -6,12 +6,11 @@ defined( 'ABSPATH' ) || die( 'Cheatin uh?' );
*/
if ( function_exists( 'is_amp_endpoint' ) ) :
add_filter( 'imagify_allow_picture_tags_for_webp', 'imagify_amp_disable_picture_on_endpoint' );
add_filter( 'imagify_allow_picture_tags_for_nextgen', 'imagify_amp_disable_picture_on_endpoint' );
/**
* Do not use <picture> tags in AMP pages.
*
* @since 1.9
* @author Grégory Viguier
* @since 1.9
*
* @param bool $allow True to allow the use of <picture> tags (default). False to prevent their use.
* @return bool

View File

@@ -5,8 +5,6 @@ use Imagify\Traits\InstanceGetterTrait;
use Imagify_Enable_Media_Replace_Deprecated;
use Imagify_Filesystem;
defined( 'ABSPATH' ) || die( 'Cheatin uh?' );
/**
* Compat class for Enable Media Replace plugin.
*
@@ -40,12 +38,12 @@ class Main extends Imagify_Enable_Media_Replace_Deprecated {
protected $old_backup_path;
/**
* List of paths to the old WebP files.
* List of paths to the old next-gen files.
*
* @var array
* @since 1.9.8
*/
protected $old_webp_paths = [];
protected $old_nextgen_paths = [];
/**
* Launch the hooks before the files and data are replaced.
@@ -84,29 +82,26 @@ class Main extends Imagify_Enable_Media_Replace_Deprecated {
}
/**
* Keep track of existing WebP files.
* Keep track of existing next-gen files.
*
* Whether the user chooses to rename the files or not, we will need to delete the current WebP files before creating new ones:
* Whether the user chooses to rename the files or not, we will need to delete the current next-gen files before creating new ones:
* - Rename the files: the old ones must be removed, they are useless now.
* - Do not rename the files: the thumbnails may still get new names because of the suffix containing the image dimensions, which may differ (for example when thumbnails are scaled, not cropped).
* In this last case, the thumbnails with the old dimensions are removed from the drive and from the WPs post meta, so there is no need of keeping orphan WebP files that would stay on the drive for ever, even after the attachment is deleted from WP.
* In this last case, the thumbnails with the old dimensions are removed from the drive and from the WPs post meta, so there is no need of keeping orphan next-gen files that would stay on the drive for ever, even after the attachment is deleted from WP.
*/
foreach ( $this->process->get_media()->get_media_files() as $media_file ) {
$this->old_webp_paths[] = imagify_path_to_webp( $media_file['path'] );
foreach ( [ 'avif', 'webp' ] as $format ) {
$this->old_nextgen_paths[] = imagify_path_to_nextgen( $media_file['path'], $format );
}
}
// Delete the old backup file and old WebP files.
// Delete the old backup file and old next-gen files.
add_action( 'imagify_before_auto_optimization', [ $this, 'delete_backup' ] );
add_action( 'imagify_not_optimized_attachment_updated', [ $this, 'delete_backup' ] );
}
/** ----------------------------------------------------------------------------------------- */
/** HOOKS =================================================================================== */
/** ----------------------------------------------------------------------------------------- */
/**
* Delete previous backup file and WebP files.
* Delete previous backup file and next-gen files.
* This is done after the images have been already replaced by Enable Media Replace.
*
* @since 1.8.4
@@ -126,19 +121,14 @@ class Main extends Imagify_Enable_Media_Replace_Deprecated {
$this->old_backup_path = false;
}
if ( ! empty( $this->old_webp_paths ) ) {
// Delete old WebP files.
$this->old_webp_paths = array_filter( $this->old_webp_paths, [ $filesystem, 'exists' ] );
array_map( [ $filesystem, 'delete' ], $this->old_webp_paths );
$this->old_webp_paths = [];
if ( ! empty( $this->old_nextgen_paths ) ) {
// Delete old next-gen files.
$this->old_nextgen_paths = array_filter( $this->old_nextgen_paths, [ $filesystem, 'exists' ] );
array_map( [ $filesystem, 'delete' ], $this->old_nextgen_paths );
$this->old_nextgen_paths = [];
}
}
/** ----------------------------------------------------------------------------------------- */
/** TOOLS =================================================================================== */
/** ----------------------------------------------------------------------------------------- */
/**
* Get the optimization process corresponding to the current media.
*

View File

@@ -142,7 +142,7 @@ class NGG extends AbstractBulk {
) );
$wpdb->flush();
unset( $ngg_table, $data_table, $webp_suffix );
unset( $ngg_table, $data_table, $suffix );
$data = [
'ids' => [],
@@ -169,7 +169,7 @@ class NGG extends AbstractBulk {
$backup_path = get_imagify_ngg_attachment_backup_path( $file_path );
if ( ! $this->filesystem->exists( $backup_path ) ) {
// No backup, no WebP.
// No backup, no next-gen.
$data['errors']['no_backup'][] = $file_id;
continue;
}

View File

@@ -150,74 +150,80 @@ function _imagify_ngg_media_library_imported_image_data( $image, $attachment ) {
}
/**
* WebP for the full size.
* Next-gen for the full size.
* Look for an existing copy locally:
* - if it exists, copy it (and its optimization data),
* - if not, add it to the optimization queue.
*/
$add_full_webp = $wp_media->is_image() && get_imagify_option( 'convert_to_webp' );
$add_full_nextgen = $wp_media->is_image();
if ( $add_full_webp ) {
// It's a supported image and WebP conversion is enabled.
$wp_full_path_webp = false;
$webp_size_name = 'full' . $wp_process::WEBP_SUFFIX;
$wp_webp_data = $wp_data->get_size_data( $webp_size_name );
if ( $add_full_nextgen ) {
$formats = [
'avif' => $wp_process::AVIF_SUFFIX,
'webp' => $wp_process::WEBP_SUFFIX,
];
// Get the path to the WebP image if it exists.
$wp_full_path_webp = $wp_process->get_fullsize_file()->get_path_to_webp();
foreach ( $formats as $extension => $suffix ) {
$wp_full_path_nextgen = false;
$nextgen_size_name = 'full' . $suffix;
$wp_nextgen_data = $wp_data->get_size_data( $nextgen_size_name );
if ( $wp_full_path_webp && ! $filesystem->exists( $wp_full_path_webp ) ) {
$wp_full_path_webp = false;
}
// Get the path to the next-gen image if it exists.
$wp_full_path_nextgen = $wp_process->get_fullsize_file()->get_path_to_nextgen( $extension );
if ( $wp_full_path_webp ) {
// We know we have a WebP version. Make sure we have the right data.
$wp_webp_data['success'] = true;
if ( $wp_full_path_nextgen && ! $filesystem->exists( $wp_full_path_nextgen ) ) {
$wp_full_path_nextgen = false;
}
if ( empty( $wp_webp_data['original_size'] ) ) {
// The WebP data is missing.
$full_size_weight = $wp_full_size_data['original_size'];
if ( $wp_full_path_nextgen ) {
// We know we have a next-gen version. Make sure we have the right data.
$wp_nextgen_data['success'] = true;
if ( ! $full_size_weight && $wp_backup_path ) {
// For some reason we don't have the original file weight, but we can get it from the backup file.
$full_size_weight = $filesystem->size( $wp_backup_path );
if ( empty( $wp_nextgen_data['original_size'] ) ) {
// The next-gen data is missing.
$full_size_weight = $wp_full_size_data['original_size'];
if ( $full_size_weight ) {
$wp_webp_data['original_size'] = $full_size_weight;
if ( ! $full_size_weight && $wp_backup_path ) {
// For some reason we don't have the original file weight, but we can get it from the backup file.
$full_size_weight = $filesystem->size( $wp_backup_path );
if ( $full_size_weight ) {
$wp_nextgen_data['original_size'] = $full_size_weight;
}
}
}
}
if ( ! empty( $wp_webp_data['original_size'] ) && empty( $wp_webp_data['optimized_size'] ) ) {
// The WebP file size.
$wp_webp_data['optimized_size'] = $filesystem->size( $wp_full_path_webp );
}
if ( ! empty( $wp_nextgen_data['original_size'] ) && empty( $wp_nextgen_data['optimized_size'] ) ) {
// The next-gen file size.
$wp_nextgen_data['optimized_size'] = $filesystem->size( $wp_full_path_nextgen );
}
if ( empty( $wp_webp_data['original_size'] ) || empty( $wp_webp_data['optimized_size'] ) ) {
// We must have both original and optimized sizes.
$wp_webp_data = [];
}
}
if ( $wp_full_path_webp && $wp_webp_data ) {
// We have the file and the data.
// Copy the file.
$ngg_full_file = new File( $ngg_media->get_raw_fullsize_path() );
$ngg_full_path_webp = $ngg_full_file->get_path_to_webp(); // Destination.
if ( $ngg_full_path_webp ) {
$copied = $filesystem->copy( $wp_full_path_webp, $ngg_full_path_webp, true );
if ( $copied ) {
// Success.
$filesystem->chmod_file( $ngg_full_path_webp );
$add_full_webp = false;
if ( empty( $wp_nextgen_data['original_size'] ) || empty( $wp_nextgen_data['optimized_size'] ) ) {
// We must have both original and optimized sizes.
$wp_nextgen_data = [];
}
}
if ( ! $add_full_webp ) {
// The WebP file has been successfully copied: now, copy the data.
$ngg_process->get_data()->update_size_optimization_data( $webp_size_name, $wp_webp_data );
if ( $wp_full_path_nextgen && $wp_nextgen_data ) {
// We have the file and the data.
// Copy the file.
$ngg_full_file = new File( $ngg_media->get_raw_fullsize_path() );
$ngg_full_path_nextgen = $ngg_full_file->get_path_to_nextgen( $extension ); // Destination.
if ( $ngg_full_path_nextgen ) {
$copied = $filesystem->copy( $wp_full_path_nextgen, $ngg_full_path_nextgen, true );
if ( $copied ) {
// Success.
$filesystem->chmod_file( $ngg_full_path_nextgen );
$add_full_nextgen = false;
}
}
if ( ! $add_full_nextgen ) {
// The next-gen file has been successfully copied: now, copy the data.
$ngg_process->get_data()->update_size_optimization_data( $nextgen_size_name, $wp_nextgen_data );
}
}
}
}
@@ -226,9 +232,20 @@ function _imagify_ngg_media_library_imported_image_data( $image, $attachment ) {
$sizes = $ngg_media->get_media_files();
unset( $sizes['full'] );
if ( $add_full_webp ) {
// We could not use a local WebP copy: ask for a new one.
$sizes[ $webp_size_name ] = [];
if ( $add_full_nextgen ) {
// We could not use a local next-gen copy: ask for a new one.
$formats = imagify_nextgen_images_formats();
foreach ( $formats as $format ) {
if ( 'webp' === $format ) {
$suffix = $wp_process::WEBP_SUFFIX;
} elseif ( 'avif' === $format ) {
$suffix = $wp_process::AVIF_SUFFIX;
}
$sizes[ 'full' . $suffix ] = [];
}
}
if ( ! $sizes ) {
@@ -282,7 +299,7 @@ function imagify_ngg_cleanup_after_media_deletion( $image_id, $image ) {
/**
* The backup file has already been deleted by NGG.
* Delete the WebP versions and the optimization data.
* Delete the next-gen versions and the optimization data.
*/
$process->delete_nextgen_files();

View File

@@ -158,19 +158,19 @@ class Main extends \Imagify_Regenerate_Thumbnails_Deprecated {
/**
* Optimize the sizes that have been regenerated.
*/
// If the media has WebP versions, recreate them for the sizes that have been regenerated.
// If the media has next-gen versions, recreate them for the sizes that have been regenerated.
$data = $process->get_data();
$optimization_data = $data->get_optimization_data();
if ( ! empty( $optimization_data['sizes'] ) ) {
foreach ( $optimization_data['sizes'] as $size_name => $size_data ) {
$non_webp_size_name = $process->is_size_next_gen( $size_name );
$non_nextgen_size_name = $process->is_size_next_gen( $size_name );
if ( ! $non_webp_size_name || ! isset( $sizes[ $non_webp_size_name ] ) ) {
if ( ! $non_nextgen_size_name || ! isset( $sizes[ $non_nextgen_size_name ] ) ) {
continue;
}
// Add the WebP size.
// Add the next-gen size.
$sizes[ $size_name ] = [];
}
}