PHPackages                             mahdy/wpnonce - 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. mahdy/wpnonce

ActiveLibrary

mahdy/wpnonce
=============

running wordpress nonce in opject orianted manner

1.0.0(8y ago)018MITPHP

Since Nov 29Pushed 8y ago1 watchersCompare

[ Source](https://github.com/mahdy-nasr/WpNonce)[ Packagist](https://packagist.org/packages/mahdy/wpnonce)[ Docs](https://github.com/mahdy-nasr/WpNonce)[ RSS](/packages/mahdy-wpnonce/feed)WikiDiscussions master Synced 3d ago

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

WpNonce
=======

[](#wpnonce)

Wordpress nonce in an object-oriented manner

Usage
-----

[](#usage)

this package used instead of wp\_nonce\_\*() functions in WordPress. it built in an object-oriented way and also make the code more readable.

Environment
-----------

[](#environment)

it tested against WordPress v4.9.

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

[](#installation)

either via direct composer command :

```
composer require mahdy/wpnonce
```

or via editing composer.json file and then use composer update

```
{
    "require": {
        "mahdy/wpnonce" : "1.0.0"
    }
}
```

How to use
----------

[](#how-to-use)

the package used for generating and verifying the WordPress Nonce.

### Set the Action

[](#set-the-action)

1- via constructor

```
$nonce =  new \WpNonce\Nonce("Xaction");
```

2- via setter function

```
$nonce =  new \WpNonce\Nonce();
$nonce->setAction("Xaction");
```

### Set the name (Optional)

[](#set-the-name-optional)

It used for URL and form field. The default value is "\_wpnonce"

```
$nonce->setName("theNewName");
```

### Generate the Nonce string

[](#generate-the-nonce-string)

1- Exciplicitly

```
/*if you didn't set the action in constructor, you have to use setter before to use this function*/
$nonce_string = $nonce->generateNonce();
```

2- As string

```
/*use the object directly */
$str = "the following object will return as Nonce string ".$nonce;
```

### Generate the Nonce URL

[](#generate-the-nonce-url)

```
$url = "https://somewebsite.com/";
$nonce_url = $nonce->generateNonceUrl($url);
```

### Generate Nonce Field in form

[](#generate-nonce-field-in-form)

It take 2 optional parametars: generateNonceField($referer = true, $echo = true)

```
$nonce_HTML_input = $generateNonceField()
```

### Verifying Nonce string

[](#verifying-nonce-string)

it return 1 if the nonce generated in last 12h and 2 if it generated in last 24h

```
if (\WpNonce\NonceVerifier::verify($nonce, $action)) {...}
```

### Verify Nonce from submitted

[](#verify-nonce-from-submitted)

Verifying using checkAdminReferer($action, $input\_name = "\_wpnonce") function.

```
if (\WpNonce\NonceVerifier::checkAdminReferer($action)) {...}
```

### Verify Ajax requist

[](#verify-ajax-requist)

the function checkAjaxReferer($action, $arg\_name = false, $die = true) has 2 optional parametars.

```
if (\WpNonce\NonceVerifier::checkAjaxReferer($action)) {...}
```

Running the UnitTest
--------------------

[](#running-the-unittest)

1- you have first to install PHPUnit

2- open the package folder: vendor/mahdy/wpnonce change to this directory to run the phpunit

3- before run change the vendor/mahdy/wpnonce/bootstrap.php and change the WORDPRESS\_PATH to your WordPress installation directory.

4- in command line from package directory run

```
$ phpunit
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

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

Unknown

Total

1

Last Release

3088d ago

### Community

Maintainers

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

---

Top Contributors

[![mahdy-nasr](https://avatars.githubusercontent.com/u/17709323?v=4)](https://github.com/mahdy-nasr "mahdy-nasr (12 commits)")

### Embed Badge

![Health badge](/badges/mahdy-wpnonce/health.svg)

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

PHPackages © 2026

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