| @@ -6,42 +6,30 @@ | ||
| 6 | 6 | final class Optml_Main { |
| 7 | 7 | /** |
| 8 | 8 | * Optml_Main The single instance of Starter_Plugin. |
| 9 | 9 | * |
| 10 | - * @var Optml_Main|null | |
| 10 | + * @var object | |
| 11 | 11 | * @access private |
| 12 | 12 | * @since 1.0.0 |
| 13 | 13 | */ |
| 14 | 14 | private static $_instance = null; |
| 15 | 15 | |
| 16 | - | |
| 17 | 16 | /** |
| 18 | - * Holds the manager class. | |
| 17 | + * Holds the replacer class. | |
| 19 | 18 | * |
| 20 | 19 | * @access public |
| 21 | 20 | * @since 1.0.0 |
| 22 | - * @var Optml_Manager Manager instance. | |
| 21 | + * @var Optml_Replacer Replacer instance. | |
| 23 | 22 | */ |
| 24 | - public $manager; | |
| 25 | - | |
| 23 | + public $replacer; | |
| 26 | 24 | /** |
| 27 | - * Holds the media_offload class. | |
| 25 | + * Holds the replacer class. | |
| 28 | 26 | * |
| 29 | 27 | * @access public |
| 30 | 28 | * @since 1.0.0 |
| 31 | - * @var Optml_Media_Offload instance. | |
| 29 | + * @var Optml_Rest Replacer instance. | |
| 32 | 30 | */ |
| 33 | - public $media_offload; | |
| 34 | - | |
| 35 | - /** | |
| 36 | - * Holds the rest class. | |
| 37 | - * | |
| 38 | - * @access public | |
| 39 | - * @since 1.0.0 | |
| 40 | - * @var Optml_Rest REST instance. | |
| 41 | - */ | |
| 42 | 31 | public $rest; |
| 43 | - | |
| 44 | 32 | /** |
| 45 | 33 | * Holds the admin class. |
| 46 | 34 | * |
| 47 | 35 | * @access public |
| @@ -50,39 +38,13 @@ | ||
| 50 | 38 | */ |
| 51 | 39 | public $admin; |
| 52 | 40 | |
| 53 | 41 | /** |
| 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 | - /** | |
| 63 | - * Holds the cli class. | |
| 64 | - * | |
| 65 | - * @access public | |
| 66 | - * @since 1.0.0 | |
| 67 | - * @var Optml_Cli Cli instance. | |
| 68 | - */ | |
| 69 | - public $cli; | |
| 70 | - | |
| 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 | - /** | |
| 80 | 42 | * Optml_Main constructor. |
| 81 | 43 | */ |
| 82 | 44 | public function __construct() { |
| 83 | - register_activation_hook( OPTML_BASEFILE, [ $this, 'activate' ] ); | |
| 84 | - register_deactivation_hook( OPTML_BASEFILE, [ $this, 'deactivate' ] ); | |
| 45 | + | |
| 46 | + register_activation_hook( OPTML_BASEFILE, array( $this, 'activate' ) ); | |
| 85 | 47 | } |
| 86 | 48 | |
| 87 | 49 | /** |
| 88 | 50 | * Main Starter_Plugin Instance |
| @@ -88,138 +50,23 @@ | ||
| 88 | 50 | * Main Starter_Plugin Instance |
| 89 | 51 | * |
| 90 | 52 | * Ensures only one instance of Starter_Plugin is loaded or can be loaded. |
| 91 | 53 | * |
| 54 | + * @since 1.0.0 | |
| 92 | 55 | * @return Optml_Main Plugin instance. |
| 93 | - * @since 1.0.0 | |
| 94 | 56 | */ |
| 95 | 57 | public static function instance() { |
| 96 | - $vendor_file = OPTML_PATH . 'vendor/autoload.php'; | |
| 97 | - if ( is_readable( $vendor_file ) ) { | |
| 98 | - include_once $vendor_file; | |
| 58 | + if ( is_null( self::$_instance ) ) { | |
| 59 | + self::$_instance = new self(); | |
| 60 | + self::$_instance->replacer = Optml_Replacer::instance(); | |
| 61 | + self::$_instance->rest = new Optml_Rest(); | |
| 62 | + self::$_instance->admin = new Optml_Admin(); | |
| 99 | 63 | } |
| 100 | 64 | |
| 101 | - if ( null === self::$_instance ) { | |
| 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' ] ); | |
| 110 | - self::$_instance = new self(); | |
| 111 | - self::$_instance->manager = Optml_Manager::instance(); | |
| 112 | - self::$_instance->rest = new Optml_Rest(); | |
| 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(); | |
| 117 | - if ( class_exists( 'WP_CLI' ) ) { | |
| 118 | - self::$_instance->cli = new Optml_Cli(); | |
| 119 | - } | |
| 120 | - } | |
| 121 | - | |
| 122 | 65 | return self::$_instance; |
| 123 | 66 | } |
| 124 | 67 | |
| 125 | 68 | /** |
| 126 | - * Register Conflicts to watch for | |
| 127 | - * | |
| 128 | - * @param array $conflicts_to_register A list of class names of conflicts to register. | |
| 129 | - * | |
| 130 | - * @return array | |
| 131 | - * @since 2.0.6 | |
| 132 | - * @access public | |
| 133 | - */ | |
| 134 | - public static function register_conflicts( $conflicts_to_register = [] ) { | |
| 135 | - $conflicts_to_register = array_merge( | |
| 136 | - $conflicts_to_register, | |
| 137 | - [ | |
| 138 | - 'Optml_Jetpack_Photon', | |
| 139 | - 'Optml_Wprocket', | |
| 140 | - 'Optml_Divi', | |
| 141 | - 'Optml_w3_total_cache_cdn', | |
| 142 | - 'Optml_Smush', | |
| 143 | - 'Optml_Litespeed', | |
| 144 | - 'Optml_Autoptimize', | |
| 145 | - 'Optml_Perfmatters', | |
| 146 | - ] | |
| 147 | - ); | |
| 148 | - | |
| 149 | - return $conflicts_to_register; | |
| 150 | - } | |
| 151 | - | |
| 152 | - /** | |
| 153 | - * Add settings to the logger data. | |
| 154 | - * | |
| 155 | - * @param array $data Logger data. | |
| 156 | - * | |
| 157 | - * @return array | |
| 158 | - */ | |
| 159 | - public static function add_settings( $data ): array { | |
| 160 | - $data = is_array( $data ) ? $data : []; | |
| 161 | - | |
| 162 | - $saved_data = ( new Optml_Settings() )->get_raw_settings(); | |
| 163 | - unset( $saved_data['service_data'] ); | |
| 164 | - unset( $saved_data['api_key'] ); | |
| 165 | - | |
| 166 | - return array_merge( $data, $saved_data ); | |
| 167 | - } | |
| 168 | - /** | |
| 169 | - * Change review message. | |
| 170 | - * | |
| 171 | - * @param string $message Old review message. | |
| 172 | - * | |
| 173 | - * @return string New review message. | |
| 174 | - */ | |
| 175 | - public static function change_review_message( $message ) { | |
| 176 | - return str_replace( '{product}', 'Optimole', $message ); | |
| 177 | - } | |
| 178 | - | |
| 179 | - /** | |
| 180 | - * Register product into SDK. | |
| 181 | - * | |
| 182 | - * @param array $products All products. | |
| 183 | - * | |
| 184 | - * @return array Registered product. | |
| 185 | - */ | |
| 186 | - public static function register_sdk( $products ) { | |
| 187 | - $products[] = OPTML_BASEFILE; | |
| 188 | - | |
| 189 | - return $products; | |
| 190 | - } | |
| 191 | - | |
| 192 | - /** | |
| 193 | - * Adds aditional CSS for uninstall feedback popup. | |
| 194 | - */ | |
| 195 | - public static function adds_uf_css() { | |
| 196 | - ?> | |
| 197 | - <style type="text/css"> | |
| 198 | - body.plugins-php .optimole_wp-container #TB_title { | |
| 199 | - background-position: 30px 10px; | |
| 200 | - background-size: 80px; | |
| 201 | - } | |
| 202 | - | |
| 203 | - body.plugins-php .optimole_wp-container input.button:hover, | |
| 204 | - body.plugins-php .optimole_wp-container input.button { | |
| 205 | - background: #5080C1; | |
| 206 | - } | |
| 207 | - </style> | |
| 208 | - <?php | |
| 209 | - } | |
| 210 | - | |
| 211 | - /** | |
| 212 | - * Change icon for uninstall feedback. | |
| 213 | - * | |
| 214 | - * @return string Registered product. | |
| 215 | - */ | |
| 216 | - public static function change_icon( $old_icon ) { | |
| 217 | - | |
| 218 | - return OPTML_URL . 'assets/img/logo.png'; | |
| 219 | - } | |
| 220 | - | |
| 221 | - /** | |
| 222 | 69 | * Load the localisation file. |
| 223 | 70 | * |
| 224 | 71 | * @access public |
| 225 | 72 | * @since 1.0.0 |
| @@ -234,8 +81,9 @@ | ||
| 234 | 81 | * @access public |
| 235 | 82 | * @since 1.0.0 |
| 236 | 83 | */ |
| 237 | 84 | public function activate() { |
| 85 | + | |
| 238 | 86 | update_option( OPTML_NAMESPACE . '-version', OPTML_VERSION ); |
| 239 | 87 | |
| 240 | 88 | if ( is_multisite() ) { |
| 241 | 89 | return; |
| @@ -244,20 +92,8 @@ | ||
| 244 | 92 | set_transient( 'optml_fresh_install', true, MINUTE_IN_SECONDS ); |
| 245 | 93 | } |
| 246 | 94 | |
| 247 | 95 | /** |
| 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 | - /** | |
| 260 | 96 | * Cloning is forbidden. |
| 261 | 97 | * |
| 262 | 98 | * @access public |
| 263 | 99 | * @since 1.0.0 |
| @@ -275,19 +111,5 @@ | ||
| 275 | 111 | public function __wakeup() { |
| 276 | 112 | _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'optimole-wp' ), '1.0.0' ); |
| 277 | 113 | } |
| 278 | 114 | |
| 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 | - } | |
| 293 | 115 | } |