| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: EWWW Image Optimizer |
| 4 |
* Plugin URI: https://ewww.io/ |
| 5 |
* |
| 6 |
* Compatibility Description: Enables support for these EWWW Image Optimizer Image Optimizer features |
| 7 |
* |
| 8 |
* https://github.com/wpCloud/wp-stateless/issues/371 |
| 9 |
*/ |
| 10 |
|
| 11 |
namespace wpCloud\StatelessMedia { |
| 12 |
|
| 13 |
if(!class_exists('wpCloud\StatelessMedia\EWWW')) { |
| 14 |
|
| 15 |
class EWWW extends ICompatibility { |
| 16 |
protected $id = 'ewww'; |
| 17 |
protected $title = 'EWWW Image Optimizer'; |
| 18 |
protected $constant = 'WP_STATELESS_COMPATIBILITY_EWWW'; |
| 19 |
protected $description = 'Enables limited support for EWWW Image Optimizer in CDN mode.'; |
| 20 |
protected $plugin_file = ['ewww-image-optimizer/ewww-image-optimizer.php']; |
| 21 |
|
| 22 |
public function module_init($sm){ |
| 23 |
// add_filter( 'ewww_image_optimizer_pre_optimization', array($this, 'pre_optimization'), 10, 3 ); |
| 24 |
add_action( 'ewww_image_optimizer_post_optimization', array($this, 'post_optimization'), 10, 3 ); |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* Try to restore images before compression |
| 29 |
* |
| 30 |
*/ |
| 31 |
public function pre_optimization( $file, $type, $fullsize ) { |
| 32 |
// wp_stateless_file_name filter will remove the basedir from the path and prepend with root dir. |
| 33 |
$name = apply_filters( 'wp_stateless_file_name', $file); |
| 34 |
do_action( 'sm:sync::syncFile', $name, $file, true, array('stateless' => false, 'download' => true)); |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* If image size not exist then upload it to GS. |
| 39 |
* |
| 40 |
*/ |
| 41 |
public function post_optimization($file, $type, $fullsize){ |
| 42 |
// wp_stateless_file_name filter will remove the basedir from the path and prepend with root dir. |
| 43 |
$name = apply_filters( 'wp_stateless_file_name', $file); |
| 44 |
do_action( 'sm:sync::syncFile', $name, $file, true); |
| 45 |
|
| 46 |
// if($fullsize && file_exists($file . '.bak')) |
| 47 |
// do_action( 'sm:sync::syncFile', $name . '.bak', $file . '.bak', true); |
| 48 |
|
| 49 |
if(file_exists($file . '.webp')) |
| 50 |
do_action( 'sm:sync::syncFile', $name . '.webp', $file . '.webp', true); |
| 51 |
} |
| 52 |
|
| 53 |
} |
| 54 |
|
| 55 |
} |
| 56 |
|
| 57 |
} |
| 58 |
|