-
Notifications
You must be signed in to change notification settings - Fork 205
/
dokan-class.php
executable file
·489 lines (420 loc) · 13.8 KB
/
dokan-class.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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
<?php
use WeDevs\Dokan\DependencyManagement\Container;
/**
* WeDevs_Dokan class
*
* @class WeDevs_Dokan The class that holds the entire WeDevs_Dokan plugin
*
* @property WeDevs\Dokan\Commission $commission Instance of Commission class
* @property WeDevs\Dokan\Order\Manager $order Instance of Order Manager class
* @property WeDevs\Dokan\Product\Manager $product Instance of Order Manager class
* @property WeDevs\Dokan\Vendor\Manager $vendor Instance of Vendor Manager Class
* @property WeDevs\Dokan\BackgroundProcess\Manager $bg_process Instance of WeDevs\Dokan\BackgroundProcess\Manager class
* @property WeDevs\Dokan\Withdraw\Manager $withdraw Instance of WeDevs\Dokan\Withdraw\Manager class
* @property WeDevs\Dokan\Frontend\Frontend $frontend_manager Instance of \WeDevs\Dokan\Frontend\Frontend class
* @property WeDevs\Dokan\Registration $registration Instance of WeDevs\Dokan\Registration class
*/
final class WeDevs_Dokan {
/**
* Plugin version
*
* @var string
*/
public $version = '3.14.3';
/**
* Instance of self
*
* @var WeDevs_Dokan
*/
private static $instance = null;
/**
* Minimum PHP version required
*
* @var string
*/
private $min_php = '7.4';
/**
* Holds various class instances
*
* @since 2.6.10
*
* @var array
*/
private $legacy_container = [];
/**
* Databse version key
*
* @since 3.0.0
*
* @var string
*/
private $db_version_key = 'dokan_theme_version';
/**
* Constructor for the WeDevs_Dokan class
*
* Sets up all the appropriate hooks and actions
* within our plugin.
*/
private function __construct() {
$this->define_constants();
register_activation_hook( DOKAN_FILE, [ $this, 'activate' ] );
register_deactivation_hook( DOKAN_FILE, [ $this, 'deactivate' ] );
add_action( 'before_woocommerce_init', [ $this, 'declare_woocommerce_feature_compatibility' ] );
add_action( 'woocommerce_loaded', [ $this, 'init_plugin' ] );
add_action( 'woocommerce_flush_rewrite_rules', [ $this, 'flush_rewrite_rules' ] );
// Register admin notices to container and load notices
$this->get_container()->get( 'admin_notices' );
$this->init_appsero_tracker();
add_action( 'plugins_loaded', [ $this, 'woocommerce_not_loaded' ], 11 );
}
/**
* Initializes the WeDevs_Dokan() class
*
* Checks for an existing WeDevs_WeDevs_Dokan() instance
* and if it doesn't find one, create it.
*/
public static function init() {
if ( self::$instance === null ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Magic getter to bypass referencing objects
*
* @since 2.6.10
*
* @param string $prop
*
* @return object Class Instance
*/
public function __get( $prop ) {
if ( array_key_exists( $prop, $this->legacy_container ) ) {
return $this->legacy_container[ $prop ];
}
if ( $this->get_container()->has( $prop ) ) {
return $this->get_container()->get( $prop );
}
}
/**
* Check if the PHP version is supported
*
* @return bool
*/
public function is_supported_php() {
if ( version_compare( PHP_VERSION, $this->min_php, '<=' ) ) {
return false;
}
return true;
}
/**
* Get the plugin path.
*
* @return string
*/
public function plugin_path() {
return untrailingslashit( plugin_dir_path( DOKAN_FILE ) );
}
/**
* Get the template path.
*
* @return string
*/
public function template_path() {
return apply_filters( 'dokan_template_path', 'dokan/' );
}
/**
* Placeholder for activation function
*
* Nothing being called here yet.
*/
public function activate() {
if ( ! $this->has_woocommerce() ) {
set_transient( 'dokan_wc_missing_notice', true );
}
if ( ! $this->is_supported_php() ) {
require_once WC_ABSPATH . 'includes/wc-notice-functions.php';
/* translators: 1: Required PHP Version 2: Running php version */
wc_print_notice( sprintf( __( 'The Minimum PHP Version Requirement for <b>Dokan</b> is %1$s. You are Running PHP %2$s', 'dokan-lite' ), $this->min_php, phpversion() ), 'error' );
exit;
}
require_once __DIR__ . '/includes/functions.php';
require_once __DIR__ . '/includes/functions-compatibility.php';
$this->get_container()->get( 'upgrades' );
$installer = new \WeDevs\Dokan\Install\Installer();
$installer->do_install();
// rewrite rules during dokan activation
if ( $this->has_woocommerce() ) {
$this->flush_rewrite_rules();
}
}
/**
* Flush rewrite rules after dokan is activated or woocommerce is activated
*
* @since 3.2.8
*/
public function flush_rewrite_rules() {
// fix rewrite rules
$this->get_container()->get( 'rewrite' )->register_rule();
flush_rewrite_rules();
}
/**
* Placeholder for deactivation function
*
* Nothing being called here yet.
*/
public function deactivate() {
delete_transient( 'dokan_wc_missing_notice', true );
}
/**
* Initialize plugin for localization
*
* @uses load_plugin_textdomain()
*/
public function localization_setup() {
load_plugin_textdomain( 'dokan-lite', false, dirname( plugin_basename( DOKAN_FILE ) ) . '/languages/' );
}
/**
* Define all constants
*
* @return void
*/
public function define_constants() {
defined( 'DOKAN_PLUGIN_VERSION' ) || define( 'DOKAN_PLUGIN_VERSION', $this->version );
defined( 'DOKAN_DIR' ) || define( 'DOKAN_DIR', __DIR__ );
defined( 'DOKAN_INC_DIR' ) || define( 'DOKAN_INC_DIR', __DIR__ . '/includes' );
defined( 'DOKAN_LIB_DIR' ) || define( 'DOKAN_LIB_DIR', __DIR__ . '/lib' );
defined( 'DOKAN_PLUGIN_ASSEST' ) || define( 'DOKAN_PLUGIN_ASSEST', plugins_url( 'assets', DOKAN_FILE ) );
// give a way to turn off loading styles and scripts from parent theme
defined( 'DOKAN_LOAD_STYLE' ) || define( 'DOKAN_LOAD_STYLE', true );
defined( 'DOKAN_LOAD_SCRIPTS' ) || define( 'DOKAN_LOAD_SCRIPTS', true );
}
/**
* Add High Performance Order Storage Support
*
* @since 3.8.0
*
* @return void
*/
public function declare_woocommerce_feature_compatibility() {
if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', DOKAN_FILE, true );
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'cart_checkout_blocks', DOKAN_FILE, true );
}
}
/**
* Load the plugin after WP User Frontend is loaded
*
* @return void
*/
public function init_plugin() {
$this->includes();
$this->init_hooks();
do_action( 'dokan_loaded' );
}
/**
* Initialize the actions
*
* @return void
*/
public function init_hooks() {
// Localize our plugin
add_action( 'init', [ $this, 'localization_setup' ] );
// initialize the classes
add_action( 'init', [ $this, 'init_classes' ], 4 );
add_action( 'init', [ $this, 'wpdb_table_shortcuts' ], 1 );
add_action( 'plugins_loaded', [ $this, 'after_plugins_loaded' ] );
add_filter( 'plugin_action_links_' . plugin_basename( DOKAN_FILE ), [ $this, 'plugin_action_links' ] );
add_action( 'in_plugin_update_message-dokan-lite/dokan.php', [ \WeDevs\Dokan\Install\Installer::class, 'in_plugin_update_message' ] );
add_action( 'widgets_init', [ $this, 'register_widgets' ] );
}
/**
* Include all the required files
*
* @return void
*/
public function includes() {
require_once DOKAN_DIR . '/deprecated/deprecated-functions.php';
require_once DOKAN_DIR . '/deprecated/deprecated-hooks.php';
require_once DOKAN_INC_DIR . '/functions.php';
if ( ! function_exists( 'dokan_pro' ) ) {
require_once DOKAN_INC_DIR . '/reports.php';
}
require_once DOKAN_INC_DIR . '/Order/functions.php';
require_once DOKAN_INC_DIR . '/Product/functions.php';
require_once DOKAN_INC_DIR . '/Withdraw/functions.php';
require_once DOKAN_INC_DIR . '/functions-compatibility.php';
require_once DOKAN_INC_DIR . '/wc-functions.php';
require_once DOKAN_INC_DIR . '/wc-template.php';
require_once DOKAN_DIR . '/deprecated/deprecated-classes.php';
if ( is_admin() ) {
require_once DOKAN_INC_DIR . '/Admin/functions.php';
} else {
require_once DOKAN_INC_DIR . '/template-tags.php';
}
require_once DOKAN_INC_DIR . '/store-functions.php';
}
/**
* Init all the classes
*
* @return void
*/
public function init_classes() {
$common_services = $this->get_container()->get( 'common-service' );
if ( is_admin() ) {
$admin_services = $this->get_container()->get( 'admin-service' );
} else {
$frontend_services = $this->get_container()->get( 'frontend-service' );
}
$container_services = $this->get_container()->get( 'container-service' );
$this->legacy_container = apply_filters( 'dokan_get_class_container', $this->legacy_container );
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
$ajax_services = $this->get_container()->get( 'ajax-service' );
}
}
/**
* Load table prefix for withdraw and orders table
*
* @since 1.0
*
* @return void
*/
public function wpdb_table_shortcuts() {
global $wpdb;
$wpdb->dokan_withdraw = $wpdb->prefix . 'dokan_withdraw';
$wpdb->dokan_orders = $wpdb->prefix . 'dokan_orders';
$wpdb->dokan_announcement = $wpdb->prefix . 'dokan_announcement';
$wpdb->dokan_refund = $wpdb->prefix . 'dokan_refund';
$wpdb->dokan_vendor_balance = $wpdb->prefix . 'dokan_vendor_balance';
}
/**
* Executed after all plugins are loaded
*
* At this point Dokan Pro is loaded
*
* @since 2.8.7
*
* @return void
*/
public function after_plugins_loaded() {
// Initiate background processes
$processes = get_option( 'dokan_background_processes', [] );
if ( ! empty( $processes ) ) {
$update = false;
foreach ( $processes as $processor => $file ) {
if ( file_exists( $file ) ) {
include_once $file;
new $processor();
} else {
$update = true;
unset( $processes[ $processor ] );
}
}
if ( $update ) {
update_option( 'dokan_background_processes', $processes );
}
}
}
/**
* Register widgets
*
* @since 2.8
*
* @return void
*/
public function register_widgets() {
$this->get_container()->get( 'widgets' );
}
/**
* Returns if the plugin is in PRO version
*
* @since 2.4
*
* @return bool
*/
public function is_pro_exists() {
return apply_filters( 'dokan_is_pro_exists', false );
}
/**
* Plugin action links
*
* @param array $links
*
* @since 2.4
*
* @return array
*/
public function plugin_action_links( $links ) {
if ( ! $this->is_pro_exists() ) {
$links[] = '<a href="https://dokan.co/wordpress/" style="color: #389e38;font-weight: bold;" target="_blank">' . __( 'Get Pro', 'dokan-lite' ) . '</a>';
}
$links[] = '<a href="' . admin_url( 'admin.php?page=dokan#/settings' ) . '">' . __( 'Settings', 'dokan-lite' ) . '</a>';
$links[] = '<a href="https://dokan.co/docs/wordpress/" target="_blank">' . __( 'Documentation', 'dokan-lite' ) . '</a>';
return $links;
}
/**
* Initialize Appsero Tracker
*
* @return void
*/
public function init_appsero_tracker() {
$this->get_container()->get( 'tracker' );
}
/**
* Check whether woocommerce is installed and active
*
* @since 2.9.16
*
* @return bool
*/
public function has_woocommerce() {
return class_exists( 'WooCommerce' );
}
/**
* Check whether woocommerce is installed
*
* @since 3.2.8
*
* @return bool
*/
public function is_woocommerce_installed() {
return in_array( 'woocommerce/woocommerce.php', array_keys( get_plugins() ), true );
}
/**
* Handles scenerios when WooCommerce is not active
*
* @since 2.9.27
*
* @return void
*/
public function woocommerce_not_loaded() {
if ( did_action( 'woocommerce_loaded' ) || ! is_admin() ) {
return;
}
require_once DOKAN_INC_DIR . '/functions.php';
if ( get_transient( '_dokan_setup_page_redirect' ) ) {
dokan_redirect_to_admin_setup_wizard();
}
new \WeDevs\Dokan\Admin\SetupWizardNoWC();
}
/**
* Get Dokan db version key
*
* @since 3.0.0
*
* @return string
*/
public function get_db_version_key() {
return $this->db_version_key;
}
/**
* Retrieve the container instance.
*
* @since 3.13.0
*
* @return Container
*/
public function get_container(): Container {
return dokan_get_container();
}
}