PluginProbe
Image Optimizer – Compress Images and Convert to WebP or AVIF / 1.7.7
Image Optimizer – Compress Images and Convert to WebP or AVIF v1.7.7
1.7.7 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 All 33 releases
← All changes | modules/settings/module.php +106 -10 1.6.01.7.7 View file →
@@ -3,10 +3,17 @@
3 3 namespace ImageOptimization\Modules\Settings;
4 4
5 5 use ImageOptimization\Classes\Image\Image_Conversion_Option;
6 6 use ImageOptimization\Classes\Module_Base;
7 -use ImageOptimization\Modules\Settings\Banners\Sale_Banner;
8 -use ImageOptimization\Modules\Settings\Classes\Settings;
7 +use ImageOptimization\Modules\Settings\{
8 + Banners\Sale_Banner,
9 + Banners\Elementor_Birthday_Banner,
10 + Classes\Settings,
11 +};
12 +use ImageOptimization\Modules\Stats\Classes\Optimization_Stats;
13 +use ImageOptimization\Classes\Client\Client;
14 +use ImageOptimization\Modules\ConnectManager\Components\Connect as Connect_Manager_Connect;
15 +use ImageOptimization\Modules\Connect\Classes\Config;
9 16
10 17 if ( ! defined( 'ABSPATH' ) ) {
11 18 exit; // Exit if accessed directly
12 19 }
@@ -20,15 +27,15 @@
20 27 public function get_name(): string {
21 28 return 'settings';
22 29 }
23 30
24 - public static function component_list() : array {
31 + public static function component_list(): array {
25 32 return [
26 33 'Settings_Pointer',
27 34 ];
28 35 }
29 36
30 - public static function get_options() : array {
37 + public static function get_options(): array {
31 38 return [
32 39 'compression_level' => [ 'default' => 'lossy' ],
33 40 'optimize_on_upload' => [
34 41 'type' => 'boolean',
@@ -57,8 +64,21 @@
57 64 'custom_sizes' => [
58 65 'type' => 'string',
59 66 'default' => 'all',
60 67 ],
68 + 'help_videos' => [
69 + 'type' => 'object',
70 + 'show_in_rest' => [
71 + 'schema' => [
72 + 'type' => 'object',
73 + 'additionalProperties' => true,
74 + ],
75 + ],
76 + ],
77 + 'migration_popup_dismissed' => [
78 + 'type' => 'boolean',
79 + 'default' => false,
80 + ],
61 81 ];
62 82 }
63 83
64 84 public function register_options() {
@@ -81,9 +101,10 @@
81 101 }
82 102
83 103 public function render_app() {
84 104 ?>
85 - <?php Sale_Banner::get_banner( 'https://go.elementor.com/io-bf-banner/' ); ?>
105 + <?php Sale_Banner::get_banner( 'https://go.elementor.com/IO-BF-sale' ); ?>
106 + <?php Elementor_Birthday_Banner::get_banner( 'https://go.elementor.com/IO-10th-bd-sale' ); ?>
86 107
87 108 <!-- The hack required to wrap WP notifications -->
88 109 <div class="wrap">
89 110 <h1 style="display: none;" role="presentation"></h1>
@@ -93,18 +114,36 @@
93 114 <?php
94 115 }
95 116
96 117 public function register_page() {
97 - add_media_page(
98 - __( 'Image Optimizer', 'image-optimization' ),
99 - __( 'Image Optimizer', 'image-optimization' ),
118 + add_submenu_page(
119 + 'elementor-home',
120 + __( 'Image Optimization', 'image-optimization' ),
121 + __( 'Image Optimization', 'image-optimization' ),
100 122 self::SETTING_CAPABILITY,
101 123 self::SETTING_BASE_SLUG,
102 124 [ $this, 'render_app' ],
103 - 6
125 + 50
104 126 );
127 +
128 + $this->add_menu_item_class( 'elementor-home', self::SETTING_BASE_SLUG, 'image-optimizer-menu' );
105 129 }
106 130
131 + private function add_menu_item_class( string $parent_slug, string $menu_slug, string $class ) {
132 + global $submenu;
133 +
134 + if ( ! isset( $submenu[ $parent_slug ] ) ) {
135 + return;
136 + }
137 +
138 + foreach ( $submenu[ $parent_slug ] as &$item ) {
139 + if ( $item[2] === $menu_slug ) {
140 + $item[4] = isset( $item[4] ) ? $item[4] . ' ' . $class : $class;
141 + break;
142 + }
143 + }
144 + }
145 +
107 146 /**
108 147 * The handler converts an old CONVERT_TO_WEBP option to the new CONVERT_TO_FORMAT option.
109 148 * TODO: [Stability] Remove this fallback after all users updated
110 149 *
@@ -127,8 +166,52 @@
127 166
128 167 delete_option( Settings::CONVERT_TO_WEBP_OPTION_NAME );
129 168 }
130 169
170 + /**
171 + * The handler triggers stats recalculation on custom sizes update.
172 + *
173 + * @param $result
174 + * @param $name
175 + *
176 + * @return void
177 + */
178 + public function recalculate_stats_on_custom_sizes_update( $result, $name ) {
179 + if ( Settings::CUSTOM_SIZES_OPTION_NAME === $name ) {
180 + Optimization_Stats::get_image_stats( null, true );
181 + }
182 + }
183 +
184 + public function cleanup_data() {
185 + delete_transient( Client::SITE_INFO_TRANSIENT );
186 + delete_transient( Connect_Manager_Connect::STATUS_CHECK_TRANSIENT );
187 + }
188 +
189 + /**
190 + * Register or update site data for One connect
191 + * @throws Exception
192 + */
193 + public function on_migration_run() {
194 + $old_options = [
195 + 'image_optimizer_client_id',
196 + 'image_optimizer_client_secret',
197 + 'image_optimizer_home_url',
198 + 'image_optimizer_access_token',
199 + 'image_optimizer_token_id',
200 + 'image_optimizer_refresh_token',
201 + 'image_optimizer_user_access_token',
202 + 'image_optimizer_owner_user_id',
203 + 'image_optimizer_subscription_id',
204 + Settings::SUBSCRIPTION_ID,
205 + ];
206 +
207 + $this->cleanup_data();
208 +
209 + foreach ( $old_options as $option ) {
210 + delete_option( $option );
211 + }
212 + }
213 +
131 214 public function __construct() {
132 215 $this->register_components();
133 216
134 217 add_action( 'admin_init', [ $this, 'register_options' ] );
@@ -133,7 +216,20 @@
133 216
134 217 add_action( 'admin_init', [ $this, 'register_options' ] );
135 218 add_action( 'rest_api_init', [ $this, 'register_options' ] );
136 219 add_action( 'admin_init', [ $this, 'maybe_migrate_legacy_conversion_option' ] );
137 - add_action( 'admin_menu', [ $this, 'register_page' ] );
220 + add_action( 'admin_menu', [ $this, 'register_page' ], 99 );
221 + add_action( 'rest_pre_update_setting', [ $this, 'recalculate_stats_on_custom_sizes_update' ], 10, 2 );
222 +
223 + add_action( 'elementor_one/' . Config::APP_PREFIX . '_connected', [ $this, 'cleanup_data' ] );
224 + add_action( 'elementor_one/' . Config::APP_PREFIX . '_disconnected', [ $this, 'cleanup_data' ] );
225 + add_action( 'elementor_one/' . Config::APP_PREFIX . '_migration_run', [ $this, 'on_migration_run' ] );
226 +
227 + // Add action on switch domain for update access token
228 + add_action( 'elementor_one/' . Config::APP_PREFIX . '_switched_domain', function( $facade ) {
229 + $facade->service()->renew_access_token();
230 + } );
231 + add_action( 'elementor_one/switched_domain', function( $facade ) {
232 + $facade->service()->renew_access_token();
233 + } );
138 234 }
139 235 }