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

ActiveWordpress-plugin[Utility &amp; Helpers](/categories/utility)

wberredo/nonce
==============

Use wordpress nonce functions in a object oriented environment.

2.0.0(9y ago)4454MITPHP

Since Feb 25Pushed 9y agoCompare

[ Source](https://github.com/WBerredo/nonce)[ Packagist](https://packagist.org/packages/wberredo/nonce)[ Docs](https://github.com/wberredo/nonce)[ RSS](/packages/wberredo-nonce/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (2)DependenciesVersions (5)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/fae46ffac04f6aa6c220527ed12253aa760ed7e911493239ec2f30bc2c478b4f/68747470733a2f2f706f7365722e707567782e6f72672f776265727265646f2f6e6f6e63652f762f737461626c65)](https://packagist.org/packages/wberredo/nonce)[![Latest Unstable Version](https://camo.githubusercontent.com/5d9a11f04682adacdba59ee7012442208db8b450227076ca86e57c2f8c11b2c2/68747470733a2f2f706f7365722e707567782e6f72672f776265727265646f2f6e6f6e63652f762f756e737461626c65)](https://packagist.org/packages/wberredo/nonce)[![License](https://camo.githubusercontent.com/9c1524bda1b35316aca8d60494ba28e19e71eabc45db15eba05afeddf0eac835/68747470733a2f2f706f7365722e707567782e6f72672f776265727265646f2f6e6f6e63652f6c6963656e7365)](https://packagist.org/packages/wberredo/nonce)

nonce
=====

[](#nonce)

Use wordpress nonce functions in a object oriented environment.

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

[](#installation)

Add this package as requirement at your composer.json file and then run 'composer update'

```
"wberredo/nonce": "1.0.*"
```

Or directly run

```
composer require wberredo/nonce
```

Setup
-----

[](#setup)

If you want to change some configs before you start to generate nonces, you will use *Nonce\_Config* class.

```
// set lifetime for 4 hours
Nonce_Config::set_nonce_lifetime( 4 * HOUR_IN_SECONDS );

// set message showed when showAys is called
Nonce_Config::set_error_message( "Are you sure" );
```

Usage
-----

[](#usage)

To create a nonce you have to use the *Nonce\_Generator* class and to verify a nonce already created you will need the *Nonce\_Verifier*class.

### Nonce\_Generator

[](#nonce_generator)

To generate a nonce

```
$nonce_gen = new Nonce_Generator( "default-action" );
$nonce = $nonce_gen->generate_nonce();
```

To generate a URL nonce

```
// you can also set parameters with set functions
$nonce_gen = new Nonce_Generator();
$complete_url = $nonce_gen
                    ->set_url( "http://github.com/WBerredo" )
                    ->set_action( "default_action" )
                    ->generate_nonce_url();
```

To retrieve a nonce field.

```
$nonce_gen = new Nonce_Generator();
$nonceField = $nonce_gen
                    ->set_action( "default_action" )
                    ->generate_nonce_field( "nonce", "referer", "do_not_echo" );

// to print the nonce field you have to set the last param as true
$nonce_gen
    ->generate_nonce_field( "nonce", "referer", "echo" );
```

To Display 'Are you sure you want to do this?' message (or the new message set with Nonce\_Config#setErrorMessage) to confirm the action being taken.

```
Nonce_Generator::show_ays( 'action' );
```

### Nonce\_Verifier

[](#nonce_verifier)

To verify a nonce

```
if ( Nonce_Verifier::verify( $nonce, $defaultAction ) ) {
// if is valid
} else {
// if is not valid
}
```

To verify a URL nonce

```
if ( Nonce_Verifier::verify_url( $complete_url, $defaultAction ) ) {
// if is valid
} else {
// if is not valid
}
```

To tests either if the current request carries a valid nonce, or if the current request was referred from an administration screen

```
if ( Nonce_Verifier::verify_admin_referer( $defaultAction ) ) {
// if is valid
} else {
// if is not valid
}
```

To verify the AJAX request, to prevent any processing of requests which are passed in by third-party sites or systems.

```
if ( Nonce_Verifier::verify_ajax_referer( $defaultAction ) ) {
// if is valid
} else {
// if is not valid
}
```

Contributing
------------

[](#contributing)

1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request :D

Tests
-----

[](#tests)

1. **Install PHPUnit.** WordPress uses PHPUnit, the standard for unit testing PHP projects. Installation instructions can be found in [the PHPUnit manual](https://phpunit.de/manual/current/en/installation.html)or on the [PHPUnit Github repository](https://github.com/sebastianbergmann/phpunit#readme).
2. **Check out the test repository.** The WordPress tests live in the core development repository, at :

```
svn co https://develop.svn.wordpress.org/trunk/ wordpress-develop
cd wordpress-develop
```

3. **Create an empty MySQL database.** The test suite will delete all data from all tables for whichever MySQL database it is configured. Use a separate database.
4. **Set up a config file.** Copy wp-tests-config-sample.php to wp-tests-config.php, and enter your database credentials. Use a separate database.
5. **Change the path of Wordpress project** in the bootstrap.php file of the plugin

```
/**
* The path to the WordPress tests checkout.
*/
define( 'WP_TESTS_DIR', '/home/berredo/Documents/repository/wordpress/wordpress-develop/tests/phpunit/' );
```

6. **Go to plugin's folder**

```
cd vendor/wberredo/nonce
```

7. **Run phpunit** to test

```
phpunit
```

Thanks to
---------

[](#thanks-to)

- [Wordpress Nonces Documentation](https://codex.wordpress.org/WordPress_Nonces)
- [Wordpress Automated Testing Documentation](https://make.wordpress.org/core/handbook/testing/automated-testing/)

License
-------

[](#license)

[MIT](http://opensource.org/licenses/MIT)

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity66

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 ~33 days

Total

2

Last Release

3332d ago

Major Versions

1.0.0 → 2.0.02017-03-31

### Community

Maintainers

![](https://www.gravatar.com/avatar/08ce7f417bb764bf62c28081f5dcb2227723077080d87b760f202980b658bd63?d=identicon)[WBerredo](/maintainers/WBerredo)

---

Top Contributors

[![WBerredo](https://avatars.githubusercontent.com/u/5039531?v=4)](https://github.com/WBerredo "WBerredo (30 commits)")

---

Tags

noncewordpresswordpress-librarywordpress-pluginwordpresswpOOPnonce

### Embed Badge

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

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

###  Alternatives

[roots/bedrock

WordPress boilerplate with Composer, easier configuration, and an improved folder structure

6.5k441.8k2](/packages/roots-bedrock)[ffraenz/private-composer-installer

A composer install helper for private packages

2331.7M5](/packages/ffraenz-private-composer-installer)[tareq1988/wordpress-settings-api-class

WordPress settings API Abstraction Class

46611.1k3](/packages/tareq1988-wordpress-settings-api-class)[proteusthemes/wp-customizer-utilities

Advanced WordPress customizer controls and settings for better user experience.

329.4k1](/packages/proteusthemes-wp-customizer-utilities)[typisttech/wp-option-store

Extending WordPress Options API, read options from places other than database, the OOP way

1517.3k2](/packages/typisttech-wp-option-store)[typisttech/wp-admin-notices

A simplified OOP implementation of the WordPress admin notices

141.2k](/packages/typisttech-wp-admin-notices)

PHPackages © 2026

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