flexible-shipping
/
vendor_prefixed
/
wpdesk
/
wp-pointer
/
src
/
WPDesk
/
Pointer
/
PointerConditions.php
views
2 weeks ago
PointerConditions.php
2 weeks ago
PointerMessage.php
2 weeks ago
PointerPosition.php
2 weeks ago
PointersScripts.php
2 weeks ago
PointerConditions.php
98 lines
| 1 | <?php |
| 2 | |
| 3 | namespace FSVendor\WPDesk\Pointer; |
| 4 | |
| 5 | /** |
| 6 | * Pointer conditions. |
| 7 | * |
| 8 | * @package WPDesk\Pointer |
| 9 | */ |
| 10 | class PointerConditions |
| 11 | { |
| 12 | /** |
| 13 | * @var null|string|array |
| 14 | */ |
| 15 | private $screenId; |
| 16 | /** |
| 17 | * @var null|string |
| 18 | */ |
| 19 | private $capability; |
| 20 | /** |
| 21 | * PointerConditions constructor. |
| 22 | * |
| 23 | * @param null|string|array $screenId Screen id. null or empty string - all screens. |
| 24 | * @param null|string $capability User capability. null or empty string for all capabilities. |
| 25 | */ |
| 26 | public function __construct($screenId = null, $capability = null) |
| 27 | { |
| 28 | $this->screenId = $screenId; |
| 29 | $this->capability = $capability; |
| 30 | } |
| 31 | /** |
| 32 | * @return array|string|null |
| 33 | */ |
| 34 | public function getScreenId() |
| 35 | { |
| 36 | return $this->screenId; |
| 37 | } |
| 38 | /** |
| 39 | * @param array|string|null $screenId |
| 40 | */ |
| 41 | public function setScreenId($screenId) |
| 42 | { |
| 43 | $this->screenId = $screenId; |
| 44 | } |
| 45 | /** |
| 46 | * @return string |
| 47 | */ |
| 48 | public function getCapability() |
| 49 | { |
| 50 | return $this->capability; |
| 51 | } |
| 52 | /** |
| 53 | * @param string $capability |
| 54 | */ |
| 55 | public function setCapability($capability) |
| 56 | { |
| 57 | $this->capability = $capability; |
| 58 | } |
| 59 | /** |
| 60 | * @return bool |
| 61 | */ |
| 62 | private function areScreenIdMet() |
| 63 | { |
| 64 | $screenIdMet = \false; |
| 65 | if (!empty($this->screenId)) { |
| 66 | if (!is_array($this->screenId)) { |
| 67 | $this->screenId = array($this->screenId); |
| 68 | } |
| 69 | $screen = get_current_screen(); |
| 70 | if (null !== $screen && in_array($screen->id, $this->screenId, \true)) { |
| 71 | $screenIdMet = \true; |
| 72 | } |
| 73 | } else { |
| 74 | $screenIdMet = \true; |
| 75 | } |
| 76 | return $screenIdMet; |
| 77 | } |
| 78 | /** |
| 79 | * @return bool |
| 80 | */ |
| 81 | private function areCapabilityMet() |
| 82 | { |
| 83 | if (!empty($this->capability)) { |
| 84 | $capabilityMet = current_user_can($this->capability); |
| 85 | } else { |
| 86 | $capabilityMet = \true; |
| 87 | } |
| 88 | return $capabilityMet; |
| 89 | } |
| 90 | /** |
| 91 | * @return bool |
| 92 | */ |
| 93 | public function areConditionsMet() |
| 94 | { |
| 95 | return $this->areCapabilityMet() && $this->areScreenIdMet(); |
| 96 | } |
| 97 | } |
| 98 |