forked from wp-erp/wp-erp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-erp.php
310 lines (263 loc) · 8.35 KB
/
wp-erp.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
<?php
/**
* Plugin Name: WP ERP
* Description: ERP solution for WordPress. Built-in modules include HR and CRM.
* Plugin URI: http://wperp.com
* Author: weDevs
* Author URI: https://wedevs.com
* Version: 1.0-beta1
* License: GPL2
* Text Domain: wp-erp
* Domain Path: /i18n/languages/
*
* Copyright (c) 2016 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
* **********************************************************************
*/
// don't call the file directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* WeDevs_ERP class
*
* @class WeDevs_ERP The class that holds the entire WeDevs_ERP plugin
*/
final class WeDevs_ERP {
/**
* Plugin version
*
* @var string
*/
public $version = '1.0-beta1';
/**
* Minimum PHP version required
*
* @var string
*/
private $min_php = '5.4.0';
/**
* Holds various class instances
*
* @var array
*/
private $container = array();
/**
* Initializes the WeDevs_ERP() class
*
* Checks for an existing WeDevs_ERP() instance
* and if it doesn't find one, creates it.
*/
public static function init() {
static $instance = false;
if ( ! $instance ) {
$instance = new self();
}
return $instance;
}
/**
* Constructor for the WeDevs_ERP class
*
* Sets up all the appropriate hooks and actions
* within our plugin.
*/
public function __construct() {
// dry check on older PHP versions, if found deactivate itself with an error
register_activation_hook( __FILE__, array( $this, 'auto_deactivate' ) );
if ( ! $this->is_supported_php() ) {
return;
}
// Define constants
$this->define_constants();
// Include required files
$this->includes();
// instantiate classes
$this->instantiate();
// Initialize the action hooks
$this->init_actions();
// load the modules
$this->load_module();
// Loaded action
do_action( 'erp_loaded' );
}
/**
* Magic getter to bypass referencing plugin.
*
* @param $prop
*
* @return mixed
*/
public function __get( $prop ) {
if ( array_key_exists( $prop, $this->container ) ) {
return $this->container[ $prop ];
}
return $this->{$prop};
}
/**
* Magic isset to bypass referencing plugin.
*
* @param $prop
*
* @return mixed
*/
public function __isset( $prop ) {
return isset( $this->{$prop} ) || isset( $this->container[ $prop ] );
}
/**
* Check if the PHP version is supported
*
* @return bool
*/
public function is_supported_php() {
if ( version_compare( PHP_VERSION, $this->min_php, '<=' ) ) {
return false;
}
return true;
}
/**
* Bail out if the php version is lower than
*
* @return void
*/
function auto_deactivate() {
if ( $this->is_supported_php() ) {
return;
}
deactivate_plugins( basename( __FILE__ ) );
$error = __( '<h1>An Error Occured</h1>', 'wp-erp' );
$error .= __( '<h2>Your installed PHP Version is: ', 'wp-erp' ) . PHP_VERSION . '</h2>';
$error .= __( '<p>The <strong>WP ERP</strong> plugin requires PHP version <strong>', 'wp-erp' ) . $this->min_php . __( '</strong> or greater', 'wp-erp' );
$error .= __( '<p>The version of your PHP is ', 'wp-erp' ) . '<a href="http://php.net/supported-versions.php" target="_blank"><strong>' . __( 'unsupported and old', 'wp-erp' ) . '</strong></a>.';
$error .= __( 'You should update your PHP software or contact your host regarding this matter.</p>', 'wp-erp' );
wp_die( $error, __( 'Plugin Activation Error', 'wp-erp' ), array( 'response' => 200, 'back_link' => true ) );
}
/**
* Define the plugin constants
*
* @return void
*/
private function define_constants() {
define( 'WPERP_VERSION', $this->version );
define( 'WPERP_FILE', __FILE__ );
define( 'WPERP_PATH', dirname( WPERP_FILE ) );
define( 'WPERP_INCLUDES', WPERP_PATH . '/includes' );
define( 'WPERP_MODULES', WPERP_PATH . '/modules' );
define( 'WPERP_URL', plugins_url( '', WPERP_FILE ) );
define( 'WPERP_ASSETS', WPERP_URL . '/assets' );
define( 'WPERP_VIEWS', WPERP_INCLUDES . '/admin/views' );
}
/**
* Include the required files
*
* @return void
*/
private function includes() {
include dirname( __FILE__ ) . '/vendor/autoload.php';
require_once WPERP_INCLUDES . '/class-install.php';
require_once WPERP_INCLUDES . '/functions.php';
require_once WPERP_INCLUDES . '/actions-filters.php';
require_once WPERP_INCLUDES . '/functions-html.php';
require_once WPERP_INCLUDES . '/functions-company.php';
require_once WPERP_INCLUDES . '/functions-people.php';
if ( is_admin() ) {
require_once WPERP_INCLUDES . '/admin/functions.php';
require_once WPERP_INCLUDES . '/admin/class-menu.php';
require_once WPERP_INCLUDES . '/admin/class-admin.php';
}
}
/**
* Instantiate classes
*
* @return void
*/
private function instantiate() {
new \WeDevs\ERP\Admin\User_Profile();
new \WeDevs\ERP\Scripts();
$this->container['modules'] = new \WeDevs\ERP\Framework\Modules();
$this->container['emailer'] = \WeDevs\ERP\Emailer::init();
$this->container['integration'] = \WeDevs\ERP\Integration::init();
}
/**
* Initialize WordPress action hooks
*
* @return void
*/
private function init_actions() {
// Localize our plugin
add_action( 'init', array( $this, 'localization_setup' ) );
add_action( 'init', array( $this, 'setup_database' ) );
// initialize emailer class
add_action( 'erp_loaded', array( $this->container['emailer'], 'init_emails' ) );
// initialize integration class
add_action( 'erp_loaded', array( $this->container['integration'], 'init_integrations' ) );
}
/**
* Initialize plugin for localization
*
* @uses load_plugin_textdomain()
*/
public function localization_setup() {
load_plugin_textdomain( 'wp-erp', false, dirname( plugin_basename( __FILE__ ) ) . '/i18n/languages/' );
}
/**
* Setup database related tasks
*
* @return void
*/
public function setup_database() {
global $wpdb;
$wpdb->erp_peoplemeta = $wpdb->prefix . 'erp_peoplemeta';
}
/**
* Load the current ERP module
*
* We don't load every module at once, just load
* what is necessary
*
* @return void
*/
public function load_module() {
$modules = $this->modules->get_modules();
if ( ! $modules ) {
return;
}
foreach ($modules as $key => $module) {
if ( ! $this->modules->is_module_active( $key ) ) {
continue;
}
if ( isset( $module['callback'] ) && class_exists( $module['callback'] ) ) {
new $module['callback']( $this );
}
}
}
} // WeDevs_ERP
/**
* Init the wperp plugin
*
* @return WeDevs_ERP the plugin object
*/
function wperp() {
return WeDevs_ERP::init();
}
// kick it off
wperp();