Jake Vanderwerf
2026-08-28 a9654f00c8fbc9934289d761843ddd071025013f
inc/managers/Referrals.php
@@ -1,6 +1,7 @@
<?php
namespace JVBase\managers;
use Exception;
use JVBase\Instance;
use JVBase\integrations\services\Cloudflare;
use JVBase\meta\Form;
@@ -63,14 +64,9 @@
      $this->role = Site::getReferralRole();
      $this->default_settings['referral_role'] = $this->role;
      $this->cache = Cache::for('referrals', WEEK_IN_SECONDS);
//    $this->requestCache = Cache::for('referral_requests', WEEK_IN_SECONDS)->connect('referrals', true);
      $this->statsCache = Cache::for('referral_stats', WEEK_IN_SECONDS)->connect('referrals', true)->user();
      if (JVB_TESTING) {
         $this->cache->flush();
//       $this->requestCache->flush();
         $this->statsCache->flush();
      }
      $this->cache = Cache::for('referrals');
      $this->statsCache = Cache::for('referral_stats', null, WEEK_IN_SECONDS)->user();
      $this->referralPage = $this->getReferralPageId();
      $this->settings = $this->getRewardSettings();
@@ -852,7 +848,7 @@
   public function getTopReferrers(int $limit = 10, string $period = 'all'): array
   {
      return $this->statsCache->remember(
         $this->statsCache->generateKey(['per_page' => $limit, 'period' => $period]),
         ['per_page' => $limit, 'period' => $period],
         function() use ($limit, $period) {
            $where = '';
            if ($period !== 'all') {
@@ -915,7 +911,7 @@
         'From ' . $yesterday
      );
      $content .= Emails::getInstance()->spacer(20);
      $content .= Emails::getInstance()->spacer();
      $content .= Emails::getInstance()->h2('New Referrals');
      // Build list of referrals
@@ -985,7 +981,7 @@
            Emails::getInstance()->stat($from_user->referral_count, 'Total Referrals'),
            Emails::getInstance()->stat($from_user->treated_count, 'Treated')
         ];
         $cardContent .= Emails::getInstance()->grid($stats, 2);
         $cardContent .= Emails::getInstance()->grid($stats);
         $content .= Emails::getInstance()->card($cardContent);
         $rank++;
@@ -1005,7 +1001,7 @@
    */
   protected function generateCSV(array $referrals): string
   {
      $cache = Cache::for('referralCSV', HOUR_IN_SECONDS)->connect('referrals');
      $cache = Cache::for('referralCSV');
      return $cache->remember(
         'csv',
         function () use ($referrals) {
@@ -1228,7 +1224,7 @@
      }
      // Check if code is unique
      if ($this->isCodeTaken($code, $user_id)) {
      if ($this->isCodeTaken($code)) {
         add_action('user_profile_update_errors', function($errors) {
            $errors->add('referral_code_taken',
               'This referral code is already in use.');
@@ -1277,7 +1273,7 @@
      Cloudflare::getInstance()->renderTurnstile();
      $turnstile = ob_get_clean();
      $reward_text = $this->getRewardText(true);
      $reward_text = $this->getRewardText();
      // Pre-fill code if from referral link
      $prefill_code = $_GET['ref'] ?? '';
@@ -2786,7 +2782,7 @@
            'message' => 'Referral settings saved successfully!'
         ];
      } catch (\Exception $e) {
      } catch (Exception $e) {
         return [
            'success' => false,
            'message' => 'Failed to save settings: ' . $e->getMessage()