PluginProbe
Simple Analytics / 1.110
Simple Analytics v1.110
1.110 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 All 99 releases
simpleanalytics / src / Settings / Blocks / Fields / Input.php

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

94 lines 2.1 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\SettingName;
7 use SimpleAnalytics\Support\OnloadCallback;
8 use SimpleAnalytics\Settings\Concerns\HasDocs;
9 use SimpleAnalytics\Settings\Concerns\HasPlaceholder;
10 use SimpleAnalytics\UI\LabelComponent;
11
12 class Input extends Field
13 {
14 use HasDocs;
15 use HasPlaceholder;
16
17 /**
18 * @var string
19 */
20 protected $type = 'text';
21
22 /**
23 * @var bool
24 */
25 protected $autofocus = false;
26
27 /**
28 * @var string|null
29 */
30 protected $placeholder;
31
32 public function getValueSanitizer(): callable
33 {
34 if ($this->getKey() === SettingName::ONLOAD_CALLBACK) {
35 return [OnloadCallback::class, 'sanitize'];
36 }
37 return 'sanitize_text_field';
38 }
39
40 public function getValueType(): string
41 {
42 return 'string';
43 }
44
45 public function render(): void
46 {
47 ?>
48 <?php
49 (new LabelComponent($this->getLabel(), $this->docs, $this->getKey()))();
50 ?>
51 <input
52 type="<?php
53 echo esc_attr($this->type);
54 ?>"
55 name="<?php
56 echo esc_attr($this->getKey());
57 ?>"
58 id="<?php
59 echo esc_attr($this->getKey());
60 ?>"
61 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"
62 placeholder="<?php
63 echo esc_attr($this->placeholder);
64 ?>"
65 <?php
66 if ($this->autofocus) echo "autofocus";
67 ?>
68 value="<?php
69 echo esc_attr(Setting::get($this->getKey()));
70 ?>"
71 >
72 <?php
73 if ($this->description): ?>
74 <p class="mt-2 text-sm text-gray-500">
75 <?php echo esc_html($this->description); ?>
76 </p>
77 <?php endif;
78 }
79
80 public function type(string $type): self
81 {
82 $this->type = $type;
83
84 return $this;
85 }
86
87 public function autofocus(): self
88 {
89 $this->autofocus = true;
90
91 return $this;
92 }
93 }
94