PluginProbe
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization / 3.1.1
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization v3.1.1
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
optimole-wp / inc / main.php

main.php in Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization 3.1.1, at inc/main.php

241 lines 5.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Main Plugin Class
5 */
6 final class Optml_Main {
7 /**
8 * Optml_Main The single instance of Starter_Plugin.
9 *
10 * @var object
11 * @access private
12 * @since 1.0.0
13 */
14 private static $_instance = null;
15
16
17 /**
18 * Holds the manager class.
19 *
20 * @access public
21 * @since 1.0.0
22 * @var Optml_Manager Manager instance.
23 */
24 public $manager;
25
26 /**
27 * Holds the rest class.
28 *
29 * @access public
30 * @since 1.0.0
31 * @var Optml_Rest REST instance.
32 */
33 public $rest;
34
35 /**
36 * Holds the admin class.
37 *
38 * @access public
39 * @since 1.0.0
40 * @var Optml_Admin Admin instance.
41 */
42 public $admin;
43
44 /**
45 * Holds the cli class.
46 *
47 * @access public
48 * @since 1.0.0
49 * @var Optml_Cli Cli instance.
50 */
51 public $cli;
52
53 /**
54 * Optml_Main constructor.
55 */
56 public function __construct() {
57
58 register_activation_hook( OPTML_BASEFILE, [ $this, 'activate' ] );
59 }
60
61 /**
62 * Main Starter_Plugin Instance
63 *
64 * Ensures only one instance of Starter_Plugin is loaded or can be loaded.
65 *
66 * @return Optml_Main Plugin instance.
67 * @since 1.0.0
68 */
69 public static function instance() {
70 if ( null === self::$_instance ) {
71 add_filter( 'themeisle_sdk_products', [ __CLASS__, 'register_sdk' ] );
72 add_filter( 'optimole-wp_uninstall_feedback_icon', [ __CLASS__, 'change_icon' ] );
73 add_filter( 'optimole_wp_uninstall_feedback_after_css', [ __CLASS__, 'adds_uf_css' ] );
74 add_filter( 'optimole_wp_feedback_review_message', [ __CLASS__, 'change_review_message' ] );
75 add_filter( 'optimole_wp_logger_heading', [ __CLASS__, 'change_review_message' ] );
76 add_filter( 'optml_default_settings', [ __CLASS__, 'change_lazyload_default' ] );
77 add_filter( 'optml_register_conflicts', [ __CLASS__, 'register_conflicts' ] );
78 self::$_instance = new self();
79 self::$_instance->manager = Optml_Manager::instance();
80 self::$_instance->rest = new Optml_Rest();
81 self::$_instance->admin = new Optml_Admin();
82 self::$_instance->media_offload = new Optml_Media_Offload();
83 if ( class_exists( 'WP_CLI' ) ) {
84 self::$_instance->cli = new Optml_Cli();
85 }
86 }
87 $vendor_file = OPTML_PATH . 'vendor/autoload.php';
88 if ( is_readable( $vendor_file ) ) {
89 include_once $vendor_file;
90 }
91
92 return self::$_instance;
93 }
94
95 /**
96 * Register Conflicts to watch for
97 *
98 * @param array $conflicts_to_register A list of class names of conflicts to register.
99 *
100 * @return array
101 * @since 2.0.6
102 * @access public
103 */
104 public static function register_conflicts( $conflicts_to_register = [] ) {
105 $conflicts_to_register = array_merge(
106 $conflicts_to_register,
107 [
108 'Optml_Elementor',
109 'Optml_Beaver',
110 'Optml_Jetpack_Photon',
111 'Optml_Jetpack_Lazyload',
112 'Optml_Wprocket',
113 'Optml_Divi',
114 'Optml_w3_total_cache_cdn',
115 ]
116 );
117
118 return $conflicts_to_register;
119 }
120
121 /**
122 * Change lazyload default for new users.
123 *
124 * @param array $defaults Old defaults.
125 *
126 * @return array New defaults.
127 */
128 public static function change_lazyload_default( $defaults ) {
129 $install_time = get_option( 'optimole_wp_install', 0 );
130
131 if ( $install_time < 1545652321 ) {
132 return $defaults;
133 }
134
135 $defaults['lazyload'] = 'enabled';
136
137 return $defaults;
138 }
139
140 /**
141 * Change review message.
142 *
143 * @param string $message Old review message.
144 *
145 * @return string New review message.
146 */
147 public static function change_review_message( $message ) {
148 return str_replace( '{product}', 'Optimole', $message );
149 }
150
151 /**
152 * Register product into SDK.
153 *
154 * @param array $products All products.
155 *
156 * @return array Registered product.
157 */
158 public static function register_sdk( $products ) {
159 $products[] = OPTML_BASEFILE;
160
161 return $products;
162 }
163
164 /**
165 * Adds aditional CSS for uninstall feedback popup.
166 */
167 public static function adds_uf_css() {
168 ?>
169 <style type="text/css">
170 body.plugins-php .optimole_wp-container #TB_title {
171 background-position: 30px 10px;
172 background-size: 80px;
173 }
174
175 body.plugins-php .optimole_wp-container input.button:hover,
176 body.plugins-php .optimole_wp-container input.button {
177 background: #5080C1;
178 }
179 </style>
180 <?php
181 }
182
183 /**
184 * Change icon for uninstall feedback.
185 *
186 * @return string Registered product.
187 */
188 public static function change_icon( $old_icon ) {
189
190 return OPTML_URL . 'assets/img/logo.png';
191 }
192
193 /**
194 * Load the localisation file.
195 *
196 * @access public
197 * @since 1.0.0
198 */
199 public function load_plugin_textdomain() {
200 load_plugin_textdomain( 'optimole-wp', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
201 }
202
203 /**
204 * Install routine actions.
205 *
206 * @access public
207 * @since 1.0.0
208 */
209 public function activate() {
210
211 update_option( OPTML_NAMESPACE . '-version', OPTML_VERSION );
212
213 if ( is_multisite() ) {
214 return;
215 }
216
217 set_transient( 'optml_fresh_install', true, MINUTE_IN_SECONDS );
218 }
219
220 /**
221 * Cloning is forbidden.
222 *
223 * @access public
224 * @since 1.0.0
225 */
226 public function __clone() {
227 _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'optimole-wp' ), '1.0.0' );
228 }
229
230 /**
231 * Unserializing instances of this class is forbidden.
232 *
233 * @access public
234 * @since 1.0.0
235 */
236 public function __wakeup() {
237 _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'optimole-wp' ), '1.0.0' );
238 }
239
240 }
241