PluginProbe
Image Optimization – Compress Images and Convert to WebP or AVIF / 1.6.5
Image Optimization – Compress Images and Convert to WebP or AVIF v1.6.5
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.5, at modules/optimization/module.php

106 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 ];
39 }
40
41 /**
42 * Enqueue styles and scripts
43 */
44 public function enqueue_scripts() {
45 $asset_file = include IMAGE_OPTIMIZATION_ASSETS_PATH . 'build/control.asset.php';
46
47 foreach ( $asset_file['dependencies'] as $style ) {
48 wp_enqueue_style( $style );
49 }
50
51 wp_enqueue_style(
52 'image-optimization-control',
53 $this->get_css_assets_url( 'control' ),
54 [],
55 IMAGE_OPTIMIZATION_VERSION,
56 );
57
58 wp_enqueue_script(
59 'image-optimization-control',
60 $this->get_js_assets_url( 'control' ),
61 $asset_file['dependencies'],
62 IMAGE_OPTIMIZATION_VERSION,
63 true
64 );
65
66 wp_set_script_translations( 'image-optimization-control', 'image-optimization' );
67
68 wp_localize_script(
69 'image-optimization-control',
70 'imageOptimizerControlSettings',
71 [
72 'optimizeSingleImageNonce' => wp_create_nonce( Optimize_Single_Image::NONCE_NAME ),
73 'restoreSingleImageNonce' => wp_create_nonce( Restore_Single::NONCE_NAME ),
74 ]
75 );
76 }
77
78 public static function load_template( $path, $name, $args = [] ): bool {
79 $templates_path = sprintf(
80 '%s/templates/%s/%s.php',
81 dirname( __FILE__ ),
82 $path,
83 $name
84 );
85
86 try {
87 load_template( $templates_path, false, $args );
88 } catch ( Throwable $t ) {
89 return false;
90 }
91
92 return true;
93 }
94
95 /**
96 * Module constructor.
97 */
98 public function __construct() {
99 $this->register_components();
100 $this->register_routes();
101
102 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
103 add_action( 'elementor/editor/after_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
104 }
105 }
106