WpNonce is a static wrapper class for Wordpress wp_nonce* functions.
composer require alexlg89/wpnonce
Or just add
"require alexlg89/wpnonce": "0.0.1"
to your compsoer.json file and run a compposer update.
$url = 'http://mysite.com/custommers';
$action = 'add-customer';
$name = '_myNonce';
$nonceUrl = WpNonce::url($url, $action, $name);Or just use the default name by skipping the last parameter.
$nonceUrl = WpNonce::url($url, $action);$action = 'add-customer';
WpNonce::field($action);You also can set the referer as second parameter
$referer = 'http://mysite.com/dashboard';
WpNonce::field($action, $referer);The third parameter alows you to just get the nonce field and skip the referer field, if set to false.
WpNonce::field($action, $referer, false);You can let the field function return the html as string, if you set the fourth parameter to false.
$html = WpNonce::field($action, $referer, true, false);$action = 'add-customer';
$nonce = WpNonce::create($action);$action = 'add-customer';
$name = '_myNonce';
$retval = WpNonce::checkAdminReferer($action, $name);Or just use the default name by skipping the last parameter.
$retval = WpNonce::checkAdminReferer($action);$action = 'add-customer';
$queryArg = '_myNonce';
$retval = WpNonce::check_ajax_referer($action, $queryArg);If the third parameter is set to false, the script won't die, if the nonce is invalid
$retval = WpNonce::check_ajax_referer($action, $queryArg, false);$nonce = 'an2bf72h';
$action = 'add-customer';
$retval = WpNonce::verify($nonce, $action);const DEFAULT_NONCE = '_wpnonce';