|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* YIKES Inc. Easy Forms. |
|
4
|
|
|
* |
|
5
|
|
|
* @package YIKES\EasyForms |
|
6
|
|
|
* @author Freddie Mixell |
|
7
|
|
|
* @license GPL2 |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace YIKES\EasyForms\Form; |
|
11
|
|
|
|
|
12
|
|
|
use Closure; |
|
13
|
|
|
use YIKES\EasyForms\Assets\AssetsAware; |
|
14
|
|
|
use YIKES\EasyForms\Assets\AssetsAwareness; |
|
15
|
|
|
use YIKES\EasyForms\Service; |
|
16
|
|
|
use YIKES\EasyForms\View\FormEscapedView; |
|
17
|
|
|
use YIKES\EasyForms\View\TemplatedView; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Abstract Class BaseForm |
|
21
|
|
|
* |
|
22
|
|
|
* @since %VERSION% |
|
23
|
|
|
* @package YIKES\EasyForms |
|
24
|
|
|
*/ |
|
25
|
|
|
abstract class BaseForm implements Service, AssetsAware { |
|
26
|
|
|
|
|
27
|
|
|
use AssetsAwareness; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Register the current Registerable. |
|
31
|
|
|
* |
|
32
|
|
|
* @since %VERSION% |
|
33
|
|
|
*/ |
|
34
|
|
|
public function register() { |
|
35
|
|
|
$this->register_assets(); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Verify the nonce and return the result. |
|
40
|
|
|
* |
|
41
|
|
|
* @since %VERSION% |
|
42
|
|
|
* @return bool |
|
43
|
|
|
*/ |
|
44
|
|
|
protected function verify_nonce() { |
|
45
|
|
|
$nonce_name = $this->get_nonce_name(); |
|
46
|
|
|
|
|
47
|
|
|
if ( ! array_key_exists( $nonce_name, $_POST ) ) { |
|
48
|
|
|
return false; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
$nonce = $_POST[ $nonce_name ]; |
|
52
|
|
|
|
|
53
|
|
|
$result = wp_verify_nonce( |
|
54
|
|
|
$nonce, |
|
55
|
|
|
$this->get_nonce_action() |
|
56
|
|
|
); |
|
57
|
|
|
|
|
58
|
|
|
return false !== $result; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Get the name of the nonce. |
|
63
|
|
|
* |
|
64
|
|
|
* @since %VERSION% |
|
65
|
|
|
* @return string |
|
66
|
|
|
*/ |
|
67
|
|
|
protected function get_nonce_name() { |
|
68
|
|
|
return "{$this->get_id()}_nonce"; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Get the ID for the nonce. |
|
73
|
|
|
* |
|
74
|
|
|
* @since %VERSION% |
|
75
|
|
|
* @return string |
|
76
|
|
|
*/ |
|
77
|
|
|
abstract protected function get_id(); |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Get the action for the nonce. |
|
81
|
|
|
* |
|
82
|
|
|
* @since %VERSION% |
|
83
|
|
|
* @return string |
|
84
|
|
|
*/ |
|
85
|
|
|
protected function get_nonce_action() { |
|
86
|
|
|
return "{$this->get_id()}_action"; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Make sure the data is saved to the DB. |
|
91
|
|
|
* |
|
92
|
|
|
* @since %VERSION% |
|
93
|
|
|
* |
|
94
|
|
|
* @param int $post_id The post ID to save. |
|
95
|
|
|
*/ |
|
96
|
|
|
abstract protected function persist( $post_id ); |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Get the view URI to use when rendering the form. |
|
100
|
|
|
* |
|
101
|
|
|
* @since %VERSION% |
|
102
|
|
|
* @return string The View URI. |
|
103
|
|
|
*/ |
|
104
|
|
|
abstract protected function get_view_uri(); |
|
105
|
|
|
} |
|
106
|
|
|
|