Jake Vanderwerf
2026-08-28 5b50afdcafd150186ea5c7b0e1cad98065590b35
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,9 +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();
      $this->cache = Cache::for('referrals');
      $this->statsCache = Cache::for('referral_stats', null, WEEK_IN_SECONDS)->user();
      $this->referralPage = $this->getReferralPageId();
      $this->settings = $this->getRewardSettings();
@@ -910,7 +911,7 @@
         'From ' . $yesterday
      );
      $content .= Emails::getInstance()->spacer(20);
      $content .= Emails::getInstance()->spacer();
      $content .= Emails::getInstance()->h2('New Referrals');
      // Build list of referrals
@@ -980,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++;
@@ -1000,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) {
@@ -1223,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.');
@@ -1239,7 +1240,7 @@
    * Display user's referral code and share options
    * Use in templates or dashboard with: echo jvbReferralShareWidget();
    *
    * @return string HTML output
    * @return array HTML output
    */
   public function outputShareWidget(array $actions):array
   {
@@ -1272,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'] ?? '';
@@ -1846,8 +1847,7 @@
    * Add referral settings subpage to admin menu
    * Add referral settings subpage to admin menu
    *
    * @param array $subpages
    * @return array
    * @return void
    */
   public static function addSubpage():void
   {
@@ -2781,7 +2781,7 @@
            'message' => 'Referral settings saved successfully!'
         ];
      } catch (\Exception $e) {
      } catch (Exception $e) {
         return [
            'success' => false,
            'message' => 'Failed to save settings: ' . $e->getMessage()