| | |
| | | protected array $options; |
| | | protected mixed $default; |
| | | protected string $subtype; |
| | | protected string $placeholder; |
| | | protected bool $hidden = false; |
| | | protected int $min; |
| | | protected int $max; |
| | | |
| | | public function __construct(string $name, string $label, string $type, callable|string|bool $permission) |
| | | { |
| | | $this->name = $name; |
| | | $this->label = $label; |
| | | $this->type = $type; |
| | | $this->permission = $permission; |
| | | $this->permission = is_callable($permission) ? Closure::fromCallable($permission) : $permission; |
| | | } |
| | | |
| | | public function checkPermission():bool |
| | |
| | | |
| | | public function setSubType(string $type):void |
| | | { |
| | | $this->subType = $type; |
| | | $this->subtype = $type; |
| | | } |
| | | |
| | | public function setMin(int $min):void |
| | | { |
| | | $this->min = $min; |
| | | } |
| | | public function setMax(int $max):void |
| | | { |
| | | $this->max = $max; |
| | | } |
| | | |
| | | public function setPlaceholder(string $string):void |
| | | { |
| | | $this->placeholder = sanitize_text_field($string); |
| | | } |
| | | |
| | | public function getConfig():array |
| | |
| | | if ($this->hidden) { |
| | | $conf['hidden'] = true; |
| | | } |
| | | if (isset($this->min)) { |
| | | $conf['min'] = $this->min; |
| | | } |
| | | if (isset($this->max)) { |
| | | $conf['max'] = $this->max; |
| | | } |
| | | if (isset($this->placeholder)) { |
| | | $conf['placeholder'] = $this->placeholder; |
| | | } |
| | | return $conf; |
| | | } |
| | | |
| | | } |