PHPackages                             stellarwp/superglobals - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. stellarwp/superglobals

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

stellarwp/superglobals
======================

A library that handles access to superglobals.

2.0.0(4mo ago)2378.2k↑291.9%[1 PRs](https://github.com/stellarwp/superglobals/pulls)MITPHPCI passing

Since May 22Pushed 4mo ago4 watchersCompare

[ Source](https://github.com/stellarwp/superglobals)[ Packagist](https://packagist.org/packages/stellarwp/superglobals)[ RSS](/packages/stellarwp-superglobals/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (6)Dependencies (5)Versions (9)Used By (0)

StellarWP SuperGlobals
======================

[](#stellarwp-superglobals)

[![Tests](https://github.com/stellarwp/superglobals/workflows/Tests/badge.svg)](https://github.com/stellarwp/superglobals/actions?query=branch%3Amain) [![Static Analysis](https://github.com/stellarwp/superglobals/actions/workflows/static-analysis.yml/badge.svg)](https://github.com/stellarwp/superglobals/actions/workflows/static-analysis.yml)

A library that handles access to superglobals.

Why create a library for this? WordPress .org does not like plugins to directly access superglobals, so this library was created to handle this in a consistent and safe way and can be included as a composer dependency.

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Usage](#usage)
    - [`SuperGlobals::get_get_var( $var, $default = null )`](#superglobalsget_get_var-var-default--null-)
    - [`SuperGlobals::get_post_var( $var, $default = null )`](#superglobalsget_post_var-var-default--null-)
    - [`SuperGlobals::get_raw_superglobal( string $superglobal )`](#superglobalsget_raw_superglobal-string-superglobal-)
    - [`SuperGlobals::get_sanitized_superglobal( string $superglobal )`](#superglobalsget_sanitized_superglobal-string-superglobal-)
    - [`SuperGlobals::get_server_var( $var, $default = null )`](#superglobalsget_server_var-var-default--null-)
    - [`SuperGlobals::get_var( $var, $default = null )`](#superglobalsget_var-var-default--null-)
    - [`SuperGlobals::sanitize_deep( $value )`](#superglobalssanitize_deep-value-)

Installation
------------

[](#installation)

It's recommended that you install SuperGlobals as a project dependency via [Composer](https://getcomposer.org/):

```
composer require stellarwp/superglobals
```

> We *actually* recommend that this library gets included in your project using [Strauss](https://github.com/BrianHenryIE/strauss).
>
> Luckily, adding Strauss to your `composer.json` is only slightly more complicated than adding a typical dependency, so checkout our [strauss docs](https://github.com/stellarwp/global-docs/blob/main/docs/strauss-setup.md).

**An important note on namespaces:**

> The docs will in this repo all use `StellarWP\SuperGlobals` as the base namespace, however, if you are using [Strauss](#strauss)to prefix namespaces in your project, you will need to adapt the namespaces accordingly. (Example: `Boom\Shakalaka\StellarWP\SuperGlobals`)

Usage
-----

[](#usage)

### `SuperGlobals::get_get_var( $var, $default = null )`

[](#superglobalsget_get_var-var-default--null-)

Get a `$_GET` value and recursively sanitize it using `SuperGlobals::sanitize_deep()`.

#### Example

[](#example)

```
use StellarWP\SuperGlobals\SuperGlobals;

// Get $_GET['post_id']
$var = SuperGlobals::get_get_var( 'post_id' );

// Provide a default value if the variable is not set or fails to sanitize.
$var = SuperGlobals::get_get_var( 'post_id', 12 );
```

### `SuperGlobals::get_post_var( $var, $default = null )`

[](#superglobalsget_post_var-var-default--null-)

Get a `$_POST` value and recursively sanitize it using `SuperGlobals::sanitize_deep()`.

#### Example

[](#example-1)

```
use StellarWP\SuperGlobals\SuperGlobals;

// Get $_POST['post_id']
$var = SuperGlobals::get_post_var( 'post_id' );

// Provide a default value if the variable is not set or fails to sanitize.
$var = SuperGlobals::get_post_var( 'post_id', 12 );
```

### `SuperGlobals::get_raw_superglobal( string $superglobal )`

[](#superglobalsget_raw_superglobal-string-superglobal-)

Gets the requested superglobal variable. Options are `ENV`, `GET`, `POST`, `REQUEST`, or `SERVER`.

#### Example

[](#example-2)

```
use StellarWP\SuperGlobals\SuperGlobals;

// Get $_ENV
$env     = SuperGlobals::get_raw_superglobal( 'ENV' );

// Get $_GET
$get     = SuperGlobals::get_raw_superglobal( 'GET' );

// Get $_POST
$post    = SuperGlobals::get_raw_superglobal( 'POST' );

// Get $_REQUEST
$request = SuperGlobals::get_raw_superglobal( 'REQUEST' );

// Get $_SERVER
$server  = SuperGlobals::get_raw_superglobal( 'SERVER' );
```

### `SuperGlobals::get_sanitized_superglobal( string $superglobal )`

[](#superglobalsget_sanitized_superglobal-string-superglobal-)

Gets the requested superglobal variable, sanitized. Options are `ENV`, `GET`, `POST`, `REQUEST`, or `SERVER`.

#### Example

[](#example-3)

```
use StellarWP\SuperGlobals\SuperGlobals;

// Get $_ENV
$env     = SuperGlobals::get_sanitized_superglobal( 'ENV' );

// Get $_GET
$get     = SuperGlobals::get_sanitized_superglobal( 'GET' );

// Get $_POST
$post    = SuperGlobals::get_sanitized_superglobal( 'POST' );

// Get $_REQUEST
$request = SuperGlobals::get_sanitized_superglobal( 'REQUEST' );

// Get $_SERVER
$server  = SuperGlobals::get_sanitized_superglobal( 'SERVER' );
```

### `SuperGlobals::get_server_var( $var, $default = null )`

[](#superglobalsget_server_var-var-default--null-)

Get a `$_SERVER` value and recursively sanitize it using `SuperGlobals::sanitize_deep()`.

#### Example

[](#example-4)

```
use StellarWP\SuperGlobals\SuperGlobals;

// Get $_SERVER['REQUEST_URI']
$var = SuperGlobals::get_server_var( 'REQUEST_URI' );

// Provide a default value if the variable is not set or fails to sanitize.
$var = SuperGlobals::get_server_var( 'REQUEST_URI', 'http://example.com' );
```

### `SuperGlobals::get_var( $var, $default = null )`

[](#superglobalsget_var-var-default--null-)

Gets a value from `$_REQUEST`, `$_POST`, or `$_GET` and recursively sanitizes it using `SuperGlobals::sanitize_deep()`.

#### Example

[](#example-5)

```
use StellarWP\SuperGlobals\SuperGlobals;

// Get $_REQUEST['post_id'] or $_POST['post_id'] or $_GET['post_id'], wherever it lives.
$var = SuperGlobals::get_var( 'post_id' );

// Provide a default value if the variable is not set or fails to sanitize.
$var = SuperGlobals::get_var( 'post_id', 12 );
```

### `SuperGlobals::sanitize_deep( $value )`

[](#superglobalssanitize_deep-value-)

Sanitizes a value recursively using appropriate sanitization functions depending on the type of the value.

Important

During deep sanitization, any nested array value that cannot be safely sanitized is **removed entirely** (its key is unset). This is intentional: missing data is safer and more predictable than retaining invalid or corrupted values.

#### Example

[](#example-6)

```
use StellarWP\SuperGlobals\SuperGlobals;

$var = SuperGlobals::sanitize_deep( $some_var );
```

###  Health Score

46

—

FairBetter than 92% of packages

Maintenance74

Regular maintenance activity

Popularity38

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 62.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~125 days

Recently: every ~157 days

Total

6

Last Release

143d ago

Major Versions

1.3.0 → 2.0.02026-02-09

### Community

Maintainers

![](https://www.gravatar.com/avatar/e3171496e198834c638911ad3c3220bec77871cdf6557eaa9e2a58d16600a1a1?d=identicon)[bordoni](/maintainers/bordoni)

![](https://www.gravatar.com/avatar/70a2847a265444714b48c64eceb3ca742baa3a56757ce65b18bd7bbbbf910312?d=identicon)[dpanta94](/maintainers/dpanta94)

![](https://www.gravatar.com/avatar/97fd764aa710e8d8263a7e3b3fececdfd736b8aad8055227bf592ddf50ad15ba?d=identicon)[stellarwp](/maintainers/stellarwp)

![](https://www.gravatar.com/avatar/ec4ef25906386b60f5f66b3d03064e3bb700bedc94ee8558918565612c74aef3?d=identicon)[johnhooks](/maintainers/johnhooks)

---

Top Contributors

[![borkweb](https://avatars.githubusercontent.com/u/430385?v=4)](https://github.com/borkweb "borkweb (15 commits)")[![defunctl](https://avatars.githubusercontent.com/u/1066195?v=4)](https://github.com/defunctl "defunctl (9 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/stellarwp-superglobals/health.svg)

```
[![Health](https://phpackages.com/badges/stellarwp-superglobals/health.svg)](https://phpackages.com/packages/stellarwp-superglobals)
```

###  Alternatives

[firegento/extendedimport

Extended Import Features (ported from AvS\_FastSimpleImport)

6347.3k2](/packages/firegento-extendedimport)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
