Esempio n. 1
0
/**
 * Calls the EDD Software Licensing API to perform licensing tasks on the addon's store server.
 *
 * @since 4.4.5
 */
function wprss_edd_licensing_api($addon, $license_key = NULL, $action = 'check_license', $return = 'license')
{
    // If no license argument was given
    if ($license_key === NULL) {
        // Get the license key
        $license_key = wprss_get_license_key($addon);
    }
    // Get the license status from the DB
    $license_status = wprss_get_license_status($addon);
    // Prepare constants
    $item_name = strtoupper($addon);
    $item_name_constant = constant("WPRSS_{$item_name}_SL_ITEM_NAME");
    $store_url_constant = constant("WPRSS_{$item_name}_SL_STORE_URL");
    // data to send in our API request
    $api_params = array('edd_action' => $action, 'license' => sanitize_text_field($license_key), 'item_name' => urlencode($item_name_constant), 'url' => urlencode(network_site_url()), 'time' => time());
    // Send the request to the API
    $response = wp_remote_get(add_query_arg($api_params, $store_url_constant));
    // If the response is an error, return the value in the DB
    if (is_wp_error($response)) {
        return $license_status;
    }
    // decode the license data
    $license_data = json_decode(wp_remote_retrieve_body($response));
    // Update the DB option
    $license_statuses = get_option('wprss_settings_license_statuses');
    $license_statuses["{$addon}_license_status"] = $license_data->license;
    $license_statuses["{$addon}_license_expires"] = $license_data->expires;
    update_option('wprss_settings_license_statuses', $license_statuses);
    // Return the data
    if (strtoupper($return) === 'ALL') {
        return $license_data;
    } else {
        return $license_data->{$return};
    }
}
Esempio n. 2
0
/**
 * Calls the EDD Software Licensing API to perform licensing tasks on the addon's store server.
 *
 * @since 4.4.5
 */
function wprss_edd_licensing_api($addon, $license_key = NULL, $action = 'check_license')
{
    // If no license argument was given
    if ($license_key === NULL) {
        // Get the license key
        $license_key = wprss_get_license_key($addon);
    }
    // Get the license status from the DB
    $license_status = wprss_get_license_status($addon);
    // Prepare constants
    $item_name = strtoupper($addon);
    $item_name_constant = constant("WPRSS_{$item_name}_SL_ITEM_NAME");
    $store_url_constant = constant("WPRSS_{$item_name}_SL_STORE_URL");
    // data to send in our API request
    $api_params = array('edd_action' => $action, 'license' => $license_key, 'item_name' => urlencode($item_name_constant));
    // Call the custom API.
    $response = wp_remote_get(add_query_arg($api_params, $store_url_constant));
    // If the response is an error, return the value in the DB
    if (is_wp_error($response)) {
        return $license_status;
    }
    // decode the license data
    $license_data = json_decode(wp_remote_retrieve_body($response));
    // Update the DB option
    $license_statuses["{$addon}_license_status"] = $license_data->license;
    update_option('wprss_settings_license_statuses', $license_statuses);
    // Return TRUE if it is 'active', FALSE otherwise
    return $license_data->license;
}