|
1
|
|
|
<?php |
|
2
|
|
|
if ( ! defined( 'ABSPATH' ) ) exit; |
|
3
|
|
|
|
|
4
|
|
|
//Main plugin object to define the plugin |
|
5
|
|
|
if ( ! class_exists( 'PLUGIN_BUILD' ) ) { |
|
6
|
|
|
|
|
7
|
|
|
final class PLUGIN_BUILD { |
|
8
|
|
|
|
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
public function installation() { |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* |
|
15
|
|
|
* Plugin installation |
|
16
|
|
|
* |
|
17
|
|
|
if (class_exists('PLUGIN_INSTALL')) { |
|
18
|
|
|
|
|
19
|
|
|
$install = new PLUGIN_INSTALL(); |
|
20
|
|
|
$install->textDomin = 'textdomain'; |
|
21
|
|
|
$install->phpVerAllowed = ''; |
|
22
|
|
|
$install->pluginPageLinks = array( |
|
23
|
|
|
array( |
|
24
|
|
|
'slug' => '', |
|
25
|
|
|
'label' => '' |
|
26
|
|
|
), |
|
27
|
|
|
); |
|
28
|
|
|
$install->execute(); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
$this->corn(); |
|
32
|
|
|
* |
|
33
|
|
|
*/ |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
//Custom corn class, register it while activation |
|
39
|
|
|
public function corn() { |
|
40
|
|
|
|
|
41
|
|
|
if ( class_exists( 'PLUGIN_CRON' ) ) { |
|
42
|
|
|
$cron = new PLUGIN_CRON(); |
|
43
|
|
|
$schedule = $cron->schedule_task( |
|
|
|
|
|
|
44
|
|
|
array( |
|
45
|
|
|
'timestamp' => current_time('timestamp'), |
|
|
|
|
|
|
46
|
|
|
'recurrence' => 'amaz_24_hrs', |
|
47
|
|
|
// Use custom_corn_hook to hook into any cron process, anywhere in the plugin. |
|
48
|
|
|
'hook' => 'custom_corn_hook' |
|
49
|
|
|
) ); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
public function db_install() { |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* |
|
60
|
|
|
* Install database by defining your SQL |
|
61
|
|
|
* |
|
62
|
|
|
if ( class_exists( 'PLUGIN_DB' ) ) { |
|
63
|
|
|
$db = new PLUGIN_DB(); |
|
64
|
|
|
$db->table = 'plugin_db_table_name'; |
|
65
|
|
|
$db->sql = "ID mediumint(9) NOT NULL AUTO_INCREMENT, |
|
66
|
|
|
date date NOT NULL, |
|
67
|
|
|
UNIQUE KEY ID (ID)"; |
|
68
|
|
|
$db->build(); |
|
69
|
|
|
} |
|
70
|
|
|
* |
|
71
|
|
|
* |
|
72
|
|
|
* Optionally check if the DB table is installed correctly |
|
73
|
|
|
* |
|
74
|
|
|
if (get_option('_plugin_db_exist') == '0') { |
|
75
|
|
|
add_action( 'admin_notices', 'db_error_msg' ); |
|
76
|
|
|
} |
|
77
|
|
|
* |
|
78
|
|
|
*/ |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* |
|
82
|
|
|
* Install DB options |
|
83
|
|
|
* |
|
84
|
|
|
$options = array( |
|
85
|
|
|
array( 'option_name', '__value__' ), |
|
86
|
|
|
); |
|
87
|
|
|
foreach ($options as $value) { |
|
88
|
|
|
update_option( $value[0], $value[1] ); |
|
89
|
|
|
} |
|
90
|
|
|
* |
|
91
|
|
|
*/ |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
//Notice of DB |
|
97
|
|
|
public function db_error_msg() { ?> |
|
98
|
|
|
|
|
99
|
|
|
<div class="notice notice-error is-dismissible"> |
|
100
|
|
|
<p><?php _e( 'Database table Not installed correctly.', 'textdomain' ); ?></p> |
|
|
|
|
|
|
101
|
|
|
</div> |
|
102
|
|
|
<?php |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
|
|
106
|
|
|
|
|
107
|
|
|
public function db_uninstall() { |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* |
|
111
|
|
|
* Important table name declarition |
|
112
|
|
|
* |
|
113
|
|
|
$tableName = 'plugin_db_table'; |
|
114
|
|
|
|
|
115
|
|
|
global $wpdb; |
|
116
|
|
|
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}$tableName" ); |
|
117
|
|
|
$options = array( |
|
118
|
|
|
'_plugin_db_exist' |
|
119
|
|
|
); |
|
120
|
|
|
foreach ($options as $value) { |
|
121
|
|
|
delete_option($value); |
|
122
|
|
|
} |
|
123
|
|
|
* |
|
124
|
|
|
*/ |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
|
|
128
|
|
|
|
|
129
|
|
|
//Include scripts |
|
130
|
|
|
public function scripts() { |
|
131
|
|
|
|
|
132
|
|
|
if ( class_exists( 'CGSS_SCRIPT' ) ) new CGSS_SCRIPT(); |
|
|
|
|
|
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
|
|
136
|
|
|
|
|
137
|
|
|
//Include settings pages |
|
138
|
|
|
public function settings() { |
|
139
|
|
|
|
|
140
|
|
|
if ( class_exists( 'PLUGIN_SETTINGS' ) ) new PLUGIN_SETTINGS(); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
|
|
144
|
|
|
//Include widget classes |
|
145
|
|
|
public function widgets() { |
|
146
|
|
|
|
|
147
|
|
|
if ( class_exists( 'PLUGIN_WIDGET' ) ) new PLUGIN_WIDGET(); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
|
|
151
|
|
|
|
|
152
|
|
|
//Include metabox classes |
|
153
|
|
|
public function metabox() { |
|
154
|
|
|
|
|
155
|
|
|
if ( class_exists( 'PLUGIN_METABOX' ) ) new PLUGIN_METABOX(); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
|
|
159
|
|
|
|
|
160
|
|
|
//Include shortcode classes |
|
161
|
|
|
public function shortcode() { |
|
162
|
|
|
|
|
163
|
|
|
if ( class_exists( 'PLUGIN_SHORTCODE' ) ) new PLUGIN_SHORTCODE(); |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
|
|
167
|
|
|
|
|
168
|
|
|
//Add functionality files |
|
169
|
|
|
public function functionality() { |
|
170
|
|
|
|
|
171
|
|
|
require_once ('src/install.php'); |
|
172
|
|
|
require_once ('src/db.php'); |
|
173
|
|
|
require_once ('src/settings.php'); |
|
174
|
|
|
require_once ('src/widget.php'); |
|
175
|
|
|
require_once ('src/metabox.php'); |
|
176
|
|
|
require_once ('src/shortcode.php'); |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
|
|
180
|
|
|
|
|
181
|
|
|
//Call the dependency files |
|
182
|
|
|
public function helpers() { |
|
183
|
|
|
|
|
184
|
|
|
require_once ('lib/cron.php'); |
|
185
|
|
|
require_once ('lib/api.php'); |
|
186
|
|
|
require_once ('lib/table.php'); |
|
187
|
|
|
require_once ('lib/ajax.php'); |
|
188
|
|
|
require_once ('lib/upload.php'); |
|
189
|
|
|
require_once ('lib/script.php'); |
|
190
|
|
|
|
|
191
|
|
|
/** |
|
192
|
|
|
* Available classes: |
|
193
|
|
|
* |
|
194
|
|
|
* PLUGIN_CORN, PLUGIN_API, PLUGIN_TABLE, PLUGIN_AJAX, PLUGIN_UPLOAD, PLUGIN_SCRIPT |
|
195
|
|
|
*/ |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
|
|
199
|
|
|
|
|
200
|
|
|
public function __construct() { |
|
201
|
|
|
|
|
202
|
|
|
$this->helpers(); |
|
203
|
|
|
$this->functionality(); |
|
204
|
|
|
|
|
205
|
|
|
register_activation_hook( PLUGIN_FILE, array( $this, 'db_install' ) ); |
|
|
|
|
|
|
206
|
|
|
|
|
207
|
|
|
//remove the DB upon uninstallation |
|
208
|
|
|
register_uninstall_hook( PLUGIN_FILE, array( 'PLUGIN_BUILD', 'db_uninstall' ) ); //$this won't work here. |
|
|
|
|
|
|
209
|
|
|
|
|
210
|
|
|
add_action('init', array($this, 'installation')); |
|
|
|
|
|
|
211
|
|
|
|
|
212
|
|
|
$this->scripts(); |
|
213
|
|
|
|
|
214
|
|
|
$this->widgets(); |
|
215
|
|
|
$this->metabox(); |
|
216
|
|
|
$this->shortcode(); |
|
217
|
|
|
$this->settings(); |
|
218
|
|
|
} |
|
219
|
|
|
} |
|
220
|
|
|
} ?> |