https://github.com/patelutkarsh/wp-nonce-wrapper
Simplified usage of WordPress nonce
https://github.com/patelutkarsh/wp-nonce-wrapper
Last synced: about 2 months ago
JSON representation
Simplified usage of WordPress nonce
- Host: GitHub
- URL: https://github.com/patelutkarsh/wp-nonce-wrapper
- Owner: PatelUtkarsh
- License: gpl-3.0
- Created: 2016-01-20T18:20:36.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2021-10-13T14:26:13.000Z (over 3 years ago)
- Last Synced: 2025-02-16T17:56:20.162Z (5 months ago)
- Language: PHP
- Homepage:
- Size: 33.2 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: license.txt
Awesome Lists containing this project
README
# wp-nonce-wrapper
Use WordPress Nonce an object oriented way[](https://travis-ci.org/PatelUtkarsh/wp-nonce-wrapper)
## Installation:
```
"spock/wp-nonce-wrapper": "0.4"
```to your composer.json file and run a `composer update`
Or
```
composer require spock/wp-nonce-wrapper
```## Usage:
Get Nonce with expiry:
```php
use spock\helper\Nonce_Wrapper;
$nonce_obj = new Nonce_Wrapper('doing_some_form_job', 60*60); // 60 sec * 60 min = 1hr; Note: default is 1 day.
$nonce = $nonce_obj->create_nonce();
```Verify Nonce:
```php
$nonce = $_REQUEST['nonce'];
$nonce_obj = new Nonce_Wrapper('doing_some_form_job');
if ( $nonce_obj->verify_nonce( $nonce ) )
//Verified Source
else
// Unknown Source
```Create nonce input field:
```php
//This will echo input field
$nonce_obj->create_nonce_field();
```Create nonce url
```php
$url = $nonce_obj->create_nonce_url( 'http://w.org' );
```Check user is coming from another admin page.
```php
// This will check current url
if ($nonce_obj->check_admin_referral())
//doing it right
else
//doing it wrong
```
## Changelog### 0.4 ###
* Remove php magic method usage
* Refactor code
* Improved documentation### 0.3 ###
* Nonce expire control added
* Added missing nonce function### 0.2 ###
* Nonce field support
* Nonce url support
* Check user is coming from admin referral### 0.1 ###
* Initial basic functionality