forked from piatkowski/wckalkulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wc-kalkulator.php
235 lines (207 loc) · 6.38 KB
/
wc-kalkulator.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<?php
/**
* Plugin Name: WC Kalkulator
* Description: Description: Store Manager can add fieldsets to Products and Orders. WC Kalkulator allows to order and calculate the price of the product based on the values of the fields selected by the Customer.
* Version: 1.6.1
* Author: Krzysztof Piątkowski
* Author URI: https://wckalkulator.com
* Text Domain: wc-kalkulator
* Domain Path: /languages
* License: GPLv2
* Requires PHP: 5.6
* Network: true
*/
namespace WCKalkulator;
use WCKalkulator\Woocommerce\Attribute;
use WCKalkulator\Woocommerce\Product;
if (!defined('ABSPATH')) {
wp_die("No direct access!");
}
include __DIR__ . '/vendor/autoload.php';
if (!class_exists('WCKalkulator\Plugin')) {
/**
* The Plugin
* @package WCKalkulator
*/
class Plugin
{
const VERSION = "1.6.1";
const NAME = "wc-kalkulator";
/**
* @var string
*/
private static $path = "";
/**
* @var string
*/
private static $url = "";
/**
* @var Product
*/
public static $product;
/**
* @var array
*/
public static $defined_fields = array(
Fields\NumberField::class,
Fields\SelectField::class,
Fields\DropdownField::class,
Fields\CheckboxField::class,
Fields\CheckboxgroupField::class,
Fields\TextField::class,
Fields\TextareaField::class,
Fields\ColorpickerField::class,
Fields\DatepickerField::class,
Fields\RangedatepickerField::class,
Fields\EmailField::class,
Fields\RadioField::class,
Fields\ImageselectField::class,
Fields\FileuploadField::class,
Fields\ImageuploadField::class,
Fields\HtmlField::class,
Fields\HeadingField::class,
Fields\ParagraphField::class,
Fields\FormulaField::class,
Fields\LinkField::class,
Fields\AttachmentField::class,
Fields\ImageswatchesField::class,
Fields\ColorswatchesField::class,
Fields\EmptyField::class,
Fields\HiddenField::class
);
/**
* Run the plugin
*
* @since 1.0.0
*/
public static function run()
{
register_activation_hook(__FILE__, array(__CLASS__, 'activation'));
register_deactivation_hook(__FILE__, array(__CLASS__, 'deactivation'));
self::$url = plugins_url('', __FILE__);
self::$path = WP_PLUGIN_DIR . '/' . Plugin::NAME;
FieldsetPostType::init();
GlobalParametersPostType::init();
Ajax::init();
Product::init();
Settings::init();
AdminNotice::init();
Cron::init();
Attribute::init();
add_action('plugins_loaded', array(__CLASS__, 'load_text_domain'));
add_action('current_screen', array(__CLASS__, 'current_screen'));
}
/**
* Load text domain
* @return void
*/
public static function load_text_domain()
{
load_plugin_textdomain(
'wc-kalkulator',
false,
dirname(plugin_basename(__FILE__)) . '/languages'
);
}
/**
* Adds actions and filters on admin screens
*
* @param $screen
* @return void
* @since 1.5.0
*/
public static function current_screen($screen)
{
$pages = array(
'product_page_wck_settings'
);
$post_types = array(
FieldsetPostType::POST_TYPE,
GlobalParametersPostType::POST_TYPE
);
if (isset($screen->post_type) && in_array($screen->post_type, $post_types) || in_array($screen->base, $pages)) {
add_action('in_admin_header', array(__CLASS__, 'in_admin_header'));
wp_register_style('wckalkulator_admin_nav_css', Plugin::url() . '/assets/css/admin.nav.min.css');
wp_enqueue_style('wckalkulator_admin_nav_css');
}
}
/**
* Renders admin naviation toolbar
*
* @return void
* @since 1.5.0
*/
public static function in_admin_header()
{
echo View::render('admin/navigation', array(
'items' => apply_filters('wck_admin_navigation', array())
));
}
/**
* Get the plugin's path
*
* @return string
* @since 1.1.0
*/
public static function path()
{
return self::$path;
}
/**
* Get the plugin's url
*
* @return string
* @since 1.1.0
*/
public static function url()
{
return self::$url;
}
/**
* Deletes ths Plugin's data
*
* @since 1.1.0
*/
public static function uninstall()
{
global $wpdb;
delete_option('wck_version');
if (function_exists('is_multisite') && is_multisite()) {
$blog_sql = "SELECT blog_id FROM $wpdb->blogs WHERE archived = '0' AND spam = '0' AND deleted = '0'";
$blog_ids = $wpdb->get_col($blog_sql);
if ($blog_ids) {
foreach ($blog_ids as $blog_id) {
switch_to_blog($blog_id);
FieldsetPostType::delete_all_posts();
GlobalParametersPostType::delete_all_posts();
}
restore_current_blog();
}
} else {
FieldsetPostType::delete_all_posts();
GlobalParametersPostType::delete_all_posts();
}
}
/**
* Store the current version number of this plugin
*
* @return void
* @since 1.0.0
*/
public static function activation()
{
update_option('wck_version', self::VERSION);
}
/**
* Delete cron jobs
*
* @return void
* @since 1.3.0
*/
public static function deactivation()
{
Cron::deactivate();
}
}
Plugin::run();
}