| 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 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 |
/** |
| 36 |
* Holds the rest class. |
| 37 |
* |
| 38 |
* @access public |
| 39 |
* @since 1.0.0 |
| 40 |
* @var Optml_Rest REST instance. |
| 41 |
*/ |
| 42 |
public $rest; |
| 43 |
|
| 44 |
/** |
| 45 |
* Holds the admin class. |
| 46 |
* |
| 47 |
* @access public |
| 48 |
* @since 1.0.0 |
| 49 |
* @var Optml_Admin Admin instance. |
| 50 |
*/ |
| 51 |
public $admin; |
| 52 |
|
| 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 |
/** |
| 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 |
* Optml_Main constructor. |
| 73 |
*/ |
| 74 |
public function __construct() { |
| 75 |
register_activation_hook( OPTML_BASEFILE, [ $this, 'activate' ] ); |
| 76 |
register_deactivation_hook( OPTML_BASEFILE, [ $this, 'deactivate' ] ); |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* Main Starter_Plugin Instance |
| 81 |
* |
| 82 |
* Ensures only one instance of Starter_Plugin is loaded or can be loaded. |
| 83 |
* |
| 84 |
* @return Optml_Main Plugin instance. |
| 85 |
* @since 1.0.0 |
| 86 |
*/ |
| 87 |
public static function instance() { |
| 88 |
if ( null === self::$_instance ) { |
| 89 |
add_filter( 'themeisle_sdk_products', [ __CLASS__, 'register_sdk' ] ); |
| 90 |
add_filter( 'themeisle_sdk_ran_promos', '__return_true' ); |
| 91 |
add_filter( 'optimole-wp_uninstall_feedback_icon', [ __CLASS__, 'change_icon' ] ); |
| 92 |
add_filter( 'optimole_wp_uninstall_feedback_after_css', [ __CLASS__, 'adds_uf_css' ] ); |
| 93 |
add_filter( 'optimole_wp_feedback_review_message', [ __CLASS__, 'change_review_message' ] ); |
| 94 |
add_filter( 'optimole_wp_logger_heading', [ __CLASS__, 'change_review_message' ] ); |
| 95 |
add_filter( 'optml_register_conflicts', [ __CLASS__, 'register_conflicts' ] ); |
| 96 |
self::$_instance = new self(); |
| 97 |
self::$_instance->manager = Optml_Manager::instance(); |
| 98 |
self::$_instance->rest = new Optml_Rest(); |
| 99 |
self::$_instance->admin = new Optml_Admin(); |
| 100 |
self::$_instance->dam = new Optml_Dam(); |
| 101 |
self::$_instance->media_offload = Optml_Media_Offload::instance(); |
| 102 |
if ( class_exists( 'WP_CLI' ) ) { |
| 103 |
self::$_instance->cli = new Optml_Cli(); |
| 104 |
} |
| 105 |
} |
| 106 |
$vendor_file = OPTML_PATH . 'vendor/autoload.php'; |
| 107 |
if ( is_readable( $vendor_file ) ) { |
| 108 |
include_once $vendor_file; |
| 109 |
} |
| 110 |
|
| 111 |
return self::$_instance; |
| 112 |
} |
| 113 |
|
| 114 |
/** |
| 115 |
* Register Conflicts to watch for |
| 116 |
* |
| 117 |
* @param array $conflicts_to_register A list of class names of conflicts to register. |
| 118 |
* |
| 119 |
* @return array |
| 120 |
* @since 2.0.6 |
| 121 |
* @access public |
| 122 |
*/ |
| 123 |
public static function register_conflicts( $conflicts_to_register = [] ) { |
| 124 |
$conflicts_to_register = array_merge( |
| 125 |
$conflicts_to_register, |
| 126 |
[ |
| 127 |
'Optml_Jetpack_Photon', |
| 128 |
'Optml_Jetpack_Lazyload', |
| 129 |
'Optml_Wprocket', |
| 130 |
'Optml_Divi', |
| 131 |
'Optml_w3_total_cache_cdn', |
| 132 |
] |
| 133 |
); |
| 134 |
|
| 135 |
return $conflicts_to_register; |
| 136 |
} |
| 137 |
|
| 138 |
/** |
| 139 |
* Change review message. |
| 140 |
* |
| 141 |
* @param string $message Old review message. |
| 142 |
* |
| 143 |
* @return string New review message. |
| 144 |
*/ |
| 145 |
public static function change_review_message( $message ) { |
| 146 |
return str_replace( '{product}', 'Optimole', $message ); |
| 147 |
} |
| 148 |
|
| 149 |
/** |
| 150 |
* Register product into SDK. |
| 151 |
* |
| 152 |
* @param array $products All products. |
| 153 |
* |
| 154 |
* @return array Registered product. |
| 155 |
*/ |
| 156 |
public static function register_sdk( $products ) { |
| 157 |
$products[] = OPTML_BASEFILE; |
| 158 |
|
| 159 |
return $products; |
| 160 |
} |
| 161 |
|
| 162 |
/** |
| 163 |
* Adds aditional CSS for uninstall feedback popup. |
| 164 |
*/ |
| 165 |
public static function adds_uf_css() { |
| 166 |
?> |
| 167 |
<style type="text/css"> |
| 168 |
body.plugins-php .optimole_wp-container #TB_title { |
| 169 |
background-position: 30px 10px; |
| 170 |
background-size: 80px; |
| 171 |
} |
| 172 |
|
| 173 |
body.plugins-php .optimole_wp-container input.button:hover, |
| 174 |
body.plugins-php .optimole_wp-container input.button { |
| 175 |
background: #5080C1; |
| 176 |
} |
| 177 |
</style> |
| 178 |
<?php |
| 179 |
} |
| 180 |
|
| 181 |
/** |
| 182 |
* Change icon for uninstall feedback. |
| 183 |
* |
| 184 |
* @return string Registered product. |
| 185 |
*/ |
| 186 |
public static function change_icon( $old_icon ) { |
| 187 |
|
| 188 |
return OPTML_URL . 'assets/img/logo.png'; |
| 189 |
} |
| 190 |
|
| 191 |
/** |
| 192 |
* Load the localisation file. |
| 193 |
* |
| 194 |
* @access public |
| 195 |
* @since 1.0.0 |
| 196 |
*/ |
| 197 |
public function load_plugin_textdomain() { |
| 198 |
load_plugin_textdomain( 'optimole-wp', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); |
| 199 |
} |
| 200 |
|
| 201 |
/** |
| 202 |
* Install routine actions. |
| 203 |
* |
| 204 |
* @access public |
| 205 |
* @since 1.0.0 |
| 206 |
*/ |
| 207 |
public function activate() { |
| 208 |
update_option( OPTML_NAMESPACE . '-version', OPTML_VERSION ); |
| 209 |
|
| 210 |
if ( is_multisite() ) { |
| 211 |
return; |
| 212 |
} |
| 213 |
|
| 214 |
set_transient( 'optml_fresh_install', true, MINUTE_IN_SECONDS ); |
| 215 |
} |
| 216 |
|
| 217 |
/** |
| 218 |
* Deactivate routine actions. |
| 219 |
* |
| 220 |
* @access public |
| 221 |
* @since 3.11.0 |
| 222 |
*/ |
| 223 |
public function deactivate() { |
| 224 |
// Clear registered cron events. |
| 225 |
wp_clear_scheduled_hook( 'optml_daily_sync' ); |
| 226 |
wp_clear_scheduled_hook( 'optml_pull_image_data_init' ); |
| 227 |
} |
| 228 |
|
| 229 |
/** |
| 230 |
* Cloning is forbidden. |
| 231 |
* |
| 232 |
* @access public |
| 233 |
* @since 1.0.0 |
| 234 |
*/ |
| 235 |
public function __clone() { |
| 236 |
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'optimole-wp' ), '1.0.0' ); |
| 237 |
} |
| 238 |
|
| 239 |
/** |
| 240 |
* Unserializing instances of this class is forbidden. |
| 241 |
* |
| 242 |
* @access public |
| 243 |
* @since 1.0.0 |
| 244 |
*/ |
| 245 |
public function __wakeup() { |
| 246 |
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'optimole-wp' ), '1.0.0' ); |
| 247 |
} |
| 248 |
|
| 249 |
} |
| 250 |
|