PluginProbe
Simple Analytics / 1.67
Simple Analytics v1.67
1.109 1.108 1.107 1.106 1.73 1.74 1.75 1.76 1.77 1.78 1.79 1.8 1.80 1.81 1.82 1.83 1.84 1.85 1.86 1.87 1.88 1.89 1.9 1.90 1.91 All 98 releases
simpleanalytics / src / Settings / Blocks / Fields / Input.php

Input.php in Simple Analytics 1.67, at src/Settings/Blocks/Fields/Input.php

89 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace SimpleAnalytics\Settings\Blocks\Fields;
4
5 use SimpleAnalytics\Setting;
6 use SimpleAnalytics\Settings\Concerns\HasDocs;
7 use SimpleAnalytics\Settings\Concerns\HasPlaceholder;
8 use SimpleAnalytics\UI\LabelComponent;
9
10 class Input extends Field
11 {
12 use HasDocs;
13 use HasPlaceholder;
14
15 /**
16 * @var string
17 */
18 protected $type = 'text';
19
20 /**
21 * @var bool
22 */
23 protected $autofocus = false;
24
25 /**
26 * @var string|null
27 */
28 protected $placeholder;
29
30 public function getValueSanitizer(): callable
31 {
32 return 'sanitize_text_field';
33 }
34
35 public function getValueType(): string
36 {
37 return 'string';
38 }
39
40 public function render(): void
41 {
42 ?>
43 <?php
44 (new LabelComponent($this->getLabel(), $this->docs, $this->getKey()))();
45 ?>
46 <input
47 type="<?php
48 echo esc_attr($this->type);
49 ?>"
50 name="<?php
51 echo esc_attr($this->getKey());
52 ?>"
53 id="<?php
54 echo esc_attr($this->getKey());
55 ?>"
56 class="mt-2 block w-full rounded-md border-0 placeholder:text-gray-400 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 py-1.5 focus:ring-primary focus:ring-2 focus:ring-inset sm:max-w-md sm:text-sm sm:leading-6"
57 placeholder="<?php
58 echo esc_attr($this->placeholder);
59 ?>"
60 <?php
61 if ($this->autofocus) echo "autofocus";
62 ?>
63 value="<?php
64 echo esc_attr(Setting::get($this->getKey()));
65 ?>"
66 >
67 <?php
68 if ($this->description): ?>
69 <p class="mt-2 text-sm text-gray-500">
70 <?php echo esc_html($this->description); ?>
71 </p>
72 <?php endif;
73 }
74
75 public function type(string $type): self
76 {
77 $this->type = $type;
78
79 return $this;
80 }
81
82 public function autofocus(): self
83 {
84 $this->autofocus = true;
85
86 return $this;
87 }
88 }
89