PluginProbe
Image Optimization – Compress Images and Convert to WebP or AVIF / 1.6.8
Image Optimization – Compress Images and Convert to WebP or AVIF v1.6.8
1.7.6 1.7.5 1.7.4 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 All 32 releases
image-optimization / modules / optimization / module.php

module.php in Image Optimization – Compress Images and Convert to WebP or AVIF 1.6.8, at modules/optimization/module.php

110 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ImageOptimization\Modules\Optimization;
3
4 use ImageOptimization\Classes\Module_Base;
5 use ImageOptimization\Modules\Backups\Rest\Restore_Single;
6 use ImageOptimization\Modules\Optimization\Rest\Optimize_Single_Image;
7 use Throwable;
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit; // Exit if accessed directly.
11 }
12
13 class Module extends Module_Base {
14 public function get_name(): string {
15 return 'optimization';
16 }
17
18 public static function routes_list() : array {
19 return [
20 'Optimize_Single_Image',
21 'Optimize_Bulk',
22 'Get_Bulk_Optimization_Images',
23 'Optimization_Status',
24 'Cancel_Bulk_Optimization',
25 ];
26 }
27
28 public static function component_list() : array {
29 return [
30 'Avif_Compatibility',
31 'Media_Control',
32 'Single_Optimization',
33 'Upload_Optimization',
34 'Bulk_Optimization',
35 'List_View_Pointer',
36 'Admin_Bulk_Actions',
37 'Admin_Filter',
38 'Retry',
39 'Actions_Cleanup',
40 ];
41 }
42
43 /**
44 * Enqueue styles and scripts
45 */
46 public function enqueue_scripts() {
47 $asset_file = include IMAGE_OPTIMIZATION_ASSETS_PATH . 'build/control.asset.php';
48
49 foreach ( $asset_file['dependencies'] as $style ) {
50 wp_enqueue_style( $style );
51 }
52
53 add_thickbox();
54
55 wp_enqueue_style(
56 'image-optimization-control',
57 $this->get_css_assets_url( 'control' ),
58 [],
59 IMAGE_OPTIMIZATION_VERSION,
60 );
61
62 wp_enqueue_script(
63 'image-optimization-control',
64 $this->get_js_assets_url( 'control' ),
65 $asset_file['dependencies'],
66 IMAGE_OPTIMIZATION_VERSION,
67 true
68 );
69
70 wp_set_script_translations( 'image-optimization-control', 'image-optimization' );
71
72 wp_localize_script(
73 'image-optimization-control',
74 'imageOptimizerControlSettings',
75 [
76 'optimizeSingleImageNonce' => wp_create_nonce( Optimize_Single_Image::NONCE_NAME ),
77 'restoreSingleImageNonce' => wp_create_nonce( Restore_Single::NONCE_NAME ),
78 ]
79 );
80 }
81
82 public static function load_template( $path, $name, $args = [] ): bool {
83 $templates_path = sprintf(
84 '%s/templates/%s/%s.php',
85 dirname( __FILE__ ),
86 $path,
87 $name
88 );
89
90 try {
91 load_template( $templates_path, false, $args );
92 } catch ( Throwable $t ) {
93 return false;
94 }
95
96 return true;
97 }
98
99 /**
100 * Module constructor.
101 */
102 public function __construct() {
103 $this->register_components();
104 $this->register_routes();
105
106 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
107 add_action( 'elementor/editor/after_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
108 }
109 }
110