Wallogit.com
2017 © Pedro Peláez
Implementation of the whole featured WordPress Nonces in an object oriented way. Included in the root directory is a unit test case.
A compose package which serves the functionality of working with WordPress Nonces in object oriented environment, (*1)
Table of contents: * Requirements * Installation * Usage, (*2)
You can install this class both on command-line or by pasting it into the root of your plugin directory., (*3)
Using Composer, add Custom Nonce Class to your plugin's dependencies., (*4)
composer require okuley/wordpress-nonce:dev-master
Setup the minimum required thigs:, (*5)
<?php require_once __DIR__ . '/../vendor/autoload.php'; // Autoload files using Composer autoload use Nonces\WpNonce; // Instantiate an object of the class $nonce = new WpNonce();
Adding a nonce to a URL:, (*6)
$url="/../wp-admin/post.php?post=48"; $complete_url = $nonce->wp_nonce_url( $url, 'edit-post_'.$post->ID );
Adding a nonce to a form:, (*7)
$nonce->get_wp_nonce_field( 'delete-post_'.$post_id );
creating a nonce:, (*8)
$newnonce = $nonce->wp_create_nonce( 'action_'.$post->id );
Verifying a nonce:, (*9)
$nonce->wp_verify_nonce_field( 'delete-post_'.$post_id );
Verifying a nonce passed in an AJAX request:, (*10)
$nonce->wp_check_ajax_referer( 'post-comment' );
Verifying a nonce passed in some other context:, (*11)
$nonce->wp_check_admin_referer( $_REQUEST['my_nonce'], 'edit-post_'.$post->ID );