2017 © Pedro Peláez
 

library wp-nonce

Object oriented implementation of Wordpress nonces

image

farsil/wp-nonce

Object oriented implementation of Wordpress nonces

  • Thursday, February 22, 2018
  • by farsil
  • Repository
  • 1 Watchers
  • 0 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

wp-nonce

wp-nonce is a replacement library for wordpress nonces written in PHP. It aims to provide an object oriented interface that can be used in lieu of the wordpress wp_nonce_* functions., (*1)

Installation

Add the following entry to the required list in your composer.json:, (*2)

"farsil/wp-nonce": "v1.0.*"

Or, alternatively, run:, (*3)

$ composer require farsil/wp-nonce

Usage

Nonce generation is performed through the Nonce_Generator class, and nonce validation is performed through the Nonce_Validator class. The method names are reminiscent of the corresponding methods of the Wordpress core functions, and behave similarly, with a few differences. See the documentation for additional details., (*4)

Example

<?php
// We don't need to load themes
define( 'WP_USE_THEMES', false );

// This line assumes your Wordpress installation is in your PHP include path,
// change accordingly if it is not the case.
require_once 'wp-load.php';

// Let composer autoload wp-nonce classes.
require_once 'vendor/autoload.php';

// Generate a new nonce. Default lifetime is 1 day.
$gen = new Wordpress\Nonce_Generator( 'test-nonce' );
$token = $gen->generate();

// In order to properly validate the generated token, the constructor parameters
// need to match those used in Nonce_Generator.
$val = new Wordpress\Nonce_Validator( 'test-nonce' );
echo $val->verify( $token );

Expected Output:, (*5)

1

Tests

wp-nonce includes a comprehensive PHPUnit test suite. Since wp-nonce includes a phpunit.xml.dist file, all you need to do is to navigate to the project root, and run:, (*6)

$ php /path/to/phpunit.phar --include-path=/path/to/wordpress

The Versions

22/02 2018

dev-master

9999999-dev

Object oriented implementation of Wordpress nonces

  Sources   Download

MIT

The Requires

  • php >=7.0

 

by Marco Buzzanca

wordpress oop nonce

22/02 2018

v1.0.0

1.0.0.0

Object oriented implementation of Wordpress nonces

  Sources   Download

MIT

The Requires

  • php >=7.0

 

by Marco Buzzanca

wordpress oop nonce