Jake Vanderwerf
2026-08-28 a9654f00c8fbc9934289d761843ddd071025013f
inc/integrations/_Base.php
@@ -2,6 +2,7 @@
namespace JVBase\integrations;
use JVBase\managers\Cache;
use JVBase\managers\Errors;
use JVBase\managers\IconsManager;
if (!defined('ABSPATH')) {
@@ -30,14 +31,8 @@
    */
   protected string $apiVersion;
   protected Cache $cache;
   //Use Trait "Requests" to set this
   protected bool $hasRequests = false;
   protected ?RateLimits $requestLimiter = null;
   //Use Trait "OAuth" to set this
   protected ?RateLimits $oauthLimiter = null;
   protected bool $hasOAuth = false;
   //Use trait "Webhooks" to set this true
   protected bool $hasWebhooks = false;
   protected ?string $cacheName = null;
   /**
    * @var array Each item in the array becomes a li element in the ordered list of instructions
@@ -60,9 +55,39 @@
    * @var bool Flag to indicate there are extra options that warrant a dedicated options page for this service
    * Usually used for default field values for syncable services
    */
   public bool $hasExtraOptions = false;
   public static bool $hasExtraOptions = false;
   public bool $hasBatchCreate = false;
   public bool $hasBatchUpdate = false;
   public bool $hasBatchDelete = false;
   public bool $canCreateOnUpdate = false;
   /**
    * Post Syncing Capabilities
    * Define what sync operations this integration supports
    */
   protected array $canSync = [
      'initial' => false,    // Can share new posts to the service
      'update' => false,     // Can update already-shared posts
      'delete' => false,     // Can remove posts from the service
   ];
   /**
    * @var array // Post types that can be synced (e.g., ['artwork', 'tattoo']): usually built by Registrar.php if the integration name exists as a key in [ 'integrations' => []]
    */
   protected array $syncPostTypes = [];
   /**
    * @var array Taxonomies that can be synced (e.g., ['category', 'section']): usually built by Registrar.php if the integration name exists as a key in [ 'integrations' => []]
    */
   protected array $syncTaxonomies = [];
   /**
    * @var array User roles that can be synced (e.g., ['customer']): usually built by Registrar.php if the integration name exists as a key in [ 'integrations' => []]
    */
   protected array $syncUsers = [];
   /**
    * @var array Integration's specific content types. An array of [ TYPE => [$fields] ] Set by child classes' setContentTypes
    */
   protected array $contentTypes = [];
   protected array $credentials;
   /**
@@ -75,13 +100,16 @@
   public function loadCredentials():array
   {
      return Auth::getInstance()->getCredentials($this->service_name, $this->userID);
      if (!isset($this->credentials)) {
         $this->credentials = Auth::getInstance()->getCredentials($this->service_name, $this->userID);
      }
      return $this->credentials;
   }
   protected function logError(string $method, string $message, array $context = []):void
   {
      $context['service'] = $this->service_name;
      JVB()->error()->log('['.self::class.']'.$method, $message, $context);
      Errors::getInstance()->log('['.self::class.']'.$method, $message, $context);
   }
   protected function getReturnURL():string
@@ -107,4 +135,36 @@
      }
      return jvbDashIcon($icon);
   }
   protected function initializeRateLimiters():void
   {
      if (method_exists($this, 'initializeRequestLimiter')) {
         $this->initializeRequestLimiter();
      }
      if (method_exists($this, 'initializeOAuthRateLimiter')) {
         $this->initializeOAuthRateLimiter();
      }
   }
   public function response(bool $success, string $message, array $data = []):array
   {
      $response = [
         'success'   => $success,
         'message'   => $message
      ];
      if (!empty($data)) {
         $response['data'] = $data;
      }
      return $response;
   }
   public function getAllowedContent():array
   {
      return array_keys($this->contentTypes);
   }
   public function getServiceName():string
   {
      return $this->service_name;
   }
}