pmpro_getAddons

Get addon information from PMPro server.

Description

pmpro_getAddons(); 

Usage

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

Defined (1)

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

/includes/addons.php  
  1. function pmpro_getAddons() 
  2. //check if forcing a pull from the server 
  3. $addons = get_option("pmpro_addons", array()); 
  4. $addons_timestamp = get_option("pmpro_addons_timestamp", 0); 
  5.  
  6. //if no addons locally, we need to hit the server 
  7. if(empty($addons) || !empty($_REQUEST['force-check']) || current_time('timestamp') > $addons_timestamp+86400) 
  8. /** 
  9. * Filter to change thetimeoutfor this wp_remote_get() request. 
  10. * @since 1.8.5.1 
  11. * @param int $timeout The number of seconds before the request times out 
  12. */ 
  13. $timeout = apply_filters("pmpro_get_addons_timeout", 5); 
  14.  
  15. //get em 
  16. $remote_addons = wp_remote_get(PMPRO_LICENSE_SERVER . "addons/", $timeout); 
  17.  
  18. //make sure we have at least an array to pass back 
  19. if(empty($addons)) 
  20. $addons = array(); 
  21.  
  22. //test response 
  23. if(is_wp_error($remote_addons)) { 
  24. //error 
  25. pmpro_setMessage("Could not connect to the PMPro License Server to updateaddoninformation. Try again later.", "error"); 
  26. elseif(!empty($remote_addons) && $remote_addons['response']['code'] == 200) 
  27. //update addons in cache 
  28. $addons = json_decode(wp_remote_retrieve_body($remote_addons), true); 
  29. delete_option('pmpro_addons'); 
  30. add_option("pmpro_addons", $addons, NULL, 'no'); 
  31.  
  32. //save timestamp of last update 
  33. delete_option('pmpro_addons_timestamp'); 
  34. add_option("pmpro_addons_timestamp", current_time('timestamp'), NULL, 'no');  
  35. }  
  36.  
  37. return $addons;