2017 © Pedro Peláez
 

composer-wordpress-package wpnonce

Wrapper Class for Wordpress wp_nonce* functions.

image

alexlg89/wpnonce

Wrapper Class for Wordpress wp_nonce* functions.

  • Friday, March 31, 2017
  • by Alexlg89
  • Repository
  • 1 Watchers
  • 0 Stars
  • 11 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

WpNonce

WpNonce is a static wrapper class for Wordpress wp_nonce* functions., (*1)

Install

composer require alexlg89/wpnonce

Or just add, (*2)

"require alexlg89/wpnonce": "0.0.1"

to your compsoer.json file and run a compposer update., (*3)

Usage:

Create an URL with a nonce parameter

$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., (*4)

$nonceUrl = WpNonce::url($url, $action);

Create a nonce field with a specific action

$action = 'add-customer';
WpNonce::field($action);

You also can set the referer as second parameter, (*5)

$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., (*6)

WpNonce::field($action, $referer, false);

You can let the field function return the html as string, if you set the fourth parameter to false., (*7)

$html = WpNonce::field($action, $referer, true, false);

Create a nonce with a specific action

$action = 'add-customer';
$nonce = WpNonce::create($action);

Check an URL for a vaild nonce

$action = 'add-customer';
$name = '_myNonce';
$retval = WpNonce::checkAdminReferer($action, $name);

Or just use the default name by skipping the last parameter., (*8)

$retval = WpNonce::checkAdminReferer($action);

Check an AJAX URL for a vaild nonce

$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, (*9)

$retval = WpNonce::check_ajax_referer($action, $queryArg, false);

Verify a nonce with a specific action

$nonce = 'an2bf72h';
$action = 'add-customer';
$retval = WpNonce::verify($nonce, $action);

Default nonce

const DEFAULT_NONCE = '_wpnonce';

The Versions

31/03 2017

dev-master

9999999-dev

Wrapper Class for Wordpress wp_nonce* functions.

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

by Alexander Elert

31/03 2017

0.0.1

0.0.1.0

Wrapper Class for Wordpress wp_nonce* functions.

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

by Alexander Elert