1
|
|
|
<?php |
2
|
|
|
namespace EventEspresso\admin_pages\general_settings; |
3
|
|
|
|
4
|
|
|
use EE_Admin_Two_Column_Layout; |
5
|
|
|
use EE_Error; |
6
|
|
|
use EE_Form_Section_HTML; |
7
|
|
|
use EE_Form_Section_Proper; |
8
|
|
|
use EE_Text_Input; |
9
|
|
|
use EE_Yes_No_Input; |
10
|
|
|
use EEH_HTML; |
11
|
|
|
use EEH_Template; |
12
|
|
|
use EventEspresso\core\exceptions\InvalidDataTypeException; |
13
|
|
|
use EventEspresso\core\exceptions\InvalidFormSubmissionException; |
14
|
|
|
use EventEspresso\core\libraries\form_sections\form_handlers\FormHandler; |
15
|
|
|
use InvalidArgumentException; |
16
|
|
|
use LogicException; |
17
|
|
|
|
18
|
|
|
defined('ABSPATH') || exit; |
19
|
|
|
|
20
|
|
|
|
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Class AdminOptionsSettings |
24
|
|
|
* class for handling admin options settings |
25
|
|
|
* |
26
|
|
|
* @package Event Espresso |
27
|
|
|
* @author Brent Christensen |
28
|
|
|
* @since $VID:$ |
29
|
|
|
*/ |
30
|
|
|
class AdminOptionsSettings extends FormHandler |
31
|
|
|
{ |
32
|
|
|
|
33
|
|
|
protected $template_args = array(); |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Form constructor. |
37
|
|
|
* |
38
|
|
|
* @param \EE_Registry $registry |
39
|
|
|
*/ |
40
|
|
|
public function __construct(\EE_Registry $registry) { |
41
|
|
|
parent::__construct( |
42
|
|
|
esc_html__('Admin Options', 'event_espresso'), |
43
|
|
|
esc_html__('Admin Options', 'event_espresso'), |
44
|
|
|
'admin_option_settings', |
45
|
|
|
'', |
46
|
|
|
FormHandler::DO_NOT_SETUP_FORM, |
47
|
|
|
$registry |
48
|
|
|
); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param array $template_args |
55
|
|
|
*/ |
56
|
|
|
public function setTemplateArgs(array $template_args) |
57
|
|
|
{ |
58
|
|
|
$this->template_args = $template_args; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* creates and returns the actual form |
65
|
|
|
* |
66
|
|
|
* @return EE_Form_Section_Proper |
67
|
|
|
* @throws \EE_Error |
68
|
|
|
*/ |
69
|
|
|
public function generate() |
70
|
|
|
{ |
71
|
|
|
$form = new \EE_Form_Section_Proper( |
72
|
|
|
array( |
73
|
|
|
'name' => 'admin_option_settings', |
74
|
|
|
'html_id' => 'admin_option_settings', |
75
|
|
|
'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
76
|
|
|
'subsections' => array( |
77
|
|
|
'help_tour_activation_hdr' => new EE_Form_Section_HTML( |
78
|
|
|
EEH_HTML::h2( |
79
|
|
|
esc_html__('Help Tour Global Activation', 'event_espresso') |
80
|
|
|
. ' ' |
81
|
|
|
. EEH_HTML::span( |
82
|
|
|
EEH_Template::get_help_tab_link('help_tour_activation_info'), |
83
|
|
|
'help_tour_activation' |
84
|
|
|
), |
85
|
|
|
'', 'ee-admin-settings-hdr' |
86
|
|
|
) |
87
|
|
|
), |
88
|
|
|
'help_tour_activation' => new EE_Yes_No_Input( |
89
|
|
|
array( |
90
|
|
|
'html_label_text' => esc_html__('Activate Global Help Tours?', 'event_espresso'), |
91
|
|
|
'html_help_text' => esc_html__( |
92
|
|
|
'This toggles whether the Event Espresso help tours are active globally or not.', |
93
|
|
|
'event_espresso' |
94
|
|
|
), |
95
|
|
|
'default' => isset($this->registry->CFG->admin->help_tour_activation) |
96
|
|
|
? filter_var($this->registry->CFG->admin->help_tour_activation, FILTER_VALIDATE_BOOLEAN) |
97
|
|
|
: true, |
98
|
|
|
'required' => false |
99
|
|
|
) |
100
|
|
|
), |
101
|
|
|
'compatibility_hdr' => new EE_Form_Section_HTML( |
102
|
|
|
EEH_HTML::h2( |
103
|
|
|
esc_html__('Compatibility Settings', 'event_espresso'), |
104
|
|
|
'', 'ee-admin-settings-hdr' |
105
|
|
|
) |
106
|
|
|
), |
107
|
|
|
'encode_session_data' => new EE_Yes_No_Input( |
108
|
|
|
array( |
109
|
|
|
'html_label_text' => esc_html__('Encode Session Data?', 'event_espresso'), |
110
|
|
|
'html_help_text' => sprintf( |
111
|
|
|
esc_html__( |
112
|
|
|
'Some servers and database configurations can cause problems when saving the Event Espresso session data. Setting this option to "Yes" adds an extra layer of encoding to session data to prevent serialization errors, but can be incompatible with some server configurations.%1$sIf you receive "500 internal server" type errors during registration, try turning this option on.%1$sIf you get fatal PHP errors regarding missing base64 functions, then turn this option off.', |
113
|
|
|
'event_espresso' |
114
|
|
|
), |
115
|
|
|
'<br>' |
116
|
|
|
), |
117
|
|
|
'default' => $this->registry->CFG->admin->encode_session_data(), |
118
|
|
|
'required' => false |
119
|
|
|
) |
120
|
|
|
), |
121
|
|
|
) |
122
|
|
|
) |
123
|
|
|
); |
124
|
|
|
if ( |
125
|
|
|
$this->registry->CAP->current_user_can( |
126
|
|
|
'manage_options', |
127
|
|
|
'display_admin_settings_options_promote_and_affiliate' |
128
|
|
|
) |
129
|
|
|
) { |
130
|
|
|
$form->add_subsections( |
131
|
|
|
array( |
132
|
|
|
'promote_ee_hdr' => new EE_Form_Section_HTML( |
133
|
|
|
EEH_HTML::h2( |
134
|
|
|
esc_html__('Promote Event Espresso', 'event_espresso') |
135
|
|
|
. ' ' |
136
|
|
|
. EEH_HTML::span( |
137
|
|
|
EEH_Template::get_help_tab_link('affiliate_info'), |
138
|
|
|
'affiliate_info' |
139
|
|
|
), |
140
|
|
|
'', 'ee-admin-settings-hdr' |
141
|
|
|
) |
142
|
|
|
), |
143
|
|
|
'show_reg_footer' => new EE_Yes_No_Input( |
144
|
|
|
array( |
145
|
|
|
'html_label_text' => esc_html__( |
146
|
|
|
'Link to Event Espresso in your Registration Page?', |
147
|
|
|
'event_espresso' |
148
|
|
|
) |
149
|
|
|
. EEH_Template::get_help_tab_link('email_validation_info'), |
150
|
|
|
'html_help_text' => esc_html__( |
151
|
|
|
'adds an unobtrusive link to Event Espresso\'s website in the footer of your registration form. Get an affiliate link (see below) and make money if people click the link and purchase Event Espresso.', |
152
|
|
|
'event_espresso' |
153
|
|
|
), |
154
|
|
|
'default' => isset($this->registry->CFG->admin->show_reg_footer) |
155
|
|
|
? filter_var($this->registry->CFG->admin->show_reg_footer, FILTER_VALIDATE_BOOLEAN) |
156
|
|
|
: true, |
157
|
|
|
'required' => false |
158
|
|
|
) |
159
|
|
|
), |
160
|
|
|
'affiliate_id' => new EE_Text_Input( |
161
|
|
|
array( |
162
|
|
|
'html_label_text' => sprintf( |
163
|
|
|
esc_html__('Event Espresso %sAffiliate%s ID', 'event_espresso'), |
164
|
|
|
'<a href="http://eventespresso.com/affiliates/" target="_blank">', |
165
|
|
|
'</a>' |
166
|
|
|
), |
167
|
|
|
'html_help_text' => esc_html__( |
168
|
|
|
'Earn cash for promoting Event Espresso.', |
169
|
|
|
'event_espresso' |
170
|
|
|
), |
171
|
|
|
'html_class' => 'regular-text', |
172
|
|
|
'default' => isset($this->registry->CFG->admin->affiliate_id) |
173
|
|
|
? $this->registry->CFG->admin->get_pretty('affiliate_id') |
174
|
|
|
: '', |
175
|
|
|
'required' => false |
176
|
|
|
) |
177
|
|
|
), |
178
|
|
|
), |
179
|
|
|
'help_tour_activation_hdr' |
180
|
|
|
); |
181
|
|
|
} |
182
|
|
|
return $form; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
|
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* takes the generated form and displays it along with ony other non-form HTML that may be required |
189
|
|
|
* returns a string of HTML that can be directly echoed in a template |
190
|
|
|
* |
191
|
|
|
* @return string |
192
|
|
|
* @throws LogicException |
193
|
|
|
* @throws \EE_Error |
194
|
|
|
*/ |
195
|
|
|
public function display() |
196
|
|
|
{ |
197
|
|
|
add_filter( |
198
|
|
|
'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form', |
199
|
|
|
array($this, 'handleOldAdminOptionsSettingsAction') |
200
|
|
|
); |
201
|
|
|
return parent::display(); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
|
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @return string |
208
|
|
|
*/ |
209
|
|
|
public function handleOldAdminOptionsSettingsAction() |
210
|
|
|
{ |
211
|
|
|
ob_start(); |
212
|
|
|
do_action('AHEE__admin_option_settings__template__before', $this->template_args); |
213
|
|
|
return ob_get_clean(); |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
|
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* handles processing the form submission |
220
|
|
|
* returns true or false depending on whether the form was processed successfully or not |
221
|
|
|
* |
222
|
|
|
* @param array $form_data |
223
|
|
|
* @return bool |
224
|
|
|
* @throws InvalidFormSubmissionException |
225
|
|
|
* @throws EE_Error |
226
|
|
|
* @throws LogicException |
227
|
|
|
* @throws InvalidArgumentException |
228
|
|
|
* @throws InvalidDataTypeException |
229
|
|
|
*/ |
230
|
|
|
public function process($form_data = array()) |
231
|
|
|
{ |
232
|
|
|
// process form |
233
|
|
|
$valid_data = (array)parent::process($form_data); |
234
|
|
|
if (empty($valid_data)) { |
235
|
|
|
return false; |
|
|
|
|
236
|
|
|
} |
237
|
|
|
$this->registry->CFG->admin->show_reg_footer = isset( $form_data['show_reg_footer'] ) |
238
|
|
|
? absint( $form_data['show_reg_footer'] ) |
239
|
|
|
: $this->registry->CFG->admin->show_reg_footer; |
240
|
|
|
$this->registry->CFG->admin->affiliate_id = isset( $form_data['affiliate_id'] ) |
241
|
|
|
? sanitize_text_field( $form_data['affiliate_id'] ) |
242
|
|
|
: $this->registry->CFG->admin->affiliate_id; |
243
|
|
|
$this->registry->CFG->admin->help_tour_activation = isset( $form_data['help_tour_activation'] ) |
244
|
|
|
? absint( $form_data['help_tour_activation']) |
245
|
|
|
: $this->registry->CFG->admin->help_tour_activation; |
246
|
|
|
if (isset($form_data['encode_session_data'])) { |
247
|
|
|
$this->registry->CFG->admin->set_encode_session_data($form_data['encode_session_data']); |
248
|
|
|
} |
249
|
|
|
return false; |
|
|
|
|
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
} |
253
|
|
|
// End of file AdminOptionsSettings.php |
254
|
|
|
// Location: EventEspresso\admin_pages\general_settings/AdminOptionsSettings.php |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.