Nuonce
Nuonce tries to simplify the handling with Nonces in PHP OOP., (*1)
Install
composer require Darkflameninja/Nuonce
Or just add, (*2)
"require Darkflameninja/Nuonce": "1.0"
to your composer.json file and run a composer update., (*3)
Usage:
Define your action & nonce
$yourobj = new Nuonce($action, $nonce); // if your input == ''(in both cases),it's predefined as action = nonce_action & nonce = _wpnonce
Create an URL
$url = $yourobj->url($url, $name);
Create a nonce field
$yourobj->field($name);
You also can set the referer as first parameter, (*4)
$referer = 'http://mysite.com/something';
$yourobj->field($referer);
Skip the referer by setting it false., (*5)
$yourobj->field($referer, false);
Create a nonce
$nonce = $yourobj->create();
Check an URL for a valid nonce
$retval = $yourobj->AdminReferer($queryArg);
Check an AJAX URL for a valid nonce
$queryArg = '_myNonce';
$retval = $yourobj->AjaxReferer($queryArg);
If the third parameter is set to false, the script won't die, if the nonce is invalid, (*6)
$retval = $yourobj->AjaxReferer($queryArg, false);
Verify a nonce
$retval = $yourobj->verify();