2017 © Pedro Peláez
 

library wpnonce

running wordpress nonce in opject orianted manner

image

mahdy/wpnonce

running wordpress nonce in opject orianted manner

  • Thursday, November 30, 2017
  • by mahdynasr
  • Repository
  • 1 Watchers
  • 0 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

WpNonce

Wordpress nonce in an object-oriented manner, (*1)

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

Environment

it tested against WordPress v4.9., (*3)

Installation

either via direct composer command :, (*4)

composer require mahdy/wpnonce

or via editing composer.json file and then use composer update, (*5)

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

How to use

the package used for generating and verifying the WordPress Nonce., (*6)

Set the Action

1- via constructor, (*7)

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

2- via setter function, (*8)

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

Set the name (Optional)

It used for URL and form field. The default value is "_wpnonce", (*9)

$nonce->setName("theNewName");

Generate the Nonce string

1- Exciplicitly, (*10)

/*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, (*11)

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

Generate the Nonce URL

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

Generate Nonce Field in form

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

$nonce_HTML_input = $generateNonceField()

Verifying Nonce string

it return 1 if the nonce generated in last 12h and 2 if it generated in last 24h, (*13)

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

Verify Nonce from submitted

Verifying using checkAdminReferer($action, $input_name = "_wpnonce") function., (*14)

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

Verify Ajax requist

the function checkAjaxReferer($action, $arg_name = false, $die = true) has 2 optional parametars., (*15)

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

Running the UnitTest

1- you have first to install PHPUnit, (*16)

2- open the package folder: vendor/mahdy/wpnonce change to this directory to run the phpunit, (*17)

3- before run change the vendor/mahdy/wpnonce/bootstrap.php and change the WORDPRESS_PATH to your WordPress installation directory., (*18)

4- in command line from package directory run, (*19)

$ phpunit

The Versions

30/11 2017

dev-master

9999999-dev https://github.com/mahdy-nasr/WpNonce

running wordpress nonce in opject orianted manner

  Sources   Download

MIT

by Mahdy Nasr

29/11 2017

1.0.0

1.0.0.0 https://github.com/mahdy-nasr/WpNonce

running wordpress nonce in opject orianted manner

  Sources   Download

MIT

by Mahdy Nasr