1
|
|
|
<?php |
2
|
|
|
if ( ! defined( 'ABSPATH' ) ) exit; |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Main plugin object to define the plugin |
6
|
|
|
*/ |
7
|
|
|
if ( ! class_exists( 'PLUGIN_BUILD' ) ) { |
8
|
|
|
|
9
|
|
|
final class PLUGIN_BUILD { |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @var String |
13
|
|
|
*/ |
14
|
|
|
protected $version = '1.2.1'; |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Plugin Instance. |
19
|
|
|
* |
20
|
|
|
* @var PLUGIN_BUILD the PLUGIN Instance |
21
|
|
|
*/ |
22
|
|
|
protected static $_instance; |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Text domain to be used throughout the plugin |
27
|
|
|
* |
28
|
|
|
* @var String |
29
|
|
|
*/ |
30
|
|
|
protected static $text_domain = 'textdomain'; |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Minimum PHP version allowed for the plugin |
35
|
|
|
* |
36
|
|
|
* @var String |
37
|
|
|
*/ |
38
|
|
|
protected static $php_ver_allowed = '5.3'; |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* DB tabble used in plugin |
43
|
|
|
* |
44
|
|
|
* @var String |
45
|
|
|
*/ |
46
|
|
|
protected static $plugin_table = 'plugin_db_table_name'; |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Plugin listing page links, along with Deactivate |
51
|
|
|
* |
52
|
|
|
* @var Array |
53
|
|
|
*/ |
54
|
|
|
protected static $plugin_page_links = array( |
55
|
|
|
array( |
56
|
|
|
'slug' => '', |
57
|
|
|
'label' => '' |
58
|
|
|
) ); |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Main Plugin Instance. |
63
|
|
|
* |
64
|
|
|
* @return PLUGIN_BUILD |
65
|
|
|
*/ |
66
|
|
|
public static function instance() { |
67
|
|
|
|
68
|
|
|
if ( is_null( self::$_instance ) ) { |
69
|
|
|
self::$_instance = new self(); |
70
|
|
|
self::$_instance->init(); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return self::$_instance; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Install plugin setup |
79
|
|
|
* |
80
|
|
|
* @return Void |
81
|
|
|
*/ |
82
|
|
|
public function installation() { |
83
|
|
|
|
84
|
|
|
if (class_exists('PLUGIN_INSTALL')) { |
85
|
|
|
|
86
|
|
|
$install = new PLUGIN_INSTALL(); |
87
|
|
|
$install->text_domain = self::$text_domain; |
88
|
|
|
$install->php_ver_allowed = self::$php_ver_allowed; |
89
|
|
|
$install->plugin_page_links = self::$plugin_page_links; |
90
|
|
|
$install->execute(); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Custom corn class, register it while activation |
97
|
|
|
* |
98
|
|
|
* @return Void |
99
|
|
|
*/ |
100
|
|
|
public function cron_activation() { |
101
|
|
|
|
102
|
|
|
if ( class_exists( 'PLUGIN_CRON' ) ) { |
103
|
|
|
|
104
|
|
|
$cron = new PLUGIN_CRON(); |
105
|
|
|
$schedule = $cron->schedule_task( |
|
|
|
|
106
|
|
|
array( |
107
|
|
|
'timestamp' => current_time('timestamp'), |
|
|
|
|
108
|
|
|
//'schedule' can be 'hourly', 'daily', 'weekly' or anything custom as defined in PLUGIN_CRON |
109
|
|
|
'recurrence' => 'schedule', |
110
|
|
|
// Use custom_corn_hook to hook into any cron process, anywhere in the plugin. |
111
|
|
|
'hook' => 'custom_cron_hook' |
112
|
|
|
) ); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Install plugin data |
120
|
|
|
* |
121
|
|
|
* @return Void |
122
|
|
|
*/ |
123
|
|
|
public function db_install() { |
124
|
|
|
|
125
|
|
|
if ( class_exists( 'PLUGIN_DB' ) ) { |
126
|
|
|
|
127
|
|
|
$db = new PLUGIN_DB(); |
128
|
|
|
$db->table = self::$plugin_table; |
129
|
|
|
$db->sql = "ID mediumint(9) NOT NULL AUTO_INCREMENT, |
130
|
|
|
date date NOT NULL, |
131
|
|
|
UNIQUE KEY ID (ID)"; |
132
|
|
|
$db->build(); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
if (get_option( '_plugin_db_exist') == '0' ) { |
|
|
|
|
136
|
|
|
add_action( 'admin_notices', array( $this, 'db_error_msg' ) ); |
|
|
|
|
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
$options = array( |
140
|
|
|
array( 'option_name', '__value__' ), |
141
|
|
|
); |
142
|
|
|
foreach ( $options as $value ) { |
143
|
|
|
update_option( $value[0], $value[1] ); |
|
|
|
|
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Notice of DB |
150
|
|
|
* |
151
|
|
|
* @return string |
152
|
|
|
*/ |
153
|
|
|
public function db_error_msg() { ?> |
154
|
|
|
|
155
|
|
|
<div class="notice notice-error is-dismissible"> |
156
|
|
|
<p><?php _e( 'Database table Not installed correctly.', 'textdomain' ); ?></p> |
|
|
|
|
157
|
|
|
</div> |
158
|
|
|
<?php |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Uninstall plugin data |
164
|
|
|
* |
165
|
|
|
* @return Void |
166
|
|
|
*/ |
167
|
|
|
public function db_uninstall() { |
168
|
|
|
|
169
|
|
|
$table_name = self::$plugin_table; |
170
|
|
|
|
171
|
|
|
global $wpdb; |
172
|
|
|
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}$table_name" ); |
173
|
|
|
|
174
|
|
|
$options = array( |
175
|
|
|
'_plugin_db_exist' |
176
|
|
|
); |
177
|
|
|
foreach ( $options as $value ) { |
178
|
|
|
delete_option( $value ); |
|
|
|
|
179
|
|
|
} |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* CRON callback |
185
|
|
|
* |
186
|
|
|
* @return Void |
187
|
|
|
*/ |
188
|
|
|
public function do_cron_job_function() { |
189
|
|
|
|
190
|
|
|
//Do cron function |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Run CRON action |
196
|
|
|
* |
197
|
|
|
* @return Void |
198
|
|
|
*/ |
199
|
|
|
public function custom_cron_hook_cb() { |
200
|
|
|
|
201
|
|
|
add_action( 'custom_cron_hook', array( $this, 'do_cron_job_function' ) ); |
|
|
|
|
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* Uninstall CRON hook |
207
|
|
|
* |
208
|
|
|
* @return Void |
209
|
|
|
*/ |
210
|
|
|
public function cron_uninstall() { |
211
|
|
|
|
212
|
|
|
wp_clear_scheduled_hook( 'custom_cron_hook' ); |
|
|
|
|
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* Include scripts |
218
|
|
|
* |
219
|
|
|
* @return Void |
220
|
|
|
*/ |
221
|
|
|
public function scripts() { |
222
|
|
|
|
223
|
|
|
if ( class_exists( 'PLUGIN_SCRIPT' ) ) new PLUGIN_SCRIPT(); |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* Include settings pages |
229
|
|
|
* |
230
|
|
|
* @return Void |
231
|
|
|
*/ |
232
|
|
|
public function settings() { |
233
|
|
|
|
234
|
|
|
if ( class_exists( 'PLUGIN_SETTINGS' ) ) new PLUGIN_SETTINGS(); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* Include widget classes |
240
|
|
|
* |
241
|
|
|
* @return Void |
242
|
|
|
*/ |
243
|
|
|
public function widgets() { |
244
|
|
|
|
245
|
|
|
if ( class_exists( 'PLUGIN_WIDGET' ) ) new PLUGIN_WIDGET(); |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
*Include metabox classes |
251
|
|
|
* |
252
|
|
|
* @return Void |
253
|
|
|
*/ |
254
|
|
|
public function metabox() { |
255
|
|
|
|
256
|
|
|
if ( class_exists( 'PLUGIN_METABOX' ) ) new PLUGIN_METABOX(); |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* Include shortcode classes |
262
|
|
|
* |
263
|
|
|
* @return Void |
264
|
|
|
*/ |
265
|
|
|
public function shortcode() { |
266
|
|
|
|
267
|
|
|
if ( class_exists( 'PLUGIN_SHORTCODE' ) ) new PLUGIN_SHORTCODE(); |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* Add the functionality files |
273
|
|
|
* Available classes: PLUGIN_INSTALL, PLUGIN_DB, PLUGIN_METABOX, PLUGIN_QUERY, PLUGIN_SETTINGS, PLUGIN_SHORTCODE, PLUGIN_WIDGET |
274
|
|
|
* |
275
|
|
|
* @return Void |
276
|
|
|
*/ |
277
|
|
|
public function functionality() { |
278
|
|
|
|
279
|
|
|
require_once( 'src/install.php' ); |
280
|
|
|
require_once( 'src/db.php' ); |
281
|
|
|
require_once( 'src/query.php' ); |
282
|
|
|
require_once( 'src/settings.php' ); |
283
|
|
|
require_once( 'src/widget.php' ); |
284
|
|
|
require_once( 'src/metabox.php' ); |
285
|
|
|
require_once( 'src/shortcode.php' ); |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
|
289
|
|
|
/** |
290
|
|
|
* Call the dependency files |
291
|
|
|
* Available classes: PLUGIN_CORN, PLUGIN_API, PLUGIN_TABLE, PLUGIN_AJAX, PLUGIN_UPLOAD, PLUGIN_SCRIPT |
292
|
|
|
* |
293
|
|
|
* @return Void |
294
|
|
|
*/ |
295
|
|
|
public function helpers() { |
296
|
|
|
|
297
|
|
|
require_once( 'lib/cron.php' ); |
298
|
|
|
require_once( 'lib/api.php' ); |
299
|
|
|
require_once( 'lib/table.php' ); |
300
|
|
|
require_once( 'lib/ajax.php' ); |
301
|
|
|
require_once( 'lib/upload.php' ); |
302
|
|
|
require_once( 'lib/script.php' ); |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* Instantiate the plugin |
308
|
|
|
* |
309
|
|
|
* @return Void |
310
|
|
|
*/ |
311
|
|
|
public function init() { |
312
|
|
|
|
313
|
|
|
$this->helpers(); |
314
|
|
|
$this->functionality(); |
315
|
|
|
|
316
|
|
|
register_activation_hook( PLUGIN_FILE, array( $this, 'db_install' ) ); |
|
|
|
|
317
|
|
|
register_activation_hook( PLUGIN_FILE, array($this, 'cron_activation' ) ); |
318
|
|
|
|
319
|
|
|
//remove the DB and CORN upon uninstallation |
320
|
|
|
//$this won't work here. |
321
|
|
|
register_uninstall_hook( PLUGIN_FILE, array( 'PLUGIN_BUILD', 'db_uninstall' ) ); |
|
|
|
|
322
|
|
|
register_uninstall_hook( PLUGIN_FILE, array( 'PLUGIN_BUILD', 'cron_uninstall' ) ); |
323
|
|
|
|
324
|
|
|
add_action( 'init', array( $this, 'installation' ) ); |
|
|
|
|
325
|
|
|
add_action( 'init', array( $this, 'custom_cron_hook_cb' ) ); |
326
|
|
|
|
327
|
|
|
$this->scripts(); |
328
|
|
|
$this->widgets(); |
329
|
|
|
$this->metabox(); |
330
|
|
|
$this->shortcode(); |
331
|
|
|
$this->settings(); |
332
|
|
|
} |
333
|
|
|
} |
334
|
|
|
} ?> |
335
|
|
|
|