Esempio n. 1
0
function pmpro_getCancellationRate($period, $levels = 'all', $status = NULL)
{
    //make sure status is an array
    if (!is_array($status)) {
        $status = array($status);
    }
    //check for a transient
    $cache = get_transient("pmpro_report_cancellation_rate");
    $hash = md5($period . $levels . implode('', $status));
    if (!empty($cache) && !empty($cache[$hash])) {
        return $cache[$hash];
    }
    $signups = pmpro_getSignups($period, $levels);
    $cancellations = pmpro_getCancellations($period, $levels, $status);
    if (empty($signups)) {
        return false;
    }
    $rate = number_format($cancellations / $signups * 100, 2);
    //save in cache
    if (!empty($cache) && !empty($cache[$period])) {
        $cache[$period][$levels] = $rate;
    } elseif (!empty($cache)) {
        $cache[$period] = array($levels => $rate);
    } else {
        $cache = array($period => array($levels => $rate));
    }
    set_transient("pmpro_report_cancellation_rate", $cache, 3600 * 24);
    return $rate;
}
function pmpro_getCancellationRate($period, $levels = 'all')
{
    //check for a transient
    $cache = get_transient("pmpro_report_cancellation_rate");
    if (!empty($cache) && !empty($cache[$period]) && !empty($cache[$period][$levels])) {
        return $cache[$period][$levels];
    }
    $signups = pmpro_getSignups($period, $levels);
    $cancellations = pmpro_getCancellations($period, $levels);
    if (empty($signups)) {
        return false;
    }
    $rate = number_format($cancellations / $signups * 100, 2);
    //save in cache
    if (!empty($cache) && !empty($cache[$period])) {
        $cache[$period][$levels] = $rate;
    } elseif (!empty($cache)) {
        $cache[$period] = array($levels => $rate);
    } else {
        $cache = array($period => array($levels => $rate));
    }
    set_transient("pmpro_report_cancellation_rate", $cache, 3600 * 24);
    return $rate;
}