Demonstration of using WordPress nonces with object oriented approach.
- PHP 5.6
- WordPress 4.0.0
The code refers to the wordPress workflow for nonce URL creation and verification. For more info see Codex.
Note: You can place "src" folder in the worpdress plugins directlory and it start working as a plugin.
To add a nonce to a URL, WordPress uses wp_nonce_url()
specifying the bare url and a string representing the action. Optionally is possible to specify a string for the name parameter, otherwise it defaults to '_wpnonce'.
Similarly, to generate a url with a nonce query parameter use the WP_Nonce_Class
class with the proper action value and optionally with the proper name parameter, otherwise it defaults to '_wp_nonce'.
$url_generate = new WP_Nonce_Class();
So, use the GetNonceURL()
method with the proper url to generate the url with the nonce.
$url = $url_generate->GetNonceURL( 'http://pph.me/neilbannet' );