PluginProbe ʕ •ᴥ•ʔ
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.2.0
Kirki – Freeform Page Builder, Website Builder & Customizer v6.2.0
6.2.0 6.1.1 6.1.0 6.0.14 6.0.13 6.0.12 6.0.11 6.0.10 6.0.9 6.0.8 6.0.7 6.0.6 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.19 4.0.20 4.0.21 4.0.22 4.0.23 4.0.24 4.1 4.2.0 5.0.0 5.1.0 5.1.1 5.2.0 5.2.1 5.2.2 5.2.3 6.0.0 trunk 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.1.0 3.1.1 3.1.2
kirki / app / helpers.php
kirki / app Last commit date
Casts 2 weeks ago Constants 5 days ago Contracts 5 days ago DTO 5 days ago FormActions 5 days ago Http 5 days ago Managers 5 days ago Models 5 days ago Providers 5 days ago Resources 5 days ago Rules 5 days ago Services 5 days ago Supports 5 days ago Traits 5 days ago Utils 1 month ago Wordpress 1 month ago helpers.php 5 days ago
helpers.php
203 lines
1 <?php
2
3 namespace Kirki\App;
4
5 use Kirki\Framework\Sanitizer;
6
7 defined('ABSPATH') || exit;
8
9 if (!function_exists('Kirki\App\get_timezone')) {
10 function get_timezone($is_utc = false)
11 {
12 if ($is_utc) {
13 return 'UTC';
14 }
15
16 return wp_timezone();
17 }
18 }
19
20 if (!function_exists('Kirki\App\get_upload_directory')) {
21 /**
22 * Get the base upload directory path
23 *
24 * @return string
25 */
26 function get_upload_directory()
27 {
28 return wp_upload_dir()['basedir'];
29 }
30 }
31
32 if (!function_exists('Kirki\App\get_upload_directory_url')) {
33 /**
34 * Get the base upload directory url
35 *
36 * @return string
37 */
38 function get_upload_directory_url()
39 {
40 return wp_upload_dir()['baseurl'];
41 }
42 }
43
44 if (!function_exists('Kirki\App\to_boolean')) {
45 /**
46 * Return boolean value
47 * @param mixed $value
48 * @return bool
49 */
50 function to_boolean($value)
51 {
52 if (is_bool($value)) {
53 return $value;
54 }
55
56 if (is_null($value)) {
57 return false;
58 }
59
60 if (is_string($value)) {
61 if ($value === '' || $value === '0' || strtolower($value) === 'false') {
62 return false;
63 }
64 }
65
66 if (is_numeric($value) && (int) $value === 0) {
67 return false;
68 }
69
70 if (is_array($value) || is_object($value)) {
71 return !empty($value);
72 }
73
74 return true;
75 }
76 }
77
78 if (!function_exists('Kirki\App\is_truthy')) {
79 /**
80 * Return is empty array
81 * @param mixed $value
82 * @return bool
83 */
84 function is_truthy($value)
85 {
86 $value = to_boolean($value);
87
88 return $value === true;
89 }
90 }
91
92 if (!function_exists('Kirki\App\is_falsy')) {
93 /**
94 * Return is empty array
95 * @param mixed $value
96 * @return bool
97 */
98 function is_falsy($value)
99 {
100 $value = to_boolean($value);
101
102 return $value === false;
103 }
104 }
105
106 if (!function_exists('Kirki\App\is_not_empty_array')) {
107 /**
108 * Return is not empty array
109 * @param mixed $value
110 * @return bool
111 */
112 function is_not_empty_array($value)
113 {
114 if (!is_array($value)) {
115 return false;
116 }
117
118 return count($value) > 0;
119 }
120 }
121
122 if (!function_exists('Kirki\App\get_editor_mode')) {
123 /**
124 * Get editor mode value
125 *
126 * @return string
127 */
128 function get_editor_mode()
129 {
130 return 'kirki';
131 }
132 }
133
134 if (!function_exists('Kirki\App\soft_flush_rewrite_rules')) {
135 /**
136 * Soft flush rewrite rules
137 *
138 * @return void
139 */
140 function soft_flush_rewrite_rules()
141 {
142 flush_rewrite_rules(false);
143 }
144 }
145
146
147 if (!function_exists('Kirki\App\get_request_header')) {
148 /**
149 * Get request header by header name with sanitization
150 *
151 * @param string $header_name
152 *
153 * @return string|null
154 */
155 function get_request_header(string $header_name)
156 {
157 if (function_exists('getallheaders')) {
158 $headers = getallheaders();
159
160 return Sanitizer::apply_rule($headers[$header_name] ?? null, Sanitizer::TEXT);
161 }
162
163 // Fallback because `getallheaders()` is not guaranteed to exist in every PHP environment
164 $normalized_name = strtolower(trim($header_name));
165 $content_headers = ['content-type', 'content-length', 'content-md5'];
166
167 $header_key = in_array($normalized_name, $content_headers, true)
168 ? str_replace('-', '_', strtoupper($normalized_name))
169 : 'HTTP_' . str_replace('-', '_', strtoupper($normalized_name));
170
171 $value = filter_input(INPUT_SERVER, $header_key, FILTER_UNSAFE_RAW);
172
173 if (is_null($value) || $value === '' || $value === false) {
174 return null;
175 }
176
177 return Sanitizer::apply_rule($value, Sanitizer::TEXT);
178 }
179 }
180
181 if (!function_exists('Kirki\App\ensure_array')) {
182 /**
183 * Ensure that the value is an array.
184 *
185 * @param mixed $value
186 *
187 * @return array
188 */
189 function ensure_array($value)
190 {
191 if (is_array($value)) {
192 return $value;
193 }
194
195 if (is_string($value)) {
196 $decoded = json_decode($value, true);
197
198 return is_array($decoded) ? $decoded : $value;
199 }
200
201 return $value;
202 }
203 }