Giter Club home page Giter Club logo

wp-nonce's Introduction

Build Status

WPNonce

WordPress Nonce In An Object Oriented Way.

Basic Usage

  1. Create a demo composer.json file in your plugin.
  2. Run composer install
  3. It will load plugin dependency in a vendor/ folder

demo composer.json

{
    "repositories": [
        {
            "type": "vcs",
            "url" : "https://github.com/mehulkaklotar/wp-nonce"
        }
    ],
    "require": {
        "mehulkaklotar/wp-nonce" : "1.0.*"
    }
}

Here I have created a demo plugin to use this system. WP Nonce Client

The Settings:

WP Nonce need an action to find the current action which is secured by a nonce. The first parameter of the configuration defines this name. Usually forms or URLs passes the nonce. The second parameter is for request key. In this case, we would expect the nonce to be in $_REQUEST['request_name'].

$setting = new NonceSetting( 
	'action', 
	'request_name' 
);

To Create a Nonce

To create a simple Nonce, use NonceCreate:

$nonce_create = new NonceCreate( $setting );
$nonce = $nonce_create->create();

To add a nonce to an URL, you can use

$nonce_create = new NonceCreateURL( $setting );
$url = $nonce_create->create_url( 'http://example.com/' );

Return URL will be: http://example.com/?request_name=$nonce

To add a form field:

$create = new NonceCreateField( $setting );
$field = $create->create_field();

Return field will be: <input type="hidden" name="request_name" value="$nonce">

Replicate wp_nonce_field() functionality by adding two parameters: (bool) $referer and (bool) $echo. Both are set to false by default.

Set $referer to true, field will be appended with the URL of the current page. Set $echo to true, it will echo the field, before create_url().

To Verify a Nonce

To verify a nonce, you can use NonceVerify:

$nonce_verify = new NonceVerify( $setting );
$is_valid = $nonce_verify->verify( $nonce );

wp-nonce's People

Contributors

mehulkaklotar avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.