Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/paid-memberships-pro/includes/upgradecheck.php

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + <?php
2 + /*
3 + These functions below handle DB upgrades, etc
4 + */
5 + function pmpro_checkForUpgrades() {
6 + global $wpdb;
7 + $pmpro_db_version = get_option("pmpro_db_version");
8 +
9 + //if we can't find the DB tables, reset db_version to 0
10 + $wpdb->hide_errors();
11 + $wpdb->pmpro_membership_levels = $wpdb->prefix . 'pmpro_membership_levels';
12 + $table_exists = $wpdb->query("SHOW TABLES LIKE '" . $wpdb->pmpro_membership_levels . "'");
13 + if(!$table_exists)
14 + $pmpro_db_version = 0;
15 +
16 + //default options
17 + if(!$pmpro_db_version) {
18 + update_option( 'pmpro_wizard_redirect', true ); // This is for defaulting to the wizard on first activation.
19 + require_once(PMPRO_DIR . "/includes/updates/upgrade_1.php");
20 + $pmpro_db_version = pmpro_upgrade_1();
21 + }
22 +
23 + //upgrading from early early versions of PMPro
24 + if($pmpro_db_version < 1.115) {
25 + require_once(PMPRO_DIR . "/includes/updates/upgrade_1_1_15.php");
26 + $pmpro_db_version = pmpro_upgrade_1_1_15();
27 + }
28 +
29 + //upgrading from early early versions of PMPro
30 + if($pmpro_db_version < 1.23) {
31 + require_once(PMPRO_DIR . "/includes/updates/upgrade_1_2_3.php");
32 + $pmpro_db_version = pmpro_upgrade_1_2_3();
33 + }
34 +
35 + //upgrading from early early versions of PMPro
36 + if($pmpro_db_version < 1.318) {
37 + require_once(PMPRO_DIR . "/includes/updates/upgrade_1_3_18.php");
38 + $pmpro_db_version = pmpro_upgrade_1_3_18();
39 + }
40 +
41 + //upgrading from early early versions of PMPro
42 + if($pmpro_db_version < 1.4) {
43 + require_once(PMPRO_DIR . "/includes/updates/upgrade_1_4.php");
44 + $pmpro_db_version = pmpro_upgrade_1_4();
45 + }
46 +
47 + //upgrading from early early versions of PMPro
48 + if($pmpro_db_version < 1.42) {
49 + require_once(PMPRO_DIR . "/includes/updates/upgrade_1_4_2.php");
50 + $pmpro_db_version = pmpro_upgrade_1_4_2();
51 + }
52 +
53 + //upgrading from early early versions of PMPro
54 + if($pmpro_db_version < 1.48) {
55 + require_once(PMPRO_DIR . "/includes/updates/upgrade_1_4_8.php");
56 + $pmpro_db_version = pmpro_upgrade_1_4_8();
57 + }
58 +
59 + //upgrading from early early versions of PMPro
60 + if($pmpro_db_version < 1.5) {
61 + require_once(PMPRO_DIR . "/includes/updates/upgrade_1_5.php");
62 + $pmpro_db_version = pmpro_upgrade_1_5();
63 + }
64 +
65 + //upgrading from early early versions of PMPro
66 + if($pmpro_db_version < 1.59) {
67 + require_once(PMPRO_DIR . "/includes/updates/upgrade_1_5_9.php");
68 + $pmpro_db_version = pmpro_upgrade_1_5_9();
69 + }
70 +
71 + //upgrading from early early versions of PMPro
72 + if($pmpro_db_version < 1.6) {
73 + require_once(PMPRO_DIR . "/includes/updates/upgrade_1_6.php");
74 + $pmpro_db_version = pmpro_upgrade_1_6();
75 + }
76 +
77 + //fix for fresh 1.7 installs
78 + if($pmpro_db_version == 1.7)
79 + {
80 + //check if we have an id column in the memberships_users table
81 + $wpdb->pmpro_memberships_users = $wpdb->prefix . 'pmpro_memberships_users';
82 + $col = $wpdb->get_var("SELECT id FROM $wpdb->pmpro_memberships_users LIMIT 1");
83 + if($wpdb->last_error == "Unknown column 'id' in 'field list'")
84 + {
85 + //redo 1.5 fix
86 + require_once(PMPRO_DIR . "/includes/updates/upgrade_1_5.php");
87 + pmpro_upgrade_1_5();
88 + }
89 +
90 + pmpro_db_delta();
91 +
92 + update_option("pmpro_db_version", "1.703");
93 + $pmpro_db_version = 1.703;
94 + }
95 +
96 + //updates from this point on should be like this if DB only
97 + if($pmpro_db_version < 1.71)
98 + {
99 + pmpro_db_delta();
100 + update_option("pmpro_db_version", "1.71");
101 + $pmpro_db_version = 1.71;
102 + }
103 +
104 + //register capabilities required for menus now
105 + if($pmpro_db_version < 1.79)
106 + {
107 + //need to register caps for menu
108 + pmpro_activation();
109 +
110 + update_option("pmpro_db_version", "1.79");
111 + $pmpro_db_version = 1.79;
112 + }
113 +
114 + //set default filter_queries setting
115 + if($pmpro_db_version < 1.791)
116 + {
117 + if(!get_option("pmpro_showexcerpts"))
118 + update_option("pmpro_filterqueries", 1);
119 + else
120 + update_option("pmpro_filterqueries", 0);
121 +
122 + update_option("pmpro_db_version", "1.791");
123 + $pmpro_db_version = 1.791;
124 + }
125 +
126 + //fix subscription ids on stripe orders
127 + require_once(PMPRO_DIR . "/includes/updates/upgrade_1_8_6_9.php"); //need to include this for AJAX calls
128 + if($pmpro_db_version < 1.869) {
129 + $pmpro_db_version = pmpro_upgrade_1_8_6_9();
130 + }
131 +
132 + /*
133 + v1.8.8
134 + * Fixing old $0 Stripe orders.
135 + * Fixing old Authorize.net orders with empty status.
136 + */
137 + require_once(PMPRO_DIR . "/includes/updates/upgrade_1_8_8.php");
138 + if($pmpro_db_version < 1.88) {
139 + $pmpro_db_version = pmpro_upgrade_1_8_8();
140 + }
141 +
142 + /*
143 + v1.8.9.1
144 + * Fixing Stripe orders where user_id/membership_id = 0
145 + * Updated in v1.9.2.2 to check for namespace compatibility first,
146 + since the Stripe class isn't loaded for PHP < 5.3.29
147 + */
148 + if (version_compare( PHP_VERSION, '5.3.29', '>=' )) {
149 + require_once(PMPRO_DIR . "/includes/updates/upgrade_1_8_9_1.php");
150 + if($pmpro_db_version < 1.891) {
151 + $pmpro_db_version = pmpro_upgrade_1_8_9_1();
152 + }
153 + } elseif($pmpro_db_version < 1.891) {
154 + $pmpro_db_version = 1.891; //skipping this update because Stripe is not supported
155 + }
156 +
157 + /*
158 + v1.8.9.2 (db v1.9)
159 + * Changed 'code' column of pmpro_membership_orders table to 32 characters.
160 + */
161 + if($pmpro_db_version < 1.892) {
162 + pmpro_db_delta();
163 +
164 + $pmpro_db_version = 1.892;
165 + update_option("pmpro_db_version", "1.892");
166 + }
167 +
168 + /*
169 + v1.8.9.3 (db v1.91)
170 + * Fixing incorrect start and end dates.
171 + */
172 + require_once(PMPRO_DIR . "/includes/updates/upgrade_1_8_9_3.php");
173 + if($pmpro_db_version < 1.91) {
174 + $pmpro_db_version = pmpro_upgrade_1_8_9_3();
175 + }
176 +
177 + /*
178 + v1.8.10 (db v1.92)
179 +
180 + Added checkout_id column to pmpro_membership_orders
181 + */
182 + if($pmpro_db_version < 1.92) {
183 + pmpro_db_delta();
184 +
185 + $pmpro_db_version = 1.92;
186 + update_option("pmpro_db_version", "1.92");
187 + }
188 +
189 + /*
190 + v1.8.10.2 (db v1.93)
191 +
192 + Run dbDelta again to fix broken/missing orders tables.
193 + */
194 + if($pmpro_db_version < 1.93) {
195 + pmpro_db_delta();
196 +
197 + $pmpro_db_version = 1.93;
198 + update_option("pmpro_db_version", "1.93");
199 + }
200 +
201 + require_once( PMPRO_DIR . "/includes/updates/upgrade_1_9_4.php" );
202 + if($pmpro_db_version < 1.94) {
203 + $pmpro_db_version = pmpro_upgrade_1_9_4();
204 + }
205 +
206 + if($pmpro_db_version < 1.944) {
207 + pmpro_cleanup_memberships_users_table();
208 + $pmpro_db_version = '1.944';
209 + update_option('pmpro_db_version', '1.944');
210 + }
211 +
212 + if ( $pmpro_db_version < 2.1 ) {
213 + pmpro_db_delta();
214 +
215 + $pmpro_db_version = 2.1;
216 + update_option( 'pmpro_db_version', '2.1' );
217 + }
218 +
219 + /**
220 + * Version 2.4
221 + * Fixing subscription_transaction_id
222 + * for orders created through a Stripe Update.
223 + */
224 + require_once( PMPRO_DIR . "/includes/updates/upgrade_2_4.php" );
225 + if($pmpro_db_version < 2.4) {
226 + $pmpro_db_version = pmpro_upgrade_2_4();
227 + }
228 +
229 + /**
230 + * Version 2.5
231 + * Running pmpro_db_delta to install the ordermeta table.
232 + */
233 + if( $pmpro_db_version < 2.5 ) {
234 + pmpro_db_delta();
235 + $pmpro_db_version = 2.5;
236 + update_option( 'pmpro_db_version', '2.5' );
237 + }
238 +
239 + /**
240 + * Version 2.6
241 + * Running pmpro_db_delta to update column types to bigint/etc
242 + */
243 + require_once( PMPRO_DIR . "/includes/updates/upgrade_2_6.php" );
244 + if( $pmpro_db_version < 2.6 ) {
245 + pmpro_db_delta();
246 + $pmpro_db_version = pmpro_upgrade_2_6();
247 + update_option( 'pmpro_db_version', '2.6' );
248 + }
249 +
250 + /**
251 + * Version 2.7.1
252 + * Running pmpro_db_delta to fix the primary key in a couple tables.
253 + */
254 + if( $pmpro_db_version < 2.71 ) {
255 + pmpro_db_delta();
256 + update_option( 'pmpro_db_version', '2.71' );
257 + }
258 +
259 + /**
260 + * Version 2.8
261 + * Default option for Wisdom tracking.
262 + */
263 + if ( $pmpro_db_version < 2.8 ) {
264 + update_option('pmpro_wisdom_opt_out', 0);
265 + update_option( 'pmpro_db_version', '2.8' );
266 + }
267 +
268 + /**
269 + * Version 2.9.4
270 + * Check the current domain and store it
271 + */
272 + if ( $pmpro_db_version < 2.94 ) {
273 + update_option( 'pmpro_last_known_url', get_site_url() );
274 + update_option( 'pmpro_db_version', '2.94' );
275 + }
276 +
277 + /**
278 + * Version 2.10
279 + * We are increasing Stripe application fee, but if the site is already being
280 + * charged at 1%, we want to let them keep that fee.
281 + * We are also fixing the pmpro_wisdom_opt_out option.
282 + */
283 + if ( $pmpro_db_version < 2.95 ) { // 2.95 since 2.10 would be lower than previous update.
284 + require_once( PMPRO_DIR . "/includes/updates/upgrade_2_10.php" );
285 + pmpro_upgrade_2_10();
286 + update_option( 'pmpro_db_version', '2.95' );
287 + }
288 +
289 + /**
290 + * Version 2.10.6
291 + * Check for sensitive information in ordermeta.
292 + */
293 + require_once( PMPRO_DIR . "/includes/updates/upgrade_2_10_6.php" ); // Need to include this for admin notice.
294 + if ( $pmpro_db_version < 2.96 ) { // 2.96 since 2.106 would be lower than previous update.
295 + pmpro_upgrade_2_10_6(); // This function will update the db version.
296 + }
297 +
298 + /**
299 + * Version 2.12
300 + * Update the database to use varchar instead of enums.
301 + */
302 + if ( $pmpro_db_version < 2.97 ) { // 2.97 since 2.12 would be lower than previous update.
303 + pmpro_db_delta();
304 + update_option( 'pmpro_db_version', '2.97' );
305 + }
306 +
307 + /**
308 + * Version 3.0 (db v3.0-3.009 for RC's)
309 + * Running `pmpro_db_delta` to add subscription and subscription meta tables.
310 + * Populate subscription and subscription meta tables based on this site's order data.
311 + * Updates all orders in `cancelled` status to `success` so that we can remove cancelled status.
312 + */
313 + require_once( PMPRO_DIR . "/includes/updates/upgrade_3_0.php" );
314 + if ( $pmpro_db_version < 3.001 ) {
315 + // Run the dbDelta function to add new tables.
316 + pmpro_db_delta();
317 +
318 + // Determine if the migration script has already ran ($pmpro_db_version >= 3.0).
319 + $rerunning_migration = $pmpro_db_version >= 3.0;
320 +
321 + // Run the migration script.
322 + $pmpro_db_version = pmpro_upgrade_3_0( $rerunning_migration );
323 +
324 + // If the migration script has already ran, we need to update the db version to the latest version.
325 + update_option( 'pmpro_db_version', '3.001' );
326 + }
327 +
328 + /**
329 + * Version 3.0.2
330 + * Default sites that are already using outdated page templates to continue using them.
331 + */
332 + if ( $pmpro_db_version < 3.02 ) {
333 + require_once( PMPRO_DIR . "/includes/updates/upgrade_3_0_2.php" );
334 + pmpro_upgrade_3_0_2(); // This function will update the db version.
335 + }
336 +
337 + /**
338 + * Version 3.1
339 + * Delete the option for pmpro_accepted_credit_cards.
340 + * Modify and set new options for membership required messages.
341 + */
342 + require_once( PMPRO_DIR . "/includes/updates/upgrade_3_1.php" );
343 + if ( $pmpro_db_version < 3.1001 ) {
344 + // Run the dbDelta function for fixing some int columns to be bigint.
345 + pmpro_db_delta();
346 +
347 + // Run the upgrade function for 3.1.
348 + pmpro_upgrade_3_1();
349 + update_option( 'pmpro_db_version', '3.1001' );
350 + }
351 +
352 + /**
353 + * Version 3.2
354 + * Notice that PPE is no longer automatically bundled with Website Payments Pro.
355 + * Adding billing_street2 to the orders table.
356 + */
357 + require_once( PMPRO_DIR . "/includes/updates/upgrade_3_2.php" );
358 + if ( $pmpro_db_version < 3.2 ) {
359 + pmpro_db_delta();
360 + pmpro_upgrade_3_2();
361 + update_option( 'pmpro_db_version', '3.2' );
362 + }
363 +
364 + /**
365 + * Version 3.3.1
366 + * Adding `one_use_per_user` column to discount codes.
367 + */
368 + if ( $pmpro_db_version < 3.3 ) {
369 + pmpro_db_delta();
370 + update_option( 'pmpro_db_version', '3.3' );
371 + }
372 +
373 + /**
374 + * Version 3.4
375 + * Allowing subscription transaction IDs up to 64 characters.
376 + */
377 + if ( $pmpro_db_version < 3.4 ) {
378 + pmpro_db_delta();
379 + update_option( 'pmpro_db_version', '3.4' );
380 + }
381 +
382 + /**
383 + * Version 3.4.2
384 + * Fixing broken Payflow deprecation.
385 + */
386 + if ( $pmpro_db_version < 3.402 ) {
387 + // Check if there are any Payflow settings.
388 + if ( ! empty( get_option( 'pmpro_payflow_partner' ) ) ) {
389 + // Get the current list of undeprecated gateways.
390 + $undeprecated_gateways = get_option( 'pmpro_undeprecated_gateways' );
391 + if ( empty( $undeprecated_gateways ) ) {
392 + $undeprecated_gateways = array();
393 + } elseif ( is_string( $undeprecated_gateways ) ) {
394 + // pmpro_setOption turns this into a comma separated string
395 + $undeprecated_gateways = explode( ',', $undeprecated_gateways );
396 + }
397 +
398 + // If Payflow isn't in the list, add it.
399 + if ( ! in_array( 'payflowpro', $undeprecated_gateways ) ) {
400 + $undeprecated_gateways[] = 'payflowpro';
401 + update_option( 'pmpro_undeprecated_gateways', $undeprecated_gateways );
402 + }
403 + }
404 +
405 + update_option( 'pmpro_db_version', '3.402' );
406 + }
407 +
408 + if ( $pmpro_db_version < 3.5 ) {
409 + require_once( PMPRO_DIR . "/includes/updates/upgrade_3_5.php" );
410 + pmpro_db_delta();
411 + pmpro_upgrade_3_5(); // This function will update the db version.
412 + update_option( 'pmpro_db_version', '3.5' );
413 + }
414 +
415 + if ( $pmpro_db_version < 3.53 ) {
416 + // Clear out any scheduled recurring tasks.
417 + add_action( 'action_scheduler_init', function() {
418 + PMPro_Action_Scheduler::clear_recurring_tasks();
419 + });
420 + update_option( 'pmpro_db_version', '3.53' );
421 + }
422 +
423 + }
424 +
425 + function pmpro_db_delta() {
426 + require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
427 +
428 + global $wpdb;
429 + $wpdb->hide_errors();
430 + $wpdb->pmpro_membership_levels = $wpdb->prefix . 'pmpro_membership_levels';
431 + $wpdb->pmpro_memberships_users = $wpdb->prefix . 'pmpro_memberships_users';
432 + $wpdb->pmpro_memberships_categories = $wpdb->prefix . 'pmpro_memberships_categories';
433 + $wpdb->pmpro_memberships_pages = $wpdb->prefix . 'pmpro_memberships_pages';
434 + $wpdb->pmpro_membership_orders = $wpdb->prefix . 'pmpro_membership_orders';
435 + $wpdb->pmpro_discount_codes = $wpdb->prefix . 'pmpro_discount_codes';
436 + $wpdb->pmpro_discount_codes_levels = $wpdb->prefix . 'pmpro_discount_codes_levels';
437 + $wpdb->pmpro_discount_codes_uses = $wpdb->prefix . 'pmpro_discount_codes_uses';
438 + $wpdb->pmpro_membership_levelmeta = $wpdb->prefix . 'pmpro_membership_levelmeta';
439 + $wpdb->pmpro_subscriptions = $wpdb->prefix . 'pmpro_subscriptions';
440 + $wpdb->pmpro_membership_ordermeta = $wpdb->prefix . 'pmpro_membership_ordermeta';
441 + $wpdb->pmpro_subscriptionmeta = $wpdb->prefix . 'pmpro_subscriptionmeta';
442 + $wpdb->pmpro_groups = $wpdb->prefix . 'pmpro_groups';
443 + $wpdb->pmpro_membership_levels_groups = $wpdb->prefix . 'pmpro_membership_levels_groups';
444 +
445 + $collate = '';
446 + if ( $wpdb->has_cap( 'collation' ) ) {
447 + $collate = $wpdb->get_charset_collate();
448 + }
449 +
450 + /*
451 + * Indexes have a maximum size of 767 bytes. Historically, we haven't need to be concerned about that.
452 + * As of 4.2, however, we moved to utf8mb4, which uses 4 bytes per character. This means that an index which
453 + * used to have room for floor(767/3) = 255 characters, now only has room for floor(767/4) = 191 characters.
454 + *
455 + * Copied from Core WP.
456 + */
457 + $max_index_length = 191;
458 +
459 + //wp_pmpro_membership_levels
460 + $sqlQuery = "
461 + CREATE TABLE `" . $wpdb->pmpro_membership_levels . "` (
462 + `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
463 + `name` varchar(255) NOT NULL,
464 + `description` longtext NOT NULL,
465 + `confirmation` longtext NOT NULL,
466 + `initial_payment` decimal(18,8) NOT NULL DEFAULT '0.00',
467 + `billing_amount` decimal(18,8) NOT NULL DEFAULT '0.00',
468 + `cycle_number` int(11) NOT NULL DEFAULT '0',
469 + `cycle_period` varchar(10) DEFAULT 'Month',
470 + `billing_limit` int(11) NOT NULL COMMENT 'After how many cycles should billing stop?',
471 + `trial_amount` decimal(18,8) NOT NULL DEFAULT '0.00',
472 + `trial_limit` int(11) NOT NULL DEFAULT '0',
473 + `allow_signups` tinyint(4) NOT NULL DEFAULT '1',
474 + `expiration_number` int(10) unsigned NOT NULL,
475 + `expiration_period` varchar(10) NOT NULL,
476 + PRIMARY KEY (`id`),
477 + KEY `allow_signups` (`allow_signups`),
478 + KEY `initial_payment` (`initial_payment`),
479 + KEY `name` (`name`(" . $max_index_length . "))
480 + ) $collate;
481 + ";
482 + dbDelta($sqlQuery);
483 +
484 + //wp_pmpro_membership_orders
485 + $sqlQuery = "
486 + CREATE TABLE `" . $wpdb->pmpro_membership_orders . "` (
487 + `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
488 + `code` varchar(32) NOT NULL,
489 + `session_id` varchar(64) NOT NULL DEFAULT '',
490 + `user_id` bigint(20) unsigned NOT NULL DEFAULT '0',
491 + `membership_id` int(11) unsigned NOT NULL DEFAULT '0',
492 + `paypal_token` varchar(64) NOT NULL DEFAULT '',
493 + `billing_name` varchar(128) NOT NULL DEFAULT '',
494 + `billing_street` varchar(128) NOT NULL DEFAULT '',
495 + `billing_street2` varchar(128) NOT NULL DEFAULT '',
496 + `billing_city` varchar(128) NOT NULL DEFAULT '',
497 + `billing_state` varchar(32) NOT NULL DEFAULT '',
498 + `billing_zip` varchar(16) NOT NULL DEFAULT '',
499 + `billing_country` varchar(128) NOT NULL,
500 + `billing_phone` varchar(32) NOT NULL,
501 + `subtotal` varchar(16) NOT NULL DEFAULT '',
502 + `tax` varchar(16) NOT NULL DEFAULT '',
503 + `checkout_id` bigint(20) NOT NULL DEFAULT '0',
504 + `total` varchar(16) NOT NULL DEFAULT '',
505 + `payment_type` varchar(64) NOT NULL DEFAULT '',
506 + `cardtype` varchar(32) NOT NULL DEFAULT '',
507 + `accountnumber` varchar(32) NOT NULL DEFAULT '',
508 + `expirationmonth` char(2) NOT NULL DEFAULT '',
509 + `expirationyear` varchar(4) NOT NULL DEFAULT '',
510 + `status` varchar(32) NOT NULL DEFAULT '',
511 + `gateway` varchar(64) NOT NULL,
512 + `gateway_environment` varchar(64) NOT NULL,
513 + `payment_transaction_id` varchar(64) NOT NULL,
514 + `subscription_transaction_id` varchar(64) NOT NULL,
515 + `timestamp` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
516 + `affiliate_id` varchar(32) NOT NULL,
517 + `affiliate_subid` varchar(32) NOT NULL,
518 + `notes` TEXT NOT NULL,
519 + PRIMARY KEY (`id`),
520 + UNIQUE KEY `code` (`code`),
521 + KEY `session_id` (`session_id`),
522 + KEY `user_id` (`user_id`),
523 + KEY `membership_id` (`membership_id`),
524 + KEY `status` (`status`),
525 + KEY `timestamp` (`timestamp`),
526 + KEY `gateway` (`gateway`),
527 + KEY `gateway_environment` (`gateway_environment`),
528 + KEY `payment_transaction_id` (`payment_transaction_id`),
529 + KEY `subscription_transaction_id` (`subscription_transaction_id`),
530 + KEY `affiliate_id` (`affiliate_id`),
531 + KEY `affiliate_subid` (`affiliate_subid`),
532 + KEY `checkout_id` (`checkout_id`)
533 + ) $collate;
534 + ";
535 + dbDelta($sqlQuery);
536 +
537 + //wp_pmpro_memberships_categories
538 + $sqlQuery = "
539 + CREATE TABLE `" . $wpdb->pmpro_memberships_categories . "` (
540 + `membership_id` int(11) unsigned NOT NULL,
541 + `category_id` bigint(20) unsigned NOT NULL,
542 + `modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
543 + PRIMARY KEY (`membership_id`,`category_id`),
544 + UNIQUE KEY `category_membership` (`category_id`,`membership_id`)
545 + ) $collate;
546 + ";
547 + dbDelta($sqlQuery);
548 +
549 + //wp_pmpro_memberships_pages
550 + $sqlQuery = "
551 + CREATE TABLE `" . $wpdb->pmpro_memberships_pages . "` (
552 + `membership_id` int(11) unsigned NOT NULL,
553 + `page_id` bigint(20) unsigned NOT NULL,
554 + `modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
555 + PRIMARY KEY (`page_id`,`membership_id`),
556 + UNIQUE KEY `membership_page` (`membership_id`,`page_id`)
557 + ) $collate;
558 + ";
559 + dbDelta($sqlQuery);
560 +
561 + //wp_pmpro_memberships_users
562 + $sqlQuery = "
563 + CREATE TABLE `" . $wpdb->pmpro_memberships_users . "` (
564 + `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
565 + `user_id` bigint(20) unsigned NOT NULL,
566 + `membership_id` int(11) unsigned NOT NULL,
567 + `code_id` bigint(20) unsigned NOT NULL,
568 + `initial_payment` decimal(18,8) NOT NULL,
569 + `billing_amount` decimal(18,8) NOT NULL,
570 + `cycle_number` int(11) NOT NULL,
571 + `cycle_period` varchar(10) NOT NULL DEFAULT 'Month',
572 + `billing_limit` int(11) NOT NULL,
573 + `trial_amount` decimal(18,8) NOT NULL,
574 + `trial_limit` int(11) NOT NULL,
575 + `status` varchar(20) NOT NULL DEFAULT 'active',
576 + `startdate` datetime NOT NULL,
577 + `enddate` datetime DEFAULT NULL,
578 + `modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
579 + PRIMARY KEY (`id`),
580 + KEY `membership_id` (`membership_id`),
581 + KEY `modified` (`modified`),
582 + KEY `code_id` (`code_id`),
583 + KEY `enddate` (`enddate`),
584 + KEY `user_id` (`user_id`),
585 + KEY `status` (`status`)
586 + ) $collate;
587 + ";
588 + dbDelta($sqlQuery);
589 +
590 + //wp_pmpro_discount_codes
591 + $sqlQuery = "
592 + CREATE TABLE `" . $wpdb->pmpro_discount_codes . "` (
593 + `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
594 + `code` varchar(32) NOT NULL,
595 + `starts` date NOT NULL,
596 + `expires` date NOT NULL,
597 + `uses` int(11) NOT NULL,
598 + `one_use_per_user` tinyint(4) NOT NULL DEFAULT '0',
599 + PRIMARY KEY (`id`),
600 + UNIQUE KEY `code` (`code`),
601 + KEY `starts` (`starts`),
602 + KEY `expires` (`expires`)
603 + ) $collate;
604 + ";
605 + dbDelta($sqlQuery);
606 +
607 + //wp_pmpro_discount_codes_levels
608 + $sqlQuery = "
609 + CREATE TABLE `" . $wpdb->pmpro_discount_codes_levels . "` (
610 + `code_id` bigint(20) unsigned NOT NULL,
611 + `level_id` int(11) unsigned NOT NULL,
612 + `initial_payment` decimal(18,8) NOT NULL DEFAULT '0.00',
613 + `billing_amount` decimal(18,8) NOT NULL DEFAULT '0.00',
614 + `cycle_number` int(11) NOT NULL DEFAULT '0',
615 + `cycle_period` varchar(10) DEFAULT 'Month',
616 + `billing_limit` int(11) NOT NULL COMMENT 'After how many cycles should billing stop?',
617 + `trial_amount` decimal(18,8) NOT NULL DEFAULT '0.00',
618 + `trial_limit` int(11) NOT NULL DEFAULT '0',
619 + `expiration_number` int(10) unsigned NOT NULL,
620 + `expiration_period` varchar(10) NOT NULL,
621 + PRIMARY KEY (`code_id`,`level_id`),
622 + KEY `initial_payment` (`initial_payment`)
623 + ) $collate;
624 + ";
625 + dbDelta($sqlQuery);
626 +
627 + //wp_pmpro_discount_codes_uses
628 + $sqlQuery = "
629 + CREATE TABLE `" . $wpdb->pmpro_discount_codes_uses . "` (
630 + `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
631 + `code_id` bigint(20) unsigned NOT NULL,
632 + `user_id` bigint(20) unsigned NOT NULL,
633 + `order_id` bigint(20) unsigned NOT NULL,
634 + `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
635 + PRIMARY KEY (`id`),
636 + KEY `user_id` (`user_id`),
637 + KEY `timestamp` (`timestamp`)
638 + ) $collate;
639 + ";
640 + dbDelta($sqlQuery);
641 +
642 + //pmpro_membership_levelmeta
643 + $sqlQuery = "
644 + CREATE TABLE `" . $wpdb->pmpro_membership_levelmeta . "` (
645 + `meta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
646 + `pmpro_membership_level_id` int(11) unsigned NOT NULL,
647 + `meta_key` varchar(255) NOT NULL,
648 + `meta_value` longtext,
649 + PRIMARY KEY (`meta_id`),
650 + KEY `pmpro_membership_level_id` (`pmpro_membership_level_id`),
651 + KEY `meta_key` (`meta_key`(" . $max_index_length . "))
652 + ) $collate;
653 + ";
654 + dbDelta($sqlQuery);
655 +
656 + //pmpro_membership_subscriptions
657 + $sqlQuery = "
658 + CREATE TABLE `" . $wpdb->pmpro_subscriptions . "` (
659 + `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
660 + `user_id` bigint(20) unsigned NOT NULL,
661 + `membership_level_id` int(11) unsigned NOT NULL,
662 + `gateway` varchar(64) NOT NULL,
663 + `gateway_environment` varchar(64) NOT NULL,
664 + `subscription_transaction_id` varchar(64) NOT NULL,
665 + `status` varchar(20) NOT NULL DEFAULT 'active',
666 + `startdate` datetime DEFAULT NULL,
667 + `enddate` datetime DEFAULT NULL,
668 + `next_payment_date` datetime DEFAULT NULL,
669 + `billing_amount` decimal(18,8) NOT NULL DEFAULT '0.00',
670 + `cycle_number` int(11) NOT NULL DEFAULT '0',
671 + `cycle_period` varchar(10) NOT NULL DEFAULT 'Month',
672 + `billing_limit` int(11) NOT NULL DEFAULT '0',
673 + `trial_amount` decimal(18,8) NOT NULL DEFAULT '0.00',
674 + `trial_limit` int(11) NOT NULL DEFAULT '0',
675 + `modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
676 + PRIMARY KEY (`id`),
677 + UNIQUE KEY `subscription_link` (`subscription_transaction_id`, `gateway_environment`, `gateway`),
678 + KEY `user_id` (`user_id`),
679 + KEY `next_payment_date` (`next_payment_date`)
680 + ) $collate;
681 + ";
682 + dbDelta($sqlQuery);
683 +
684 + //pmpro_membership_ordermeta
685 + $sqlQuery = "
686 + CREATE TABLE `" . $wpdb->pmpro_membership_ordermeta . "` (
687 + `meta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
688 + `pmpro_membership_order_id` bigint(20) unsigned NOT NULL,
689 + `meta_key` varchar(255) NOT NULL,
690 + `meta_value` longtext,
691 + PRIMARY KEY (`meta_id`),
692 + KEY `pmpro_membership_order_id` (`pmpro_membership_order_id`),
693 + KEY `meta_key` (`meta_key`(" . $max_index_length . "))
694 + ) $collate;
695 + ";
696 + dbDelta($sqlQuery);
697 +
698 + //pmpro_subscriptionmeta
699 + $sqlQuery = "
700 + CREATE TABLE `" . $wpdb->pmpro_subscriptionmeta . "` (
701 + `meta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
702 + `pmpro_subscription_id` bigint(20) unsigned NOT NULL,
703 + `meta_key` varchar(255) NOT NULL,
704 + `meta_value` longtext,
705 + PRIMARY KEY (`meta_id`),
706 + KEY `pmpro_subscription_id` (`pmpro_subscription_id`),
707 + KEY `meta_key` (`meta_key`(" . $max_index_length . "))
708 + ) $collate;
709 + ";
710 + dbDelta($sqlQuery);
711 +
712 + //pmpro_groups
713 + $sqlQuery = "
714 + CREATE TABLE `" . $wpdb->pmpro_groups . "` (
715 + `id` int unsigned NOT NULL AUTO_INCREMENT,
716 + `name` varchar(255) NOT NULL,
717 + `allow_multiple_selections` tinyint NOT NULL DEFAULT '1',
718 + `displayorder` int,
719 + PRIMARY KEY (`id`),
720 + KEY `name` (`name`(" . $max_index_length . "))
721 + ) $collate;
722 + ";
723 + dbDelta($sqlQuery);
724 +
725 + //pmpro_membership_levels_groups
726 + $sqlQuery = "
727 + CREATE TABLE `" . $wpdb->pmpro_membership_levels_groups . "` (
728 + `id` int unsigned NOT NULL AUTO_INCREMENT,
729 + `level` int unsigned NOT NULL DEFAULT '0',
730 + `group` int unsigned NOT NULL DEFAULT '0',
731 + PRIMARY KEY (`id`),
732 + KEY `level` (`level`),
733 + KEY `group` (`group`)
734 + ) $collate;
735 + ";
736 + dbDelta($sqlQuery);
737 + }
738 +