pmpro_membership_level_profile_fields

The Paid Memberships Pro pmpro membership level profile fields function.

Description

pmpro_membership_level_profile_fields( $user ); 

Parameters (1)

0. $user
The user.

Usage

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

Defined (1)

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

/includes/profile.php  
  1. function pmpro_membership_level_profile_fields($user) 
  2. global $current_user; 
  3.  
  4. $server_tz = date_default_timezone_get(); 
  5. $wp_tz = get_option( 'timezone_string' ); 
  6.  
  7. //option "timezone_string" is empty ifsetto UTC+0 
  8. if(empty($wp_tz)) 
  9. $wp_tz = 'UTC'; 
  10.  
  11. date_default_timezone_set($wp_tz); 
  12.  
  13. $membership_level_capability = apply_filters("pmpro_edit_member_capability", "manage_options"); 
  14. if(!current_user_can($membership_level_capability)) 
  15. return false; 
  16.  
  17. global $wpdb; 
  18. /**$user->membership_level = $wpdb->get_row("SELECT l.id AS ID, l.name AS name 
  19. FROM {$wpdb->pmpro_membership_levels} AS l 
  20. JOIN {$wpdb->pmpro_memberships_users} AS mu ON (l.id = mu.membership_id) 
  21. WHERE mu.user_id = " . $user->ID . " 
  22. LIMIT 1");*/ 
  23. $user->membership_level = pmpro_getMembershipLevelForUser($user->ID); 
  24.  
  25. $levels = $wpdb->get_results( "SELECT * FROM {$wpdb->pmpro_membership_levels}", OBJECT ); 
  26.  
  27. if(!$levels) 
  28. return ""; 
  29. ?> 
  30. <h3><?php _e("Membership Level", 'paid-memberships-pro' ); ?></h3> 
  31. <table class="form-table"> 
  32. <?php 
  33. $show_membership_level = true; 
  34. $show_membership_level = apply_filters("pmpro_profile_show_membership_level", $show_membership_level, $user); 
  35. if($show_membership_level) 
  36. ?> 
  37. <tr> 
  38. <th><label for="membership_level"><?php _e("Current Level", 'paid-memberships-pro' ); ?></label></th> 
  39. <td> 
  40. <select name="membership_level"> 
  41. <option value="" <?php if(empty($user->membership_level->ID)) { ?>selected="selected"<?php } ?>>-- <?php _e("None", 'paid-memberships-pro' );?> --</option> 
  42. <?php 
  43. foreach($levels as $level) 
  44. ?> 
  45. <option value="<?php echo $level->id?>" <?php selected($level->id, (isset($user->membership_level->ID) ? $user->membership_level->ID : 0 )); ?>><?php echo $level->name?></option> 
  46. <?php 
  47. ?> 
  48. </select> 
  49. <span id="current_level_cost"> 
  50. <?php 
  51. $membership_values = pmpro_getMembershipLevelForUser($user->ID);  
  52.  
  53. //we tweak the initial payment here so the text here effectively shows the recurring amount 
  54. if(!empty($membership_values)) 
  55. $membership_values->original_initial_payment = $membership_values->initial_payment; 
  56. $membership_values->initial_payment = $membership_values->billing_amount; 
  57.  
  58. if(empty($membership_values) || pmpro_isLevelFree($membership_values)) 
  59. {  
  60. if(!empty($membership_values->original_initial_payment) && $membership_values->original_initial_payment > 0) 
  61. echo "Paid " . pmpro_formatPrice($membership_values->original_initial_payment) . "."; 
  62. else 
  63. _e('Not paying.', 'paid-memberships-pro' );  
  64. }  
  65. else 
  66. {  
  67. echo pmpro_getLevelCost($membership_values, true, true); 
  68. ?> 
  69. </span> 
  70. <p id="cancel_description" class="description hidden"><?php _e("This will not change thesubscriptionat thegatewayunless the 'Cancel' checkbox is selected below.", 'paid-memberships-pro' ); ?></p> 
  71. </td> 
  72. </tr> 
  73. <?php 
  74.  
  75. $show_expiration = true; 
  76. $show_expiration = apply_filters("pmpro_profile_show_expiration", $show_expiration, $user); 
  77. if($show_expiration) 
  78.  
  79. //is there an end date? 
  80. $user->membership_level = pmpro_getMembershipLevelForUser($user->ID); 
  81. $end_date = (!empty($user->membership_level) && !empty($user->membership_level->enddate)); // Returned as UTC timestamp 
  82.  
  83. // Convert UTC to local time 
  84. if ( $end_date ) { 
  85. $user->membership_level->enddate = strtotime( $wp_tz, $user->membership_level->enddate ); 
  86.  
  87. //some vars for the dates 
  88. $current_day = date_i18n("j", current_time('timestamp'));  
  89. if($end_date) 
  90. $selected_expires_day = date_i18n("j", $user->membership_level->enddate); 
  91. else 
  92. $selected_expires_day = $current_day; 
  93.  
  94. $current_month = date_i18n("M", current_time('timestamp'));  
  95. if($end_date) 
  96. $selected_expires_month = date_i18n("m", $user->membership_level->enddate); 
  97. else 
  98. $selected_expires_month = date_i18n("m"); 
  99.  
  100. $current_year = date_i18n("Y", current_time('timestamp'));  
  101. if($end_date) 
  102. $selected_expires_year = date_i18n("Y", $user->membership_level->enddate); 
  103. else 
  104. $selected_expires_year = (int)$current_year + 1; 
  105. ?> 
  106. <tr> 
  107. <th><label for="expiration"><?php _e("Expires", 'paid-memberships-pro' ); ?></label></th> 
  108. <td> 
  109. <select id="expires" name="expires"> 
  110. <option value="0" <?php if(!$end_date) { ?>selected="selected"<?php } ?>><?php _e("No", 'paid-memberships-pro' );?></option> 
  111. <option value="1" <?php if($end_date) { ?>selected="selected"<?php } ?>><?php _e("Yes", 'paid-memberships-pro' );?></option> 
  112. </select> 
  113. <span id="expires_date" <?php if(!$end_date) { ?>style="display: none;"<?php } ?>> 
  114. on 
  115. <select name="expires_month"> 
  116. <?php  
  117. for($i = 1; $i < 13; $i++) 
  118. ?> 
  119. <option value="<?php echo $i?>" <?php if($i == $selected_expires_month) { ?>selected="selected"<?php } ?>><?php echo date_i18n("M", strtotime($i . "/1/" . $current_year, current_time("timestamp")))?></option> 
  120. <?php 
  121. ?> 
  122. </select> 
  123. <input name="expires_day" type="text" size="2" value="<?php echo $selected_expires_day?>" /> 
  124. <input name="expires_year" type="text" size="4" value="<?php echo $selected_expires_year?>" /> 
  125. </span> 
  126. <script> 
  127. jQuery('#expires').change(function() { 
  128. if(jQuery(this).val() == 1) 
  129. jQuery('#expires_date').show(); 
  130. else 
  131. jQuery('#expires_date').hide(); 
  132. }); 
  133. </script> 
  134. </td> 
  135. </tr> 
  136. <tr class="more_level_options"> 
  137. <th></th> 
  138. <td> 
  139. <label for="send_admin_change_email"><input value="1" id="send_admin_change_email" name="send_admin_change_email" type="checkbox"> Send the user an email about this change.</label> 
  140. </td> 
  141. </tr> 
  142. <tr class="more_level_options"> 
  143. <th></th> 
  144. <td> 
  145. <label for="cancel_subscription"><input value="1" id="cancel_subscription" name="cancel_subscription" type="checkbox"> Cancel this user'ssubscriptionat the gateway.</label> 
  146. </td> 
  147. </tr> 
  148. <?php 
  149. ?> 
  150. </table> 
  151. <script> 
  152. jQuery(document).ready(function() { 
  153. //vars for fields 
  154. var $membership_level_select = jQuery("[name=membership_level]"); 
  155. var $expires_select = jQuery("[name=expires]"); 
  156. var $expires_month_select = jQuery("[name=expires_month]"); 
  157. var $expires_day_text = jQuery("[name=expires_day]"); 
  158. var $expires_year_text = jQuery("[name=expires_year]"); 
  159.  
  160. //note old data to check for changes 
  161. var old_level = $membership_level_select.val(); 
  162. var old_expires = $expires_select.val(); 
  163. var old_expires_month = $expires_month_select.val(); 
  164. var old_expires_day = $expires_day_text.val(); 
  165. var old_expires_year = $expires_year_text.val(); 
  166.  
  167. var current_level_cost = jQuery("#current_level_cost").text(); 
  168.  
  169. //hide by default 
  170. jQuery(".more_level_options").hide(); 
  171.  
  172. function pmpro_checkForLevelChangeInProfile() 
  173. //cancelling sub or not 
  174. if($membership_level_select.val() == 0) { 
  175. jQuery("#cancel_subscription").attr('checked', true); 
  176. jQuery("#current_level_cost").text("Not paying."); 
  177. else { 
  178. jQuery("#cancel_subscription").attr('checked', false); 
  179. jQuery("#current_level_cost").text(current_level_cost); 
  180.  
  181. //did level or expiration change? 
  182. if( 
  183. $membership_level_select.val() != old_level || 
  184. $expires_select.val() != old_expires || 
  185. $expires_month_select.val() != old_expires_month || 
  186. $expires_day_text.val() != old_expires_day || 
  187. $expires_year_text.val() != old_expires_year 
  188. jQuery(".more_level_options").show(); 
  189. jQuery("#cancel_description").show();  
  190. else 
  191. jQuery(".more_level_options").hide(); 
  192. jQuery("#cancel_description").hide();  
  193.  
  194. //run check when fields change 
  195. $membership_level_select.change(function() { 
  196. pmpro_checkForLevelChangeInProfile(); 
  197. }); 
  198. $expires_select.change(function() { 
  199. pmpro_checkForLevelChangeInProfile(); 
  200. }); 
  201. $expires_month_select.change(function() { 
  202. pmpro_checkForLevelChangeInProfile(); 
  203. }); 
  204. $expires_day_text.change(function() { 
  205. pmpro_checkForLevelChangeInProfile(); 
  206. }); 
  207. $expires_year_text.change(function() { 
  208. pmpro_checkForLevelChangeInProfile(); 
  209. });  
  210.  
  211. jQuery("#cancel_subscription").change(function() { 
  212. if(jQuery(this).attr('checked') == 'checked') 
  213. jQuery("#cancel_description").hide(); 
  214. jQuery("#current_level_cost").text("Not paying."); 
  215. else 
  216. jQuery("#current_level_cost").text(current_level_cost); 
  217. jQuery("#cancel_description").show(); 
  218. }); 
  219. }); 
  220. </script> 
  221. <?php 
  222. do_action("pmpro_after_membership_level_profile_fields", $user); 
  223.  
  224. date_default_timezone_set( $server_tz );