PluginProbe
WP Directory Kit / 1.1.0
WP Directory Kit v1.1.0
1.5.6 1.5.5 1.5.4 1.5.3 trunk 1.1.0 1.1.6 1.1.8 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.8 1.4.0 1.4.1 All 35 releases
wpdirectorykit / includes / class-wpdirectorykit-activator.php

class-wpdirectorykit-activator.php in WP Directory Kit 1.1.0, at includes/class-wpdirectorykit-activator.php

344 lines 13.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Fired during plugin activation
5 *
6 * @link listing-themes.com
7 * @since 1.0.0
8 *
9 * @package Wpdirectorykit
10 * @subpackage Wpdirectorykit/includes
11 */
12
13 /**
14 * Fired during plugin activation.
15 *
16 * This class defines all code necessary to run during the plugin's activation.
17 *
18 * @since 1.0.0
19 * @package Wpdirectorykit
20 * @subpackage Wpdirectorykit/includes
21 * @author listing-themes.com <dev@listing-themes.com>
22 */
23
24 if ( ! defined( 'ABSPATH' ) ) {
25 exit; // Exit if accessed directly.
26 }
27 class Wpdirectorykit_Activator {
28
29 public static $db_version = 1.9;
30
31 /**
32 * Short Description. (use period)
33 *
34 * Long Description.
35 *
36 * @since 1.0.0
37 */
38 public static function activate() {
39
40 $prefix = 'wdk_';
41
42 // Default options
43 add_option($prefix.'is_location_enabled', '1');
44 add_option($prefix.'is_category_enabled', '1');
45 add_option($prefix.'is_results_page_require', '1');
46 add_option($prefix.'is_address_enabled', '1');
47
48 // By default set London position
49 add_option($prefix.'default_lat', 51.505);
50 add_option($prefix.'default_lng', -0.09);
51
52 }
53
54 public static function plugins_loaded(){
55 if ( get_site_option( 'wdk_db_version' ) === false ||
56 get_site_option( 'wdk_db_version' ) < self::$db_version ) {
57 self::install();
58 }
59
60 }
61
62 // https://codex.wordpress.org/Creating_Tables_with_Plugins
63 public static function install() {
64 global $wpdb;
65
66 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
67 $charset_collate = $wpdb->get_charset_collate();
68 // For init version 1.0
69 if(get_site_option( 'wdk_db_version' ) === false)
70 {
71 // Main table for visited pages
72
73 $table_name = $wpdb->prefix . 'wdk_fields';
74
75 $sql = "CREATE TABLE IF NOT EXISTS $table_name (
76 `idfield` int(11) NOT NULL AUTO_INCREMENT,
77 `date` datetime DEFAULT NULL,
78 `lang_code` varchar(8) DEFAULT NULL,
79 `order_index` int(11) DEFAULT NULL,
80 `field_type` varchar(45) DEFAULT NULL,
81 `is_locked` tinyint(1) DEFAULT NULL,
82 `is_table_visible` tinyint(1) DEFAULT NULL,
83 `is_visible_frontend` tinyint(1) DEFAULT NULL,
84 `is_visible_dashboard` tinyint(1) DEFAULT NULL,
85 `is_hardlocked` tinyint(1) DEFAULT NULL,
86 `is_required` tinyint(1) DEFAULT NULL,
87 `is_translatable` tinyint(1) DEFAULT NULL,
88 `is_quickvisible` tinyint(1) DEFAULT NULL,
89 `max_length` int(11) DEFAULT NULL,
90 `repository_id` int(11) DEFAULT NULL,
91 `files` int(11) DEFAULT NULL,
92 `icon_id` int(11) DEFAULT NULL,
93 `columns_number` int(11) DEFAULT NULL,
94 `hubspot_id` varchar(60) DEFAULT NULL,
95 `field_label` varchar(50) DEFAULT NULL,
96 `prefix` varchar(30) DEFAULT NULL,
97 `suffix` varchar(30) DEFAULT NULL,
98 `values_list` varchar(160) DEFAULT NULL,
99 `hint` varchar(160) DEFAULT NULL,
100 PRIMARY KEY (idfield)
101 ) $charset_collate COMMENT='Custom Fields Data for WP DIrectory Kit';";
102
103 dbDelta( $sql );
104
105 $table_name = $wpdb->prefix . 'wdk_listings';
106
107 $sql = "CREATE TABLE IF NOT EXISTS $table_name (
108 `idlisting` int(11) NOT NULL AUTO_INCREMENT,
109 `post_id` int(11) NOT NULL,
110 `transition_id` varchar(100) DEFAULT NULL,
111 `category_id` int(11) DEFAULT NULL,
112 `location_id` int(11) DEFAULT NULL,
113 `is_primary` tinyint(1) DEFAULT NULL,
114 `last_edit_user_id` int(11) DEFAULT NULL,
115 `related_id` int(11) DEFAULT NULL,
116 `is_featured` tinyint(1) DEFAULT NULL,
117 `is_activated` tinyint(1) DEFAULT NULL,
118 `lat` decimal(9,6) DEFAULT NULL,
119 `lng` decimal(9,6) DEFAULT NULL,
120 `address` varchar(200) DEFAULT NULL,
121 `rank` int(11) DEFAULT NULL,
122 `date` datetime DEFAULT NULL,
123 `date_modified` datetime DEFAULT NULL,
124 `date_activated` datetime DEFAULT NULL,
125 `date_rank_expire` datetime DEFAULT NULL,
126 `date_alert` datetime DEFAULT NULL,
127 `date_notify` datetime DEFAULT NULL,
128 `date_repost` datetime DEFAULT NULL,
129 `date_renew` datetime DEFAULT NULL,
130 `date_activation_paid` datetime DEFAULT NULL,
131 `date_featured_paid` datetime DEFAULT NULL,
132 `date_status` datetime DEFAULT NULL,
133 `date_expire` datetime DEFAULT NULL,
134 `status` varchar(45) DEFAULT NULL,
135 `last_edit_ip` varchar(45) DEFAULT NULL,
136 `counter_views` int(11) DEFAULT NULL,
137 `reviews_stars` int(11) DEFAULT NULL,
138 `listing_images` text,
139 `affilate_id` int(11) DEFAULT NULL,
140 `not_notified_user` tinyint(1) DEFAULT NULL,
141 `hubspot_id` varchar(60) DEFAULT NULL,
142 PRIMARY KEY (idlisting),
143 UNIQUE KEY (post_id)
144 ) $charset_collate;";
145
146 dbDelta( $sql );
147
148 $table_name = $wpdb->prefix . 'wdk_listings_fields';
149
150 $sql = "CREATE TABLE IF NOT EXISTS `$table_name` (
151 `idlistings_fields` int(11) NOT NULL AUTO_INCREMENT,
152 `post_id` int(11) NOT NULL,
153 `lang_code` varchar(8) COLLATE utf8_unicode_ci DEFAULT NULL,
154 PRIMARY KEY (idlistings_fields),
155 UNIQUE KEY (post_id)
156 ) $charset_collate;";
157
158 dbDelta( $sql );
159
160 $table_name = $wpdb->prefix . 'wdk_categories';
161
162 $sql = "CREATE TABLE IF NOT EXISTS `$table_name` (
163 `idcategory` int(11) NOT NULL AUTO_INCREMENT,
164 `parent_id` int(11) DEFAULT NULL,
165 `page_id` int(11) DEFAULT NULL,
166 `lang_code` varchar(8) DEFAULT NULL,
167 `date` datetime DEFAULT NULL,
168 `parent_path` text,
169 `order_index` int(11) DEFAULT NULL,
170 `level` int(11) DEFAULT NULL,
171 `icon_id` int(11) DEFAULT NULL,
172 `image_id` int(11) DEFAULT NULL,
173 `font_icon_code` varchar(64) DEFAULT NULL,
174 `code` varchar(6) DEFAULT NULL,
175 `hubspot_id` varchar(60) DEFAULT NULL,
176 `category_title` varchar(160) DEFAULT NULL,
177 PRIMARY KEY (idcategory)
178 ) $charset_collate;";
179
180 dbDelta( $sql );
181
182 $table_name = $wpdb->prefix . 'wdk_locations';
183
184 $sql = "CREATE TABLE IF NOT EXISTS `$table_name` (
185 `idlocation` int(11) NOT NULL AUTO_INCREMENT,
186 `parent_id` int(11) DEFAULT NULL,
187 `page_id` int(11) DEFAULT NULL,
188 `lang_code` varchar(8) DEFAULT NULL,
189 `date` datetime DEFAULT NULL,
190 `parent_path` text,
191 `order_index` int(11) DEFAULT NULL,
192 `level` int(11) DEFAULT NULL,
193 `icon_id` int(11) DEFAULT NULL,
194 `image_id` int(11) DEFAULT NULL,
195 `font_icon_code` varchar(64) DEFAULT NULL,
196 `code` varchar(6) DEFAULT NULL,
197 `hubspot_id` varchar(60) DEFAULT NULL,
198 `location_title` varchar(160) DEFAULT NULL,
199 PRIMARY KEY (idlocation)
200 ) $charset_collate;";
201
202 dbDelta( $sql );
203
204 $table_name = $wpdb->prefix . 'wdk_searchform';
205
206 $sql = "CREATE TABLE IF NOT EXISTS `$table_name` (
207 `idsearchform` int(11) NOT NULL AUTO_INCREMENT,
208 `date` datetime DEFAULT NULL,
209 `searchform_name` varchar(160) COLLATE utf8_unicode_ci DEFAULT NULL,
210 `searchform_json` text COLLATE utf8_unicode_ci,
211 PRIMARY KEY (idsearchform)
212 ) $charset_collate;";
213
214 dbDelta( $sql );
215
216 $table_name = $wpdb->prefix . 'wdk_resultitem';
217
218 $sql = "CREATE TABLE IF NOT EXISTS `$table_name` (
219 `idresultitem` int(11) NOT NULL AUTO_INCREMENT,
220 `date` datetime DEFAULT NULL,
221 `resultitem_name` varchar(160) COLLATE utf8_unicode_ci DEFAULT NULL,
222 `resultitem_json` text COLLATE utf8_unicode_ci,
223 PRIMARY KEY (idresultitem)
224 ) $charset_collate;";
225
226 dbDelta( $sql );
227
228 update_option( 'wdk_db_version', "1" );
229
230 }
231
232 /* version 1.1.0 db install */
233 if ( get_site_option( 'wdk_db_version' ) < '1.2' ) {
234 $table_name = $wpdb->prefix . 'wdk_messages';
235 $sql = "CREATE TABLE IF NOT EXISTS `$table_name` (
236 `idmessage` int(11) NOT NULL AUTO_INCREMENT,
237 `post_id` int DEFAULT NULL,
238 `date` datetime DEFAULT NULL,
239 `user_id_sender` int DEFAULT NULL,
240 `user_id_receiver` int DEFAULT NULL,
241 `json_object` text,
242 `email_receiver` varchar(100) DEFAULT NULL,
243 `email_sender` varchar(100) DEFAULT NULL,
244 `message` text,
245 `date_from` datetime DEFAULT NULL,
246 `date_to` datetime DEFAULT NULL,
247 `is_readed` tinyint(1) DEFAULT NULL,
248 PRIMARY KEY (idmessage)
249 ) $charset_collate;";
250
251 dbDelta( $sql );
252
253 $table_name = $wpdb->prefix . 'wdk_listings_users';
254 $sql = "CREATE TABLE IF NOT EXISTS `$table_name` (
255 `idlistings_users` int(11) NOT NULL AUTO_INCREMENT,
256 `post_id` int DEFAULT NULL,
257 `user_id` int DEFAULT NULL,
258 PRIMARY KEY (idlistings_users)
259 ) $charset_collate;";
260
261 dbDelta( $sql );
262 /* udpate option with db version */
263 }
264
265 /* version 1.2.0 db install */
266 if ( get_site_option( 'wdk_db_version' ) < '1.3' ) {
267
268 $table_name = $wpdb->prefix . 'wdk_categories';
269 $sql = "ALTER TABLE `$table_name` CHANGE `parent_id` `parent_id` INT(11) NULL DEFAULT '0'; ";
270 $wpdb->query($sql);
271
272 self::$db_version = 1.3;
273 /* udpate option with db version */
274 }
275
276 /* version 1.2.0 db install */
277 if ( get_site_option( 'wdk_db_version' ) < '1.4' ) {
278
279 $table_name = $wpdb->prefix . 'wdk_listings';
280 $sql = "ALTER TABLE `$table_name` ADD `is_approved` INT(1) NULL DEFAULT NULL AFTER `is_activated`; ";
281 $wpdb->query($sql);
282
283 $sql = "UPDATE `$table_name` SET `is_approved` = '1'";
284 $wpdb->query($sql);
285
286 self::$db_version = 1.4;
287 /* udpate option with db version */
288 }
289
290 if ( get_site_option( 'wdk_db_version' ) < '1.5' ) {
291
292 $table_name = $wpdb->prefix . 'wdk_listings';
293 $sql = "ALTER TABLE `$table_name` ADD `date_package_expire` DATETIME NULL AFTER `hubspot_id`, ADD `package_id` INT NULL AFTER `date_package_expire`; ";
294 $wpdb->query($sql);
295
296 self::$db_version = 1.5;
297 /* udpate option with db version */
298 }
299
300 if ( get_site_option( 'wdk_db_version' ) < '1.6' ) {
301
302 $table_name = $wpdb->prefix . 'wdk_categories';
303 $sql = "ALTER TABLE `$table_name` ADD `marker_image_id` int(11) DEFAULT NULL";
304 $wpdb->query($sql);
305
306 self::$db_version = 1.6;
307 /* udpate option with db version */
308 }
309
310 if ( get_site_option( 'wdk_db_version' ) < '1.7' ) {
311
312 $table_name = $wpdb->prefix . 'wdk_listings';
313 $sql = "ALTER TABLE `$table_name` ADD `listing_images_path` VARCHAR(200) DEFAULT ''";
314 $wpdb->query($sql);
315
316 self::$db_version = 1.7;
317 /* udpate option with db version */
318 }
319
320 if ( get_site_option( 'wdk_db_version' ) < '1.8' ) {
321
322 $table_name = $wpdb->prefix . 'wdk_listings';
323 $sql = "ALTER TABLE `$table_name` ADD `subscription_id` INT NULL; ";
324 $wpdb->query($sql);
325
326 self::$db_version = 1.8;
327 /* udpate option with db version */
328 }
329
330 if ( get_site_option( 'wdk_db_version' ) < '1.9' ) {
331
332 $table_name = $wpdb->prefix . 'wdk_fields';
333 $sql = "ALTER TABLE `$table_name` ADD `is_price_format` tinyint(1) DEFAULT NULL; ";
334 $wpdb->query($sql);
335
336 self::$db_version = 1.9;
337 /* udpate option with db version */
338 }
339
340 update_option( 'wdk_db_version', self::$db_version );
341 }
342
343 }
344