country_check()) { return; } // Autoloader include_once('includes/class-dhlpwc-autoloader.php'); // Set constants $this->define('DHLPWC_PLUGIN_FILE', __FILE__); $this->define('DHLPWC_PLUGIN_BASENAME', plugin_basename(__FILE__)); $this->define('DHLPWC_PLUGIN_DIR', plugin_dir_path(__FILE__)); $this->define('DHLPWC_PLUGIN_URL', plugins_url('/', __FILE__)); $this->define('DHLPWC_RELATIVE_PLUGIN_DIR', $this->get_relative_plugin_dir()); // Load translation load_plugin_textdomain('dhlpwc', false, DHLPWC_RELATIVE_PLUGIN_DIR . DIRECTORY_SEPARATOR .'languages' ); // Load controllers // These controllers are isolated from other controllers (self sufficient) new DHLPWC_Controller_Isolated_Load_Switcher(); if ($this->load_alternative_plugin()) { // Stop loading this plugin return; } // These controllers will not be encapsulated in an availability check, due to it providing screens // necessary to enable the plugin and setting up the plugin. new DHLPWC_Controller_Settings(); new DHLPWC_Controller_Admin_Settings(); $service = DHLPWC_Model_Service_Access_Control::instance(); if ($service->check(DHLPWC_Model_Service_Access_Control::ACCESS_API)) { new DHLPWC_Controller_Admin_Order_Metabox(); new DHLPWC_Controller_Admin_Order(); new DHLPWC_Controller_Admin_Product(); new DHLPWC_Controller_Checkout(); new DHLPWC_Controller_Cart(); new DHLPWC_Controller_Account(); new DHLPWC_Controller_Mail(); } } protected function get_relative_plugin_dir() { // Check if the full dir is equal to the plugin dir. For example, if it's symlinked, this following // logic to get the relative path won't work. Instead we will return the relative directory if (substr(DHLPWC_PLUGIN_DIR, 0, strlen(WP_PLUGIN_DIR)) !== WP_PLUGIN_DIR) { return trim(basename(dirname(__FILE__))); } $relative_dir = substr(DHLPWC_PLUGIN_DIR, strlen(WP_PLUGIN_DIR), strlen(DHLPWC_PLUGIN_DIR)); return trim($relative_dir, '/\\'); } protected function country_check() { if (!function_exists('wc_get_base_location')) { return false; } $country_code = wc_get_base_location(); if (!isset($country_code['country'])) { return false; } $valid_countries = array( 'NL', 'BE', 'LU', 'AT', ); if (!in_array($country_code['country'], $valid_countries)) { return false; } return true; } protected function load_alternative_plugin() { $switch_loading = get_option('woocommerce_dhlpwc_switch_loading'); return boolval($switch_loading); } protected function define($name, $value) { if (!defined($name)) { define($name, $value); } } } // Run immediately $DHLPWC = new DHLPWC(); endif;