PluginProbe
DPD SK for WooCommerce / 9.1.0
DPD SK for WooCommerce v9.1.0
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 9.1.0, at wc-dpd.php

109 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.1.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: 6.5
14 * Tested up to: 7.0.4
15 * Requires PHP: 8.1
16 * WC requires at least: 7.0
17 * WC tested up to: 11.0.1
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
88 /**
89 * Plugin activation hook -- grant the DPD capability to standard WC roles.
90 *
91 * Runs before the plugins_loaded callback above, so we load the Composer
92 * autoloader manually here. Capabilities::addCaps() is the only class we
93 * need during activation -- everything else can wait for Core::init().
94 */
95 register_activation_hook(__FILE__, static function (): void {
96 $composer_autoloader = WCDPD_PLUGIN_PATH . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
97 if (file_exists($composer_autoloader)) {
98 require_once $composer_autoloader;
99 }
100
101 if (class_exists(\WcDPD\Capabilities::class)) {
102 \WcDPD\Capabilities::addCaps();
103 }
104 });
105
106 // Uninstall logic lives in `uninstall.php` (standard WP pattern for static
107 // hooks). A closure cannot be passed to register_uninstall_hook() because WP
108 // stores the callback in an option and Closure is not serializable in PHP 8.1+.
109