| @@ -21,9 +21,9 @@ | ||
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | add_action( 'imagify_delete_media', 'imagify_cleanup_after_media_deletion' ); |
| 24 | 24 | /** |
| 25 | - * Delete the backup file and the WebP files when an attachement is deleted. | |
| 25 | + * Delete the backup file and the next-gen files when an attachement is deleted. | |
| 26 | 26 | * |
| 27 | 27 | * @since 1.9 |
| 28 | 28 | * @author Grégory Viguier |
| 29 | 29 | * |
| @@ -35,17 +35,18 @@ | ||
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | /** |
| 38 | 38 | * The optimization data will be automatically deleted by WP (post metas). |
| 39 | - * Delete the WebP versions and the backup file. | |
| 39 | + * Delete the Nextgen versions and the backup file. | |
| 40 | 40 | */ |
| 41 | - $process->delete_webp_files(); | |
| 41 | + $process->delete_nextgen_files( false, true ); | |
| 42 | + | |
| 42 | 43 | $process->delete_backup(); |
| 43 | 44 | } |
| 44 | 45 | |
| 45 | -add_filter( 'ext2type', 'imagify_add_webp_type' ); | |
| 46 | +add_filter( 'ext2type', 'imagify_add_avif_type' ); | |
| 46 | 47 | /** |
| 47 | - * Add the WebP extension to wp_get_ext_types(). | |
| 48 | + * Add the AVIF extension to wp_get_ext_types(). | |
| 48 | 49 | * |
| 49 | 50 | * @since 1.9 |
| 50 | 51 | * @author Grégory Viguier |
| 51 | 52 | * |
| @@ -51,11 +52,11 @@ | ||
| 51 | 52 | * |
| 52 | 53 | * @param array $ext2type Multi-dimensional array with extensions for a default set of file types. |
| 53 | 54 | * @return array |
| 54 | 55 | */ |
| 55 | -function imagify_add_webp_type( $ext2type ) { | |
| 56 | - if ( ! in_array( 'webp', $ext2type['image'], true ) ) { | |
| 57 | - $ext2type['image'][] = 'webp'; | |
| 56 | +function imagify_add_avif_type( $ext2type ) { | |
| 57 | + if ( ! in_array( 'avif', $ext2type['image'], true ) ) { | |
| 58 | + $ext2type['image'][] = 'avif'; | |
| 58 | 59 | } |
| 59 | 60 | return $ext2type; |
| 60 | 61 | } |
| 61 | 62 | |
| @@ -65,5 +66,47 @@ | ||
| 65 | 66 | * @since 1.9.8 |
| 66 | 67 | * @since WP 5.3 |
| 67 | 68 | * @author Grégory Viguier |
| 68 | 69 | */ |
| 69 | -add_filter( 'big_image_size_threshold', [ imagify_get_context( 'wp' ), 'get_resizing_threshold' ], IMAGIFY_INT_MAX ); | |
| 70 | +add_filter( 'big_image_size_threshold', [ imagify_get_context( 'wp' ), 'filter_big_image_size_threshold' ], IMAGIFY_INT_MAX ); | |
| 71 | + | |
| 72 | +/** | |
| 73 | + * Note the uploads WordPress 7.1 hands to the browser, which scales them itself. | |
| 74 | + * | |
| 75 | + * Fires before the attachment metadata is generated, so the threshold filter above already | |
| 76 | + * knows about it by the time it runs. | |
| 77 | + * | |
| 78 | + * @since 2.3.3 | |
| 79 | + * @since WP 7.1 | |
| 80 | + */ | |
| 81 | +add_action( 'rest_after_insert_attachment', [ imagify_get_context( 'wp' ), 'maybe_flag_client_side_scaling' ], 10, 3 ); | |
| 82 | + | |
| 83 | +/** | |
| 84 | + * Add filters to manage images formats that will be generated | |
| 85 | + * | |
| 86 | + * @return array | |
| 87 | + */ | |
| 88 | +function imagify_nextgen_images_formats() { | |
| 89 | + $value = get_imagify_option( 'optimization_format' ); | |
| 90 | + $formats = []; | |
| 91 | + | |
| 92 | + if ( 'off' !== $value ) { | |
| 93 | + $formats[ $value ] = $value; | |
| 94 | + } | |
| 95 | + | |
| 96 | + $default = $formats; | |
| 97 | + | |
| 98 | + /** | |
| 99 | + * Filters the array of next gen formats to generate with Imagify | |
| 100 | + * | |
| 101 | + * @since 2.2 | |
| 102 | + * | |
| 103 | + * @param array $formats Array of image formats | |
| 104 | + */ | |
| 105 | + $formats = apply_filters( 'imagify_nextgen_images_formats', $formats ); | |
| 106 | + | |
| 107 | + if ( ! is_array( $formats ) ) { | |
| 108 | + $formats = $default; | |
| 109 | + } | |
| 110 | + | |
| 111 | + return $formats; | |
| 112 | +} | |