pmpro_db_delta

The Paid Memberships Pro pmpro db delta function.

Description

pmpro_db_delta(); 

Usage

  1. if ( !function_exists( 'pmpro_db_delta' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'paid-memberships-pro/includes/upgradecheck.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = pmpro_db_delta(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/includes/upgradecheck.php  
  1. function pmpro_db_delta() 
  2. require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); 
  3.  
  4. global $wpdb; 
  5. $wpdb->hide_errors(); 
  6. $wpdb->pmpro_membership_levels = $wpdb->prefix . 'pmpro_membership_levels'; 
  7. $wpdb->pmpro_memberships_users = $wpdb->prefix . 'pmpro_memberships_users'; 
  8. $wpdb->pmpro_memberships_categories = $wpdb->prefix . 'pmpro_memberships_categories'; 
  9. $wpdb->pmpro_memberships_pages = $wpdb->prefix . 'pmpro_memberships_pages'; 
  10. $wpdb->pmpro_membership_orders = $wpdb->prefix . 'pmpro_membership_orders'; 
  11. $wpdb->pmpro_discount_codes = $wpdb->prefix . 'pmpro_discount_codes'; 
  12. $wpdb->pmpro_discount_codes_levels = $wpdb->prefix . 'pmpro_discount_codes_levels'; 
  13. $wpdb->pmpro_discount_codes_uses = $wpdb->prefix . 'pmpro_discount_codes_uses'; 
  14. $wpdb->pmpro_membership_levelmeta = $wpdb->prefix . 'pmpro_membership_levelmeta'; 
  15.  
  16. //wp_pmpro_membership_levels 
  17. $sqlQuery = " 
  18. CREATE TABLE `" . $wpdb->pmpro_membership_levels . "` ( 
  19. `id` int(11) unsigned NOT NULL AUTO_INCREMENT,  
  20. `name` varchar(255) NOT NULL,  
  21. `description` longtext NOT NULL,  
  22. `confirmation` longtext NOT NULL,  
  23. `initial_payment` decimal(10, 2) NOT NULL DEFAULT '0.00',  
  24. `billing_amount` decimal(10, 2) NOT NULL DEFAULT '0.00',  
  25. `cycle_number` int(11) NOT NULL DEFAULT '0',  
  26. `cycle_period` enum('Day', 'Week', 'Month', 'Year') DEFAULT 'Month',  
  27. `billing_limit` int(11) NOT NULL COMMENT 'After how many cycles should billing stop?',  
  28. `trial_amount` decimal(10, 2) NOT NULL DEFAULT '0.00',  
  29. `trial_limit` int(11) NOT NULL DEFAULT '0',  
  30. `allow_signups` tinyint(4) NOT NULL DEFAULT '1',  
  31. `expiration_number` int(10) unsigned NOT NULL,  
  32. `expiration_period` enum('Day', 'Week', 'Month', 'Year') NOT NULL,  
  33. PRIMARY KEY (`id`),  
  34. KEY `allow_signups` (`allow_signups`),  
  35. KEY `initial_payment` (`initial_payment`),  
  36. KEY `name` (`name`) 
  37. ); 
  38. "; 
  39. dbDelta($sqlQuery); 
  40.  
  41. //wp_pmpro_membership_orders 
  42. $sqlQuery = " 
  43. CREATE TABLE `" . $wpdb->pmpro_membership_orders . "` ( 
  44. `id` int(11) unsigned NOT NULL AUTO_INCREMENT,  
  45. `code` varchar(32) NOT NULL,  
  46. `session_id` varchar(64) NOT NULL DEFAULT '',  
  47. `user_id` int(11) unsigned NOT NULL DEFAULT '0',  
  48. `membership_id` int(11) unsigned NOT NULL DEFAULT '0',  
  49. `paypal_token` varchar(64) NOT NULL DEFAULT '',  
  50. `billing_name` varchar(128) NOT NULL DEFAULT '',  
  51. `billing_street` varchar(128) NOT NULL DEFAULT '',  
  52. `billing_city` varchar(128) NOT NULL DEFAULT '',  
  53. `billing_state` varchar(32) NOT NULL DEFAULT '',  
  54. `billing_zip` varchar(16) NOT NULL DEFAULT '',  
  55. `billing_country` varchar(128) NOT NULL,  
  56. `billing_phone` varchar(32) NOT NULL,  
  57. `subtotal` varchar(16) NOT NULL DEFAULT '',  
  58. `tax` varchar(16) NOT NULL DEFAULT '',  
  59. `couponamount` varchar(16) NOT NULL DEFAULT '',  
  60. `checkout_id` int(11) NOT NULL DEFAULT '0',  
  61. `certificate_id` int(11) NOT NULL DEFAULT '0',  
  62. `certificateamount` varchar(16) NOT NULL DEFAULT '',  
  63. `total` varchar(16) NOT NULL DEFAULT '',  
  64. `payment_type` varchar(64) NOT NULL DEFAULT '',  
  65. `cardtype` varchar(32) NOT NULL DEFAULT '',  
  66. `accountnumber` varchar(32) NOT NULL DEFAULT '',  
  67. `expirationmonth` char(2) NOT NULL DEFAULT '',  
  68. `expirationyear` varchar(4) NOT NULL DEFAULT '',  
  69. `status` varchar(32) NOT NULL DEFAULT '',  
  70. `gateway` varchar(64) NOT NULL,  
  71. `gateway_environment` varchar(64) NOT NULL,  
  72. `payment_transaction_id` varchar(64) NOT NULL,  
  73. `subscription_transaction_id` varchar(32) NOT NULL,  
  74. `timestamp` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',  
  75. `affiliate_id` varchar(32) NOT NULL,  
  76. `affiliate_subid` varchar(32) NOT NULL,  
  77. `notes` TEXT NOT NULL,  
  78. PRIMARY KEY (`id`),  
  79. UNIQUE KEY `code` (`code`),  
  80. KEY `session_id` (`session_id`),  
  81. KEY `user_id` (`user_id`),  
  82. KEY `membership_id` (`membership_id`),  
  83. KEY `status` (`status`),  
  84. KEY `timestamp` (`timestamp`),  
  85. KEY `gateway` (`gateway`),  
  86. KEY `gateway_environment` (`gateway_environment`),  
  87. KEY `payment_transaction_id` (`payment_transaction_id`),  
  88. KEY `subscription_transaction_id` (`subscription_transaction_id`),  
  89. KEY `affiliate_id` (`affiliate_id`),  
  90. KEY `affiliate_subid` (`affiliate_subid`),  
  91. KEY `checkout_id` (`checkout_id`) 
  92. ); 
  93. "; 
  94. dbDelta($sqlQuery); 
  95.  
  96. //wp_pmpro_memberships_categories 
  97. $sqlQuery = " 
  98. CREATE TABLE `" . $wpdb->pmpro_memberships_categories . "` ( 
  99. `membership_id` int(11) unsigned NOT NULL,  
  100. `category_id` int(11) unsigned NOT NULL,  
  101. `modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,  
  102. UNIQUE KEY `membership_category` (`membership_id`, `category_id`),  
  103. UNIQUE KEY `category_membership` (`category_id`, `membership_id`) 
  104. ); 
  105. "; 
  106. dbDelta($sqlQuery); 
  107.  
  108. //wp_pmpro_memberships_pages 
  109. $sqlQuery = " 
  110. CREATE TABLE `" . $wpdb->pmpro_memberships_pages . "` ( 
  111. `membership_id` int(11) unsigned NOT NULL,  
  112. `page_id` int(11) unsigned NOT NULL,  
  113. `modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,  
  114. UNIQUE KEY `category_membership` (`page_id`, `membership_id`),  
  115. UNIQUE KEY `membership_page` (`membership_id`, `page_id`) 
  116. ); 
  117. "; 
  118. dbDelta($sqlQuery); 
  119.  
  120. //wp_pmpro_memberships_users 
  121. $sqlQuery = " 
  122. CREATE TABLE `" . $wpdb->pmpro_memberships_users . "` ( 
  123. `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,  
  124. `user_id` int(11) unsigned NOT NULL,  
  125. `membership_id` int(11) unsigned NOT NULL,  
  126. `code_id` int(11) unsigned NOT NULL,  
  127. `initial_payment` decimal(10, 2) NOT NULL,  
  128. `billing_amount` decimal(10, 2) NOT NULL,  
  129. `cycle_number` int(11) NOT NULL,  
  130. `cycle_period` enum('Day', 'Week', 'Month', 'Year') NOT NULL DEFAULT 'Month',  
  131. `billing_limit` int(11) NOT NULL,  
  132. `trial_amount` decimal(10, 2) NOT NULL,  
  133. `trial_limit` int(11) NOT NULL,  
  134. `status` varchar(20) NOT NULL DEFAULT 'active',  
  135. `startdate` datetime NOT NULL,  
  136. `enddate` datetime DEFAULT NULL,  
  137. `modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,  
  138. PRIMARY KEY (`id`),  
  139. KEY `membership_id` (`membership_id`),  
  140. KEY `modified` (`modified`),  
  141. KEY `code_id` (`code_id`),  
  142. KEY `enddate` (`enddate`),  
  143. KEY `user_id` (`user_id`),  
  144. KEY `status` (`status`) 
  145. ); 
  146. "; 
  147. dbDelta($sqlQuery); 
  148.  
  149. //wp_pmpro_discount_codes 
  150. $sqlQuery = "  
  151. CREATE TABLE `" . $wpdb->pmpro_discount_codes . "` ( 
  152. `id` int(10) unsigned NOT NULL AUTO_INCREMENT,  
  153. `code` varchar(32) NOT NULL,  
  154. `starts` date NOT NULL,  
  155. `expires` date NOT NULL,  
  156. `uses` int(11) NOT NULL,  
  157. PRIMARY KEY (`id`),  
  158. UNIQUE KEY `code` (`code`),  
  159. KEY `starts` (`starts`),  
  160. KEY `expires` (`expires`) 
  161. ); 
  162. "; 
  163. dbDelta($sqlQuery); 
  164.  
  165. //wp_pmpro_discount_codes_levels 
  166. $sqlQuery = "  
  167. CREATE TABLE `" . $wpdb->pmpro_discount_codes_levels . "` ( 
  168. `code_id` int(11) unsigned NOT NULL,  
  169. `level_id` int(11) unsigned NOT NULL,  
  170. `initial_payment` decimal(10, 2) NOT NULL DEFAULT '0.00',  
  171. `billing_amount` decimal(10, 2) NOT NULL DEFAULT '0.00',  
  172. `cycle_number` int(11) NOT NULL DEFAULT '0',  
  173. `cycle_period` enum('Day', 'Week', 'Month', 'Year') DEFAULT 'Month',  
  174. `billing_limit` int(11) NOT NULL COMMENT 'After how many cycles should billing stop?',  
  175. `trial_amount` decimal(10, 2) NOT NULL DEFAULT '0.00',  
  176. `trial_limit` int(11) NOT NULL DEFAULT '0',  
  177. `expiration_number` int(10) unsigned NOT NULL,  
  178. `expiration_period` enum('Day', 'Week', 'Month', 'Year') NOT NULL,  
  179. PRIMARY KEY (`code_id`, `level_id`),  
  180. KEY `initial_payment` (`initial_payment`) 
  181. ); 
  182. "; 
  183. dbDelta($sqlQuery); 
  184.  
  185. //wp_pmpro_discount_codes_uses 
  186. $sqlQuery = "  
  187. CREATE TABLE `" . $wpdb->pmpro_discount_codes_uses . "` (  
  188. `id` int(10) unsigned NOT NULL AUTO_INCREMENT,  
  189. `code_id` int(10) unsigned NOT NULL,  
  190. `user_id` int(10) unsigned NOT NULL,  
  191. `order_id` int(10) unsigned NOT NULL,  
  192. `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,  
  193. PRIMARY KEY (`id`),  
  194. KEY `user_id` (`user_id`),  
  195. KEY `timestamp` (`timestamp`) 
  196. ); 
  197. "; 
  198. dbDelta($sqlQuery); 
  199.  
  200. //pmpro_membership_levelmeta 
  201. $sqlQuery = " 
  202. CREATE TABLE `" . $wpdb->pmpro_membership_levelmeta . "` ( 
  203. `meta_id` int(10) unsigned NOT NULL AUTO_INCREMENT,  
  204. `pmpro_membership_level_id` int(10) unsigned NOT NULL,  
  205. `meta_key` varchar(255) NOT NULL,  
  206. `meta_value` longtext,  
  207. PRIMARY KEY (`meta_id`),  
  208. KEY `pmpro_membership_level_id` (`pmpro_membership_level_id`),  
  209. KEY `meta_key` (`meta_key`) 
  210. ); 
  211. "; 
  212. dbDelta($sqlQuery);