pmpro_shortcode_account

Shortcode to show membership account information.

Description

pmpro_shortcode_account( $atts, (constant) $content = null, (string) $code = '' ); 

Parameters (3)

0. $atts
The atts.
1. $content — Optional. (constant) => null
The content.
2. $code — Optional. (string) => ''
The code.

Usage

  1. if ( !function_exists( 'pmpro_shortcode_account' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'paid-memberships-pro/shortcodes/pmpro_account.php'; 
  3.  
  4. // The atts. 
  5. $atts = null; 
  6.  
  7. // The content. 
  8. $content = null; 
  9.  
  10. // The code. 
  11. $code = ''; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = pmpro_shortcode_account($atts, $content, $code); 
  15.  

Defined (1)

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

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