Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/tutor-pro/addons/auth/classes/Settings.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
/**
3
+
* Manage Settings.
4
+
*
5
+
* @package TutorPro\Auth
6
+
* @author Themeum <support@themeum.com>
7
+
* @link https://themeum.com
8
+
* @since 2.1.9
9
+
*/
10
+
11
+
namespace TutorPro\Auth;
12
+
13
+
/**
14
+
* Settings Class.
15
+
*
16
+
* @since 2.1.9
17
+
*/
18
+
class Settings {
19
+
20
+
const ENABLE_2FA = 'enable_2fa';
21
+
const METHOD_2FA = 'method_2fa';
22
+
const LOCATION_2FA = 'location_2fa';
23
+
24
+
const METHOD_HONEYPOT = 'honeypot';
25
+
const METHOD_RECAPTCHA_V2 = 'recaptcha_v2';
26
+
const METHOD_RECAPTCHA_V3 = 'recaptcha_v3';
27
+
28
+
const ENABLE_SPAM_PROTECTION = 'enable_spam_protection';
29
+
const SPAM_PROTECTION_LOCATION = 'spam_protection_location';
30
+
const SPAM_PROTECTION_METHOD = 'spam_protection_method';
31
+
32
+
const RECAPTCHA_V2_SITE_KEY = 'recaptcha_v2_site_key';
33
+
const RECAPTCHA_V2_SECRET_KEY = 'recaptcha_v2_secret_key';
34
+
35
+
const RECAPTCHA_V3_SITE_KEY = 'recaptcha_v3_site_key';
36
+
const RECAPTCHA_V3_SECRET_KEY = 'recaptcha_v3_secret_key';
37
+
38
+
/**
39
+
* Register hooks.
40
+
*
41
+
* @since 2.1.9
42
+
*
43
+
* @return void
44
+
*/
45
+
public function __construct() {
46
+
add_filter( 'tutor/options/extend/attr', array( $this, 'add_auth_settings_option' ) );
47
+
}
48
+
49
+
/**
50
+
* Add settings.
51
+
*
52
+
* @since 2.1.9
53
+
*
54
+
* @param array $attr existing settings attributes.
55
+
*
56
+
* @return array
57
+
*/
58
+
public function add_auth_settings_option( $attr ) {
59
+
60
+
$methods_2fa = array(
61
+
'email' => __( 'E-mail', 'tutor-pro' ),
62
+
);
63
+
64
+
$locations_2fa = array(
65
+
'tutor_login' => __( 'Tutor Login', 'tutor-pro' ),
66
+
'wp_login' => __( 'WP Login', 'tutor-pro' ),
67
+
'both' => __( 'Tutor & WP Login', 'tutor-pro' ),
68
+
);
69
+
70
+
$spam_protection_methods = array(
71
+
'honeypot' => __( 'HoneyPot', 'tutor-pro' ),
72
+
'recaptcha_v2' => __( 'Google reCAPTCHA V2', 'tutor-pro' ),
73
+
'recaptcha_v3' => __( 'Google reCAPTCHA V3', 'tutor-pro' ),
74
+
);
75
+
76
+
$spam_protection_locations = array(
77
+
'tutor_login' => __( 'Tutor Login', 'tutor-pro' ),
78
+
'tutor_registration' => __( 'Tutor Registration', 'tutor-pro' ),
79
+
'wp_login' => __( 'WP Login', 'tutor-pro' ),
80
+
'wp_registration' => __( 'WP Registration', 'tutor-pro' ),
81
+
);
82
+
83
+
/**
84
+
* 2FA section under auth settings tab
85
+
*/
86
+
$section_2fa = array(
87
+
'label' => __( 'Two-Factor Authentication', 'tutor-pro' ),
88
+
'slug' => '2fa',
89
+
'block_type' => 'uniform',
90
+
'fields' => array(
91
+
array(
92
+
'key' => self::ENABLE_2FA,
93
+
'type' => 'toggle_switch',
94
+
'label' => __( 'Enable 2FA', 'tutor-pro' ),
95
+
'label_title' => '',
96
+
'default' => 'off',
97
+
'desc' => '',
98
+
'toggle_fields' => 'method_2fa,location_2fa',
99
+
),
100
+
array(
101
+
'key' => self::METHOD_2FA,
102
+
'type' => 'select',
103
+
'label' => __( 'Method', 'tutor-pro' ),
104
+
'default' => 'email',
105
+
'options' => $methods_2fa,
106
+
'desc' => __( 'Choose method for 2FA', 'tutor-pro' ),
107
+
),
108
+
array(
109
+
'key' => self::LOCATION_2FA,
110
+
'type' => 'select',
111
+
'label' => __( 'Location', 'tutor-pro' ),
112
+
'default' => 'tutor_login',
113
+
'options' => $locations_2fa,
114
+
'desc' => __( 'Choose location for 2FA', 'tutor-pro' ),
115
+
),
116
+
),
117
+
);
118
+
119
+
/**
120
+
* Spam protection section under auth settings tab
121
+
*/
122
+
$section_spam_protection = array(
123
+
'label' => __( 'Fraud Protection', 'tutor-pro' ),
124
+
'slug' => 'spam_protection',
125
+
'block_type' => 'uniform',
126
+
'fields' => array(
127
+
array(
128
+
'key' => self::ENABLE_SPAM_PROTECTION,
129
+
'type' => 'toggle_switch',
130
+
'label' => __( 'Enable Fraud Protection', 'tutor-pro' ),
131
+
'label_title' => '',
132
+
'default' => 'off',
133
+
'desc' => '',
134
+
'toggle_fields' => 'spam_protection_method,spam_protection_location,recaptcha_v2_site_key,recaptcha_v2_secret_key,recaptcha_v3_site_key,recaptcha_v3_secret_key',
135
+
),
136
+
array(
137
+
'key' => 'spam_protection_method',
138
+
'type' => 'select',
139
+
'label' => __( 'Method', 'tutor-pro' ),
140
+
'default' => 'honeypot',
141
+
'options' => $spam_protection_methods,
142
+
'desc' => __( 'Choose method for Fraud Protection', 'tutor-pro' ),
143
+
),
144
+
array(
145
+
'key' => self::RECAPTCHA_V2_SITE_KEY,
146
+
'type' => 'text',
147
+
'label' => __( 'v2 Site Key', 'tutor-pro' ),
148
+
'default' => '',
149
+
'desc' => __( 'Enter reCAPTCHA v2 Site Key', 'tutor-pro' ),
150
+
),
151
+
array(
152
+
'key' => self::RECAPTCHA_V2_SECRET_KEY,
153
+
'type' => 'text',
154
+
'label' => __( 'v2 Secret Key', 'tutor-pro' ),
155
+
'default' => '',
156
+
'desc' => __( 'Enter reCAPTCHA v2 Secret Key', 'tutor-pro' ),
157
+
),
158
+
array(
159
+
'key' => self::RECAPTCHA_V3_SITE_KEY,
160
+
'type' => 'text',
161
+
'label' => __( 'v3 Site Key', 'tutor-pro' ),
162
+
'default' => '',
163
+
'desc' => __( 'Enter reCAPTCHA v3 Site Key', 'tutor-pro' ),
164
+
),
165
+
array(
166
+
'key' => self::RECAPTCHA_V3_SECRET_KEY,
167
+
'type' => 'text',
168
+
'label' => __( 'v3 Secret Key', 'tutor-pro' ),
169
+
'default' => '',
170
+
'desc' => __( 'Enter reCAPTCHA v3 Secret Key', 'tutor-pro' ),
171
+
),
172
+
array(
173
+
'key' => 'spam_protection_location',
174
+
'type' => 'checkbox_horizontal',
175
+
'label' => __( 'Location', 'tutor-pro' ),
176
+
'desc' => __( 'Choose location for Fraud Protection', 'tutor-pro' ),
177
+
'default' => array( 'tutor_login', 'tutor_registration' ),
178
+
'options' => $spam_protection_locations,
179
+
),
180
+
),
181
+
);
182
+
183
+
$auth_tab = array(
184
+
'authentication' => array(
185
+
'label' => __( 'Authentication', 'tutor-pro' ),
186
+
'slug' => 'authentication',
187
+
'desc' => __( 'Authentication Settings', 'tutor-pro' ),
188
+
'template' => 'basic',
189
+
'icon' => 'tutor-icon-privacy',
190
+
'blocks' => array(
191
+
$section_2fa,
192
+
$section_spam_protection,
193
+
),
194
+
),
195
+
);
196
+
197
+
$auth_tab = apply_filters( 'tutor_pro_settings_auth_tab', $auth_tab );
198
+
199
+
return $attr + $auth_tab;
200
+
}
201
+
202
+
/**
203
+
* Check 2FA is enabled
204
+
*
205
+
* @since 2.1.9
206
+
*
207
+
* @return boolean
208
+
*/
209
+
public static function is_2fa_enabled() {
210
+
return tutils()->get_option( self::ENABLE_2FA, false );
211
+
}
212
+
213
+
/**
214
+
* Get active 2FA method
215
+
*
216
+
* @since 2.1.9
217
+
*
218
+
* @return string
219
+
*/
220
+
public static function get_2fa_method() {
221
+
return tutils()->get_option( self::METHOD_2FA, 'email' );
222
+
}
223
+
224
+
/**
225
+
* Get active 2FA location like login, registration etc
226
+
*
227
+
* @since 2.1.9
228
+
*
229
+
* @return string
230
+
*/
231
+
public static function get_2fa_location() {
232
+
return tutils()->get_option( self::LOCATION_2FA, 'both' );
233
+
}
234
+
235
+
/**
236
+
* Check spam protection enabled.
237
+
*
238
+
* @since 2.1.9
239
+
*
240
+
* @return boolean
241
+
*/
242
+
public static function is_spam_protection_enabled() {
243
+
return tutils()->get_option( self::ENABLE_SPAM_PROTECTION, false );
244
+
}
245
+
246
+
/**
247
+
* Get spam protection method
248
+
*
249
+
* @since 2.1.9
250
+
*
251
+
* @return string
252
+
*/
253
+
public static function get_spam_protection_method() {
254
+
return tutils()->get_option( self::SPAM_PROTECTION_METHOD, self::METHOD_HONEYPOT );
255
+
}
256
+
257
+
/**
258
+
* Get spam protection location.
259
+
*
260
+
* @since 2.1.9
261
+
*
262
+
* @return array
263
+
*/
264
+
public static function get_spam_protection_location() {
265
+
return tutils()->get_option( self::SPAM_PROTECTION_LOCATION, array() );
266
+
}
267
+
}
268
+