| @@ -1,0 +1,21 @@ | ||
| 1 | +<?php | |
| 2 | + | |
| 3 | +declare(strict_types=1); | |
| 4 | + | |
| 5 | +namespace Metricool\Traits; | |
| 6 | + | |
| 7 | +trait HasNonces | |
| 8 | +{ | |
| 9 | + /** | |
| 10 | + * Method for verifying the nonce | |
| 11 | + * @param mixed $nonce Preferably string, not type-casted to prevent errors | |
| 12 | + */ | |
| 13 | + protected function verifyNonce($nonce, string $action = 'metricool_nonce'): bool | |
| 14 | + { | |
| 15 | + if (is_string($nonce) === false) { | |
| 16 | + return false; | |
| 17 | + } | |
| 18 | + | |
| 19 | + return (bool) wp_verify_nonce(sanitize_text_field(wp_unslash($nonce)), $action); | |
| 20 | + } | |
| 21 | +} | |