2017 © Pedro Peláez
 

library wp-nonce-function

Object oriented functionality for WP Nonce

image

creativform/wp-nonce-function

Object oriented functionality for WP Nonce

  • Wednesday, March 8, 2017
  • by CreativForm
  • Repository
  • 1 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

WP Nonce Function

WP Nonce Function if object oriented (OOP) way to handle with WordPress wp_nonce_*() functions., (*1)

Table of contents: * Requirements * Installation * Usage, (*2)

Requirements

  • PHP >= 5.6.4
  • WordPress >= 4.6

Installation

You can install this class both on command-line or by pasting it into the root of your plugin directory., (*3)

via Command-line

Using Composer, add Custom Nonce Class to your plugin's dependencies., (*4)

composer require creativform/wp_nonce_function:dev-master

Other way

  1. Download the latest zip of this repo.
  2. Unzip the master.zip file.
  3. Copy and paste it into the root of your plugin directory.
  4. Continue with your project.

Usage

Setup the minimum required thigs:, (*5)

<?php 
// Autoload files using Composer autoload
require_once __DIR__ . '/../vendor/autoload.php';

// use class
use Nonce\WP_Nonce;


// Instantiate the class
$nonce = new WP_Nonce();

Options and Global Settup

Basic global setup for all object is nonce_name and nonce_action. You can define it once and don't use in other rendering for this session., (*6)

$nonce->option([
    'nonce_name'    => '_wpnonce',
    'nonce_action'  => 'edit-post_'.$post->ID,
]);

Also you have session time expire if you need it:, (*7)

$nonce->option( 'nonce_life',(4 * HOUR_IN_SECONDS) );

Like you see, you can pass array of settings or use single setup like above., (*8)

Examples

Adding a nonce to a URL:, (*9)

$url="/../wp-admin/post.php?post=48";
$complete_url = $nonce->url( $url );

Adding a nonce to a form:, (*10)

$nonce->field();

creating a nonce:, (*11)

$newnonce = $nonce->create();

NOTE: $nonce->create(); passing values inside other objects and you don't need to use string to pass values but optional function return value., (*12)

Verifying a nonce:, (*13)

$nonce->wp_verify();

Verifying a nonce passed in an AJAX request:, (*14)

$nonce->ajax_verify( 'post-comment' );

Verifying a nonce passed in admin area:, (*15)

$nonce->admin_verify( $_REQUEST['my_nonce'] );

Destructing and finish, (*16)

When you finish, just close this session and destruct all setups, (*17)

$nonce->clean();

The Versions

08/03 2017

dev-master

9999999-dev

Object oriented functionality for WP Nonce

  Sources   Download

GNU Library General Public License

The Requires

  • php >=5.6.4

 

by Ivijan-Stefan Stipic