-
Notifications
You must be signed in to change notification settings - Fork 4
/
dokan-migrator.php
241 lines (215 loc) · 6.12 KB
/
dokan-migrator.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
<?php
/**
* Plugin Name: Dokan Migrator
* Plugin URI: https://dokan.co/wordpress/
* Description: An e-commerce marketplace migration plugin for WordPress. Powered by WooCommerce and WeDevs.
* Version: 1.1.2
* Author: weDevs
* Author URI: https://dokan.co/
* Domain Path: /languages/
* License: GPL2
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* WC requires at least: 6.2.0
* WC tested up to: 8.4.0
* Text Domain: dokan-migrator
*
* Copyright (c) 2022 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
* **********************************************************************
*/
defined( 'ABSPATH' ) || exit;
/**
* Dokan_Migrator class
*
* @class Dokan_Migrator The class that holds the entire Dokan_Migrator plugin
*
* @property WeDevs\DokanMigrator\Migrator\Manager $migrator Instance of migrator class.
*
* @since 1.0.0
*/
final class Dokan_Migrator {
/**
* Plugin version
*
* @var string
*/
public $version = '1.1.2';
/**
* Instance of self
*
* @var Dokan_Migrator
*/
private static $instance = null;
/**
* Holds various class instances
*
* @since 1.0.0
*
* @var array
*/
private $container = [];
/**
* Class constructor.
*
* @since 1.0.0
*/
private function __construct() {
require_once __DIR__ . '/vendor/autoload.php';
// Define constants.
$this->define_constants();
register_activation_hook( __FILE__, [ $this, 'activate' ] );
// Add woocommerce HPOS support.
add_action( 'before_woocommerce_init', [ $this, 'add_plugin_hpos_support' ] );
// load the addon
add_action( 'dokan_loaded', array( $this, 'plugin_init' ) );
$this->init_appsero_tracker();
}
/**
* Initializes the class
*
* Checks for an existing instance
* and if it doesn't find one, creates it.
*
* @since 1.0.0
*
* @return self
*/
public static function init() {
if ( self::$instance === null ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Define all dokan migrator constant
*
* @since 1.0.0
*
* @return void
*/
public function define_constants() {
define( 'DOKAN_MIGRATOR_PLUGIN_VERSION', $this->version );
define( 'DOKAN_MIGRATOR_FILE', __FILE__ );
define( 'DOKAN_MIGRATOR_DIR', dirname( DOKAN_MIGRATOR_FILE ) );
define( 'DOKAN_MIGRATOR_FILE_PATH', plugin_dir_path( DOKAN_MIGRATOR_FILE ) );
define( 'DOKAN_MIGRATOR_TEMPLATE_PATH', DOKAN_MIGRATOR_FILE_PATH . 'templates/' );
define( 'DOKAN_MIGRATOR_INC', DOKAN_MIGRATOR_DIR . '/includes' );
define( 'DOKAN_MIGRATOR_PLUGIN_ASSETS_DRI', DOKAN_MIGRATOR_DIR . '/assets' );
define( 'DOKAN_MIGRATOR_PLUGIN_ASSETS', plugins_url( 'assets', DOKAN_MIGRATOR_FILE ) );
}
/**
* Executes on plugin activation.
*
* @since 1.0.0
*
* @return void
*/
public function activate() {
new WeDevs\DokanMigrator\Install\Installer();
}
/**
* Init the plugin.
*
* @since 1.0.0
*
* @return void
*/
public function plugin_init() {
// Initialize the action hooks
$this->init_classes();
}
/**
* Load plugin classes.
*
* @since 1.0.0
*
* @return void
*/
private function init_classes() {
if ( is_admin() ) {
$this->container['admin'] = new \WeDevs\DokanMigrator\Admin\Manager();
}
$this->container['migrator'] = new \WeDevs\DokanMigrator\Migrator\Manager();
$this->container = apply_filters( 'dokan_migrator_get_class_container', $this->container );
}
/**
* Magic getter to bypass referencing objects
*
* @since 1.0.0
*
* @param string $prop
*
* @return Class Instance
*/
public function __get( $prop ) {
if ( array_key_exists( $prop, $this->container ) ) {
return $this->container[ $prop ];
}
}
/**
* Initiates Appsero services.
*
* @since 1.0.0
*
* @return void
*/
public function init_appsero_tracker() {
if ( ! class_exists( '\Appsero\Client' ) ) {
return;
}
$client = new \Appsero\Client( '2852f2fd-66ff-4649-9b00-5f9ed953f8b9', 'Dokan Migrator', DOKAN_MIGRATOR_FILE );
$insights = $client->insights();
$insights->add_extra(
function() {
return array(
'dokan_migrator_version' => DOKAN_MIGRATOR_PLUGIN_VERSION,
);
}
);
$insights->init();
}
/**
* Make dokan migrator plugin HPOS supported.
*
* @since 1.1.0
*
* @return void
*/
public function add_plugin_hpos_support() {
if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
}
}
}
/**
* Load Dokan migrator plugin.
*
* @since 1.0.0
*
* @return \Dokan_Migrator
*/
function dokan_migrator() {
return Dokan_Migrator::init();
}
// Lets Go....
dokan_migrator();