PluginProbe
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization / 4.2.16
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization v4.2.16
4.2.16 4.2.15 4.2.14 4.2.13 4.2.12 4.2.11 4.2.10 4.2.9 4.2.8 4.2.7 4.2.6 4.2.5 2.5.5 2.5.6 2.5.7 3.0.0 3.0.1 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.11.0 3.11.1 3.11.2 All 137 releases
← All changes | inc/main.php +88 -8 3.10.0 → 4.2.16 View file →
@@ -6,9 +6,9 @@
6 6 final class Optml_Main {
7 7 /**
8 8 * Optml_Main The single instance of Starter_Plugin.
9 9 *
10 - * @var object
10 + * @var Optml_Main|null
11 11 * @access private
12 12 * @since 1.0.0
13 13 */
14 14 private static $_instance = null;
@@ -68,13 +68,21 @@
68 68 */
69 69 public $cli;
70 70
71 71 /**
72 + * Holds the video player class.
73 + *
74 + * @access public
75 + * @since 1.0.0
76 + * @var Optml_Video_Player Video player instance.
77 + */
78 + public $video_player;
79 + /**
72 80 * Optml_Main constructor.
73 81 */
74 82 public function __construct() {
75 -
76 83 register_activation_hook( OPTML_BASEFILE, [ $this, 'activate' ] );
84 + register_deactivation_hook( OPTML_BASEFILE, [ $this, 'deactivate' ] );
77 85 }
78 86
79 87 /**
80 88 * Main Starter_Plugin Instance
@@ -84,16 +92,23 @@
84 92 * @return Optml_Main Plugin instance.
85 93 * @since 1.0.0
86 94 */
87 95 public static function instance() {
96 + $vendor_file = OPTML_PATH . 'vendor/autoload.php';
97 + if ( is_readable( $vendor_file ) ) {
98 + include_once $vendor_file;
99 + }
100 +
88 101 if ( null === self::$_instance ) {
89 102 add_filter( 'themeisle_sdk_products', [ __CLASS__, 'register_sdk' ] );
90 - add_filter( 'themeisle_sdk_ran_promos', '__return_true' );
103 + add_filter( 'themeisle_sdk_ran_promos', [ __CLASS__, 'sdk_hide_promo_notice' ] );
91 104 add_filter( 'optimole-wp_uninstall_feedback_icon', [ __CLASS__, 'change_icon' ] );
92 105 add_filter( 'optimole_wp_uninstall_feedback_after_css', [ __CLASS__, 'adds_uf_css' ] );
93 106 add_filter( 'optimole_wp_feedback_review_message', [ __CLASS__, 'change_review_message' ] );
94 107 add_filter( 'optimole_wp_logger_heading', [ __CLASS__, 'change_review_message' ] );
95 108 add_filter( 'optml_register_conflicts', [ __CLASS__, 'register_conflicts' ] );
109 + add_filter( 'optimole_wp_logger_data', [ __CLASS__, 'add_settings' ] );
110 + add_filter( 'optimole_wp_ai_connect_metadata', [ __CLASS__, 'add_ai_connect_metadata' ] );
96 111 self::$_instance = new self();
97 112 self::$_instance->manager = Optml_Manager::instance();
98 113 self::$_instance->rest = new Optml_Rest();
99 114 self::$_instance->admin = new Optml_Admin();
@@ -98,16 +113,14 @@
98 113 self::$_instance->rest = new Optml_Rest();
99 114 self::$_instance->admin = new Optml_Admin();
100 115 self::$_instance->dam = new Optml_Dam();
101 116 self::$_instance->media_offload = Optml_Media_Offload::instance();
117 + self::$_instance->video_player = new Optml_Video_Player();
118 + new Optml_Abilities();
102 119 if ( class_exists( 'WP_CLI' ) ) {
103 120 self::$_instance->cli = new Optml_Cli();
104 121 }
105 122 }
106 - $vendor_file = OPTML_PATH . 'vendor/autoload.php';
107 - if ( is_readable( $vendor_file ) ) {
108 - include_once $vendor_file;
109 - }
110 123
111 124 return self::$_instance;
112 125 }
113 126
@@ -124,12 +137,15 @@
124 137 $conflicts_to_register = array_merge(
125 138 $conflicts_to_register,
126 139 [
127 140 'Optml_Jetpack_Photon',
128 - 'Optml_Jetpack_Lazyload',
129 141 'Optml_Wprocket',
130 142 'Optml_Divi',
131 143 'Optml_w3_total_cache_cdn',
144 + 'Optml_Smush',
145 + 'Optml_Litespeed',
146 + 'Optml_Autoptimize',
147 + 'Optml_Perfmatters',
132 148 ]
133 149 );
134 150
135 151 return $conflicts_to_register;
@@ -135,8 +151,24 @@
135 151 return $conflicts_to_register;
136 152 }
137 153
138 154 /**
155 + * Add settings to the logger data.
156 + *
157 + * @param array $data Logger data.
158 + *
159 + * @return array
160 + */
161 + public static function add_settings( $data ): array {
162 + $data = is_array( $data ) ? $data : [];
163 +
164 + $saved_data = ( new Optml_Settings() )->get_raw_settings();
165 + unset( $saved_data['service_data'] );
166 + unset( $saved_data['api_key'] );
167 +
168 + return array_merge( $data, $saved_data );
169 + }
170 + /**
139 171 * Change review message.
140 172 *
141 173 * @param string $message Old review message.
142 174 *
@@ -146,8 +178,30 @@
146 178 return str_replace( '{product}', 'Optimole', $message );
147 179 }
148 180
149 181 /**
182 + * Opt in to the SDK AI Connect module.
183 + *
184 + * @return array<string, mixed> AI Connect metadata.
185 + */
186 + public static function add_ai_connect_metadata() {
187 + return [
188 + 'name' => 'Optimole',
189 + 'notice_cases' => [
190 + __( 'make your images load faster', 'optimole-wp' ),
191 + __( 'purge cached images', 'optimole-wp' ),
192 + __( 'offload media to the cloud', 'optimole-wp' ),
193 + ],
194 + 'prompts' => [
195 + __( 'Make my images load faster: turn on lazy loading and serve them at quality 80.', 'optimole-wp' ),
196 + __( 'Offload my media library to the Optimole cloud to free up disk space.', 'optimole-wp' ),
197 + __( 'I changed my logo. Purge the cached versions so visitors get the new one.', 'optimole-wp' ),
198 + ],
199 + 'ability_prefix' => 'optimole',
200 + ];
201 + }
202 +
203 + /**
150 204 * Register product into SDK.
151 205 *
152 206 * @param array $products All products.
153 207 *
@@ -214,8 +268,20 @@
214 268 set_transient( 'optml_fresh_install', true, MINUTE_IN_SECONDS );
215 269 }
216 270
217 271 /**
272 + * Deactivate routine actions.
273 + *
274 + * @access public
275 + * @since 3.11.0
276 + */
277 + public function deactivate() {
278 + // Clear registered cron events.
279 + wp_clear_scheduled_hook( 'optml_daily_sync' );
280 + wp_clear_scheduled_hook( 'optml_pull_image_data_init' );
281 + }
282 +
283 + /**
218 284 * Cloning is forbidden.
219 285 *
220 286 * @access public
221 287 * @since 1.0.0
@@ -233,5 +299,19 @@
233 299 public function __wakeup() {
234 300 _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'optimole-wp' ), '1.0.0' );
235 301 }
236 302
303 + /**
304 + * Hide SDK promo notice for pro uses.
305 + *
306 + * @access public
307 + */
308 + public static function sdk_hide_promo_notice( $should_show ) {
309 + if ( self::$_instance->admin->settings->is_connected() ) {
310 + $service_data = self::$_instance->admin->settings->get( 'service_data' );
311 + if ( isset( $service_data['plan'] ) && 'free' !== $service_data['plan'] ) {
312 + return true;
313 + }
314 + }
315 + return $should_show;
316 + }
237 317 }