| 1 |
<?php |
| 2 |
defined( 'ABSPATH' ) or die( 'Cheatin\' uh?' ); |
| 3 |
|
| 4 |
if ( function_exists( 'wr2x_delete_attachment' ) && function_exists( 'wr2x_generate_images' ) ) : |
| 5 |
|
| 6 |
/** |
| 7 |
* Process to restore all retina versions for an attachment |
| 8 |
* |
| 9 |
* @since 1.0 |
| 10 |
*/ |
| 11 |
add_action( 'before_imagify_restore_attachment', '_imagify_wr2x_delete_attachment_on_restore' ); |
| 12 |
function _imagify_wr2x_delete_attachment_on_restore( $attachment_id ) { |
| 13 |
// Remove all retina versions if exists |
| 14 |
wr2x_delete_attachment( $attachment_id ); |
| 15 |
} |
| 16 |
|
| 17 |
add_action( 'after_imagify_restore_attachment', '_imagify_wr2x_generate_images_on_restore' ); |
| 18 |
function _imagify_wr2x_generate_images_on_restore( $attachment_id ) { |
| 19 |
// Regenerate all retina versions |
| 20 |
$metadata = wp_get_attachment_metadata( $attachment_id ); |
| 21 |
wr2x_generate_images( $metadata ); |
| 22 |
} |
| 23 |
|
| 24 |
endif; |
| 25 |
|
| 26 |
if ( function_exists( 'wr2x_get_retina' ) ) : |
| 27 |
|
| 28 |
/** |
| 29 |
* Process to generate the retina version of a thumbnail |
| 30 |
* |
| 31 |
* @since 1.0 |
| 32 |
*/ |
| 33 |
add_filter( 'imagify_fill_thumbnail_data', '_imagify_optimize_wr2x', 10, 7 ); |
| 34 |
function _imagify_optimize_wr2x( $data, $response, $id, $path, $url, $size_key, $optimization_level ) { |
| 35 |
/** |
| 36 |
* Allow to optimize the retina version generated by WP Retina x2 |
| 37 |
* |
| 38 |
* @since 1.0 |
| 39 |
* |
| 40 |
* @param bool true will force the optimization |
| 41 |
*/ |
| 42 |
$do_retina = apply_filters( 'do_imagify_optimize_retina', true ); |
| 43 |
|
| 44 |
$retina_path = wr2x_get_retina( $path ); |
| 45 |
|
| 46 |
if ( ! empty( $retina_path ) && $do_retina ) { |
| 47 |
$response = do_imagify( $retina_path, false, $optimization_level ); |
| 48 |
$data = Imagify_Attachment::fill_data( $data, $response, $id, $url, $size_key . '@2x' ); |
| 49 |
} |
| 50 |
|
| 51 |
return $data; |
| 52 |
} |
| 53 |
|
| 54 |
endif; |