-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxwp-helper-fns-req.php
184 lines (169 loc) · 5.65 KB
/
xwp-helper-fns-req.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<?php
/**
* Request helper functions definition file.
*
* @package eXtended WordPress
* @subpackage Helper\Functions
*/
use XWP\Helper\Functions as f;
if ( ! function_exists( 'xwp_can_load_rest_ns' ) ) :
/**
* Check if a REST namespace should be loaded. Useful to maintain site performance even when lots of REST namespaces are registered.
*
* @param string $space The namespace to check.
* @param string|null $route REST route being checked. Optional.
* @param array $known Known namespaces that we know are safe to not load if the request is not for them.
* @return bool
*/
function xwp_can_load_rest_ns( string $space, ?string $route = null, array $known = array() ): bool {
return f\Request::should_load_rest_ns( $space, $route, $known );
}
endif;
if ( ! function_exists( 'xwp_fetch_get_var' ) ) :
/**
* Get an item of `GET` data if set, otherwise return a default value.
*
* @template T of string|int|bool|float|array|null
*
* @param string $key GET key.
* @param T $def Default value.
* @return (T is string ? string : (T is int ? int : (T is array ? T : (T is float ? float : (T is bool ? bool : (T is null ? null : mixed))))))
*/
function xwp_fetch_get_var( string $key, mixed $def = null ): mixed {
return f\Request::fetch_get_var( $key, $def );
}
endif;
if ( ! function_exists( 'xwp_fetch_post_var' ) ) :
/**
* Get an item of `POST` data if set, otherwise return a default value.
*
* @template T of string|int|bool|float|array|null
*
* @param string $key POST key.
* @param T $def Default value.
* @return (T is string ? string : (T is int ? int : (T is array ? T : (T is float ? float : (T is bool ? bool : (T is null ? null : mixed))))))
*/
function xwp_fetch_post_var( string $key, mixed $def = null ): mixed {
return f\Request::fetch_post_var( $key, $def );
}
endif;
if ( ! function_exists( 'xwp_fetch_req_var' ) ) :
/**
* Get an item of `REQUEST`data if set, otherwise return a default value.
*
* @template T of string|int|bool|float|array|null
*
* @param string $key REQUEST key.
* @param T $def Default value.
* @return (T is string ? string : (T is int ? int : (T is array ? T : (T is float ? float : (T is bool ? bool : (T is null ? null : mixed))))))
*/
function xwp_fetch_req_var( $key, $def = null ) {
return f\Request::fetch_req_var( $key, $def );
}
endif;
if ( ! function_exists( 'xwp_fetch_server_var' ) ) :
/**
* Get an item of `SERVER` data if set, otherwise return a default value.
*
* @template T of string|int|bool|float|array|null
*
* @param string $key SERVER key.
* @param T $def Default value.
* @return (T is string ? string : (T is int ? int : (T is array ? T : (T is float ? float : (T is bool ? bool : (T is null ? null : mixed))))))
*/
function xwp_fetch_server_var( string $key, mixed $def = null ): mixed {
return f\Request::fetch_server_var( $key, $def );
}
endif;
if ( ! function_exists( 'xwp_fetch_cookie_var' ) ) :
/**
* Get an item of `COOKIE` data if set, otherwise return a default value.
*
* @param string $key COOKIE key.
* @param string $def Default value.
* @return string
*/
function xwp_fetch_cookie_var( string $key, string $def = '' ): string {
return f\Request::fetch_cookie_var( $key, $def );
}
endif;
if ( ! function_exists( 'xwp_fetch_files_var' ) ) :
/**
* Get an item of `FILES` data if set, otherwise return a default value.
*
* @param string $key FILES key.
* @param string $def Default value.
* @return mixed Value sanitized by xwp_uclean.
*/
function xwp_fetch_files_var( $key, $def = null ) {
return f\Request::fetch_files_var( $key, $def );
}
endif;
if ( ! function_exists( 'xwp_get_arr' ) ) :
/**
* Get the unslashed and cleaned $_GET array.
*
* @template T of array
* @param T $def Default value.
* @return T
*/
function xwp_get_arr( array $def = array() ): array {
return f\Request::fetch_get_arr( $def );
}
endif;
if ( ! function_exists( 'xwp_post_arr' ) ) :
/**
* Get the unslashed and cleaned $_POST array.
*
* @template T of array
* @param T $def Default value.
* @return T
*/
function xwp_post_arr( array $def = array() ): array {
return f\Request::fetch_post_arr( $def );
}
endif;
if ( ! function_exists( 'xwp_req_arr' ) ) :
/**
* Get the unslashed and cleaned $_REQUEST array.
*
* @template T of array
* @param T $def Default value.
* @return T
*/
function xwp_req_arr( array $def = array() ): array {
return f\Request::fetch_req_arr( $def );
}
endif;
if ( ! function_exists( 'xwp_server_arr' ) ) :
/**
* Get the unslashed and cleaned $_SERVER array.
*
* @template T of array
* @param T $def Default value.
* @return T
*/
function xwp_server_arr( array $def = array() ): array {
return f\Request::fetch_server_arr( $def );
}
endif;
if ( ! function_exists( 'xwp_cookie_arr' ) ) :
/**
* Get the unslashed and cleaned $_COOKIE array.
*
* @return array<string, mixed>
*/
function xwp_cookie_arr(): array {
return f\Request::fetch_cookie_arr();
}
endif;
if ( ! function_exists( 'xwp_files_arr' ) ) :
/**
* Get the unslashed and cleaned $_FILES array.
*
* @return array<string, mixed>
*/
function xwp_files_arr(): array {
return f\Request::fetch_files_arr();
}
endif;