PluginProbe
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization / 2.5.5
Optimole – Optimize Images | Convert WebP & AVIF | CDN & Lazy Load | Image Optimization v2.5.5
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 2.5.5, at inc/main.php

240 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, array( $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', 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' ) );
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 if ( class_exists( 'WP_CLI' ) ) {
83 self::$_instance->cli = new Optml_Cli();
84 }
85 }
86 $vendor_file = OPTML_PATH . 'vendor/autoload.php';
87 if ( is_readable( $vendor_file ) ) {
88 include_once $vendor_file;
89 }
90
91 return self::$_instance;
92 }
93
94 /**
95 * Register Conflicts to watch for
96 *
97 * @param array $conflicts_to_register A list of class names of conflicts to register.
98 *
99 * @return array
100 * @since 2.0.6
101 * @access public
102 */
103 public static function register_conflicts( $conflicts_to_register = array() ) {
104 $conflicts_to_register = array_merge(
105 $conflicts_to_register,
106 array(
107 'Optml_Elementor',
108 'Optml_Beaver',
109 'Optml_Jetpack_Photon',
110 'Optml_Jetpack_Lazyload',
111 'Optml_Wprocket',
112 'Optml_Divi',
113 'Optml_w3_total_cache_cdn',
114 )
115 );
116
117 return $conflicts_to_register;
118 }
119
120 /**
121 * Change lazyload default for new users.
122 *
123 * @param array $defaults Old defaults.
124 *
125 * @return array New defaults.
126 */
127 public static function change_lazyload_default( $defaults ) {
128 $install_time = get_option( 'optimole_wp_install', 0 );
129
130 if ( $install_time < 1545652321 ) {
131 return $defaults;
132 }
133
134 $defaults['lazyload'] = 'enabled';
135
136 return $defaults;
137 }
138
139 /**
140 * Change review message.
141 *
142 * @param string $message Old review message.
143 *
144 * @return string New review message.
145 */
146 public static function change_review_message( $message ) {
147 return str_replace( '{product}', 'Optimole', $message );
148 }
149
150 /**
151 * Register product into SDK.
152 *
153 * @param array $products All products.
154 *
155 * @return array Registered product.
156 */
157 public static function register_sdk( $products ) {
158 $products[] = OPTML_BASEFILE;
159
160 return $products;
161 }
162
163 /**
164 * Adds aditional CSS for uninstall feedback popup.
165 */
166 public static function adds_uf_css() {
167 ?>
168 <style type="text/css">
169 body.plugins-php .optimole_wp-container #TB_title {
170 background-position: 30px 10px;
171 background-size: 80px;
172 }
173
174 body.plugins-php .optimole_wp-container input.button:hover,
175 body.plugins-php .optimole_wp-container input.button {
176 background: #5080C1;
177 }
178 </style>
179 <?php
180 }
181
182 /**
183 * Change icon for uninstall feedback.
184 *
185 * @return string Registered product.
186 */
187 public static function change_icon( $old_icon ) {
188
189 return OPTML_URL . 'assets/img/logo.png';
190 }
191
192 /**
193 * Load the localisation file.
194 *
195 * @access public
196 * @since 1.0.0
197 */
198 public function load_plugin_textdomain() {
199 load_plugin_textdomain( 'optimole-wp', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
200 }
201
202 /**
203 * Install routine actions.
204 *
205 * @access public
206 * @since 1.0.0
207 */
208 public function activate() {
209
210 update_option( OPTML_NAMESPACE . '-version', OPTML_VERSION );
211
212 if ( is_multisite() ) {
213 return;
214 }
215
216 set_transient( 'optml_fresh_install', true, MINUTE_IN_SECONDS );
217 }
218
219 /**
220 * Cloning is forbidden.
221 *
222 * @access public
223 * @since 1.0.0
224 */
225 public function __clone() {
226 _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'optimole-wp' ), '1.0.0' );
227 }
228
229 /**
230 * Unserializing instances of this class is forbidden.
231 *
232 * @access public
233 * @since 1.0.0
234 */
235 public function __wakeup() {
236 _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'optimole-wp' ), '1.0.0' );
237 }
238
239 }
240