/shortcodes/pmpro_account.php

  1. <?php 
  2. /** 
  3. Shortcode to show membership account information 
  4. */ 
  5. function pmpro_shortcode_account($atts, $content=null, $code="") 
  6. global $wpdb, $pmpro_msg, $pmpro_msgt, $pmpro_levels, $current_user, $levels; 
  7.  
  8. // $atts ::= array of attributes 
  9. // $content ::= text within enclosing form of shortcode element 
  10. // $code ::= the shortcode found, when == callback name 
  11. // examples: [pmpro_account] [pmpro_account sections="membership, profile"/] 
  12.  
  13. extract(shortcode_atts(array( 
  14. 'section' => '',  
  15. 'sections' => 'membership, profile, invoices, links'  
  16. ), $atts)); 
  17.  
  18. //did they use 'section' instead of 'sections'? 
  19. if(!empty($section)) 
  20. $sections = $section; 
  21.  
  22. //Extract the user-defined sections for the shortcode 
  23. $sections = array_map('trim', explode(", ", $sections));  
  24. ob_start(); 
  25.  
  26. //if a member is logged in, show them some info here (1. past invoices. 2. billing information with button to update.) 
  27. if(pmpro_hasMembershipLevel()) 
  28. $ssorder = new MemberOrder(); 
  29. $ssorder->getLastMemberOrder(); 
  30. $mylevels = pmpro_getMembershipLevelsForUser(); 
  31. $pmpro_levels = pmpro_getAllLevels(false, true); // just to be sure - include only the ones that allow signups 
  32. $invoices = $wpdb->get_results("SELECT *, UNIX_TIMESTAMP(timestamp) as timestamp FROM $wpdb->pmpro_membership_orders WHERE user_id = '$current_user->ID' AND status NOT IN('refunded', 'review', 'token', 'error') ORDER BY timestamp DESC LIMIT 6"); 
  33. ?>  
  34. <div id="pmpro_account">  
  35. <?php if(in_array('membership', $sections) || in_array('memberships', $sections)) { ?> 
  36. <div id="pmpro_account-membership" class="pmpro_box"> 
  37.  
  38. <h3><?php _e("My Memberships", 'paid-memberships-pro' );?></h3> 
  39. <table width="100%" cellpadding="0" cellspacing="0" border="0"> 
  40. <thead> 
  41. <tr> 
  42. <th><?php _e("Level", 'paid-memberships-pro' );?></th> 
  43. <th><?php _e("Billing", 'paid-memberships-pro' ); ?></th> 
  44. <th><?php _e("Expiration", 'paid-memberships-pro' ); ?></th> 
  45. </tr> 
  46. </thead> 
  47. <tbody> 
  48. <?php 
  49. foreach($mylevels as $level) { 
  50. ?> 
  51. <tr> 
  52. <td class="pmpro_account-membership-levelname"> 
  53. <?php echo $level->name?> 
  54. <div class="pmpro_actionlinks"> 
  55. <?php do_action("pmpro_member_action_links_before"); ?> 
  56.  
  57. <?php if( array_key_exists($level->id, $pmpro_levels) && pmpro_isLevelExpiringSoon( $level ) ) { ?> 
  58. <a href="<?php echo pmpro_url("checkout", "?level=" . $level->id, "https")?>"><?php _e("Renew", 'paid-memberships-pro' );?></a> 
  59. <?php } ?> 
  60.  
  61. <?php if((isset($ssorder->status) && $ssorder->status == "success") && (isset($ssorder->gateway) && in_array($ssorder->gateway, array("authorizenet", "paypal", "stripe", "braintree", "payflow", "cybersource"))) && pmpro_isLevelRecurring($level)) { ?> 
  62. <a href="<?php echo pmpro_url("billing", "", "https")?>"><?php _e("Update Billing Info", 'paid-memberships-pro' ); ?></a> 
  63. <?php } ?> 
  64.  
  65. <?php  
  66. //To do: Only show CHANGE link if this level is in a group that has upgrade/downgrade rules 
  67. if(count($pmpro_levels) > 1 && !defined("PMPRO_DEFAULT_LEVEL")) { ?> 
  68. <a href="<?php echo pmpro_url("levels")?>"><?php _e("Change", 'paid-memberships-pro' );?></a> 
  69. <?php } ?> 
  70. <a href="<?php echo pmpro_url("cancel", "?levelstocancel=" . $level->id)?>"><?php _e("Cancel", 'paid-memberships-pro' );?></a> 
  71. <?php do_action("pmpro_member_action_links_after"); ?> 
  72. </div> <!-- end pmpro_actionlinks --> 
  73. </td> 
  74. <td class="pmpro_account-membership-levelfee"> 
  75. <p><?php echo pmpro_getLevelCost($level, true, true);?></p> 
  76. </td> 
  77. <td class="pmpro_account-membership-expiration"> 
  78. <?php  
  79. if($level->enddate) 
  80. $expiration_text = date(get_option('date_format'), $level->enddate); 
  81. else 
  82. $expiration_text = "---"; 
  83.  
  84. echo apply_filters( 'pmpro_account_membership_expiration_text', $expiration_text, $level ); 
  85. ?> 
  86. </td> 
  87. </tr> 
  88. <?php } ?> 
  89. </tbody> 
  90. </table> 
  91. <?php //Todo: If there are multiple levels defined that aren't all in the same group defined as upgrades/downgrades ?> 
  92. <div class="pmpro_actionlinks"> 
  93. <a href="<?php echo pmpro_url("levels")?>"><?php _e("View all Membership Options", 'paid-memberships-pro' );?></a> 
  94. </div> 
  95.  
  96. </div> <!-- end pmpro_account-membership --> 
  97. <?php } ?> 
  98.  
  99. <?php if(in_array('profile', $sections)) { ?> 
  100. <div id="pmpro_account-profile" class="pmpro_box">  
  101. <?php wp_get_current_user(); ?>  
  102. <h3><?php _e("My Account", 'paid-memberships-pro' );?></h3> 
  103. <?php if($current_user->user_firstname) { ?> 
  104. <p><?php echo $current_user->user_firstname?> <?php echo $current_user->user_lastname?></p> 
  105. <?php } ?> 
  106. <ul> 
  107. <?php do_action('pmpro_account_bullets_top');?> 
  108. <li><strong><?php _e("Username", 'paid-memberships-pro' );?>:</strong> <?php echo $current_user->user_login?></li> 
  109. <li><strong><?php _e("Email", 'paid-memberships-pro' );?>:</strong> <?php echo $current_user->user_email?></li> 
  110. <?php do_action('pmpro_account_bullets_bottom');?> 
  111. </ul> 
  112. <div class="pmpro_actionlinks"> 
  113. <a href="<?php echo admin_url('profile.php')?>"><?php _e("Edit Profile", 'paid-memberships-pro' );?></a> 
  114. <a href="<?php echo admin_url('profile.php')?>"><?php _e('Change Password', 'paid-memberships-pro' );?></a> 
  115. </div> 
  116. </div> <!-- end pmpro_account-profile --> 
  117. <?php } ?> 
  118.  
  119. <?php if(in_array('invoices', $sections) && !empty($invoices)) { ?>  
  120. <div id="pmpro_account-invoices" class="pmpro_box"> 
  121. <h3><?php _e("Past Invoices", 'paid-memberships-pro' );?></h3> 
  122. <table width="100%" cellpadding="0" cellspacing="0" border="0"> 
  123. <thead> 
  124. <tr> 
  125. <th><?php _e("Date", 'paid-memberships-pro' ); ?></th> 
  126. <th><?php _e("Level", 'paid-memberships-pro' ); ?></th> 
  127. <th><?php _e("Amount", 'paid-memberships-pro' ); ?></th> 
  128. </tr> 
  129. </thead> 
  130. <tbody> 
  131. <?php  
  132. $count = 0; 
  133. foreach($invoices as $invoice)  
  134. {  
  135. if($count++ > 4) 
  136. break; 
  137.  
  138. //get an member order object 
  139. $invoice_id = $invoice->id; 
  140. $invoice = new MemberOrder; 
  141. $invoice->getMemberOrderByID($invoice_id); 
  142. $invoice->getMembershipLevel();  
  143. ?> 
  144. <tr id="pmpro_account-invoice-<?php echo $invoice->code; ?>"> 
  145. <td><a href="<?php echo pmpro_url("invoice", "?invoice=" . $invoice->code)?>"><?php echo date_i18n(get_option("date_format"), $invoice->timestamp)?></td> 
  146. <td><?php if(!empty($invoice->membership_level)) echo $invoice->membership_level->name; else echo __("N/A", 'paid-memberships-pro' );?></td> 
  147. <td><?php echo pmpro_formatPrice($invoice->total)?></td> 
  148. </tr> 
  149. <?php  
  150. ?> 
  151. </tbody> 
  152. </table>  
  153. <?php if($count == 6) { ?> 
  154. <div class="pmpro_actionlinks"><a href="<?php echo pmpro_url("invoice"); ?>"><?php _e("View All Invoices", 'paid-memberships-pro' );?></a></div> 
  155. <?php } ?> 
  156. </div> <!-- end pmpro_account-invoices --> 
  157. <?php } ?> 
  158.  
  159. <?php if(in_array('links', $sections) && (has_filter('pmpro_member_links_top') || has_filter('pmpro_member_links_bottom'))) { ?> 
  160. <div id="pmpro_account-links" class="pmpro_box"> 
  161. <h3><?php _e("Member Links", 'paid-memberships-pro' );?></h3> 
  162. <ul> 
  163. <?php  
  164. do_action("pmpro_member_links_top"); 
  165. ?> 
  166.  
  167. <?php  
  168. do_action("pmpro_member_links_bottom"); 
  169. ?> 
  170. </ul> 
  171. </div> <!-- end pmpro_account-links -->  
  172. <?php } ?> 
  173. </div> <!-- end pmpro_account -->  
  174. <?php 
  175.  
  176. $content = ob_get_contents(); 
  177. ob_end_clean(); 
  178.  
  179. return $content; 
  180. add_shortcode('pmpro_account', 'pmpro_shortcode_account'); 
.