From 474109a5df0a06f5343ab184838fe2d80e3872a8 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Sun, 11 Jan 2026 19:23:20 +0000
Subject: [PATCH] =Fixed timeline CRUD.js issue where this.activeItem was set null when we still needed it
---
inc/managers/RoleManager.php | 71 +++++++++++++++++++++++++----------
1 files changed, 51 insertions(+), 20 deletions(-)
diff --git a/inc/managers/RoleManager.php b/inc/managers/RoleManager.php
index b575a04..4913bc4 100644
--- a/inc/managers/RoleManager.php
+++ b/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
--
Gitblit v1.10.0