pmpro_upgrade_1_8_6_9_ajax

If a site has > 100 orders then we run this pasrt of the update via AJAX from the updates page.

Description

pmpro_upgrade_1_8_6_9_ajax(); 

Usage

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

Defined (1)

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

/includes/updates/upgrade_1_8_6_9.php  
  1. function pmpro_upgrade_1_8_6_9_ajax() { 
  2. global $wpdb; 
  3.  
  4. //keeping track of whichorderwe're working on 
  5. $last_order_id = get_option('pmpro_upgrade_1_8_6_9_last_order_id', 0); 
  6.  
  7. //get orders 
  8. $orders = $wpdb->get_results("SELECT id, user_id, membership_id, subscription_transaction_id FROM $wpdb->pmpro_membership_orders WHERE id > $last_order_id ANDgateway= stripe AND subscription_transaction_id LIKE 'cus_%'ORDERBY id LIMIT 100"); 
  9.  
  10. if(empty($orders)) { 
  11. //done with this update 
  12. pmpro_removeUpdate('pmpro_upgrade_1_8_6_9_ajax'); 
  13. delete_option('pmpro_upgrade_1_8_6_9_last_order_id'); 
  14. } else { 
  15. $subids = array(); //cache of subids found 
  16. foreach($orders as $order) { 
  17. $last_order_id = $order->id; //keeping track of the lastorderwe processed 
  18. if(!empty($subids[$order->subscription_transaction_id])) { 
  19. $wpdb->query("UPDATE $wpdb->pmpro_membership_ordersSETsubscription_transaction_id = '" . esc_sql($subids[$order->subscription_transaction_id]) . "' WHERE id = '" . $order->id . "' LIMIT 1"); 
  20. elseif(isset($subids[$order->subscription_transaction_id])) { 
  21. //no sub id found, so let it go 
  22. else { 
  23. //need to look for a sub id in the database 
  24. $subid = $wpdb->get_var("SELECT subscription_transaction_id FROM $wpdb->pmpro_membership_orders WHERE membership_id = '" . $order->membership_id . "' AND user_id = '" . $order->user_id . "' AND subscription_transaction_id LIKE 'sub_%' LIMIT 1"); 
  25. $subids[$order->subscription_transaction_id] = $subid; 
  26. if(!empty($subid)) { 
  27. $wpdb->query("UPDATE $wpdb->pmpro_membership_ordersSETsubscription_transaction_id = '" . esc_sql($subid) . "' WHERE id = '" . $order->id . "' LIMIT 1"); 
  28. else { 
  29. //no sub id found, so let it go 
  30.  
  31. update_option('pmpro_upgrade_1_8_6_9_last_order_id', $last_order_id);