Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Created September 18, 2018 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommcfarlin/b1eac5df600177b7beb423477ccceee6 to your computer and use it in GitHub Desktop.
Save tommcfarlin/b1eac5df600177b7beb423477ccceee6 to your computer and use it in GitHub Desktop.
[WordPress] Secure WordPress Form Submission: An Object-Oriented Approach
<?php
protected function verifyRequest($nonce, $action);
<?php
protected function verifyRequest($nonce, $action)
{
return isset($_GET[$nonce]) &&
wp_verify_nonce(strip_tags(stripslashes($_GET[$nonce])), $action);
}
<?php
protected function verifyRequest($nonce, $action)
{
return
(
isset($_GET[$nonce]) &&
wp_verify_nonce(strip_tags(stripslashes($_GET[$nonce])), $action)
) ||
(
isset($_POST[$nonce]) &&
wp_verify_nonce(strip_tags(stripslashes($_POST[$nonce])), $action)
);
}
<?php
private function verifyPostRequest($nonce, $action)
{
return
isset($_POST[$nonce]) &&
wp_verify_nonce(strip_tags(stripslashes(filter_input(INPUT_POST, $nonce))), $action);
}
<?php
private function verifyGetRequest($nonce, $action)
{
return
isset($_GET[$nonce]) &&
wp_verify_nonce(strip_tags(stripslashes(filter_input(INPUT_GET, $nonce))), $action);
}
<?php
protected function verifyRequest($nonce, $action)
{
switch (strtolower($_SERVER['REQUEST_METHOD'])) {
case 'post':
return $this->verifyPostRequest($nonce, $action);
break;
case 'get':
return $this->verifyGetRequest($nonce, $action);
break;
default:
return false;
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment