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

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

bornforlamp/wp-object-nonce
===========================

Classes that serves the WordPress Nonces functionality in an object oriented way.

010PHP

Since Feb 20Pushed 2y ago1 watchersCompare

[ Source](https://github.com/bornforlamp/wp-object-nonce)[ Packagist](https://packagist.org/packages/bornforlamp/wp-object-nonce)[ RSS](/packages/bornforlamp-wp-object-nonce/feed)WikiDiscussions main Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

wp-object-nonce
===============

[](#wp-object-nonce)

Composer package, that serves the functionality working with WordPress Nonces (`wp_nonce_*()`) in an OOP.

Requirements
------------

[](#requirements)

- PHP 5.6+
- Composer
- WordPress 4.8.3+

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

[](#installation)

Install with [Composer](https://getcomposer.org):

```
$ composer require bornforlamp/wp-object-nonce
```

Run the tests
-------------

[](#run-the-tests)

To run tests, executes commands below:

```
$ cd vendor/bornforlamp/wp-object-nonce
$ composer install
$ vendor/bin/phpunit
```

Usage
-----

[](#usage)

The code refers to the wordPress workflow for nonce creation and verification. For more info see [Codex](https://codex.wordpress.org/WordPress_Nonces).

### Nonce Generation

[](#nonce-generation)

In WordPress the nonce generation is achieved with the `wp_create_nonce()` function specifying a string representing the action.

Similarly, to proceed with nonce generation use the `Nonce_Generator` class with the proper *action*:

```
$generator = new Nonce_Generator( 'action_parameter' );
```

Then, to generate the nonce use the `generate_nonce()` method:

```
$nonce = $generator->generate_nonce();
```

### Nonce Url Generation

[](#nonce-url-generation)

To add a nonce to a URL, WordPress uses `wp_nonce_url()` specifying the bare *url* and a string representing the *action*. Optionally is possible to specify a string for the *name* parameter, otherwise it defaults to *'\_wpnonce'*.

Similarly, to generate a url with a nonce query parameter use the `Nonce_Url_Generator` class with the proper *action* value and optionally with the proper *name* parameter, otherwise it defaults to *'\_wp\_nonce'*.

```
$url_generator = new Nonce_Url_Generator( 'action_parameter' );
```

So, use the `generate_nonce_url()` method with the proper *url* to generate the url with the nonce.

```
$url = $url_generator->generate_nonce_url( 'https://harshadmane.in' );
```

The same class can also generate a nonce directly:

```
$nonce = $url_generator->generate_nonce();
```

### Nonce Field Generation

[](#nonce-field-generation)

To add a nonce to a form, WordPress uses `wp_nonce_field()` specifying a string representing the *action*. By default `wp_nonce_field()` generates two hidden fields, one whose value is the nonce and one whose value is the current url (the referrer), and it echoes the result.

Similarly, to generate form fields with nonce use the `Nonce_Field_Generator` class with the proper *action* value:

```
$field_generator = new Nonce_Field_Generator( 'action_parameter' );
```

Optionally, the constructor accepts other parameters that affects the nonce field generation result (`generate_nonce_field()` method):

1. *name*: the name of the nonce field. Defaults to *'\_wpnonce'*.
2. *referer*: boolean value to add an hidden field with refer url value. Set it to *false* to not add the field. Defaults to *true*.
3. *echo*: boolean value to print the field/s. Set it to *false* to not print the fields. Defaults to *true*.

So, use the `generate_nonce_field()` method to generate the field/s with the nonce.

```
$field_generated = $field_generator->generate_nonce_field()
```

The same class can also generate a nonce directly:

```
$nonce = $field_generator->generate_nonce();
```

### Nonce Validation

[](#nonce-validation)

To verify a nonce WordPress uses `wp_verify_nonce()` specifying the *nonce* and the string representing the *action*.

Similarly, validating funtionality is provided through the `Nonce_Validator` class; the constructor accept an *action* parameter (the same used to generate the nonce we want to validate) to verify the nonce:

```
$validator = new Nonce_Validator( 'action_parameter' );
```

#### Nonce Straight Validation

[](#nonce-straight-validation)

To validate a nonce use the `validate_nonce()` method with the *nonce* to verify as parameter:

```
$is_valid = $validator->validate_nonce($nonce);
```

If the validation is successful the method returns *true*; *false* otherwise.

#### Nonce Request Validation

[](#nonce-request-validation)

To validate a nonce received in a page through request (GET or POST) use the `validate_request()` method:

```
$is_valid = $validator->validate_request();
```

If the validation is successful the method returns *true*; *false* otherwise.

###  Health Score

13

—

LowBetter than 1% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity19

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/2e74314758f9ec2a288cc9626376aca659bba8e2a96b607789193dc0d39939cf?d=identicon)[bornforlamp](/maintainers/bornforlamp)

---

Top Contributors

[![bornforlamp](https://avatars.githubusercontent.com/u/79363411?v=4)](https://github.com/bornforlamp "bornforlamp (2 commits)")

### Embed Badge

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

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

PHPackages © 2026

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