pmpro_cron_expire_memberships

The Paid Memberships Pro pmpro cron expire memberships function.

Description

pmpro_cron_expire_memberships(); 

Usage

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

Defined (1)

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

/scheduled/crons.php  
  1. function pmpro_cron_expire_memberships() 
  2. global $wpdb; 
  3.  
  4. //make sure we only run once a day 
  5. $today = date_i18n("Y-m-d", current_time("timestamp")); 
  6.  
  7. //look for memberships that expired before today 
  8. $sqlQuery = "SELECT mu.user_id, mu.membership_id, mu.startdate, mu.enddate FROM $wpdb->pmpro_memberships_users mu WHERE mu.status = 'active' AND mu.enddate IS NOT NULL AND mu.enddate <> '' AND mu.enddate <> '0000-00-00 00:00:00' AND DATE(mu.enddate) <= '" . $today . "'ORDERBY mu.enddate"; 
  9.  
  10. if(defined('PMPRO_CRON_LIMIT')) 
  11. $sqlQuery .= " LIMIT " . PMPRO_CRON_LIMIT; 
  12.  
  13. $expired = $wpdb->get_results($sqlQuery); 
  14.  
  15. foreach($expired as $e) 
  16. do_action("pmpro_membership_pre_membership_expiry", $e->user_id, $e->membership_id ); 
  17.  
  18. //remove their membership 
  19. pmpro_changeMembershipLevel(false, $e->user_id, 'expired'); 
  20.  
  21. do_action("pmpro_membership_post_membership_expiry", $e->user_id, $e->membership_id ); 
  22.  
  23. $send_email = apply_filters("pmpro_send_expiration_email", true, $e->user_id); 
  24. if($send_email) 
  25. //send an email 
  26. $pmproemail = new PMProEmail(); 
  27. $euser = get_userdata($e->user_id); 
  28. $pmproemail->sendMembershipExpiredEmail($euser); 
  29.  
  30. if(current_user_can('manage_options')) 
  31. printf(__("Membership expired email sent to %s. ", 'paid-memberships-pro' ), $euser->user_email); 
  32. else 
  33. echo ". ";