Hi Cristian, sounds like a good idea.
We have added a hook needed by WPML to make their plugin compatible, you can see the code here:
https://github.com/tinify/wordpress-plugin/commit/8115bba079efc81a5301bb5bd373fd9e90c07240
If you like maybe try the following code change. Notice the 2 additional hooks, one after each thumbnail size and one after completing compression of an image:
public function compress() {
if ( $this->settings->get_compressor() === null || ! $this->file_type_allowed() ) {
return;
}
$success = 0;
$failed = 0;
$compressor = $this->settings->get_compressor();
$active_tinify_sizes = $this->settings->get_active_tinify_sizes();
$uncompressed_sizes = $this->filter_image_sizes( 'uncompressed', $active_tinify_sizes );
foreach ( $uncompressed_sizes as $size_name => $size ) {
if ( ! $size->is_duplicate() ) {
$size->add_tiny_meta_start();
$this->update_tiny_post_meta();
$resize = $this->settings->get_resize_options( $size_name );
$preserve = $this->settings->get_preserve_options( $size_name );
try {
$response = $compressor->compress_file( $size->filename, $resize, $preserve );
$size->add_tiny_meta( $response );
$success++;
do_action( 'tiny_image_size_compressed', $this->id, $size->filename );
} catch ( Tiny_Exception $e ) {
$size->add_tiny_meta_error( $e );
$failed++;
}
$this->add_wp_metadata( $size_name, $size );
$this->update_tiny_post_meta();
}
}
do_action( 'tiny_image_after_compression', $this->id, $success );
return array(
'success' => $success,
'failed' => $failed,
);
}
Maybe you can try out this code or changes to the example and share the code changes?
We would be happy to include one or two hooks in the next release of the plugin scheduled for half November.