PluginProbe ʕ •ᴥ•ʔ
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.1.1
Kirki – Freeform Page Builder, Website Builder & Customizer v6.1.1
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 days ago Constants 3 days ago DTO 3 days ago Http 3 days ago Managers 3 days ago Models 3 days ago Providers 3 weeks ago Resources 3 days ago Services 3 days ago Supports 3 days ago Traits 3 weeks ago Utils 3 weeks ago Wordpress 3 weeks ago helpers.php 3 weeks ago
helpers.php
169 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 if ($is_utc) {
12 return 'UTC';
13 }
14
15 return wp_timezone();
16 }
17 }
18
19 if (!function_exists('Kirki\App\get_upload_directory')) {
20 /**
21 * Get the base upload directory path
22 *
23 * @return string
24 */
25 function get_upload_directory() {
26 return wp_upload_dir()['basedir'];
27 }
28 }
29
30 if (!function_exists('Kirki\App\get_upload_directory_url')) {
31 /**
32 * Get the base upload directory url
33 *
34 * @return string
35 */
36 function get_upload_directory_url() {
37 return wp_upload_dir()['baseurl'];
38 }
39 }
40
41 if (!function_exists('Kirki\App\to_boolean')) {
42 /**
43 * Return boolean value
44 * @param mixed $value
45 * @return bool
46 */
47 function to_boolean($value) {
48 if (is_bool($value)) {
49 return $value;
50 }
51
52 if (is_null($value)) {
53 return false;
54 }
55
56 if (is_string($value)) {
57 if ($value === '' || $value === '0' || strtolower($value) === 'false') {
58 return false;
59 }
60 }
61
62 if (is_numeric($value) && (int) $value === 0) {
63 return false;
64 }
65
66 if (is_array($value) || is_object($value)) {
67 return !empty($value);
68 }
69
70 return true;
71 }
72 }
73
74 if (!function_exists('Kirki\App\is_truthy')) {
75 /**
76 * Return is empty array
77 * @param mixed $value
78 * @return bool
79 */
80 function is_truthy($value) {
81 $value = to_boolean($value);
82
83 return $value === true;
84 }
85 }
86
87 if (!function_exists('Kirki\App\is_falsy')) {
88 /**
89 * Return is empty array
90 * @param mixed $value
91 * @return bool
92 */
93 function is_falsy($value) {
94 $value = to_boolean($value);
95
96 return $value === false;
97 }
98 }
99
100 if (!function_exists('Kirki\App\is_not_empty_array')) {
101 /**
102 * Return is not empty array
103 * @param mixed $value
104 * @return bool
105 */
106 function is_not_empty_array($value) {
107 if (!is_array($value)) {
108 return false;
109 }
110
111 return count($value) > 0;
112 }
113 }
114
115 if (!function_exists('Kirki\App\get_editor_mode')) {
116 /**
117 * Get editor mode value
118 *
119 * @return string
120 */
121 function get_editor_mode() {
122 return 'kirki';
123 }
124 }
125
126 if (!function_exists('Kirki\App\soft_flush_rewrite_rules')) {
127 /**
128 * Soft flush rewrite rules
129 *
130 * @return void
131 */
132 function soft_flush_rewrite_rules() {
133 flush_rewrite_rules(false);
134 }
135 }
136
137
138 if (!function_exists('Kirki\App\get_request_header')) {
139 /**
140 * Get request header by header name with sanitization
141 *
142 * @param string $header_name
143 *
144 * @return string|null
145 */
146 function get_request_header(string $header_name) {
147 if (function_exists('getallheaders')) {
148 $headers = getallheaders();
149
150 return Sanitizer::apply_rule($headers[$header_name] ?? null, Sanitizer::TEXT);
151 }
152
153 // Fallback because `getallheaders()` is not guaranteed to exist in every PHP environment
154 $normalized_name = strtolower(trim($header_name));
155 $content_headers = ['content-type', 'content-length', 'content-md5'];
156
157 $header_key = in_array($normalized_name, $content_headers, true)
158 ? str_replace('-', '_', strtoupper($normalized_name))
159 : 'HTTP_' . str_replace('-', '_', strtoupper($normalized_name));
160
161 $value = filter_input(INPUT_SERVER, $header_key, FILTER_UNSAFE_RAW);
162
163 if (is_null($value) || $value === '' || $value === false) {
164 return null;
165 }
166
167 return Sanitizer::apply_rule($value, Sanitizer::TEXT);
168 }
169 }