Jake Vanderwerf
2026-01-01 58dccc86754deda247eb49310c266f6cba86d36a
inc/managers/RoleManager.php
@@ -19,8 +19,24 @@
      $this->content = array_map(function($content) {
         return strtolower($content['plural']);
      },JVB_CONTENT);
      add_action('set_user_role', [$this, 'updateRoles'], 10, 3);
    }
   public function updateRoles(int $userID, string $role, array $oldRoles):void
   {
      if (doing_action('set_user_role') > 1) {
         return;
      }
      $temp = jvbNoBase($role);
      if (array_key_exists($temp, JVB_USER)) {
         $user = get_userdata($userID);
         if (!$user) {
            return;
         }
         $this->reset($user);
         $this->setUserAs($user, $temp);
      }
   }
    /**
     * @param WP_User $user
@@ -140,7 +156,6 @@
    /**
     * @param WP_User $user
     * @param string $type
     * @param bool $add
     *
     * @return void
     */
@@ -356,22 +371,29 @@
      }
   }
   /**
    * @param string $content
    * @return array|string[]
    * Note: must match what is created in PostTypeRegistrar.php::register
    */
   protected function getCapabilities(string $content):array
   {
      $content = jvbNoBase($content);
      if (!$this->isValidContentType($content)) {
         return [];
      }
      $plural = $this->getContentPlural($content);
      return [
         'edit_' . $plural,
         'delete_' . $plural,
         'read_' . $plural,
         'edit_published_' . $plural,
         'delete_published_' . $plural,
         'edit_private_' . $plural,
         'delete_private_' . $plural,
         'publish_' . $plural,
         "edit_{$content}",
         "read_{$content}",
         "delete_{$content}",
         "edit_{$plural}",
         "edit_others_{$plural}",
         "publish_{$plural}",
         "read_private_{$plural}",
         "edit_{$plural}",
      ];
   }
   protected function getOthersCapabilities(string $content):array
@@ -382,23 +404,32 @@
      }
      $plural = $this->getContentPlural($content);
      return [
         'edit_others_' . $plural,
         'delete_others_' . $plural,
         'read_private_' . $plural,
         'edit_private_' . $plural,
         'delete_private_' . $plural,
         "edit_others_{$plural}",
         "delete_others_{$plural}",
         "read_private_{$plural}",
         "edit_private_{$plural}",
         "delete_private_{$plural}",
      ];
   }
   private function getContentPlural(string $content): string
   public static function getPlural(string $content): string
   {
      $self = new self;
      return $self->getContentPlural($content);
   }
   public function getContentPlural(string $content): string
   {
      $content = jvbNoBase($content);
      if (array_key_exists($content, JVB_CONTENT)) {
         return strtolower(JVB_CONTENT[$content]['plural'] ?? $content . 's');
      $config = Features::getConfig($content);
      $capsMap = $config['capability_type']??[];
      if (empty($capsMap)){
         $capsMap = [
            $content,
            str_replace('-', '_',sanitize_title(strtolower(JVB_CONTENT[$content]['plural']??JVB_TAXONOMY[$content]['plural'])))
         ];
         return $capsMap[1];
      }
      return strtolower($content . 's');
      return str_replace('-', '_', sanitize_title(strtolower($content . 's')));
   }
   public function activate(): void