Jake Vanderwerf
2026-03-03 772462eeca3002a1d52508aeba485aab2b4742ad
inc/managers/InvitationsManager.php
@@ -4,6 +4,7 @@
use Exception;
use JVBase\managers\queue\executors\InvitationExecutor;
use JVBase\managers\queue\TypeConfig;
use JVBase\registrar\Registrar;
use JVBase\utility\Features;
use WP_Error;
@@ -16,9 +17,11 @@
   protected array $inviteConfig;
   protected CustomTable $table;
   protected int $expiryDays = 14;
   protected Cache $cache;
   public function __construct()
   {
      $this->setInviteConfig();
      $this->cache = Cache::for('invitations');
      $this->table = CustomTable::for('invitations');
      add_action('init', [$this, 'registerInvitationExecutors'], 5);
@@ -86,6 +89,9 @@
    */
   protected function buildInviteTypes(): array
   {
      $invitable = $this->cache->remember(
         'invitableTypes',
         function () {
      $types = [];
      // Global invitations from JVB_MEMBERSHIP
@@ -99,16 +105,22 @@
      }
      // Term invitations from invitable content taxonomies
      foreach (JVB_TAXONOMY as $taxonomy => $config) {
         if (Features::forTaxonomy($taxonomy)->has('invitable') &&
            Features::forTaxonomy($taxonomy)->has('is_content') &&
            Features::forTaxonomy($taxonomy)->has('is_ownable')) {
            $invitable = Registrar::getFeatured('invitable', 'term');
            $content = Registrar::getFeatured('is_content', 'term');
            $ownable = Registrar::getFeatured('is_ownable', 'term');
            $taxonomies = array_intersect($invitable, $content, $ownable);
            if (!empty($taxonomies)) {
               $users = Registrar::getRegistered('user');
            }
            foreach ($taxonomies as $taxonomy) {
               $registrar = Registrar::getInstance($taxonomy);
            $forContent = $config['for_content'] ?? [];
            foreach ($forContent as $content) {
               foreach ($registrar->registrar->for as $content) {
               // Find which user roles can create this content
               foreach (JVB_USER as $role => $userConfig) {
                  $creatable = Features::forUser($role)->getCreatableContent();
                  foreach ($users as $user) {
                     $userRegistrar = Registrar::getInstance($user);
                     $creatable = $userRegistrar->getCreatable();
                  if (in_array($content, $creatable)) {
                     if (!isset($types[$role])) {
                        $types[$role] = [
@@ -123,10 +135,13 @@
               }
            }
         }
      }
      return $types;
   }
      );
      return $invitable;
   }
   /******************************************************************
    * UTILITY
@@ -467,8 +482,9 @@
         $term = get_term($termID, BASE . $taxonomy);
         if ($term && !is_wp_error($term)) {
            $config = JVB_TAXONOMY[$taxonomy] ?? [];
            $singular = $config['singular'] ?? $taxonomy;
            $registrar = Registrar::getInstance($taxonomy);
            $singular = $registrar ? $registrar->getSingular() : $taxonomy;
            $termContent[] = sprintf(
               "<p>%s has also invited you to join %s. You'll be automatically added to this %s when you register.</p>",