pinkcrab / wp-nonce
Simple class based WP Nonce solution
Installs: 1 732
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 1
Requires
- php: >=7.1.0
Requires (Dev)
- dealerdirect/phpcodesniffer-composer-installer: *
- object-calisthenics/phpcs-calisthenics-rules: *
- php-stubs/wordpress-stubs: ^5.6.0
- phpstan/phpstan: ^0.12.6
- phpunit/phpunit: ^7.0
- pinkcrab/phpunit-helpers: dev-master
- roots/wordpress: ^5.5
- symfony/var-dumper: 4.*
- szepeviktor/phpstan-wordpress: ^0.7.2
- wp-coding-standards/wpcs: *
- wp-phpunit/wp-phpunit: ^5.0
This package is auto-updated.
Last update: 2024-11-11 19:47:22 UTC
README
Simple class based WP Nonce solution
For more details please visit our docs. https://app.gitbook.com/@glynn-quelch/s/pinkcrab/
Version
Release 0.1.0
Why?
Allows for use of Nonces in an oop mannor, while allowing serialisation/deserialsation of the object.
Setup
$ composer require pinkcrab/wp-nonce
$nonce = new Nonce('my_none_key'); // To get the current nonce token $nonce->token(); // To validate $nonce->validate($_POST['nonce']); // true/false // To add to url $url = $nonce->as_url('http://www.url.com', 'my_nonce'); // http://www.url.com?my_nonce={nonce_value} // Validate url. $nonce->admin_referer('my_nonce'); // true/false if set in url.
Methods
Create Instance
// Create with a custom key $custom_nonce = new Nonce('custom_key');
Once your nonce has been created, it can be serialised and/or passed around your codebase.
as_url( string $url, string $arg='_wpnonce' ): string
$nonce = new Nonce('url_key'); $custom_key_in_url = $nonce->as_url('http://test.com', 'url_nonce'); // http://test.com?url_nonce={nonce_token} $default_key_in_url = $nonce->as_url('http://test.com'); // http://test.com?_wpnonce={nonce_token}
NOTICE! This doesnt make use of the refer value found in admin nonces.
token(): string
$nonce = new Nonce('url_key'); // To get the current nonce value. print $nonce->token(); // 31b31db189 $nonce_token = nonce->token(); // 31b31db189
nonce_field($name = '_wpnonce'): string
$nonce = new Nonce('as_input'); // Create a nonce field, with a custom id/name for input print $nonce->nonce_field('my_nonce'); // <input type="hidden" id="my_nonce" name="my_nonce" value="{nonce_token}"> // Create a nonce field, with a custom id/name for input print $nonce->nonce_field(); // <input type="hidden" id="_wpnonce_" name="_wpnonce_" value="{nonce_token}">
The nonce field is not automcatically printed
validate($name = '_wpnonce'): string
$nonce = new Nonce('as_input'); // Create a nonce field, with a custom id/name for input print $nonce->nonce_field('my_nonce'); // <input type="hidden" id="my_nonce" name="my_nonce" value="{nonce_token}"> // Create a nonce field, with a custom id/name for input print $nonce->nonce_field(); // <input type="hidden" id="_wpnonce_" name="_wpnonce_" value="{nonce_token}">
The nonce field is not automcatically printed
Dependencies
- --NONE--
License
MIT License
http://www.opensource.org/licenses/mit-license.html
Change Log
0.1.0 - Created from part of PC Framework 0.1.0