-
Notifications
You must be signed in to change notification settings - Fork 8
/
wc4bp-basic-integration.php
executable file
·351 lines (316 loc) · 11 KB
/
wc4bp-basic-integration.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
<?php
/**
* Plugin Name: BuddyPress Integration for WooCommerce
* Plugin URI: https://themekraft.com/woocommerce-buddypress-integration/
* Description: Integrates WooCommerce with a BuddyPress social network
* Author: ThemeKraft
* Author URI: https://themekraft.com/products/woocommerce-buddypress-integration/
* Version: 3.4.12
* Licence: GPLv3
* Text Domain: wc4bp
* Domain Path: /languages
* Svn: wc4bp
*
* ****************************************************************************
* WC requires at least: 3.3.0
* WC tested up to: 6.2.1
* ****************************************************************************
*
* This script 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* ***************************************************************************
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
require_once dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR . 'wc4bp-exception-handler.php';
if ( ! class_exists( 'WC4BP_Loader' ) ) {
class WC4BP_Loader {
/**
* The plugin version
*/
const VERSION = '3.4.12';
/**
* Minimum required WP version
*/
const MIN_WP = '4.9';
/**
* Minimum required BP version
*/
const MIN_BP = '2.2';
/**
* Minimum required woocommerce version
*/
const MIN_WOO = '3.3';
/**
* Name of the plugin folder
*/
static $plugin_name;
/**
* Can the plugin be executed
*/
static $active = false;
/**
* @var Freemius
*/
public static $freemius;
/**
* Is true when the plugin is the premium version
*
* @var bool
*/
private static $is_pro;
/**
* Initiate the class
*
* @package WooCommerce for BuddyPress
* @since 0.1-beta
*/
public function __construct() {
try {
self::$plugin_name = __FILE__;
self::$is_pro = ( strpos( self::$plugin_name, 'premium' ) !== false );
$this->constants();
require_once dirname( __FILE__ ) . '/class/includes/class-request-helper.php';
require_once dirname( __FILE__ ) . '/class/includes/wc4bp_requirements.php';
require_once dirname( __FILE__ ) . '/class/includes/class-tgm-plugin-activation.php';
require_once dirname( __FILE__ ) . '/class/wc4bp-base.php';
require_once dirname( __FILE__ ) . '/class/wc4bp-manager.php';
require_once dirname( __FILE__ ) . '/class/wc4bp-required-php.php';
require_once dirname( __FILE__ ) . '/class/wc4bp-required.php';
require_once dirname( __FILE__ ) . '/class/wc4bp-upgrade.php';
// Init Freemius.
self::$freemius = $this->wc4bp_fs();
self::$freemius->set_basename( true, __FILE__ );
/**
* Execute on freemius load to notify the addons
*/
do_action( 'wc4bp_core_fs_loaded' );
$requirements = new WC4BP_Required_PHP( 'wc4bp' );
if ( $requirements->satisfied() ) {
new WC4BP_Required();
if ( wc4bp_Manager::is_woocommerce_active() && ( wc4bp_Manager::is_buddypress_active() || wc4bp_Manager::is_buddyboss_theme_active() ) ) {
// Adding edd migration code
new wc4bp_Manager();
new WC4BP_Upgrade( plugin_basename( dirname( __FILE__ ) ) );
// Run the activation function
register_activation_hook( __FILE__, array( $this, 'activation' ) );
/**
* Deletes all data if plugin deactivated
*/
register_deactivation_hook( __FILE__, array( $this, 'deactivation' ) );
add_action( 'plugins_loaded', array( $this, 'update' ), 10 );
add_action( 'plugins_loaded', array( $this, 'wc4bp_translate' ) );
self::getFreemius()->add_action( 'after_uninstall', array( $this, 'uninstall_cleanup' ) );
}
} else {
$faux_plugin = new WP_Faux_Plugin( __( 'WC4BP', 'wc4bp' ), $requirements->getResults() );
$faux_plugin->show_result( plugin_basename( __FILE__ ) );
}
} catch ( Exception $exception ) {
self::get_exception_handler()->save_exception( $exception->getTrace() );
}
}
public function get_version() {
return self::VERSION;
}
/**
* Create a helper function for easy Freemius SDK access.
*
* @return Freemius
*/
public function wc4bp_fs() {
global $wc4bp_fs;
try {
if ( ! isset( $wc4bp_fs ) ) {
// Include Freemius SDK.
require_once WC4BP_ABSPATH_CLASS_PATH . 'includes/freemius/start.php';
$wc4bp_fs = fs_dynamic_init(
array(
'id' => '425',
'slug' => 'wc4bp',
'type' => 'plugin',
'public_key' => 'pk_71d28f28e3e545100e9f859cf8554',
'is_premium' => true,
'premium_suffix' => 'Premium',
'has_premium_version' => true,
'has_addons' => true,
'has_paid_plans' => true,
'trial' => array(
'days' => 7,
'is_require_payment' => true,
),
'has_affiliation' => 'all',
'menu' => array(
'slug' => 'wc4bp-options-page',
'support' => false,
),
'bundle_license_auto_activation' => true,
)
);
}
} catch ( Exception $exception ) {
self::get_exception_handler()->save_exception( $exception->getTrace() );
}
return $wc4bp_fs;
}
/**
* Declare all constants
*
* @since 1.0
* @access private
*/
private function constants() {
define( 'WC4BP_VERSION', self::VERSION );
define( 'WC4BP_FOLDER', plugin_basename( dirname( __FILE__ ) ) );
define( 'WC4BP_ABSPATH', dirname( __FILE__ ) . DIRECTORY_SEPARATOR );
define( 'WC4BP_URLPATH', trailingslashit( plugins_url( '/' . WC4BP_FOLDER ) ) );
define( 'WC4BP_ABSPATH_CLASS_PATH', dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'class' . DIRECTORY_SEPARATOR );
define( 'WC4BP_ABSPATH_PATCH_PATH', dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'patch' . DIRECTORY_SEPARATOR );
define( 'WC4BP_ABSPATH_TEMPLATE_PATH', WC4BP_ABSPATH . 'templates' . DIRECTORY_SEPARATOR );
define( 'WC4BP_ABSPATH_ADMIN_PATH', dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'admin' . DIRECTORY_SEPARATOR );
define( 'WC4BP_ABSPATH_ADMIN_VIEWS_PATH', dirname( __FILE__ ) . DIRECTORY_SEPARATOR . 'admin' . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR );
define( 'WC4BP_CSS', WC4BP_URLPATH . 'admin/css/' );
define( 'WC4BP_JS', WC4BP_URLPATH . 'admin/js/' );
define( 'WC4BP_IMAGES', WC4BP_URLPATH . 'admin/images/' );
}
/**
* @return Freemius
*/
public static function getFreemius() {
return self::$freemius;
}
/**
* Load the language file
*
* @since 1.0
* @uses load_plugin_textdomain()
*/
public function wc4bp_translate() {
load_plugin_textdomain( 'wc4bp', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
/*
* Update function from version 1.3.8 to 1.4
*/
public function update() {
try {
if ( version_compare( WC4BP_VERSION, '1.4', '<' ) ) {
$billing = bp_get_option( 'wc4bp_billing_address_ids' );
$shipping = bp_get_option( 'wc4bp_shipping_address_ids' );
$billing_changed = false;
$shipping_changed = false;
if ( isset( $billing['address'] ) ) {
$billing['address_1'] = $billing['address'];
unset( $billing['address'] );
$billing_changed = true;
}
if ( isset( $billing['address-2'] ) ) {
$billing['address_2'] = $billing['address-2'];
unset( $billing['address-2'] );
$billing_changed = true;
}
if ( isset( $shipping['address'] ) ) {
$shipping['address_1'] = $shipping['address'];
unset( $shipping['address'] );
$shipping_changed = true;
}
if ( isset( $shipping['address-2'] ) ) {
$shipping['address_2'] = $shipping['address-2'];
unset( $shipping['address-2'] );
$shipping_changed = true;
}
if ( true === $billing_changed ) {
bp_update_option( 'wc4bp_billing_address_ids', $billing );
}
if ( true === $shipping_changed ) {
bp_update_option( 'wc4bp_shipping_address_ids', $shipping );
}
}
} catch ( Exception $exception ) {
self::get_exception_handler()->save_exception( $exception->getTrace() );
}
}
/**
* Generate the default data arrays
*/
public function activation() {
try {
if ( ! self::$is_pro ) {
$t = self::$plugin_name;
deactivate_plugins( 'wc4bp/wc4bp-basic-integration', true );
}
WC4BP_MyAccount::clean_my_account_cached();
include_once dirname( __FILE__ ) . '/class/core/wc4bp-sync.php';
include_once dirname( __FILE__ ) . '/admin/wc4bp-activate.php';
wc4bp_activate();
} catch ( Exception $exception ) {
self::get_exception_handler()->save_exception( $exception->getTrace() );
}
}
/**
* Deletes all data if plugin deactivated
*
* @return void
*/
public function deactivation() {
try {
$wc4bp_options_delete = get_option( 'wc4bp_options_delete' );
if ( $wc4bp_options_delete ) {
include_once dirname( __FILE__ ) . '/class/core/wc4bp-sync.php';
wc4bp_Sync::clean_xprofield_fields_cached();
WC4BP_MyAccount::clean_my_account_cached();
self::uninstall_cleanup();
}
} catch ( Exception $exception ) {
self::get_exception_handler()->save_exception( $exception->getTrace() );
}
}
/**
* @return WC4BP_Exception_Handler
*/
public static function get_exception_handler() {
return WC4BP_Exception_Handler::get_instance();
}
/**
* Clean the related plugins data when it is uninstall
*/
public function uninstall_cleanup() {
try {
// Removes all data from the database
delete_option( 'wc4bp_installed' );
delete_option( 'wc4bp_installed_date' );
delete_option( 'wc4bp_shipping_address_ids' );
delete_option( 'wc4bp_billing_address_ids' );
delete_option( 'wc4bp_options' );
delete_option( 'woocommerce-buddypress-integration' );
delete_option( 'wc4bp-basic-integration' );
delete_option( 'wc4bp_api_manager_instance' );
delete_option( 'wc4bp_api_manager_deactivate_checkbox' );
delete_option( 'wc4bp_api_manager_activated' );
delete_option( 'wc4bp_api_manager_version' );
delete_option( 'wc4bp_api_manager_checkbox' );
delete_option( 'wc4bp_options_sync' );
delete_option( 'wc4bp_options_tabs' );
delete_option( 'wc4bp_pages_options' );
delete_option( 'wc4bp_options_delete' );
} catch ( Exception $exception ) {
self::get_exception_handler()->save_exception( $exception->getTrace() );
}
}
}
// Entry point for this plugins
$GLOBALS['wc4bp_loader'] = new WC4BP_Loader();
do_action( 'wc4bp_init', $GLOBALS['wc4bp_loader'] );
}