PluginProbe
WP-Stateless – Google Cloud Storage / 3.0.2
WP-Stateless – Google Cloud Storage v3.0.2
4.4.3 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.3.0 2.3.1 2.3.2 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.2.0 3.2.1 3.2.2 All 62 releases
wp-stateless / lib / classes / compatibility / ewww.php

ewww.php in WP-Stateless – Google Cloud Storage 3.0.2, at lib/classes/compatibility/ewww.php

69 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 protected $sm_mode_not_supported = [ 'stateless' ];
22
23 public function module_init( $sm ) {
24 // add_filter( 'ewww_image_optimizer_pre_optimization', array($this, 'pre_optimization'), 10, 3 );
25 add_action( 'ewww_image_optimizer_post_optimization', array( $this, 'post_optimization' ), 10, 3 );
26 }
27
28 /**
29 * Try to restore images before compression
30 *
31 * @param $file
32 * @param $type
33 * @param $fullsize
34 */
35 public function pre_optimization( $file, $type, $fullsize ) {
36 // wp_stateless_file_name filter will remove the basedir from the path and prepend with root dir.
37 $name = apply_filters( 'wp_stateless_file_name', $file );
38 do_action( 'sm:sync::syncFile', $name, $file, true, array( 'ephemeral' => false, 'download' => true, 'use_root' => true ) );
39 }
40
41 /**
42 * If image size not exist then upload it to GS.
43 *
44 * @param $file
45 * @param $type
46 * @param $fullsize
47 */
48 public function post_optimization( $file, $type, $fullsize ) {
49 // wp_stateless_file_name filter will remove the basedir from the path and prepend with root dir.
50 $name = apply_filters( 'wp_stateless_file_name', $file );
51 do_action( 'sm:sync::syncFile', $name, $file, true, array( 'use_root' => true ) );
52
53
54 // if($fullsize && file_exists($file . '.bak'))
55 // do_action( 'sm:sync::syncFile', $name . '.bak', $file . '.bak', true);
56
57 if( file_exists( $file . '.webp' ) ) {
58 add_filter( 'upload_mimes', array( $this, 'add_webp_mime' ), 10, 2 );
59 do_action( 'sm:sync::syncFile', $name . '.webp', $file . '.webp', true, array( 'use_root' => true ) );
60 remove_filter( 'upload_mimes', array( $this, 'add_webp_mime' ), 10 );
61 }
62 }
63
64 }
65
66 }
67
68 }
69