PHPackages                             pinkcrab/wp-nonce - 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. pinkcrab/wp-nonce

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

pinkcrab/wp-nonce
=================

Simple class based WP Nonce solution

0.1.0(5y ago)12.4k[1 issues](https://github.com/Pink-Crab/Nonce/issues)1MITPHPPHP &gt;=7.1.0

Since Feb 11Pushed 5y agoCompare

[ Source](https://github.com/Pink-Crab/Nonce)[ Packagist](https://packagist.org/packages/pinkcrab/wp-nonce)[ Docs](https://pinkcrab.co.uk)[ RSS](/packages/pinkcrab-wp-nonce/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (11)Versions (2)Used By (1)

Nonce
=====

[](#nonce)

Simple class based WP Nonce solution

[![alt text](https://camo.githubusercontent.com/74d798f4a84f6dd26595462ad9ab25f5f1ed64db926942fc450cf1b1ad97f9e8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f43757272656e745f56657273696f6e2d302e312e302d79656c6c6f772e7376673f7374796c653d666c6174 " ")](https://camo.githubusercontent.com/74d798f4a84f6dd26595462ad9ab25f5f1ed64db926942fc450cf1b1ad97f9e8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f43757272656e745f56657273696f6e2d302e312e302d79656c6c6f772e7376673f7374796c653d666c6174)[![Open Source Love](https://camo.githubusercontent.com/2d4eac62d5f5830a5309100b88e0ecccb171aee1fbcd794149f4a580b0010c56/68747470733a2f2f6261646765732e66726170736f66742e636f6d2f6f732f6d69742f6d69742e7376673f763d313032)](https://github.com/ellerbrock/open-source-badge/)

[![](https://github.com/Pink-Crab/Nonce/workflows/GitHub_CI/badge.svg " ")](https://github.com/Pink-Crab/Nonce/workflows/GitHub_CI/badge.svg)[![codecov](https://camo.githubusercontent.com/5559b9367bfd5ea681c48abe1b013f930d6062f7448d37dc4a61be04178e7420/68747470733a2f2f636f6465636f762e696f2f67682f50696e6b2d437261622f4e6f6e63652f6272616e63682f6d61737465722f67726170682f62616467652e7376673f746f6b656e3d523353423457444c385a)](https://codecov.io/gh/Pink-Crab/Nonce)

For more details please visit our docs.

Version
-------

[](#version)

**Release 0.1.0**

Why?
----

[](#why)

Allows for use of Nonces in an oop mannor, while allowing serialisation/deserialsation of the object.

Setup
-----

[](#setup)

```
$ composer require pinkcrab/wp-nonce
```

```
    $nonce = new Nonce('my_none_key');

    // To get the current nonce token
    $nonce->token();

    // To validate
    $nonce->validate($_POST['nonce']); // true/false

    // To add to url
    $url = $nonce->as_url('http://www.url.com', 'my_nonce'); // http://www.url.com?my_nonce={nonce_value}

    // Validate url.
    $nonce->admin_referer('my_nonce'); // true/false if set in url.
```

Methods
=======

[](#methods)

Create Instance
---------------

[](#create-instance)

```
// Create with a custom key
$custom_nonce = new Nonce('custom_key');
```

> Once your nonce has been created, it can be serialised and/or passed around your codebase.

as\_url( string $url, string $arg='\_wpnonce' ): string
-------------------------------------------------------

[](#as_url-string-url-string-arg_wpnonce--string)

```
$nonce = new Nonce('url_key');

$custom_key_in_url = $nonce->as_url('http://test.com', 'url_nonce');
// http://test.com?url_nonce={nonce_token}

$default_key_in_url = $nonce->as_url('http://test.com');
// http://test.com?_wpnonce={nonce_token}
```

> NOTICE! This doesnt make use of the refer value found in admin nonces.

token(): string
---------------

[](#token-string)

```
$nonce = new Nonce('url_key');

// To get the current nonce value.
print $nonce->token(); // 31b31db189

$nonce_token = nonce->token(); // 31b31db189
```

nonce\_field($name = '\_wpnonce'): string
-----------------------------------------

[](#nonce_fieldname--_wpnonce-string)

```
$nonce = new Nonce('as_input');

// Create a nonce field, with a custom id/name for input
print $nonce->nonce_field('my_nonce');
//

// Create a nonce field, with a custom id/name for input
print $nonce->nonce_field();
//
```

> The nonce field is not automcatically printed

validate($name = '\_wpnonce'): string
-------------------------------------

[](#validatename--_wpnonce-string)

```
$nonce = new Nonce('as_input');

// Create a nonce field, with a custom id/name for input
print $nonce->nonce_field('my_nonce');
//

// Create a nonce field, with a custom id/name for input
print $nonce->nonce_field();
//
```

> The nonce field is not automcatically printed

Dependencies
------------

[](#dependencies)

- --NONE--

License
-------

[](#license)

### MIT License

[](#mit-license)

Change Log
----------

[](#change-log)

0.1.0 - Created from part of PC Framework 0.1.0

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

1913d ago

### Community

Maintainers

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

---

Top Contributors

[![gin0115](https://avatars.githubusercontent.com/u/28779094?v=4)](https://github.com/gin0115 "gin0115 (5 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/pinkcrab-wp-nonce/health.svg)

```
[![Health](https://phpackages.com/badges/pinkcrab-wp-nonce/health.svg)](https://phpackages.com/packages/pinkcrab-wp-nonce)
```

###  Alternatives

[whitehat101/apr1-md5

Apache's APR1-MD5 algorithm in pure PHP

349.7M10](/packages/whitehat101-apr1-md5)

PHPackages © 2026

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