| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @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 |
| | |
| | | } |
| | | $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']))) |
| | | ]; |
| | | return $capsMap[1]; |
| | | } |
| | | |
| | | return strtolower($content . 's'); |
| | | return str_replace('-', '_', sanitize_title(strtolower($content . 's'))); |
| | | } |
| | | |
| | | public function activate(): void |