Skip to content

Commit 2612690

Browse files
committed
feat(Request): Added server var fetching
1 parent 70444a5 commit 2612690

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

Request.php

+11
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@ public static function fetch_req_var( $key, $def = null ) {
6363
return self::fetch_var( $_REQUEST[ $key ], $def );
6464
}
6565

66+
/**
67+
* Fetch a variable from the $_SERVER superglobal.
68+
*
69+
* @param string $key The key to fetch.
70+
* @param mixed $def The default value.
71+
* @return mixed The fetched value.
72+
*/
73+
public static function fetch_server_var( $key, $def = null ) {
74+
return self::fetch_var( $_SERVER[ $key ], $def );
75+
}
76+
6677
/**
6778
* Fetch, unslash, and clean a variable.
6879
*

xwp-helper-fns.php

+13
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,19 @@ function xwp_fetch_req_var( $key, $def = null ) {
224224
}
225225
endif;
226226

227+
if ( ! function_exists( 'xwp_fetch_server_var' ) ) :
228+
/**
229+
* Get an item of `SERVER` data if set, otherwise return a default value.
230+
*
231+
* @param string $key SERVER key.
232+
* @param string $def Default value.
233+
* @return mixed Value sanitized by xwp_uclean.
234+
*/
235+
function xwp_fetch_server_var( $key, $def = null ) {
236+
return f\Request::fetch_server_var( $key, $def );
237+
}
238+
endif;
239+
227240

228241
if ( ! function_exists( 'xwp_format_term_name' ) ) :
229242
/**

0 commit comments

Comments
 (0)