-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlockBee.php
139 lines (111 loc) · 3.73 KB
/
BlockBee.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
<?php
/*
Plugin Name: BlockBee Cryptocurrency Payment Gateway
Plugin URI: https://blockbee.io/resources/woocommerce/
Description: Accept cryptocurrency payments on your WooCommerce website
Version: 1.0.17
Requires at least: 5
Tested up to: 6.3
WC requires at least: 5.8
WC tested up to: 8.0.2
Requires PHP: 7.2
Author: BlockBee
Author URI: https://blockbee.io/
License: MIT
*/
require_once 'define.php';
function blockbee_missing_wc_notice()
{
echo '<div class="error"><p><strong>' . sprintf(esc_html__('BlockBee requires WooCommerce to be installed and active. You can download %s here.', 'blockbee-cryptocurrency-payment-gateway'), '<a href="https://woocommerce.com/" target="_blank">WooCommerce</a>') . '</strong></p></div>';
}
function blockbee_missing_bcmath()
{
echo '<div class="error"><p><strong>' . sprintf(esc_html__('BlockBee requires PHP\'s BCMath extension. You can know more about it %s.', 'blockbee-cryptocurrency-payment-gateway'), '<a href="https://www.php.net/manual/en/book.bc.php" target="_blank">here</a>') . '</strong></p></div>';
}
function blockbee_include_gateway($methods)
{
$methods[] = 'WC_BlockBee_Gateway';
return $methods;
}
function blockbee_loader()
{
if (!class_exists('WooCommerce')) {
add_action('admin_notices', 'blockbee_missing_wc_notice');
return;
}
if (!extension_loaded('bcmath')) {
add_action('admin_notices', 'blockbee_missing_bcmath');
return;
}
$dirs = [
BLOCKBEE_PLUGIN_PATH . 'controllers/',
BLOCKBEE_PLUGIN_PATH . 'utils/',
BLOCKBEE_PLUGIN_PATH . 'languages/',
];
blockbee_include_dirs($dirs);
$mo_file_path = dirname(__FILE__) . '/languages/blockbee-crypto-payment-gateway-for-woocommerce-' . get_locale() . '.mo';
load_textdomain('blockbee', $mo_file_path);
$blockbee = new WC_BlockBee_Gateway();
}
add_action('plugins_loaded', 'blockbee_loader');
add_filter('woocommerce_payment_gateways', 'blockbee_include_gateway');
function blockbee_include_dirs($dirs)
{
foreach ($dirs as $dir) {
$files = blockbee_scan_dir($dir);
if ($files === false) continue;
foreach ($files as $f) {
blockbee_include_file($dir . $f);
}
}
}
function blockbee_include_file($file)
{
if (blockbee_is_includable($file)) {
require_once $file;
return true;
}
return false;
}
function blockbee_scan_dir($dir)
{
if (!is_dir($dir)) return false;
$file = scandir($dir);
unset($file[0], $file[1]);
return $file;
}
function blockbee_is_includable($file)
{
if (!is_file($file)) return false;
if (!file_exists($file)) return false;
if (strtolower(substr($file, -3, 3)) != 'php') return false;
return true;
}
add_filter('cron_schedules', function ($blockbee_interval) {
$blockbee_interval['blockbee_interval'] = array(
'interval' => 60,
'display' => esc_html__('BlockBee Interval'),
);
return $blockbee_interval;
});
register_activation_hook(__FILE__, 'blockbee_activation');
function blockbee_activation()
{
if (!wp_next_scheduled('blockbee_cronjob')) {
wp_schedule_event(time(), 'blockbee_interval', 'blockbee_cronjob');
}
}
register_deactivation_hook(__FILE__, 'blockbee_deactivation');
function blockbee_deactivation()
{
wp_clear_scheduled_hook('blockbee_cronjob');
}
add_action('wp_upgrade', 'blockbee_update_checker', 10, 2);
if (!wp_next_scheduled('blockbee_cronjob')) {
wp_schedule_event(time(), 'blockbee_interval', 'blockbee_cronjob');
}
add_action('before_woocommerce_init', function () {
if (class_exists(\Automattic\WooCommerce\Utilities\FeaturesUtil::class)) {
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('custom_order_tables', __FILE__, true);
}
});