Skip to content

Commit a9ce843

Browse files
authored
Added capabilities attribute for Taxonomy
1 parent d9f7ce3 commit a9ce843

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Pollora\Attributes\Taxonomy;
6+
7+
use Attribute;
8+
use Pollora\Taxonomy\Domain\Contracts\TaxonomyAttributeInterface;
9+
10+
/**
11+
* Attribute to set the capabilities parameter for a taxonomy.
12+
*
13+
* Provides an array of capabilities for this taxonomy.
14+
* See WordPress documentation for the full list of taxonomy capabilities.
15+
*
16+
* Available capabilities:
17+
* - manage_terms: capability required to access the taxonomy management screen
18+
* - edit_terms: capability required to edit terms in the taxonomy
19+
* - delete_terms: capability required to delete terms from the taxonomy
20+
* - assign_terms: capability required to assign terms in the taxonomy to posts
21+
*
22+
* @Attribute
23+
*/
24+
#[Attribute(Attribute::TARGET_CLASS)]
25+
class Capabilities extends TaxonomyAttribute
26+
{
27+
/**
28+
* Constructor.
29+
*
30+
* @param array $value The capabilities array for the taxonomy
31+
*/
32+
public function __construct(
33+
public readonly array $value
34+
) {}
35+
36+
/**
37+
* Configure the taxonomy with the capabilities parameter.
38+
*
39+
* @param TaxonomyAttributeInterface $taxonomy The taxonomy to configure
40+
*/
41+
protected function configure(TaxonomyAttributeInterface $taxonomy): void
42+
{
43+
$taxonomy->attributeArgs['capabilities'] = $this->value;
44+
}
45+
}

0 commit comments

Comments
 (0)