| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | if ( !class_exists('Easy_HTTPS_SSL') ) { |
|---|
| 4 | class Easy_HTTPS_SSL |
|---|
| 5 | { |
|---|
| 6 | public $plugin_url; |
|---|
| 7 | public $plugin_path; |
|---|
| 8 | public $plugin_configs;//TODO - does it need to be static? |
|---|
| 9 | public $admin_init; |
|---|
| 10 | public $debug_logger; |
|---|
| 11 | |
|---|
| 12 | public function __construct() { |
|---|
| 13 | $this->load_configs(); |
|---|
| 14 | $this->define_constants(); |
|---|
| 15 | $this->includes(); |
|---|
| 16 | $this->initialize_and_run_classes(); |
|---|
| 17 | |
|---|
| 18 | // Register action hooks. |
|---|
| 19 | add_action('plugins_loaded', array($this, 'plugins_loaded_handler')); |
|---|
| 20 | // Note: There is a init time tasks class which will do other init time tasks. |
|---|
| 21 | add_action('init', array($this, 'ehssl_load_language')); |
|---|
| 22 | |
|---|
| 23 | // Trigger EHSSL plugin loaded action. |
|---|
| 24 | do_action('ehssl_loaded'); |
|---|
| 25 | } |
|---|
| 26 | |
|---|
| 27 | public function plugin_url() { |
|---|
| 28 | if ($this->plugin_url) { |
|---|
| 29 | return $this->plugin_url; |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | return $this->plugin_url = plugins_url(basename(plugin_dir_path(__FILE__)), basename(__FILE__)); |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | public function plugin_path() { |
|---|
| 36 | if ($this->plugin_path) { |
|---|
| 37 | return $this->plugin_path; |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | return $this->plugin_path = untrailingslashit(plugin_dir_path(__FILE__)); |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | public function load_configs() { |
|---|
| 44 | include_once 'classes/ehssl-config.php'; |
|---|
| 45 | $this->plugin_configs = EHSSL_Config::get_instance(); |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | public function define_constants() { |
|---|
| 49 | define('EASY_HTTPS_SSL_URL', $this->plugin_url()); |
|---|
| 50 | define('EASY_HTTPS_SSL_PATH', $this->plugin_path()); |
|---|
| 51 | define('EHSSL_MANAGEMENT_PERMISSION', 'add_users'); |
|---|
| 52 | define('EHSSL_MENU_SLUG_PREFIX', 'ehssl'); |
|---|
| 53 | define('EHSSL_MAIN_MENU_SLUG', 'ehssl'); |
|---|
| 54 | define('EHSSL_SETTINGS_MENU_SLUG', 'ehssl_settings'); |
|---|
| 55 | define('EHSSL_CERTIFICATE_EXPIRY_MENU_SLUG', 'ehssl_certificate_expiry'); |
|---|
| 56 | define('EHSSL_SSL_MGMT_MENU_SLUG', 'ehssl-ssl-mgmt'); |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | public function includes() { |
|---|
| 60 | //Load common files for everywhere |
|---|
| 61 | include_once EASY_HTTPS_SSL_PATH . '/classes/ehssl-debug-logger.php'; |
|---|
| 62 | include_once EASY_HTTPS_SSL_PATH . '/classes/utilities/ehssl-utils.php'; |
|---|
| 63 | include_once EASY_HTTPS_SSL_PATH . '/classes/utilities/ehssl-ssl-utils.php'; |
|---|
| 64 | include_once EASY_HTTPS_SSL_PATH . '/classes/ehssl-cronjob.php'; |
|---|
| 65 | include_once EASY_HTTPS_SSL_PATH . '/classes/ehssl-custom-post-types.php'; |
|---|
| 66 | include_once EASY_HTTPS_SSL_PATH . '/classes/ehssl-email-handler.php'; |
|---|
| 67 | include_once EASY_HTTPS_SSL_PATH . '/classes/ehssl-init-time-tasks.php'; |
|---|
| 68 | |
|---|
| 69 | if (is_admin()) { //Load admin side only files |
|---|
| 70 | include_once EASY_HTTPS_SSL_PATH. '/admin/ehssl-admin-init.php'; |
|---|
| 71 | } else { |
|---|
| 72 | //Load front end side only files |
|---|
| 73 | } |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | public function initialize_and_run_classes() { |
|---|
| 77 | //Initialize the various classes and start running. |
|---|
| 78 | |
|---|
| 79 | //Common classes. |
|---|
| 80 | $this->debug_logger = new EHSSL_Logger(); |
|---|
| 81 | new EHSSL_Init_Time_Tasks();// This will register the init time tasks. |
|---|
| 82 | |
|---|
| 83 | if (is_admin()) { |
|---|
| 84 | // Admin side only classes. |
|---|
| 85 | $this->admin_init = new EHSSL_Admin_Init(); |
|---|
| 86 | } |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | public static function plugin_activate_handler() { |
|---|
| 90 | wp_schedule_event(time(), 'daily', 'ehssl_daily_cron_event'); |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | public static function plugin_deactivate_handler() { |
|---|
| 94 | wp_clear_scheduled_hook('ehssl_daily_cron_event'); |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | public static function plugin_uninstall_handler() { |
|---|
| 98 | //NOP. |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | public function ehssl_load_language() { |
|---|
| 102 | // Internationalization. |
|---|
| 103 | // A better practice for text domain is to use dashes instead of underscores. |
|---|
| 104 | load_plugin_textdomain('https-redirection', false, EASY_HTTPS_SSL_PATH . '/languages/'); |
|---|
| 105 | } |
|---|
| 106 | |
|---|
| 107 | public function plugins_loaded_handler() { |
|---|
| 108 | // Runs when plugins_loaded action gets fired |
|---|
| 109 | if (is_admin()) { |
|---|
| 110 | // Do admin side plugins_loaded operations |
|---|
| 111 | $this->do_db_upgrade_check(); |
|---|
| 112 | } |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | public function do_db_upgrade_check() { |
|---|
| 116 | //Check if DB needs to be updated |
|---|
| 117 | // if (is_admin()) { |
|---|
| 118 | // if (get_option('ehssl_db_version') != EASY_HTTPS_SSL_DB_VERSION) { |
|---|
| 119 | // //include_once ('file-name-installer.php'); |
|---|
| 120 | // //easy_https_run_db_upgrade(); |
|---|
| 121 | // } |
|---|
| 122 | // } |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | } // End of class. |
|---|
| 126 | |
|---|
| 127 | } // End of class not exists check. |
|---|
| 128 | |
|---|
| 129 | $GLOBALS['ehssl'] = new Easy_HTTPS_SSL(); |
|---|