PHPackages                             madaritech/wp-oop-nonces - 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. madaritech/wp-oop-nonces

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

madaritech/wp-oop-nonces
========================

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

v1.0.2(8y ago)3492MITPHPPHP &gt;=5.6

Since Nov 22Pushed 8y ago1 watchersCompare

[ Source](https://github.com/madaritech/wp-oop-nonces)[ Packagist](https://packagist.org/packages/madaritech/wp-oop-nonces)[ Docs](https://github.com/madaritech/wp-oop-nonces)[ RSS](/packages/madaritech-wp-oop-nonces/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (1)Versions (4)Used By (0)

wp-oop-nonces
=============

[](#wp-oop-nonces)

Package that serves the WordPress Nonces functionality (`wp_nonce_*()`) in an object orientated way.

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

[](#requirements)

- PHP 5.6+
- Composer
- WordPress 4.8.3+

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

[](#installation)

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

```
$ composer require madaritech/wp-oop-nonces
```

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

[](#run-the-tests)

To run tests, executes commands below:

```
$ cd vendor/madaritech/wp-oop-nonces
$ 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( 'http://www.madaritech.com' );
```

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

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity60

Established project with proven stability

 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

Every ~0 days

Total

3

Last Release

3089d ago

PHP version history (2 changes)v1.0.0PHP 5.6.\*

v1.0.1PHP &gt;=5.6

### Community

Maintainers

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

---

Top Contributors

[![madaritech](https://avatars.githubusercontent.com/u/28767004?v=4)](https://github.com/madaritech "madaritech (42 commits)")

---

Tags

wordpressOOPNonces

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/madaritech-wp-oop-nonces/health.svg)

```
[![Health](https://phpackages.com/badges/madaritech-wp-oop-nonces/health.svg)](https://phpackages.com/packages/madaritech-wp-oop-nonces)
```

###  Alternatives

[aristath/kirki

Extending the WordPress customizer

1.3k73.0k4](/packages/aristath-kirki)[afragen/git-updater

A plugin to automatically update GitHub, Bitbucket, GitLab, or Gitea hosted plugins, themes, and language packs.

3.3k1.6k](/packages/afragen-git-updater)

PHPackages © 2026

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