GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - vvasiloi/wp-nonce: OOP wrapper for Wordpress Nonce

BranchesTags
Open more actions menu

Latest commit

 

History

2 Commits
2 Commits

Folders and files

NameName
Last commit message
Last commit date
src
src
 
 
tests
tests
 
 
.env.dist
.env.dist
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
composer.json
composer.json
 
 
docker-compose.yml
docker-compose.yml
 
 
phpunit.xml.dist
phpunit.xml.dist
 
 

Repository files navigation

WP Nonce

This is an OOP wrapper for WordPress Nonce.

NonceInterface

Base interface for all nonces that has the following methods:

  • getAction() get nonce action
  • getValue() get nonce value for that action
  • validate() validate nonce against a given context

ContextInterface

Base interface for all nonce contexts. It has the following methods:

  • has() check if context has the given nonce action
  • get() returns nonce value for given action

Bundled implementations

This package ships with 2 implementations of the above interfaces: Nonce and RequestContext

Nonce

A simple implementation of NonceInterface that accepts 2 parameters: nonce action name and it's lifetime in seconds (defaults to 1h).

    $nonce = new Nonce('action');
    $isValid = $nonce->validate(); // if no context is provided, it will use RequestContext (see below)

getValue() and validate() functions adds nonce_life filter to check nonce lifetime.

RequestContext

This class uses Symfony\Component\HttpFoundation\Request to retrieve nonce value from request (query string and request body parameters).

A similar implementation could also work with headers:

use Symfony\Component\HttpFoundation\Request;

class RequestHeadersContext implements ContextInterface
{
    /**
     * @var Request
     */
    private $request;

    /**
     * @param Request|null $request
     */
    public function __construct(Request $request = null)
    {
        $this->request = null !== $request ? $request : Request::createFromGlobals();
    }

    /**
     * @param string $action
     *
     * @return bool
     */
    public function has($action)
    {
        return $this->request->headers->has($action);
    }

    /**
     * @param string $action
     *
     * @return string
     */
    public function get($action)
    {
        return $this->request->headers->get($action, '');
    }
}

Installation

composer require vvasiloi/wp-nonce

Requirements

  • PHP 5.5+
  • Composer

License

MIT

About

OOP wrapper for Wordpress Nonce

Resources

Readme
MIT license
Activity

Stars

0 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.