function affwp_delete_referral($referral)
{
    if (is_object($referral) && isset($referral->referral_id)) {
        $referral_id = $referral->referral_id;
    } elseif (is_numeric($referral)) {
        $referral_id = absint($referral);
        $referral = affwp_get_referral($referral_id);
    } else {
        return false;
    }
    if ($referral && 'paid' == $referral->status) {
        // This referral has already been paid, so decrease the affiliate's earnings
        affwp_decrease_affiliate_earnings($referral->affiliate_id, $referral->amount);
        // Decrease the referral count
        affwp_decrease_affiliate_referral_count($referral->affiliate_id);
    }
    if (affiliate_wp()->referrals->delete($referral_id)) {
        do_action('affwp_delete_referral', $referral_id);
        return true;
    }
    return false;
}
 function test_adjust_affiliate_referral_count()
 {
     $this->assertEquals(1, affwp_increase_affiliate_referral_count($this->_affiliate_id));
     $this->assertEquals(2, affwp_increase_affiliate_referral_count($this->_affiliate_id));
     $this->assertEquals(1, affwp_decrease_affiliate_referral_count($this->_affiliate_id));
     $this->assertFalse(affwp_decrease_affiliate_referral_count($this->_affiliate_id2));
 }