pmpro_getAddons
Get addon information from PMPro server.
Description
pmpro_getAddons();
Usage
if ( !function_exists( 'pmpro_getAddons' ) ) { require_once ABSPATH . PLUGINDIR . 'paid-memberships-pro/includes/addons.php'; } // NOTICE! Understand what this does before running. $result = pmpro_getAddons();
Defined (1)
The function is defined in the following location(s).
- /includes/addons.php
- function pmpro_getAddons()
- {
- //check if forcing a pull from the server
- $addons = get_option("pmpro_addons", array());
- $addons_timestamp = get_option("pmpro_addons_timestamp", 0);
- //if no addons locally, we need to hit the server
- if(empty($addons) || !empty($_REQUEST['force-check']) || current_time('timestamp') > $addons_timestamp+86400)
- {
- /**
- * Filter to change thetimeoutfor this wp_remote_get() request.
- *
- * @since 1.8.5.1
- *
- * @param int $timeout The number of seconds before the request times out
- */
- $timeout = apply_filters("pmpro_get_addons_timeout", 5);
- //get em
- $remote_addons = wp_remote_get(PMPRO_LICENSE_SERVER . "addons/", $timeout);
- //make sure we have at least an array to pass back
- if(empty($addons))
- $addons = array();
- //test response
- if(is_wp_error($remote_addons)) {
- //error
- pmpro_setMessage("Could not connect to the PMPro License Server to updateaddoninformation. Try again later.", "error");
- }
- elseif(!empty($remote_addons) && $remote_addons['response']['code'] == 200)
- {
- //update addons in cache
- $addons = json_decode(wp_remote_retrieve_body($remote_addons), true);
- delete_option('pmpro_addons');
- add_option("pmpro_addons", $addons, NULL, 'no');
- }
- //save timestamp of last update
- delete_option('pmpro_addons_timestamp');
- add_option("pmpro_addons_timestamp", current_time('timestamp'), NULL, 'no');
- }
- return $addons;
- }