forked from getdokan/dokan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdokan.php
executable file
·486 lines (416 loc) · 14.6 KB
/
dokan.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
<?php
/*
Plugin Name: Dokan
Plugin URI: https://wordpress.org/plugins/dokan-lite/
Description: An e-commerce marketplace plugin for WordPress. Powered by WooCommerce and weDevs.
Version: 2.9.9
Author: weDevs, LLC
Author URI: https://wedevs.com/
Text Domain: dokan-lite
WC requires at least: 3.0
WC tested up to: 3.5.4
Domain Path: /languages/
License: GPL2
*/
/**
* Copyright (c) 2018 weDevs (email: [email protected]). All rights reserved.
*
* Released under the GPL license
* http://www.opensource.org/licenses/gpl-license.php
*
* This is an add-on for WordPress
* http://wordpress.org/
*
* **********************************************************************
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* **********************************************************************
*/
// don't call the file directly
if ( ! defined( 'ABSPATH' ) ) exit;
/**
* Autoload class files on demand
*
* `Dokan_Installer` becomes => installer.php
* `Dokan_Template_Report` becomes => template-report.php
*
* @since 1.0
*
* @param string $class requested class name
*/
function dokan_autoload( $class ) {
if ( stripos( $class, 'Dokan_' ) !== false ) {
$class_name = str_replace( array( 'Dokan_', '_' ), array( '', '-' ), $class );
$file_path = dirname( __FILE__ ) . '/classes/' . strtolower( $class_name ) . '.php';
if ( file_exists( $file_path ) ) {
require_once $file_path;
}
}
}
spl_autoload_register( 'dokan_autoload' );
/**
* WeDevs_Dokan class
*
* @class WeDevs_Dokan The class that holds the entire WeDevs_Dokan plugin
*/
final class WeDevs_Dokan {
/**
* Plugin version
*
* @var string
*/
public $version = '2.9.9';
/**
* Minimum PHP version required
*
* @var string
*/
private $min_php = '5.6.0';
/**
* Holds various class instances
*
* @since 2.6.10
*
* @var array
*/
private $container = array();
/**
* Constructor for the WeDevs_Dokan class
*
* Sets up all the appropriate hooks and actions
* within our plugin.
*/
public function __construct() {
$this->define_constants();
register_activation_hook( __FILE__, array( $this, 'activate' ) );
register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) );
add_action( 'woocommerce_loaded', array( $this, 'init_plugin' ) );
}
/**
* Initializes the WeDevs_Dokan() class
*
* Checks for an existing WeDevs_WeDevs_Dokan() instance
* and if it doesn't find one, creates it.
*/
public static function init() {
static $instance = false;
if ( ! $instance ) {
$instance = new WeDevs_Dokan();
}
return $instance;
}
/**
* Magic getter to bypass referencing objects
*
* @since 2.6.10
*
* @param $prop
*
* @return mixed
*/
public function __get( $prop ) {
if ( array_key_exists( $prop, $this->container ) ) {
return $this->container[ $prop ];
}
return $this->{$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( __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 ( ! function_exists( 'WC' ) ) {
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
deactivate_plugins( plugin_basename( __FILE__ ) );
wp_die( '<div class="error"><p>' . sprintf( esc_html__( '<b>Dokan</b> requires <a href="%s">WooCommerce</a> to be installed & activated!', 'dokan-lite' ), '<a target="_blank" href="https://wordpress.org/plugins/woocommerce/">', '</a>' ) . '</p></div>' );
}
if ( ! $this->is_supported_php() ) {
require_once WC_ABSPATH . 'includes/wc-notice-functions.php';
wc_print_notice( sprintf( __( 'The Minimum PHP Version Requirement for <b>Dokan</b> is %s. You are Running PHP %s', 'dokan' ), $this->min_php, phpversion(), 'error' ) );
exit;
}
require_once dirname( __FILE__ ) . '/includes/functions.php';
require_once dirname( __FILE__ ) . '/includes/functions-compatibility.php';
// Background Processes
require_once dirname( __FILE__ ) . '/includes/background-processes/class-dokan-background-processes.php';
require_once dirname( __FILE__ ) . '/includes/background-processes/abstract-class-dokan-background-processes.php';
$installer = new Dokan_Installer();
$installer->do_install();
}
/**
* Placeholder for deactivation function
*
* Nothing being called here yet.
*/
public function deactivate() {
}
/**
* Initialize plugin for localization
*
* @uses load_plugin_textdomain()
*/
public function localization_setup() {
load_plugin_textdomain( 'dokan-lite', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
/**
* Define all constants
*
* @return void
*/
public function define_constants() {
define( 'DOKAN_PLUGIN_VERSION', $this->version );
define( 'DOKAN_FILE', __FILE__ );
define( 'DOKAN_DIR', dirname( __FILE__ ) );
define( 'DOKAN_INC_DIR', dirname( __FILE__ ) . '/includes' );
define( 'DOKAN_LIB_DIR', dirname( __FILE__ ) . '/lib' );
define( 'DOKAN_PLUGIN_ASSEST', plugins_url( 'assets', __FILE__ ) );
// give a way to turn off loading styles and scripts from parent theme
if ( ! defined( 'DOKAN_LOAD_STYLE' ) ) {
define( 'DOKAN_LOAD_STYLE', true );
}
if ( ! defined( 'DOKAN_LOAD_SCRIPTS' ) ) {
define( 'DOKAN_LOAD_SCRIPTS', 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
*/
function init_hooks() {
// Localize our plugin
add_action( 'init', array( $this, 'localization_setup' ) );
// initialize the classes
add_action( 'init', array( $this, 'init_classes' ),5 );
add_action( 'init', array( $this, 'wpdb_table_shortcuts' ) );
add_action( 'plugins_loaded', array( $this, 'after_plugins_loaded' ) );
add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), array( $this, 'plugin_action_links' ) );
add_action( 'in_plugin_update_message-dokan-lite/dokan.php', array( 'Dokan_Installer', 'in_plugin_update_message' ) );
add_action( 'widgets_init', array( $this, 'register_widgets' ) );
}
/**
* Include all the required files
*
* @return void
*/
function includes() {
$lib_dir = dirname( __FILE__ ) . '/lib/';
$inc_dir = dirname( __FILE__ ) . '/includes/';
$classes_dir = dirname( __FILE__ ) . '/classes/';
require_once $inc_dir . 'functions.php';
require_once $inc_dir . 'functions-depricated.php';
require_once $inc_dir . 'functions-compatibility.php';
// Traits
require_once $inc_dir . 'traits/singleton.php';
// widgets
require_once $inc_dir . 'widgets/menu-category.php';
require_once $inc_dir . 'widgets/bestselling-product.php';
require_once $inc_dir . 'widgets/top-rated-product.php';
require_once $inc_dir . 'widgets/store-menu-category.php';
require_once $inc_dir . 'widgets/store-menu.php';
require_once $inc_dir . 'widgets/store-location.php';
require_once $inc_dir . 'widgets/store-contact.php';
require_once $inc_dir . 'widgets/store-open-close.php';
require_once $inc_dir . 'wc-functions.php';
require_once $inc_dir . '/admin/setup-wizard.php';
require_once $classes_dir . 'seller-setup-wizard.php';
require_once $inc_dir . 'wc-template.php';
require_once $inc_dir . 'class-core.php';
require_once $inc_dir . 'class-shortcodes.php';
require_once $inc_dir . 'class-registration.php';
require_once $inc_dir . 'class-assets.php';
require_once $inc_dir . 'class-email.php';
require_once $inc_dir . 'class-vendor.php';
require_once $inc_dir . 'class-vendor-manager.php';
require_once $inc_dir . 'class-order-manager.php';
require_once $inc_dir . 'class-product-manager.php';
require_once $inc_dir . 'class-dokan-privacy.php';
if ( is_admin() ) {
require_once $inc_dir . 'admin/class-settings.php';
require_once $inc_dir . 'admin/class-admin.php';
require_once $inc_dir . 'admin/class-ajax.php';
require_once $inc_dir . 'admin/class-admin-pointers.php';
require_once $inc_dir . 'admin-functions.php';
require_once $inc_dir . 'admin/promotion.php';
} else {
require_once $inc_dir . 'template-tags.php';
require_once $inc_dir . 'class-theme-support.php';
}
// API includes
require_once $inc_dir . 'api/class-api-rest-controller.php';
require_once $inc_dir . 'class-api-manager.php';
// Background Processes
require_once $inc_dir . 'background-processes/class-dokan-background-processes.php';
require_once $inc_dir . 'background-processes/abstract-class-dokan-background-processes.php';
}
/**
* Init all the classes
*
* @return void
*/
function init_classes() {
if ( is_admin() ) {
new Dokan_Admin_User_Profile();
Dokan_Admin_Ajax::init();
new Dokan_Upgrade();
new Dokan_Setup_Wizard();
new Dokan_Promotion();
}
$this->container['pageview'] = new Dokan_Pageviews();
$this->container['rewrite'] = new Dokan_Rewrites();
$this->container['tracker'] = new Dokan_Tracker();
$this->container['seller_wizard'] = new Dokan_Seller_Setup_Wizard();
$this->container['core'] = new Dokan_Core();
$this->container['scripts'] = new Dokan_Assets();
$this->container['email'] = Dokan_Email::init();
$this->container['vendor'] = new Dokan_Vendor_Manager();
$this->container['product'] = new Dokan_Product_Manager();
$this->container['shortcode'] = new Dokan_Shortcodes();
$this->container['registration'] = new Dokan_Registration();
$this->container['orders'] = new Dokan_Order_Manager();
$this->container['api'] = new Dokan_API_Manager();
if ( is_user_logged_in() ) {
Dokan_Template_Main::init();
Dokan_Template_Dashboard::init();
Dokan_Template_Products::init();
Dokan_Template_Orders::init();
Dokan_Template_Withdraw::init();
Dokan_Template_Settings::init();
}
if ( ! is_admin() ) {
new Dokan_Theme_Support();
}
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
Dokan_Ajax::init()->init_ajax();
}
}
/**
* Load table prefix for withdraw and orders table
*
* @since 1.0
*
* @return void
*/
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() {
new Dokan_Background_Processes();
}
/**
* Register widgets
*
* @since 2.8
*
* @return void
*/
public function register_widgets() {
register_widget( 'Dokan_Best_Selling_Widget' );
register_widget( 'Dokan_Category_Widget' );
register_widget( 'Dokan_Store_Contact_Form' );
register_widget( 'Dokan_Store_Location' );
register_widget( 'Dokan_Store_Category_Menu' );
register_widget( 'Dokan_Toprated_Widget' );
register_widget( 'Dokan_Store_Open_Close' );
}
/**
* Returns if the plugin is in PRO version
*
* @since 2.4
*
* @return boolean
*/
public function is_pro_exists() {
return apply_filters( 'dokan_is_pro_exists' , false );
}
/**
* Plugin action links
*
* @param array $links
*
* @since 2.4
*
* @return array
*/
function plugin_action_links( $links ) {
if ( !$this->is_pro_exists() ) {
$links[] = '<a href="https://wedevs.com/dokan/" 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://docs.wedevs.com/docs/dokan/" target="_blank">' . __( 'Documentation', 'dokan-lite' ) . '</a>';
return $links;
}
} // WeDevs_Dokan
/**
* Load Dokan Plugin when all plugins loaded
*
* @return void
*/
function dokan() {
return WeDevs_Dokan::init();
}
// Lets Go....
dokan();