Element
2 days ago
Element.php
2 days ago
Nonce.php
2 days ago
NonceFactory.php
2 days ago
PreviewNonce.php
2 days ago
Nonce.php
52 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\Form; |
| 6 | |
| 7 | use AC\Request; |
| 8 | |
| 9 | class Nonce |
| 10 | { |
| 11 | private string $action; |
| 12 | |
| 13 | private string $name; |
| 14 | |
| 15 | public function __construct(string $action, string $name) |
| 16 | { |
| 17 | $this->action = $action; |
| 18 | $this->name = $name; |
| 19 | } |
| 20 | |
| 21 | public function get_action(): string |
| 22 | { |
| 23 | return $this->action; |
| 24 | } |
| 25 | |
| 26 | public function get_name(): string |
| 27 | { |
| 28 | return $this->name; |
| 29 | } |
| 30 | |
| 31 | public function create(): string |
| 32 | { |
| 33 | return wp_create_nonce($this->action); |
| 34 | } |
| 35 | |
| 36 | public function create_field(): string |
| 37 | { |
| 38 | return wp_nonce_field($this->action, $this->name, true, false); |
| 39 | } |
| 40 | |
| 41 | public function verify_nonce(string $nonce): bool |
| 42 | { |
| 43 | return (bool)wp_verify_nonce($nonce, $this->action); |
| 44 | } |
| 45 | |
| 46 | public function verify(Request $request): bool |
| 47 | { |
| 48 | return $this->verify_nonce((string)$request->get($this->name)); |
| 49 | } |
| 50 | |
| 51 | } |
| 52 |