| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
* Plugin Name: DPD SK for WooCommerce |
| 5 |
* Description: DPD SK plugin for WooCommerce which exports orders to the DPD through their API |
| 6 |
* Version: 8.4.0 |
| 7 |
* Author: Webikon |
| 8 |
* Author URI: https://www.webikon.sk |
| 9 |
* License: GPLv2 |
| 10 |
* License URI: https://www.gnu.org/licenses/gpl-2.0.txt |
| 11 |
* Text Domain: wc-dpd |
| 12 |
* Domain Path: /languages |
| 13 |
* Requires at least: 5.3 |
| 14 |
* Tested up to: 6.9 |
| 15 |
* Requires PHP: 7.4 |
| 16 |
* WC requires at least: 7.0 |
| 17 |
* WC tested up to: 10.4.3 |
| 18 |
*/ |
| 19 |
|
| 20 |
namespace WcDPD; |
| 21 |
|
| 22 |
defined('ABSPATH') || exit; |
| 23 |
|
| 24 |
/** |
| 25 |
* Global plugin constants |
| 26 |
*/ |
| 27 |
// Work out plugin folder name and store it as a constant |
| 28 |
$plugin_dir = str_replace(basename(__FILE__), "", plugin_basename(__FILE__)); |
| 29 |
$plugin_dir = substr($plugin_dir, 0, strlen($plugin_dir) - 1); |
| 30 |
define('WCDPD_PLUGIN_PATH', plugin_dir_path(__FILE__)); |
| 31 |
define('WCDPD_PLUGIN_DIR', $plugin_dir); |
| 32 |
define('WCDPD_PLUGIN_INDEX', __FILE__); |
| 33 |
define('WCDPD_PLUGIN_WC_MIN_VERSION', '7.0'); |
| 34 |
define('WCDPD_PLUGIN_ASSETS_URL', plugins_url(WCDPD_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR)); |
| 35 |
define('WCDPD_PLUGIN_TEMPLATES_PATH', WCDPD_PLUGIN_PATH . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR); |
| 36 |
|
| 37 |
/** |
| 38 |
* Declare HPOS support |
| 39 |
*/ |
| 40 |
add_action('before_woocommerce_init', function () { |
| 41 |
if (class_exists(\Automattic\WooCommerce\Utilities\FeaturesUtil::class)) { |
| 42 |
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('custom_order_tables', __FILE__, true); |
| 43 |
} |
| 44 |
}); |
| 45 |
|
| 46 |
/** |
| 47 |
* Check if WC meets the required version |
| 48 |
*/ |
| 49 |
add_action('admin_notices', function () { |
| 50 |
if (class_exists('WooCommerce') && version_compare(WC()->version, WCDPD_PLUGIN_WC_MIN_VERSION, '>=')) { |
| 51 |
return; // WooCommerce is active and meets the required version, so no notice needed |
| 52 |
} |
| 53 |
|
| 54 |
?> |
| 55 |
<div class="notice notice-error is-dismissible"> |
| 56 |
<p><?php echo sprintf(__('DPD SK for WooCommerce plugin requires WooCommerce version %s or higher to work properly. Please update WooCommerce to use this plugin.', 'wc-dpd'), WCDPD_PLUGIN_WC_MIN_VERSION); ?></p> |
| 57 |
</div> |
| 58 |
<?php |
| 59 |
}); |
| 60 |
|
| 61 |
/** |
| 62 |
* Autoload plugin files |
| 63 |
*/ |
| 64 |
add_action('plugins_loaded', function () { |
| 65 |
// Check that the composer autoloader is present |
| 66 |
$composer_autoloader = WCDPD_PLUGIN_PATH . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php'; |
| 67 |
if (!file_exists($composer_autoloader)) { |
| 68 |
return; |
| 69 |
} |
| 70 |
|
| 71 |
require_once $composer_autoloader; |
| 72 |
|
| 73 |
if (!\WcDPD\is_woocommerce_active()) { |
| 74 |
return; // WooCommerce is not active, so exit early |
| 75 |
} |
| 76 |
|
| 77 |
\WcDPD\Core::initTranslations(); |
| 78 |
|
| 79 |
// Compare the installed WooCommerce version with the required version |
| 80 |
if (!class_exists('WooCommerce') || version_compare(WC()->version, WCDPD_PLUGIN_WC_MIN_VERSION, '<')) { |
| 81 |
return; // WooCommerce is not active or doesn't meet the required version, so exit early |
| 82 |
} |
| 83 |
|
| 84 |
// Initialize the plugin |
| 85 |
\WcDPD\Core::init(); |
| 86 |
}); |
| 87 |
|