give
/
vendor
/
vendor-prefixed
/
stellarwp
/
admin-notices
/
src
/
ValueObjects
/
UserCapability.php
NoticeLocation.php
1 year ago
NoticeUrgency.php
1 year ago
ScreenCondition.php
1 year ago
Script.php
1 year ago
Style.php
1 year ago
UserCapability.php
1 year ago
UserCapability.php
44 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | |
| 6 | namespace Give\Vendors\StellarWP\AdminNotices\ValueObjects; |
| 7 | |
| 8 | /** |
| 9 | * A simple VO to encapsulate a user capability and its parameters. |
| 10 | * |
| 11 | * @since 1.0.0 |
| 12 | */ |
| 13 | class UserCapability |
| 14 | { |
| 15 | /** |
| 16 | * @var string |
| 17 | */ |
| 18 | private $capability; |
| 19 | |
| 20 | /** |
| 21 | * @var array |
| 22 | */ |
| 23 | private $parameters; |
| 24 | |
| 25 | /** |
| 26 | * @since 1.0.0 |
| 27 | */ |
| 28 | public function __construct(string $capability, array $parameters = []) |
| 29 | { |
| 30 | $this->capability = $capability; |
| 31 | $this->parameters = $parameters; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Checks of the current user passes the given capability. |
| 36 | * |
| 37 | * @since 1.0.0 |
| 38 | */ |
| 39 | public function currentUserCan(): bool |
| 40 | { |
| 41 | return current_user_can($this->capability, ...$this->parameters); |
| 42 | } |
| 43 | } |
| 44 |