PluginProbe
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization / 4.2.13
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization v4.2.13
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 3.11.3 3.12.0 3.12.1 All 134 releases
← All changes | inc/main.php +87 -33 2.5.64.2.13 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;
@@ -23,8 +23,17 @@
23 23 */
24 24 public $manager;
25 25
26 26 /**
27 + * Holds the media_offload class.
28 + *
29 + * @access public
30 + * @since 1.0.0
31 + * @var Optml_Media_Offload instance.
32 + */
33 + public $media_offload;
34 +
35 + /**
27 36 * Holds the rest class.
28 37 *
29 38 * @access public
30 39 * @since 1.0.0
@@ -41,8 +50,17 @@
41 50 */
42 51 public $admin;
43 52
44 53 /**
54 + * Holds the Dam class.
55 + *
56 + * @access public
57 + * @since 4.0
58 + * @var Optml_Dam Dam instance.
59 + */
60 + public $dam;
61 +
62 + /**
45 63 * Holds the cli class.
46 64 *
47 65 * @access public
48 66 * @since 1.0.0
@@ -50,13 +68,21 @@
50 68 */
51 69 public $cli;
52 70
53 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 + /**
54 80 * Optml_Main constructor.
55 81 */
56 82 public function __construct() {
57 -
58 - register_activation_hook( OPTML_BASEFILE, array( $this, 'activate' ) );
83 + register_activation_hook( OPTML_BASEFILE, [ $this, 'activate' ] );
84 + register_deactivation_hook( OPTML_BASEFILE, [ $this, 'deactivate' ] );
59 85 }
60 86
61 87 /**
62 88 * Main Starter_Plugin Instance
@@ -66,28 +92,33 @@
66 92 * @return Optml_Main Plugin instance.
67 93 * @since 1.0.0
68 94 */
69 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 +
70 101 if ( null === self::$_instance ) {
71 - add_filter( 'themeisle_sdk_products', array( __CLASS__, 'register_sdk' ) );
72 - add_filter( 'optimole-wp_uninstall_feedback_icon', array( __CLASS__, 'change_icon' ) );
73 - add_filter( 'optimole_wp_uninstall_feedback_after_css', array( __CLASS__, 'adds_uf_css' ) );
74 - add_filter( 'optimole_wp_feedback_review_message', array( __CLASS__, 'change_review_message' ) );
75 - add_filter( 'optimole_wp_logger_heading', array( __CLASS__, 'change_review_message' ) );
76 - add_filter( 'optml_default_settings', array( __CLASS__, 'change_lazyload_default' ) );
77 - add_filter( 'optml_register_conflicts', array( __CLASS__, 'register_conflicts' ) );
102 + add_filter( 'themeisle_sdk_products', [ __CLASS__, 'register_sdk' ] );
103 + add_filter( 'themeisle_sdk_ran_promos', [ __CLASS__, 'sdk_hide_promo_notice' ] );
104 + add_filter( 'optimole-wp_uninstall_feedback_icon', [ __CLASS__, 'change_icon' ] );
105 + add_filter( 'optimole_wp_uninstall_feedback_after_css', [ __CLASS__, 'adds_uf_css' ] );
106 + add_filter( 'optimole_wp_feedback_review_message', [ __CLASS__, 'change_review_message' ] );
107 + add_filter( 'optimole_wp_logger_heading', [ __CLASS__, 'change_review_message' ] );
108 + add_filter( 'optml_register_conflicts', [ __CLASS__, 'register_conflicts' ] );
109 + add_filter( 'optimole_wp_logger_data', [ __CLASS__, 'add_settings' ] );
78 110 self::$_instance = new self();
79 111 self::$_instance->manager = Optml_Manager::instance();
80 112 self::$_instance->rest = new Optml_Rest();
81 113 self::$_instance->admin = new Optml_Admin();
114 + self::$_instance->dam = new Optml_Dam();
115 + self::$_instance->media_offload = Optml_Media_Offload::instance();
116 + self::$_instance->video_player = new Optml_Video_Player();
82 117 if ( class_exists( 'WP_CLI' ) ) {
83 118 self::$_instance->cli = new Optml_Cli();
84 119 }
85 120 }
86 - $vendor_file = OPTML_PATH . 'vendor/autoload.php';
87 - if ( is_readable( $vendor_file ) ) {
88 - include_once $vendor_file;
89 - }
90 121
91 122 return self::$_instance;
92 123 }
93 124
@@ -99,20 +130,21 @@
99 130 * @return array
100 131 * @since 2.0.6
101 132 * @access public
102 133 */
103 - public static function register_conflicts( $conflicts_to_register = array() ) {
134 + public static function register_conflicts( $conflicts_to_register = [] ) {
104 135 $conflicts_to_register = array_merge(
105 136 $conflicts_to_register,
106 - array(
107 - 'Optml_Elementor',
108 - 'Optml_Beaver',
137 + [
109 138 'Optml_Jetpack_Photon',
110 - 'Optml_Jetpack_Lazyload',
111 139 'Optml_Wprocket',
112 140 'Optml_Divi',
113 141 'Optml_w3_total_cache_cdn',
114 - )
142 + 'Optml_Smush',
143 + 'Optml_Litespeed',
144 + 'Optml_Autoptimize',
145 + 'Optml_Perfmatters',
146 + ]
115 147 );
116 148
117 149 return $conflicts_to_register;
118 150 }
@@ -117,26 +149,23 @@
117 149 return $conflicts_to_register;
118 150 }
119 151
120 152 /**
121 - * Change lazyload default for new users.
153 + * Add settings to the logger data.
122 154 *
123 - * @param array $defaults Old defaults.
155 + * @param array $data Logger data.
124 156 *
125 - * @return array New defaults.
157 + * @return array
126 158 */
127 - public static function change_lazyload_default( $defaults ) {
128 - $install_time = get_option( 'optimole_wp_install', 0 );
159 + public static function add_settings( $data ): array {
160 + $data = is_array( $data ) ? $data : [];
129 161
130 - if ( $install_time < 1545652321 ) {
131 - return $defaults;
132 - }
162 + $saved_data = ( new Optml_Settings() )->get_raw_settings();
163 + unset( $saved_data['service_data'] );
164 + unset( $saved_data['api_key'] );
133 165
134 - $defaults['lazyload'] = 'enabled';
135 -
136 - return $defaults;
166 + return array_merge( $data, $saved_data );
137 167 }
138 -
139 168 /**
140 169 * Change review message.
141 170 *
142 171 * @param string $message Old review message.
@@ -205,9 +234,8 @@
205 234 * @access public
206 235 * @since 1.0.0
207 236 */
208 237 public function activate() {
209 -
210 238 update_option( OPTML_NAMESPACE . '-version', OPTML_VERSION );
211 239
212 240 if ( is_multisite() ) {
213 241 return;
@@ -216,8 +244,20 @@
216 244 set_transient( 'optml_fresh_install', true, MINUTE_IN_SECONDS );
217 245 }
218 246
219 247 /**
248 + * Deactivate routine actions.
249 + *
250 + * @access public
251 + * @since 3.11.0
252 + */
253 + public function deactivate() {
254 + // Clear registered cron events.
255 + wp_clear_scheduled_hook( 'optml_daily_sync' );
256 + wp_clear_scheduled_hook( 'optml_pull_image_data_init' );
257 + }
258 +
259 + /**
220 260 * Cloning is forbidden.
221 261 *
222 262 * @access public
223 263 * @since 1.0.0
@@ -235,5 +275,19 @@
235 275 public function __wakeup() {
236 276 _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'optimole-wp' ), '1.0.0' );
237 277 }
238 278
279 + /**
280 + * Hide SDK promo notice for pro uses.
281 + *
282 + * @access public
283 + */
284 + public static function sdk_hide_promo_notice( $should_show ) {
285 + if ( self::$_instance->admin->settings->is_connected() ) {
286 + $service_data = self::$_instance->admin->settings->get( 'service_data' );
287 + if ( isset( $service_data['plan'] ) && 'free' !== $service_data['plan'] ) {
288 + return true;
289 + }
290 + }
291 + return $should_show;
292 + }
239 293 }