-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbootstrap.php
141 lines (122 loc) · 4.31 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
<?php
if ( ! defined( 'WPINC' ) ) { die; }
class WooCommerce_Quick_Buy {
public $version = '1.2';
public $plugin_vars = array();
protected static $_instance = null; # Required Plugin Class Instance
protected static $frontend = null; # Required Plugin Class Instance
protected static $auto_add = null; # Required Plugin Class Instance
protected static $admin = 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();
wc_quick_buy_db_settings();
$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);
}
/**
* Loads Required Plugins For Plugin
*/
private function load_required_files(){
$this->load_files(WCQB_INC.'class-*.php');
if($this->is_request('admin')){
$this->load_files(WCQB_ADMIN.'class-*.php');
}
}
/**
* Inits loaded Class
*/
private function init_class(){
self::$frontend = new WooCommerce_Quick_Buy_FrontEnd;
self::$auto_add = new WooCommerce_Quick_Buy_Auto_Add;
if($this->is_request('admin')){ self::$admin = new WooCommerce_Quick_Buy_Admin; }
}
# Returns Plugin's Functions Instance
public function func(){ return self::$frontend; }
# Returns Plugin's Functions Instance
public function auto_add(){ return self::$auto_add; }
# 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(WCQB_TXT, false, WCQB_LANGUAGE_PATH );
}
/**
* load translated mo file based on wp settings
*/
public function load_plugin_mo_files($mofile, $domain) {
if (WCQB_TXT === $domain)
return WCQB_LANGUAGE_PATH.'/'.get_locale().'.mo';
return $mofile;
}
/**
* Define Required Constant
*/
private function define_constant(){
$this->define('WCQB_NAME', 'WooCommerce Quick Buy'); # Plugin Name
$this->define('WCQB_SLUG', 'woocommerce-quick-buy'); # Plugin Slug
$this->define('WCQB_TXT', 'woocommerce-quick-buy'); #plugin lang Domain
$this->define('WCQB_DB', 'wc_quick_buy_');
$this->define('WCQB_V',$this->version); # Plugin Version
$this->define('WCQB_PATH',plugin_dir_path( __FILE__ )); # Plugin DIR
$this->define('WCQB_LANGUAGE_PATH',WCQB_PATH.'languages'); # Plugin Language Folder
$this->define('WCQB_INC',WCQB_PATH.'includes/'); # Plugin INC Folder
$this->define('WCQB_ADMIN',WCQB_INC.'admin/'); # Plugin Admin Folder
$this->define('WCQB_URL',plugins_url('', __FILE__ ).'/'); # Plugin URL
$this->define('WCQB_CSS',WCQB_URL.'includes/css/'); # Plugin CSS URL
$this->define('WCQB_IMG',WCQB_URL.'includes/img/'); # Plugin IMG URL
$this->define('WCQB_JS',WCQB_URL.'includes/js/'); # Plugin JS URL
$this->define('WCQB_FILE',plugin_basename( __FILE__ )); # Current File
}
/**
* Define constant if not already set
* @param string $name
* @param string|bool $value
*/
protected function define($key,$value){
if(!defined($key)){
define($key,$value);
}
}
/**
* What type of request is this?
* string $type ajax, frontend or admin
* @return bool
*/
private function is_request( $type ) {
switch ( $type ) {
case 'admin' :
return is_admin();
case 'ajax' :
return defined( 'DOING_AJAX' );
case 'cron' :
return defined( 'DOING_CRON' );
case 'frontend' :
return ( ! is_admin() || defined( 'DOING_AJAX' ) ) && ! defined( 'DOING_CRON' );
}
}
}