-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.php
165 lines (141 loc) · 4.68 KB
/
bootstrap.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
<?php
/**
* Plugin Main File
*
* @link https://wordpress.org/plugins/wc-better-grouped-products/
* @package WC_Better_Grouped_Products
* @subpackage WC_Better_Grouped_Products/core
* @since 1.0
*/
if ( ! defined( 'WPINC' ) ) { die; }
class WC_Better_Grouped_Products {
public $version = '1.0';
public $plugin_vars = array();
protected static $_instance = null; # Required Plugin Class Instance
protected static $functions = null; # Required Plugin Class Instance
protected static $admin = null; # Required Plugin Class Instance
protected static $settings = null; # Required Plugin Class Instance
/**
* Creates or returns an instance of this class.
*/
public static function get_instance() {
if ( null == self::$_instance ) {
self::$_instance = new self;
}
return self::$_instance;
}
/**
* Class Constructor
*/
public function __construct() {
$this->define_constant();
$this->load_required_files();
$this->init_class();
add_action('plugins_loaded', array( $this, 'after_plugins_loaded' ));
add_filter('load_textdomain_mofile', array( $this, 'load_plugin_mo_files' ), 10, 2);
}
/**
* 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_BGP_TXT), WC_BGP_V );
}
/**
* 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_BGP_TXT), WC_BGP_V);
}
/**
* Loads Required Plugins For Plugin
*/
private function load_required_files(){
$this->load_files(WC_BGP_INC.'class-*.php');
$this->load_files(WC_BGP_ADMIN.'settings_framework/class-wp-*.php');
if(wc_bgp_is_request('admin')){
$this->load_files(WC_BGP_ADMIN.'class-*.php');
}
}
/**
* Inits loaded Class
*/
private function init_class(){
self::$functions = new WC_Better_Grouped_Products_Functions;
new WC_Better_Grouped_Products_Shortcode_Handler;
if(wc_bgp_is_request('admin')){
self::$admin = new WC_Better_Grouped_Products_Admin;
}
}
# Returns Plugin's Functions Instance
public function func(){
return self::$functions;
}
# Returns Plugin's Settings Instance
public function settings(){
return self::$settings;
}
# Returns Plugin's Admin Instance
public function admin(){
return self::$admin;
}
/**
* 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 ); }
else if($type == 'include'){ include_once( $files ); }
}
}
/**
* Set Plugin Text Domain
*/
public function after_plugins_loaded(){
load_plugin_textdomain(WC_BGP_TXT, false, WC_BGP_LANGUAGE_PATH );
}
/**
* load translated mo file based on wp settings
*/
public function load_plugin_mo_files($mofile, $domain) {
if (WC_BGP_TXT === $domain)
return WC_BGP_LANGUAGE_PATH.'/'.get_locale().'.mo';
return $mofile;
}
/**
* Define Required Constant
*/
private function define_constant(){
$this->define('WC_BGP_NAME', 'WooCommerce Better Grouped Products'); # Plugin Name
$this->define('WC_BGP_SLUG', 'wc-better-grouped-products'); # Plugin Slug
$this->define('WC_BGP_TXT', 'wc-better-grouped-products'); #plugin lang Domain
$this->define('WC_BGP_DB', 'wc_bgp_');
$this->define('WC_BGP_V',$this->version); # Plugin Version
$this->define('WC_BGP_LANGUAGE_PATH',WC_BGP_PATH.'languages'); # Plugin Language Folder
$this->define('WC_BGP_ADMIN',WC_BGP_INC.'admin/'); # Plugin Admin Folder
$this->define('WC_BGP_SETTINGS',WC_BGP_ADMIN.'settings/'); # Plugin Settings Folder
$this->define('WC_BGP_URL',plugins_url('', __FILE__ ).'/'); # Plugin URL
$this->define('WC_BGP_CSS',WC_BGP_URL.'includes/css/'); # Plugin CSS URL
$this->define('WC_BGP_IMG',WC_BGP_URL.'includes/img/'); # Plugin IMG URL
$this->define('WC_BGP_JS',WC_BGP_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);
}
}
}