PluginProbe ʕ •ᴥ•ʔ
WP 2FA – Two-factor authentication for WordPress / 2.8.0
WP 2FA – Two-factor authentication for WordPress v2.8.0
4.0.0 1.7.1 2.0.0 2.0.1 2.1.0 2.2.0 2.2.1 2.3.0 2.4.0 2.4.1 2.4.2 2.5.0 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.8.0 2.9.0 2.9.1 2.9.2 2.9.3 3.0.0 3.0.1 3.1.0 3.1.1 3.1.1.2 trunk 1.2.0 1.3.0 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.6.0 1.6.1 1.6.2 1.7.0
wp-2fa / includes / classes / Admin / Views / class-first-time-wizard-steps.php
wp-2fa / includes / classes / Admin / Views Last commit date
class-first-time-wizard-steps.php 1 year ago class-grace-period-notifications.php 1 year ago class-passord-reset-2fa.php 1 year ago class-re-login-2fa.php 1 year ago class-wizard-steps.php 1 year ago index.php 1 year ago
class-first-time-wizard-steps.php
609 lines
1 <?php
2 /**
3 * Settings page render class.
4 *
5 * @package wp2fa
6 * @subpackage views
7 * @since 1.7.0
8 * @copyright 2024 Melapress
9 * @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
10 * @link https://wordpress.org/plugins/wp-2fa/
11 */
12
13 namespace WP2FA\Admin\Views;
14
15 use WP2FA\WP2FA;
16 use WP2FA\Methods\Backup_Codes;
17 use WP2FA\Admin\Helpers\WP_Helper;
18 use WP2FA\Admin\Controllers\Settings;
19 use WP2FA\Methods\TOTP;
20
21 defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
22
23 if ( ! class_exists( '\WP2FA\Admin\Views\First_Time_Wizard_Steps' ) ) {
24 /**
25 * WP2FA First Wizard Settings view controller
26 *
27 * @since 1.7
28 */
29 class First_Time_Wizard_Steps {
30
31 /**
32 * Select method step
33 *
34 * @since 1.7.0
35 *
36 * @param boolean $setup_wizard - Boolean - is that first time wizard setup or settings page call.
37 *
38 * @return void
39 */
40 public static function select_method( $setup_wizard = false ) {
41
42 ob_start();
43 ?>
44 <h3><?php \esc_html_e( 'Which 2FA methods can your users use?', 'wp-2fa' ); ?></h3>
45 <p class="description">
46 <?php \esc_html_e( 'When you uncheck any of the below 2FA methods it won\'t be available for your users to use. You can always change this later on from the plugin\'s settings.', 'wp-2fa' ); ?>
47 </p>
48 <?php
49 $data_role = 'data-role="global"';
50 if ( ! $setup_wizard ) {
51 ?>
52 <table class="form-table">
53 <tbody>
54 <tr>
55 <th colspan="2"><?php \esc_html_e( 'Which of the below 2FA methods can users use?', 'wp-2fa' ); ?></th>
56 </tr>
57 <tr>
58 <th><label for="2fa-method"><?php \esc_html_e( 'Select the methods', 'wp-2fa' ); ?></label></th>
59 <td>
60 <?php } ?>
61 <fieldset id="2fa-method-select" class="wp-2fa-method-select">
62 <p class="method-title" style="padding-bottom: 20px;"><em><?php \esc_html_e( 'Primary 2FA methods:', 'wp-2fa' ); ?></em></p>
63 <?php
64 /**
65 * Fired right after the TOTP method HTML rendering.
66 *
67 * @param bool $wizard - Is that a wizard call or settings call.
68 * @param string $data_role - String with the JS data to add to form element.
69 * @param string $name - The name of the role.
70 *
71 * @since 2.0.0
72 */
73 \do_action( WP_2FA_PREFIX . 'methods_setup', $setup_wizard, $data_role, null );
74 ?>
75 <br />
76 <?php
77 if ( ! $setup_wizard ) {
78 $class = '';
79
80 if ( '' === trim( (string) Settings::get_role_or_default_setting( TOTP::POLICY_SETTINGS_NAME, null, null, true ) ) && '' === trim( (string) Settings::get_role_or_default_setting( 'enable_email', null, null, true ) ) && '' === trim( (string) Settings::get_role_or_default_setting( 'enable_oob_email', null, null, true ) ) ) {
81 $class = 'disabled';
82 }
83 ?>
84 <div class="method-title"><em><?php \esc_html_e( 'Secondary 2FA methods:', 'wp-2fa' ); ?></em></div>
85 <br>
86 <label for="backup-codes" class=" <?php echo $class; // phpcs:ignore ?>">
87 <input type="checkbox" class="<?php echo \esc_attr( $class ); ?>" id="backup-codes" name="wp_2fa_policy[backup_codes_enabled]"
88 <?php echo $data_role; // phpcs:ignore ?>
89 value="yes"
90 <?php checked( WP2FA::get_wp2fa_setting( Backup_Codes::get_settings_name() ), Backup_Codes::get_settings_default_value() ); ?>
91 >
92 <?php
93 \esc_html_e( 'Backup codes', 'wp-2fa' );
94 if ( $setup_wizard ) {
95 echo '<p class="description">Note: ';
96 } else {
97 echo ' - ';
98 }
99 \esc_html_e( 'Backup codes are a secondary method which you can use to log in to the website in case the primary 2FA method is unavailable. Therefore they can\'t be enabled and used as a primary method.', 'wp-2fa' );
100 if ( $setup_wizard ) {
101 echo '</p>';
102 }
103 ?>
104 </label>
105 <?php
106 /**
107 * Fires after the backup methods HTML rendering is finished.
108 *
109 * @param bool $wizard - Is that wizard ot standard setting.
110 * @param string $data_role - The JS data attribute for the form inputs.
111 * @param string $role - The name of the user role.
112 *
113 * @since 2.0.0
114 */
115 \do_action( WP_2FA_PREFIX . 'after_backup_methods_setup', $setup_wizard, $data_role, null );
116 }
117 ?>
118 </fieldset>
119 <?php
120 if ( ! $setup_wizard ) {
121 ?>
122 </td>
123 </tr>
124 </tbody>
125 </table>
126 <?php } ?>
127 <?php
128 $output = ob_get_clean();
129
130 /**
131 * At this point, none of the default providers is set / activated. This filter allows additional providers to change the behavior. Checking the input array for specific values (methods), and based on that we can raise error that none of the allowed methods has bees selected by the user, or dismiss the error otherwise.
132 *
133 * @param string $output - Parsed HTML with the methods.
134 * @param bool $setup_wizard - The type of the wizard (first time wizard / settings).
135 *
136 * @since 2.0.0
137 */
138 $output = apply_filters( WP_2FA_PREFIX . 'select_methods', $output, $setup_wizard );
139
140 echo $output; // phpcs:ignore
141 }
142
143 /**
144 * Builds the backup methods html
145 *
146 * @param boolean $setup_wizard - Is that call from the Wizard or not.
147 *
148 * @return void
149 *
150 * @since 2.4.1
151 */
152 public static function backup_method( $setup_wizard = false ) {
153
154 ob_start();
155 ?>
156 <h3><?php \esc_html_e( 'Which alternative 2FA methods can users use?', 'wp-2fa' ); ?></h3>
157 <p class="description">
158 <?php \esc_html_e( 'An alternative 2FA method allows users to configure another 2FA method that can be used as a backup should the primary 2FA method fail. This can happen if, for example, a user forgets their smartphone, the smartphone runs out of battery, or there are email deliverability problems.', 'wp-2fa' ); ?>
159 </p>
160 <p class="description">
161 <?php \esc_html_e( 'It is highly recommended to have an alternative 2FA method configured at all times. Below is a list of alternative 2FA methods available through this plugin:', 'wp-2fa' ); ?>
162 </p>
163
164 <br>
165
166 <fieldset>
167 <label for="backup-codes">
168 <input type="checkbox" id="backup-codes-global" name="wp_2fa_policy[backup_codes_enabled]" value="yes"
169 <?php checked( WP2FA::get_wp2fa_setting( Backup_Codes::get_settings_name() ), Backup_Codes::get_settings_default_value() ); ?>
170 >
171 <?php \esc_html_e( 'Backup codes', 'wp-2fa' ); ?>
172 </label>
173
174 <?php
175 echo '<p class="description">';
176 printf( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
177 '%1$1s <a href="https://melapress.com/support/kb/wp-2fa-what-are-2fa-backup-codes/?&utm_source=plugin&utm_medium=link&utm_campaign=wp2fa" target="_blank">%2$1s</a> <br><br>',
178 \esc_html__( 'Backup codes allow users to log in to WordPress should they find themselves unable to log in via the primary 2FA method. Backup codes are enabled by default and are generated during the 2FA configuration process. Each backup code can be used only once. Once the initial list is exhausted, more backup codes can be generated through the user’s WordPress profile page - ', 'wp-2fa' ),
179 \esc_html__( 'More information', 'wp-2fa' )
180 );
181 echo '</p>';
182 ?>
183
184 <?php
185 /* @free:start */
186 echo '<label>';
187 printf( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
188 '%1$1s <a href="https://melapress.com/wordpress-2fa/features/?&utm_source=plugin&utm_medium=link&utm_campaign=wp2fa" target="_blank">%2$1s</a> %3$1s',
189 \esc_html__( 'Upgrade to WP 2FA Premium for', 'wp-2fa' ),
190 \esc_html__( 'more alternative 2FA methods', 'wp-2fa' ),
191 \esc_html__( 'to give your users more options.', 'wp-2fa' )
192 );
193 echo '<label>';
194 /* @free:end */
195 ?>
196 </fieldset>
197 <?php
198 ?>
199 <?php
200 $output = ob_get_clean();
201 $output = apply_filters( WP_2FA_PREFIX . 'backup_methods', $output, $setup_wizard );
202
203 echo $output; // phpcs:ignore
204 }
205
206 /**
207 * Enforcement policy step
208 *
209 * @since 1.7.0
210 *
211 * @param boolean $setup_wizard - Boolean - is that first time wizard setup or settings page call.
212 *
213 * @return void
214 */
215 public static function enforcement_policy( $setup_wizard = false ) {
216 ?>
217 <h3 id="enforcement_settings"><?php \esc_html_e( 'Do you want to enforce 2FA for some, or all the users? ', 'wp-2fa' ); ?></h3>
218 <p class="description">
219 <?php \esc_html_e( 'When you enforce 2FA the users will be prompted to configure 2FA the next time they login. Users have a grace period for configuring 2FA. You can configure the grace period and also exclude user(s) or role(s) in this settings page. ', 'wp-2fa' ); ?> <a href="https://melapress.com/support/kb/wp-2fa-configure-2fa-policies-enforce/?&utm_source=plugin&utm_medium=link&utm_campaign=wp2fa" target="_blank" rel=noopener><?php \esc_html_e( 'Learn more.', 'wp-2fa' ); ?></a>
220 </p>
221 <?php
222 if ( ! $setup_wizard ) {
223 ?>
224 <table class="form-table js-enforcement-policy-section">
225 <tbody>
226 <tr>
227 <th><label for="enforcement-policy"><?php \esc_html_e( 'Enforce 2FA on', 'wp-2fa' ); ?></label></th>
228 <td>
229 <?php } ?>
230 <fieldset class="contains-hidden-inputs">
231 <label for="all-users" style="margin:.35em 0 .5em !important; display: block;">
232 <input type="radio" name="wp_2fa_policy[enforcement-policy]" id="all-users" value="all-users"
233 <?php checked( WP2FA::get_wp2fa_setting( 'enforcement-policy' ), 'all-users' ); ?>
234 >
235 <span><?php \esc_html_e( 'All users', 'wp-2fa' ); ?></span>
236 </label>
237
238 <?php if ( WP_Helper::is_multisite() ) : ?>
239 <label for="superadmins-only" style="margin:.35em 0 .5em !important; display: block;">
240 <input type="radio" name="wp_2fa_policy[enforcement-policy]" id="superadmins-only" value="superadmins-only"
241 <?php checked( WP2FA::get_wp2fa_setting( 'enforcement-policy' ), 'superadmins-only' ); ?> />
242 <span><?php \esc_html_e( 'Only super admins', 'wp-2fa' ); ?></span>
243 </label>
244 <label for="superadmins-siteadmins-only" style="margin:.35em 0 .5em !important; display: block;">
245 <input type="radio" name="wp_2fa_policy[enforcement-policy]" id="superadmins-siteadmins-only" value="superadmins-siteadmins-only"
246 <?php checked( WP2FA::get_wp2fa_setting( 'enforcement-policy' ), 'superadmins-siteadmins-only' ); ?> />
247 <span><?php \esc_html_e( 'Only super admins and site admins', 'wp-2fa' ); ?></span>
248 </label>
249 <?php endif; ?>
250
251 <label for="certain-roles-only" style="margin:.35em 0 .5em !important; display: block;">
252 <?php $checked = in_array( WP2FA::get_wp2fa_setting( 'enforcement-policy' ), array( 'certain-roles-only', 'certain-users-only' ), true ); ?>
253 <input type="radio" name="wp_2fa_policy[enforcement-policy]" id="certain-roles-only" value="certain-roles-only"
254 <?php ( $setup_wizard ) ? checked( WP2FA::get_wp2fa_setting( 'enforcement-policy' ), 'certain-roles-only' ) : checked( $checked ); ?>
255 data-unhide-when-checked=".certain-roles-only-inputs, .certain-users-only-inputs">
256 <span><?php \esc_html_e( 'Only for specific users and roles', 'wp-2fa' ); ?></span>
257 </label>
258 <fieldset class="hidden certain-users-only-inputs">
259 <div>
260 <p>
261 <label for="enforced_users-multi-select"><?php \esc_html_e( 'Users :', 'wp-2fa' ); ?></label> <select multiple="multiple" id="enforced_users-multi-select" name="wp_2fa_policy[enforced_users][]" style=" display:none;width:<?php echo ( $setup_wizard ) ? '100' : '50'; ?>%">
262 <?php
263 $enforced_users = (array) WP2FA::get_wp2fa_setting( 'enforced_users' );
264 foreach ( $enforced_users as $user ) {
265 ?>
266 <option selected="selected" value="<?php echo \esc_attr( $user ); ?>"><?php echo \esc_attr( $user ); ?></option>
267 <?php
268 }
269 ?>
270 </select>
271 </p>
272 </div>
273 </fieldset>
274 <fieldset class="hidden certain-roles-only-inputs">
275 <div>
276 <p style="margin-top: 0;">
277 <label for="enforced-roles-multi-select"><?php \esc_html_e( 'Roles :', 'wp-2fa' ); ?></label>
278 <select multiple="multiple" id="enforced-roles-multi-select" name="wp_2fa_policy[enforced_roles][]" style=" display:none;width:<?php echo ( $setup_wizard ) ? '100' : '50'; ?>%">
279 <?php
280 $all_roles = WP_Helper::get_roles_wp();
281 $enforced_roles = (array) WP2FA::get_wp2fa_setting( 'enforced_roles' );
282 foreach ( $all_roles as $role => $role_name ) {
283 $selected = '';
284 if ( in_array( $role, $enforced_roles, true ) ) {
285 $selected = 'selected="selected"';
286 }
287 ?>
288 <option <?php echo $selected; // phpcs:ignore ?> value="<?php echo \esc_attr( strtolower( $role ) ); ?>"><?php echo \esc_html( $role_name ); ?></option>
289 <?php
290 }
291 ?>
292 </select>
293 </p>
294 </div>
295 <?php if ( WP_Helper::is_multisite() ) { ?>
296 <p class="description">
297 <input type="checkbox" name="wp_2fa_policy[superadmins-role-add]" id="superadmins-role-add" value="yes" style="position: relative; top: -3px;"
298 <?php checked( WP2FA::get_wp2fa_setting( 'superadmins-role-add' ), 'yes' ); ?> />
299 <label for="superadmins-role-add"><?php \esc_html_e( 'Also enforce 2FA on network users with super admin privileges', 'wp-2fa' ); ?></label>
300 </p>
301 <?php } ?>
302 </fieldset>
303 <?php if ( WP_Helper::is_multisite() ) { ?>
304 <div>
305 <label for="enforce-on-multisite" style="margin:.35em 0 .5em !important; display: block;">
306 <input type="radio" name="wp_2fa_policy[enforcement-policy]" id="enforce-on-multisite" value="enforce-on-multisite"
307 <?php checked( WP2FA::get_wp2fa_setting( 'enforcement-policy' ), 'enforce-on-multisite' ); ?>
308 data-unhide-when-checked=".all-sites">
309 <span><?php \esc_html_e( 'These sub-sites', 'wp-2fa' ); ?></span>
310 </label>
311 <fieldset class="hidden all-sites">
312 <p>
313 <label for="enforced-sites-multi-select"><?php \esc_html_e( 'Sites :', 'wp-2fa' ); ?></label> <select multiple="multiple" id="enforced-sites-multi-select" name="wp_2fa_policy[included_sites][]" style="display:none; width:<?php echo ( $setup_wizard ) ? '100' : '50'; ?>%">
314 <?php
315 $selected_sites = (array) WP2FA::get_wp2fa_setting( 'included_sites' );
316 foreach ( WP_Helper::get_multi_sites() as $site ) {
317 $args = array(
318 'blog_id' => $site->blog_id,
319 );
320
321 $current_blog_details = get_blog_details( $args );
322 $selected = '';
323 if ( in_array( $site->blog_id, $selected_sites, true ) ) {
324 $selected = 'selected="selected"';
325 }
326 ?>
327 <option <?php echo $selected; // phpcs:ignore ?> value="<?php echo \esc_attr( $site->blog_id ); ?>"><?php echo \esc_html( $current_blog_details->blogname ); ?></option>
328 <?php
329 }
330 ?>
331 </select>
332 </p>
333 </fieldset>
334 </div>
335 <?php } ?>
336 <div>
337 <label for="do-not-enforce" style="margin:.35em 0 .5em !important; display: block;">
338 <input type="radio" name="wp_2fa_policy[enforcement-policy]" id="do-not-enforce" value="do-not-enforce"
339 <?php checked( WP2FA::get_wp2fa_setting( 'enforcement-policy' ), 'do-not-enforce' ); ?>
340 >
341 <span><?php \esc_html_e( 'Do not enforce on any users', 'wp-2fa' ); ?></span>
342 </label>
343 </div>
344 <br/>
345 </fieldset>
346 <?php
347 if ( ! $setup_wizard ) {
348 ?>
349 </td>
350 </tr>
351 </tbody>
352 </table>
353 <?php
354 }
355 }
356
357 /**
358 * Exclude users and groups
359 *
360 * @since 1.7.0
361 *
362 * @param boolean $setup_wizard - Boolean - is that first time wizard setup or settings page call.
363 *
364 * @return void
365 */
366 public static function exclude_users( $setup_wizard = false ) {
367 ?>
368 <h3><?php \esc_html_e( 'Do you want to exclude any users or roles from 2FA? ', 'wp-2fa' ); ?></h3>
369 <p class="description">
370 <?php \esc_html_e( 'If you are enforcing 2FA on all users but for some reason you would like to exclude individual user(s) or users with a specific role, you can exclude them below', 'wp-2fa' ); ?>
371 </p>
372 <?php
373 if ( ! $setup_wizard ) {
374 ?>
375 <table class="form-table js-enforcement-policy-section">
376 <tbody>
377 <tr>
378 <th><label id="exclude-users" for="excluded-users-multi-select"><?php \esc_html_e( 'Exclude the following users', 'wp-2fa' ); ?></label></th>
379 <td>
380 <?php } else { ?>
381 <label for="excluded-users-multi-select"><?php \esc_html_e( 'Exclude the following users', 'wp-2fa' ); ?>
382 <?php } ?>
383 <fieldset>
384 <div>
385 <select multiple="multiple" id="excluded-users-multi-select" name="wp_2fa_policy[excluded_users][]" style=" display:none;width:<?php echo ( $setup_wizard ) ? '100' : '50'; ?>%">
386 <?php
387 $excluded_users = (array) WP2FA::get_wp2fa_setting( 'excluded_users' );
388 foreach ( $excluded_users as $user ) {
389 ?>
390 <option selected="selected" value="<?php echo \esc_attr( $user ); ?>"><?php echo \esc_html( $user ); ?></option>
391 <?php
392 }
393 ?>
394 </select>
395 </div>
396 <?php
397 if ( ! $setup_wizard ) {
398 ?>
399
400 </td>
401 </tr>
402 <tr>
403 <th><label for="excluded-roles-multi-select"><?php \esc_html_e( 'Exclude the following roles', 'wp-2fa' ); ?></label></th>
404 <td>
405 <p>
406 <?php } else { ?>
407 <br>
408 <label for="excluded-roles-multi-select"><?php \esc_html_e( 'Exclude the following roles', 'wp-2fa' ); ?></label>
409 <?php } ?>
410 <select multiple="multiple" id="excluded-roles-multi-select" name="wp_2fa_policy[excluded_roles][]" style=" display:none;width:<?php echo ( $setup_wizard ) ? '100' : '50'; ?>%">
411 <?php
412 $all_roles = WP_Helper::get_roles_wp();
413 $excluded_roles = (array) WP2FA::get_wp2fa_setting( 'excluded_roles' );
414 foreach ( $all_roles as $role => $role_name ) {
415 $selected = '';
416 if ( in_array( strtolower( $role ), $excluded_roles, true ) ) {
417 $selected = 'selected="selected"';
418 }
419 ?>
420 <option <?php echo $selected; // phpcs:ignore ?> value="<?php echo \esc_attr( strtolower( $role ) ); ?>"><?php echo \esc_html( $role_name ); ?></option>
421 <?php
422 }
423 ?>
424 </select>
425 <br>
426 <?php if ( WP_Helper::is_multisite() ) { ?>
427 <div style="margin-top:10px;">
428 <input type="checkbox" name="wp_2fa_policy[superadmins-role-exclude]" id="superadmins-role-exclude" value="yes"
429 <?php checked( WP2FA::get_wp2fa_setting( 'superadmins-role-exclude' ), 'yes' ); ?> />
430 <label for="superadmins-role-exclude"><?php \esc_html_e( 'Also exclude users with super admin privilege', 'wp-2fa' ); ?></label>
431 </div>
432 <?php } ?>
433 </fieldset>
434 <?php
435 if ( ! $setup_wizard ) {
436 ?>
437 </td>
438 </tr>
439 </tbody>
440 </table>
441 <?php } ?>
442 <?php
443 }
444
445 /**
446 * Which network sites to exclude (for multisite instal)
447 *
448 * @since 1.7.0
449 *
450 * @param boolean $setup_wizard - Boolean - is that first time wizard setup or settings page call.
451 *
452 * @return void
453 */
454 public static function excluded_network_sites( $setup_wizard = false ) {
455 ?>
456 <h3><?php \esc_html_e( 'Do you want to exclude all the users of a site from 2FA? ', 'wp-2fa' ); ?></h3>
457 <p class="description">
458 <?php \esc_html_e( 'If you are enforcing 2FA on all users but for some reason you do not want to enforce it on a specific sub site, specify the sub site name below:', 'wp-2fa' ); ?>
459 </p>
460 <?php
461 if ( ! $setup_wizard ) {
462 ?>
463 <table class="form-table js-enforcement-policy-section">
464 <tbody>
465 <tr>
466 <th><label for="excluded-sites-multi-select"><?php \esc_html_e( 'Exclude the following sites', 'wp-2fa' ); ?></label></th>
467 <td>
468 <?php } ?>
469 <fieldset>
470 <?php
471 if ( $setup_wizard ) {
472 ?>
473
474 <div class="option-pill">
475 <label for="excluded_sites_search"><?php \esc_html_e( 'Exclude the following sites', 'wp-2fa' ); ?>
476 <?php } ?>
477 <select multiple="multiple" id="excluded-sites-multi-select" name="wp_2fa_policy[excluded_sites][]" style=" display:none;width:<?php echo ( $setup_wizard ) ? '100' : '50'; ?>%">
478 <?php
479 $excluded_sites = (array) WP2FA::get_wp2fa_setting( 'excluded_sites' );
480 if ( ! empty( $excluded_sites ) ) {
481 foreach ( $excluded_sites as $site_id ) {
482 $site = get_blog_details( $site_id )->blogname;
483 ?>
484 <option selected="selected" value="<?php echo \esc_attr( $site_id ); ?>"><?php echo \esc_html( $site ); ?></option>
485 <?php
486 }
487 }
488 ?>
489 </select>
490 <?php
491 if ( $setup_wizard ) {
492 ?>
493 </label>
494 </div>
495 <?php } ?>
496 </fieldset>
497 <?php
498 if ( ! $setup_wizard ) {
499 ?>
500 </td>
501 </tr>
502 </tbody>
503 </table>
504 <?php } ?>
505 <?php
506 }
507
508 /**
509 * Set the grace period
510 *
511 * @since 1.7.0
512 *
513 * @param boolean $setup_wizard - Boolean - is that first time wizard setup or settings page call.
514 *
515 * @return void
516 */
517 public static function grace_period( $setup_wizard = false ) {
518 $grace_period = (int) WP2FA::get_wp2fa_setting( 'grace-period', true );
519 /**
520 * Via that, you can change the grace period TTL.
521 *
522 * @param bool - Default at this point is true - no method is selected.
523 */
524 $testing = apply_filters( WP_2FA_PREFIX . 'allow_grace_period_in_seconds', false );
525 if ( $testing ) {
526 $grace_max = 600;
527 } else {
528 $grace_max = 10;
529 }
530 ?>
531 <fieldset class="contains-hidden-inputs">
532 <label for="no-grace-period" style="margin-bottom: 10px; display: block;">
533 <input type="radio" name="wp_2fa_policy[grace-policy]" id="no-grace-period" value="no-grace-period"
534 <?php checked( WP2FA::get_wp2fa_setting( 'grace-policy' ), 'no-grace-period' ); ?>
535 >
536 <span><?php \esc_html_e( 'Users have to configure 2FA straight away.', 'wp-2fa' ); ?></span>
537 </label>
538
539 <label for="use-grace-period">
540 <input type="radio" name="wp_2fa_policy[grace-policy]" id="use-grace-period" value="use-grace-period"
541 <?php checked( WP2FA::get_wp2fa_setting( 'grace-policy' ), 'use-grace-period' ); ?>
542 data-unhide-when-checked=".grace-period-inputs">
543 <span><?php \esc_html_e( 'Give users a grace period to configure 2FA', 'wp-2fa' ); ?></span>
544 </label>
545 <fieldset class="hidden grace-period-inputs">
546 <br/>
547 <input type="number" id="grace-period" name="wp_2fa_policy[grace-period]" value="<?php echo \esc_attr( $grace_period ); ?>" min="1" max="<?php echo \esc_attr( $grace_max ); ?>">
548 <label class="radio-inline">
549 <input class="js-nested" type="radio" name="wp_2fa_policy[grace-period-denominator]" value="hours"
550 <?php checked( WP2FA::get_wp2fa_setting( 'grace-period-denominator' ), 'hours' ); ?>
551 >
552 <?php \esc_html_e( 'hours', 'wp-2fa' ); ?>
553 </label>
554 <label class="radio-inline">
555 <input class="js-nested" type="radio" name="wp_2fa_policy[grace-period-denominator]" value="days"
556 <?php checked( WP2FA::get_wp2fa_setting( 'grace-period-denominator' ), 'days' ); ?>
557 >
558 <?php \esc_html_e( 'days', 'wp-2fa' ); ?>
559 </label>
560 <?php
561 /**
562 * Fires after the grace period. Gives the ability to change the parsed code.
563 *
564 * @param string $content - HTML content.
565 * @param string $role - The name of the role.
566 * @param string $name_prefix - Name prefix for the input name, includes the role name if provided.
567 * @param string $data_role - Data attribute - used by the JS.
568 * @param string $role_id - The role name, used to identify the inputs.
569 *
570 * @since 2.0.0
571 */
572 $after_grace_content = \apply_filters( WP_2FA_PREFIX . 'after_grace_period', '', '', 'wp_2fa_policy' );
573 echo $after_grace_content; // phpcs:ignore
574 ?>
575 <?php
576 /**
577 * Via that, you can change the grace period TTL.
578 *
579 * @param bool - Default at this point is true - no method is selected.
580 */
581 $testing = apply_filters( WP_2FA_PREFIX . 'allow_grace_period_in_seconds', false );
582 if ( $testing ) {
583 ?>
584 <label class="radio-inline">
585 <input class="js-nested" type="radio" name="wp_2fa_policy[grace-period-denominator]" value="seconds"
586 <?php checked( WP2FA::get_wp2fa_setting( 'grace-period-denominator' ), 'seconds' ); ?>
587 >
588 <?php \esc_html_e( 'Seconds', 'wp-2fa' ); ?>
589 </label>
590 <?php
591 }
592
593 if ( $setup_wizard ) {
594 $user = wp_get_current_user();
595 $last_user_to_update_settings = $user->ID;
596
597 ?>
598 <input type="hidden" id="2fa_main_user" name="wp_2fa_policy[2fa_settings_last_updated_by]" value="<?php echo \esc_attr( $last_user_to_update_settings ); ?>">
599 <?php } else { ?>
600 <p><?php \esc_html_e( 'Note: If users do not configure it within the configured stipulated time, their account will be locked and have to be unlocked manually.', 'wp-2fa' ); ?></p>
601 <?php } ?>
602 </fieldset>
603 <br/>
604 </fieldset>
605 <?php
606 }
607 }
608 }
609