-
Notifications
You must be signed in to change notification settings - Fork 1
/
trunkrs-woocommerce.php
204 lines (171 loc) · 5.59 KB
/
trunkrs-woocommerce.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<?php
/**
* Plugin Name: Trunkrs for WooCommerce
* Description: Add excellent consumer focused shipping to your WooCommerce store.
* Author: Trunkrs
* Author URI: https://trunkrs.nl
* Version: 1.2.11
* Requires at least: 3.6 & WooCommerce 3.0+
* Requires PHP: 7.1
* License: GPLv3
* Text Domain: trunkrs-for-woocommerce
*
* @wordpress-plugin
*/
if (!class_exists('TRUNKRS_WC_Bootstrapper')) {
class TRUNKRS_WC_Bootstrapper
{
private const MIN_PHP_VERSION = '7.0';
public const DOMAIN = 'trunkrs-for-woocommerce';
/**
* @var string The semver version of the plugin.
*/
public $version = '1.2.11';
/**
* @var TRUNKRS_WC_Bootstrapper The shared plugin instance.
*/
private static $_instance;
/**
* @var string The plugin base name
*/
public $pluginBasename;
/**
* @var string The plugin path
*/
public $pluginPath;
/**
* @var string The plugin URL
*/
public $pluginUrl;
/**
* @return TRUNKRS_WC_Bootstrapper
*/
public static function instance()
{
if (is_null(self::$_instance)) {
self::$_instance = new self();
}
return self::$_instance;
}
public function __construct()
{
$this->define('WC_TRUNKRS_VERSION', $this->version);
$this->pluginBasename = plugin_basename(__FILE__);
$this->pluginPath = rtrim(plugin_dir_path(__FILE__), '/\\');
$this->pluginUrl = rtrim(plugins_url('/', __FILE__), '/\\');
add_action('plugins_loaded', [$this, 'loadTranslations']);
add_action('init', [$this, 'loadMain']);
add_action('upgrader_process_complete', [$this, 'loadTables'], 10, 0);
register_activation_hook(__FILE__, [$this, 'loadTables']);
}
public function notifyWooCommerce()
{
?>
<div class="error trwc-error">
<div class="trwc-header">
<img alt="Trunkrs Logo" src="<?php echo esc_url(TRUNKRS_WC_Utils::createAssetUrl('icons/trunkrs-small-indigo.svg')) ?>" />
<h2>Trunkrs</h2>
</div>
<span class="trwc-content">
<p>
<?php esc_html_e("Voor het gebruik van Trunkrs voor WooCommerce moet je", self::DOMAIN) ?>
<a href="http://wordpress.org/extend/plugins/woocommerce/"> WooCommerce </a>
<?php esc_html_e("geinstalleerd hebben!", self::DOMAIN) ?>
</p>
</span>
</div>
<?php
}
public function notifyPHPVersion()
{
?>
<div class="error trwc-error">
<span class="trwc-header">
<img alt="Trunkrs Logo" src="<?php echo esc_url(TRUNKRS_WC_Utils::createAssetUrl('icons/trunkrs-small-indigo.svg')) ?>"/>
<h2>Trunkrs</h2>
</span>
<span class="trwc-content">
<p>
<?php
esc_html(sprintf(
__("Trunkrs voor WooCommerce heeft PHP %s of hoger nodig.", self::DOMAIN),
self::MIN_PHP_VERSION
))
?>
</p>
<p>
<a href="http://docs.wpovernight.com/general/how-to-update-your-php-version">
<?php esc_html_e("Hoe kan ik mijn PHP versie updaten.", self::DOMAIN) ?>
</a>
</p>
</span>
</div>
<?php
}
public function loadMain()
{
// Base resources
require_once($this->pluginPath . '/includes/utils.php');
require_once($this->pluginPath . '/includes/asset-loader.php');
require_once($this->pluginPath . '/includes/init-db.php');
// Load the translations
$this->loadTranslations();
if (!$this->isPHPVersionMet(self::MIN_PHP_VERSION)) {
add_action('admin_notices', [$this, 'notifyPHPVersion']);
return;
}
if (!$this->isWooCommerceActive()) {
add_action('admin_notices', [$this, 'notifyWooCommerce']);
return;
}
// Load plugin
$this->loadClasses();
}
private function define($name, $value)
{
if (!defined($name)) {
define($name, $value);
}
}
private function loadClasses()
{
$includePath = $this->pluginPath . '/includes';
require_once($includePath . '/index.php');
}
public function loadTranslations() {
$locale = get_locale();
$wpLangDir = trailingslashit(WP_LANG_DIR);
$locale = explode('_', $locale)[0];
$wpMainPluginFile = $wpLangDir . 'trunkrs-for-woocommerce/' . TRUNKRS_WC_Bootstrapper::DOMAIN . '-' . $locale . '.mo';
load_textdomain(TRUNKRS_WC_Bootstrapper::DOMAIN, $wpMainPluginFile);
$wpTextDomainFile = $wpLangDir . 'plugins/' . TRUNKRS_WC_Bootstrapper::DOMAIN . '-' . $locale . '.mo';
load_textdomain(TRUNKRS_WC_Bootstrapper::DOMAIN, $wpTextDomainFile);
$pluginTextDomainFile = dirname(plugin_basename(__FILE__)) . '/languages';
load_plugin_textdomain(TRUNKRS_WC_Bootstrapper::DOMAIN, false, $pluginTextDomainFile);
}
public function loadTables() {
require_once($this->pluginPath . '/includes/init-db.php');
TRUNKRS_WC_InitDB::init();
}
private function isWooCommerceActive()
{
$blog_plugins = get_option('active_plugins', []);
$site_plugins = get_site_option('active_sitewide_plugins', []);
return in_array('woocommerce/woocommerce.php', $blog_plugins)
|| isset($site_plugins['woocommerce/woocommerce.php']);
}
private function isPHPVersionMet($version)
{
return version_compare(PHP_VERSION, $version, '>=');
}
}
}
function TRUNKRS_WC_Bootstrapper()
{
return TRUNKRS_WC_Bootstrapper::instance();
}
function WooCommerce_Trunkrs()
{
return TRUNKRS_WC_Bootstrapper();
}
TRUNKRS_WC_Bootstrapper();