pmpro_membership_level_profile_fields_update

The Paid Memberships Pro pmpro membership level profile fields update function.

Description

pmpro_membership_level_profile_fields_update(); 

Usage

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

Defined (1)

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

/includes/profile.php  
  1. function pmpro_membership_level_profile_fields_update() 
  2. //get the user id 
  3. global $wpdb, $current_user, $user_ID; 
  4. wp_get_current_user(); 
  5.  
  6. if(!empty($_REQUEST['user_id']))  
  7. $user_ID = $_REQUEST['user_id']; 
  8.  
  9. $membership_level_capability = apply_filters("pmpro_edit_member_capability", "manage_options"); 
  10. if(!current_user_can($membership_level_capability)) 
  11. return false; 
  12.  
  13. //level change 
  14. if(isset($_REQUEST['membership_level'])) 
  15. //if the level is beingsetto 0 by the admin, it's a cancellation. 
  16. $changed_or_cancelled = ''; 
  17. if($_REQUEST['membership_level'] === 0 ||$_REQUEST['membership_level'] === '0' || $_REQUEST['membership_level'] =='') 
  18. $changed_or_cancelled = 'admin_cancelled'; 
  19. else 
  20. $changed_or_cancelled = 'admin_changed'; 
  21.  
  22. //if the cancel atgatewaybox is not checked, don't cancel  
  23. if(empty($_REQUEST['cancel_subscription'])) 
  24.  
  25. //do the change 
  26. if(pmpro_changeMembershipLevel($_REQUEST['membership_level'], $user_ID, $changed_or_cancelled)) 
  27. //it changed. send email 
  28. $level_changed = true; 
  29. elseif(!empty($_REQUEST['cancel_subscription'])) 
  30. //the level didn't change, but we were asked to cancel thesubscriptionat the gateway, let's do that 
  31. $order = new MemberOrder(); 
  32. $order->getLastMemberOrder($user_ID); 
  33.  
  34. if(!empty($order) && !empty($order->id)) 
  35. $r = $order->cancel();  
  36.  
  37. //remove filter after ward  
  38. if(empty($_REQUEST['cancel_subscription'])) 
  39.  
  40. //expiration change 
  41. if(!empty($_REQUEST['expires'])) 
  42. //update the expiration date 
  43. $expiration_date = intval($_REQUEST['expires_year']) . "-" . str_pad(intval($_REQUEST['expires_month']), 2, "0", STR_PAD_LEFT) . "-" . str_pad(intval($_REQUEST['expires_day']), 2, "0", STR_PAD_LEFT); 
  44. $sqlQuery = "UPDATE $wpdb->pmpro_memberships_usersSETenddate = '" . $expiration_date . "' WHERE status = 'active' AND membership_id = '" . intval($_REQUEST['membership_level']) . "' AND user_id = '" . $user_ID . "' LIMIT 1";  
  45. if($wpdb->query($sqlQuery)) 
  46. $expiration_changed = true; 
  47. elseif(isset($_REQUEST['expires'])) 
  48. //already blank? have to check for null or '0000-00-00 00:00:00' or '' here. 
  49. $sqlQuery = "SELECT user_id FROM $wpdb->pmpro_memberships_users WHERE (enddate IS NULL OR enddate = '' OR enddate = '0000-00-00 00:00:00') AND status = 'active' AND user_id = '" . $user_ID . "' LIMIT 1"; 
  50. $blank = $wpdb->get_var($sqlQuery); 
  51.  
  52. if(empty($blank)) 
  53. {  
  54. //null out the expiration 
  55. $sqlQuery = "UPDATE $wpdb->pmpro_memberships_usersSETenddate = NULL WHERE status = 'active' AND membership_id = '" . intval($_REQUEST['membership_level']) . "' AND user_id = '" . $user_ID . "' LIMIT 1"; 
  56. if($wpdb->query($sqlQuery)) 
  57. $expiration_changed = true; 
  58.  
  59. //emails if there was a change 
  60. if(!empty($level_changed) || !empty($expiration_changed)) 
  61. //email to admin 
  62. $pmproemail = new PMProEmail(); 
  63. if(!empty($expiration_changed)) 
  64. $pmproemail->expiration_changed = true; 
  65. $pmproemail->sendAdminChangeAdminEmail(get_userdata($user_ID)); 
  66.  
  67. //send email 
  68. if(!empty($_REQUEST['send_admin_change_email'])) 
  69. //email to member 
  70. $pmproemail = new PMProEmail(); 
  71. if(!empty($expiration_changed)) 
  72. $pmproemail->expiration_changed = true; 
  73. $pmproemail->sendAdminChangeEmail(get_userdata($user_ID));