Skip to content

Commit

Permalink
feat(Request): Added server var fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
seebeen committed Sep 6, 2024
1 parent 70444a5 commit 2612690
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ public static function fetch_req_var( $key, $def = null ) {
return self::fetch_var( $_REQUEST[ $key ], $def );
}

/**
* Fetch a variable from the $_SERVER superglobal.
*
* @param string $key The key to fetch.
* @param mixed $def The default value.
* @return mixed The fetched value.
*/
public static function fetch_server_var( $key, $def = null ) {
return self::fetch_var( $_SERVER[ $key ], $def );
}

/**
* Fetch, unslash, and clean a variable.
*
Expand Down
13 changes: 13 additions & 0 deletions xwp-helper-fns.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,19 @@ function xwp_fetch_req_var( $key, $def = null ) {
}
endif;

if ( ! function_exists( 'xwp_fetch_server_var' ) ) :
/**
* Get an item of `SERVER` data if set, otherwise return a default value.
*
* @param string $key SERVER key.
* @param string $def Default value.
* @return mixed Value sanitized by xwp_uclean.
*/
function xwp_fetch_server_var( $key, $def = null ) {
return f\Request::fetch_server_var( $key, $def );
}
endif;


if ( ! function_exists( 'xwp_format_term_name' ) ) :
/**
Expand Down

0 comments on commit 2612690

Please sign in to comment.