PHPackages                             unprefix/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. [Security](/categories/security)
4. /
5. unprefix/nonce

ActiveLibrary[Security](/categories/security)

unprefix/nonce
==============

A OOP wrapper for WordPress Nonce

16PHPCI failing

Since Nov 5Pushed 8y ago1 watchersCompare

[ Source](https://github.com/widoz/wordpress-nonce)[ Packagist](https://packagist.org/packages/unprefix/nonce)[ RSS](/packages/unprefix-nonce/feed)WikiDiscussions dev Synced 2mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

[![Build Status](https://camo.githubusercontent.com/6be0c1a5487b3de61fa8a7ced23b035718cf0905eaf8ddfa68b6f5a58a54b53a/68747470733a2f2f7472617669732d63692e6f72672f7769646f7a2f756e7072656669782d6e6f6e63652e7376673f6272616e63683d646576)](https://travis-ci.org/widoz/unprefix-nonce)[![codecov](https://camo.githubusercontent.com/628d21d7bf96133b7f0348e80254ce1a1ac78aa25103e846cfb1118a46ed7a88/68747470733a2f2f636f6465636f762e696f2f67682f7769646f7a2f756e7072656669782d6e6f6e63652f6272616e63682f6465762f67726170682f62616467652e737667)](https://codecov.io/gh/widoz/unprefix-nonce)

Unprefix Nonce
==============

[](#unprefix-nonce)

A WordPress package that wrap the nonce logic in a OOP way.

Requirements
============

[](#requirements)

- PHP 5.6+
- WordPress 4.8+
- [Slugify ^3.0](https://github.com/cocur/slugify)
- [Unprefix Template Loader ^3.0](https://github.com/widoz/template-loader)

Installation
============

[](#installation)

Use [composer](https://getcomposer.org/)

`composer require unprefix/nonce`

License
=======

[](#license)

The package is open source and released under GPL-2 license. See LICENSE for more info.

Issues
======

[](#issues)

You can submit issues via [github issues](https://github.com/widoz/unprefix-nonce/issues).

Documentation
=============

[](#documentation)

Create a basic Nonce
--------------------

[](#create-a-basic-nonce)

```
use Unprefix\Nonce\Nonce;

// This create a new nonce instance.
$nonce = new Nonce('action_name');

// To retrieve the nonce just do this.
$nonce->nonce();

// To retrieve the nonce action.
$nonce->action();
```

### Create a basic Nonce with helper

[](#create-a-basic-nonce-with-helper)

```
use Unprefix\Nonce\Nonce;

// This will generate the nonce and return the nonce string, all at once.
$nonce = Nonce::create('nonce_action');
```

Create a URL Nonce
------------------

[](#create-a-url-nonce)

The constructor for `NonceUrl` take three parameters, a `Nonce` instance, a nonce **name** and an **url** in which add the nonce.

```
use Unprefix\Nonce\NonceUrl;

$nonceUrl = new NonceUrl(
    new Nonce('nonce_action'),
    'nonce_name',
    'http://www.mycustomurl.com'
);

// Retrieve the url.
$nonceUrl->url();

// To retrieve the name.
$nonceUrl->name();
```

### Create a nonce url with helper

[](#create-a-nonce-url-with-helper)

You don't need to pass an `Nonce` instance when using the helper function, just pass the action name as first parameter.

```
use Unprefix\Nonce\NonceUrl;

// Retrieve the nonce url string at once.
$nonceUrl = NonceUrl::create('action_name', 'nonce_name', 'http://www.mycustomurl.com');
```

Create a nonce Field
--------------------

[](#create-a-nonce-field)

Like `NonceUrl` to create a `NonceField` you must pass a `Nonce` instance along with the **name** and the **referrer** parameter.

The referrer parameter is optional, you can ignore it if you don't want to include the referrer input field.

```
use Unprefix\Nonce\NonceField;

$nonceField = new NonceField(
    new Nonce('nonce_action'),
    'nonce_name',
    true
);

// Show the nonce field.
$nonceField->tmpl(
    $nonceField->data()
);
```

The `NonceField` class implements Unprefix\\TemplateInterface from [unprefix/unprefix-templateloader](https://github.com/widoz/template-loader) to print the markup of the field.

The file is searched within the `views` directory two level up of the `src/` directory.

It is possible to filter the template path by hooking into `tmploader_template_file_path` filter as you can see in [Loader.php](https://github.com/widoz/template-loader/blob/master/src/Loader.php#L256)

Also, like other classes you can use an helper function to print the field at once.

```
use Unprefix\Nonce\NonceField;

NonceField::field('nonce_action', 'nonce_name', true);
```

Verify Nonce
------------

[](#verify-nonce)

To verify a nonce it is possible to use the `NonceVerification` class.

The class provide a single method with which is possible to verify nonces, admin referrer and ajax referrer.

```
use Unprefix\Nonce\NonceValidation;

// Create the instance
$nonceVerify = new NonceVerification(
    new Nonce('nonce_action'),
    'name_action',
    'POST', // But can be GET, REQUEST
    false
);

$nonceVerify->verify();
```

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/6d39b8d5cede59a2123551e756824be76d75405fab12f4e553be05328e9b1341?d=identicon)[guido](/maintainers/guido)

---

Top Contributors

[![widoz](https://avatars.githubusercontent.com/u/1917784?v=4)](https://github.com/widoz "widoz (41 commits)")

---

Tags

composernoncepsr-4unit-testingunprefixwordpress

### Embed Badge

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

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

###  Alternatives

[defuse/php-encryption

Secure PHP Encryption Library

3.9k162.4M214](/packages/defuse-php-encryption)[roave/security-advisories

Prevents installation of composer packages with known security vulnerabilities: no API, simply require it

2.9k97.3M6.4k](/packages/roave-security-advisories)[mews/purifier

Laravel 5/6/7/8/9/10 HtmlPurifier Package

2.0k16.7M113](/packages/mews-purifier)[robrichards/xmlseclibs

A PHP library for XML Security

41278.1M118](/packages/robrichards-xmlseclibs)[bjeavons/zxcvbn-php

Realistic password strength estimation PHP library based on Zxcvbn JS

86917.5M63](/packages/bjeavons-zxcvbn-php)[enlightn/security-checker

A PHP dependency vulnerabilities scanner based on the Security Advisories Database.

33732.2M110](/packages/enlightn-security-checker)

PHPackages © 2026

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