bootstrap.php
6.4 KB
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
<?php
/**
* Plugin Main File
*
* @link https://wordpress.org/plugins/woocommerce-role-based-price/
* @package Role Based Price For WooCommerce
* @subpackage Role Based Price For WooCommerce/core
* @since 3.0
*/
if ( ! defined( 'WPINC' ) ) {
die;
}
class WooCommerce_Role_Based_Price {
protected static $_instance = null;
protected static $functions = null;
protected static $admin = null; # Required Plugin Class Instance
protected static $settings = null; # Required Plugin Class Instance
protected static $frontend = null; # Required Plugin Class Instance
protected static $shortcode_handler = null; # Required Plugin Class Instance
public $version = '3.3.5'; # Required Plugin Class INstance
public $plugin_vars = array(); # Required Plugin Class INstance
/**
* Class Constructor
*/
public function __construct() {
$this->define_constant();
$this->load_required_files();
$this->init_hooks();
do_action( 'wc_rbp_loaded' );
}
/**
* Define Required Constant
*/
private function define_constant() {
$this->define( 'WC_RBP_NAME', 'Role Based Price For WooCommerce' ); # Plugin Name
$this->define( 'WC_RBP_SLUG', 'woocommerce-role-based-price' ); # Plugin Slug
$this->define( 'WC_RBP_TXT', 'woocommerce-role-based-price' ); #plugin lang Domain
$this->define( 'WC_RBP_DB', 'wc_rbp_' );
$this->define( 'WC_RBP_V', $this->version ); # Plugin Version
$this->define( 'WC_RBP_LANGUAGE_PATH', WC_RBP_PATH . 'languages' ); # Plugin Language Folder
$this->define( 'WC_RBP_ADMIN', WC_RBP_INC . 'admin/' ); # Plugin Admin Folder
$this->define( 'WC_RBP_SETTINGS', WC_RBP_ADMIN . 'settings/' ); # Plugin Settings Folder
$this->define( 'WC_RBP_PLUGIN', WC_RBP_PATH . 'plugins/' );
$this->define( 'WC_RBP_URL', plugins_url( '', __FILE__ ) . '/' ); # Plugin URL
$this->define( 'WC_RBP_PLUGIN_URL', WC_RBP_URL . 'plugins/' ); # Plugin URL
$this->define( 'WC_RBP_CSS', WC_RBP_URL . 'includes/css/' ); # Plugin CSS URL
$this->define( 'WC_RBP_IMG', WC_RBP_URL . 'includes/img/' ); # Plugin IMG URL
$this->define( 'WC_RBP_JS', WC_RBP_URL . 'includes/js/' ); # Plugin JS URL
}
/**
* Define constant if not already set
*
* @param string $name
* @param string|bool $value
*/
protected function define( $key, $value ) {
if ( ! defined( $key ) ) {
define( $key, $value );
}
}
/**
* Loads Required Plugins For Plugin
*/
private function load_required_files() {
$this->load_files( WC_RBP_INC . 'abstract-*.php' );
$this->load_files( WC_RBP_INC . 'helpers/class-admin-notice.php' );
$this->load_files( WC_RBP_INC . 'class-*.php' );
$this->load_files( WC_RBP_ADMIN . 'settings_framework/class-wp-plugin-options.php' );
$this->load_files( WC_RBP_ADMIN . 'settings_framework/class-wp-*.php' );
if ( wc_rbp_is_request( 'admin' ) ) {
$this->load_files( WC_RBP_ADMIN . 'class-*.php' );
}
do_action( 'wc_rbp_before_addons_load' );
$this->load_addons();
}
/**
* Loads Files Based On Give Path & regex
*/
protected function load_files( $path, $type = 'require' ) {
foreach ( glob( $path ) as $files ) {
if ( $type == 'require' ) {
require_once( $files );
} elseif ( $type == 'include' ) {
include_once( $files );
}
}
}
public function load_addons() {
$addons = wc_rbp_get_active_addons();
if ( ! empty( $addons ) ) {
foreach ( $addons as $addon ) {
if ( apply_filters( 'wc_rbp_load_addon', true, $addon ) ) {
do_action( 'wc_rbp_before_' . $addon . '_addon_load' );
$this->load_addon( $addon );
do_action( 'wc_rbp_after_' . $addon . '_addon_load' );
}
}
}
}
public function load_addon( $file ) {
$other_file = apply_filters( 'wc_rbp_addon_file_location', $file );
if ( file_exists( WC_RBP_PLUGIN . $file ) ) {
$this->load_files( WC_RBP_PLUGIN . $file );
} elseif ( file_exists( $other_file ) ) {
$this->load_files( $other_file );
} else {
if ( has_action( 'wc_rbp_addon_' . $file . '_load' ) ) {
do_action( 'wc_rbp_addon_' . $file . '_load' );
} else {
wc_rbp_deactivate_addon( $file );
}
}
}
public function init_hooks() {
add_action( 'plugins_loaded', array( $this, 'after_plugins_loaded' ) );
add_filter( 'load_textdomain_mofile', array( $this, 'load_plugin_mo_files' ), 10, 2 );
add_action( 'init', array( $this, 'init' ), 0 );
}
/**
* Creates or returns an instance of this class.
*/
public static function get_instance() {
if ( null == self::$_instance ) {
self::$_instance = new self;
}
return self::$_instance;
}
# Returns Plugin's Functions Instance
/**
* Throw error on object clone.
*
* Cloning instances of the class is forbidden.
*
* @since 1.0
* @return void
*/
public function __clone() {
_doing_it_wrong( __FUNCTION__, __( 'Cloning instances of the class is forbidden.', WC_RBP_TXT ), WC_RBP_V );
}
# Returns Plugin's Functions Instance
/**
* Disable unserializing of the class
*
* Unserializing instances of the class is forbidden.
*
* @since 1.0
* @return void
*/
public function __wakeup() {
_doing_it_wrong( __FUNCTION__, __( 'Unserializing instances of the class is forbidden.', WC_RBP_TXT ), WC_RBP_V );
}
# Returns Plugin's Settings Instance
/**
* Inits loaded Class
*/
public function init() {
do_action( 'wc_rbp_before_init' );
self::$functions = new WooCommerce_Role_Based_Price_Functions;
self::$settings = new WooCommerce_Role_Based_Price_Settings_Framework;
self::$shortcode_handler = new WooCommerce_Role_Based_Price_Shortcode_Handler;
if ( wc_rbp_is_request( 'admin' ) ) {
self::$admin = new WooCommerce_Role_Based_Price_Admin;
} else {
self::$frontend = new WooCommerce_Role_Based_Price_Product_Pricing;
}
do_action( 'wc_rbp_init' );
}
# Returns Plugin's Admin Instance
public function func() {
return self::$functions;
}
public function frontend() {
return self::$frontend;
}
public function settings() {
return self::$settings;
}
public function admin() {
return self::$admin;
}
/**
* Set Plugin Text Domain
*/
public function after_plugins_loaded() {
load_plugin_textdomain( WC_RBP_TXT, false, WC_RBP_LANGUAGE_PATH );
}
/**
* load translated mo file based on wp settings
*/
public function load_plugin_mo_files( $mofile, $domain ) {
if ( WC_RBP_TXT === $domain ) {
return WC_RBP_LANGUAGE_PATH . '/' . get_locale() . '.mo';
}
return $mofile;
}
}