PluginProbe
DPD SK for WooCommerce / trunk
DPD SK for WooCommerce vtrunk
9.2.1 9.1.0 9.2.0 9.0.0 trunk 1.0.0 1.0.1 2.0.0 2.0.1 3.0.0 3.0.1 3.0.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 5.0.0 5.0.1 5.0.2 5.0.3 6.0.0 6.0.1 7.0.0 7.0.1 All 37 releases
wc-dpd / wc-dpd.php

wc-dpd.php in DPD SK for WooCommerce trunk, at wc-dpd.php

110 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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: 9.2.1
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: 6.5
14 * Tested up to: 7.0.4
15 * Requires PHP: 8.1
16 * Requires Plugins: woocommerce
17 * WC requires at least: 7.0
18 * WC tested up to: 11.0.1
19 */
20
21 namespace WcDPD;
22
23 defined('ABSPATH') || exit;
24
25 /**
26 * Global plugin constants
27 */
28 // Work out plugin folder name and store it as a constant
29 $plugin_dir = str_replace(basename(__FILE__), "", plugin_basename(__FILE__));
30 $plugin_dir = substr($plugin_dir, 0, strlen($plugin_dir) - 1);
31 define('WCDPD_PLUGIN_PATH', plugin_dir_path(__FILE__));
32 define('WCDPD_PLUGIN_DIR', $plugin_dir);
33 define('WCDPD_PLUGIN_INDEX', __FILE__);
34 define('WCDPD_PLUGIN_WC_MIN_VERSION', '7.0');
35 define('WCDPD_PLUGIN_ASSETS_URL', plugins_url(WCDPD_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR));
36 define('WCDPD_PLUGIN_TEMPLATES_PATH', WCDPD_PLUGIN_PATH . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR);
37
38 /**
39 * Declare HPOS support
40 */
41 add_action('before_woocommerce_init', function () {
42 if (class_exists(\Automattic\WooCommerce\Utilities\FeaturesUtil::class)) {
43 \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('custom_order_tables', __FILE__, true);
44 }
45 });
46
47 /**
48 * Check if WC meets the required version
49 */
50 add_action('admin_notices', function () {
51 if (class_exists('WooCommerce') && version_compare(WC()->version, WCDPD_PLUGIN_WC_MIN_VERSION, '>=')) {
52 return; // WooCommerce is active and meets the required version, so no notice needed
53 }
54
55 ?>
56 <div class="notice notice-error is-dismissible">
57 <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>
58 </div>
59 <?php
60 });
61
62 /**
63 * Autoload plugin files
64 */
65 add_action('plugins_loaded', function () {
66 // Check that the composer autoloader is present
67 $composer_autoloader = WCDPD_PLUGIN_PATH . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
68 if (!file_exists($composer_autoloader)) {
69 return;
70 }
71
72 require_once $composer_autoloader;
73
74 if (!\WcDPD\is_woocommerce_active()) {
75 return; // WooCommerce is not active, so exit early
76 }
77
78 \WcDPD\Core::initTranslations();
79
80 // Compare the installed WooCommerce version with the required version
81 if (!class_exists('WooCommerce') || version_compare(WC()->version, WCDPD_PLUGIN_WC_MIN_VERSION, '<')) {
82 return; // WooCommerce is not active or doesn't meet the required version, so exit early
83 }
84
85 // Initialize the plugin
86 \WcDPD\Core::init();
87 });
88
89 /**
90 * Plugin activation hook -- grant the DPD capability to standard WC roles.
91 *
92 * Runs before the plugins_loaded callback above, so we load the Composer
93 * autoloader manually here. Capabilities::addCaps() is the only class we
94 * need during activation -- everything else can wait for Core::init().
95 */
96 register_activation_hook(__FILE__, static function (): void {
97 $composer_autoloader = WCDPD_PLUGIN_PATH . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
98 if (file_exists($composer_autoloader)) {
99 require_once $composer_autoloader;
100 }
101
102 if (class_exists(\WcDPD\Capabilities::class)) {
103 \WcDPD\Capabilities::addCaps();
104 }
105 });
106
107 // Uninstall logic lives in `uninstall.php` (standard WP pattern for static
108 // hooks). A closure cannot be passed to register_uninstall_hook() because WP
109 // stores the callback in an option and Closure is not serializable in PHP 8.1+.
110