PluginProbe ʕ •ᴥ•ʔ
WP 2FA – Two-factor authentication for WordPress / 2.6.0
WP 2FA – Two-factor authentication for WordPress v2.6.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 2 years ago class-grace-period-notifications.php 2 years ago class-passord-reset-2fa.php 2 years ago class-wizard-steps.php 2 years ago index.php 2 years ago
class-first-time-wizard-steps.php
607 lines
1 <?php
2 /**
3 * Settings page render class.
4 *
5 * @package wp2fa
6 * @subpackage views
7 * @since 1.7.0
8 * @copyright %%YEAR%% 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=plugins&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 echo '<label>';
186 printf( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
187 '%1$1s <a href="https://melapress.com/wordpress-2fa/features/?&utm_source=plugins&utm_medium=link&utm_campaign=wp2fa" target="_blank">%2$1s</a> %3$1s',
188 esc_html__( 'Upgrade to WP 2FA Premium for', 'wp-2fa' ),
189 esc_html__( 'more alternative 2FA methods', 'wp-2fa' ),
190 esc_html__( 'to give your users more options.', 'wp-2fa' )
191 );
192 echo '<label>';
193 ?>
194 </fieldset>
195 <?php
196 ?>
197 <?php
198 $output = ob_get_clean();
199 $output = apply_filters( WP_2FA_PREFIX . 'backup_methods', $output, $setup_wizard );
200
201 echo $output; // phpcs:ignore
202 }
203
204 /**
205 * Enforcement policy step
206 *
207 * @since 1.7.0
208 *
209 * @param boolean $setup_wizard - Boolean - is that first time wizard setup or settings page call.
210 *
211 * @return void
212 */
213 public static function enforcement_policy( $setup_wizard = false ) {
214 ?>
215 <h3 id="enforcement_settings"><?php esc_html_e( 'Do you want to enforce 2FA for some, or all the users? ', 'wp-2fa' ); ?></h3>
216 <p class="description">
217 <?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=plugins&utm_medium=link&utm_campaign=wp2fa" target="_blank" rel=noopener><?php esc_html_e( 'Learn more.', 'wp-2fa' ); ?></a>
218 </p>
219 <?php
220 if ( ! $setup_wizard ) {
221 ?>
222 <table class="form-table js-enforcement-policy-section">
223 <tbody>
224 <tr>
225 <th><label for="enforcement-policy"><?php esc_html_e( 'Enforce 2FA on', 'wp-2fa' ); ?></label></th>
226 <td>
227 <?php } ?>
228 <fieldset class="contains-hidden-inputs">
229 <label for="all-users" style="margin:.35em 0 .5em !important; display: block;">
230 <input type="radio" name="wp_2fa_policy[enforcement-policy]" id="all-users" value="all-users"
231 <?php checked( WP2FA::get_wp2fa_setting( 'enforcement-policy' ), 'all-users' ); ?>
232 >
233 <span><?php esc_html_e( 'All users', 'wp-2fa' ); ?></span>
234 </label>
235
236 <?php if ( WP_Helper::is_multisite() ) : ?>
237 <label for="superadmins-only" style="margin:.35em 0 .5em !important; display: block;">
238 <input type="radio" name="wp_2fa_policy[enforcement-policy]" id="superadmins-only" value="superadmins-only"
239 <?php checked( WP2FA::get_wp2fa_setting( 'enforcement-policy' ), 'superadmins-only' ); ?> />
240 <span><?php esc_html_e( 'Only super admins', 'wp-2fa' ); ?></span>
241 </label>
242 <label for="superadmins-siteadmins-only" style="margin:.35em 0 .5em !important; display: block;">
243 <input type="radio" name="wp_2fa_policy[enforcement-policy]" id="superadmins-siteadmins-only" value="superadmins-siteadmins-only"
244 <?php checked( WP2FA::get_wp2fa_setting( 'enforcement-policy' ), 'superadmins-siteadmins-only' ); ?> />
245 <span><?php esc_html_e( 'Only super admins and site admins', 'wp-2fa' ); ?></span>
246 </label>
247 <?php endif; ?>
248
249 <label for="certain-roles-only" style="margin:.35em 0 .5em !important; display: block;">
250 <?php $checked = in_array( WP2FA::get_wp2fa_setting( 'enforcement-policy' ), array( 'certain-roles-only', 'certain-users-only' ), true ); ?>
251 <input type="radio" name="wp_2fa_policy[enforcement-policy]" id="certain-roles-only" value="certain-roles-only"
252 <?php ( $setup_wizard ) ? checked( WP2FA::get_wp2fa_setting( 'enforcement-policy' ), 'certain-roles-only' ) : checked( $checked ); ?>
253 data-unhide-when-checked=".certain-roles-only-inputs, .certain-users-only-inputs">
254 <span><?php esc_html_e( 'Only for specific users and roles', 'wp-2fa' ); ?></span>
255 </label>
256 <fieldset class="hidden certain-users-only-inputs">
257 <div>
258 <p>
259 <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'; ?>%">
260 <?php
261 $excluded_users = WP2FA::get_wp2fa_setting( 'enforced_users' );
262 foreach ( $excluded_users as $user ) {
263 ?>
264 <option selected="selected" value="<?php echo \esc_attr( $user ); ?>"><?php echo \esc_attr( $user ); ?></option>
265 <?php
266 }
267 ?>
268 </select>
269 </p>
270 </div>
271 </fieldset>
272 <fieldset class="hidden certain-roles-only-inputs">
273 <div>
274 <p style="margin-top: 0;">
275 <label for="enforced-roles-multi-select"><?php esc_html_e( 'Roles :', 'wp-2fa' ); ?></label>
276 <select multiple="multiple" id="enforced-roles-multi-select" name="wp_2fa_policy[enforced_roles][]" style=" display:none;width:<?php echo ( $setup_wizard ) ? '100' : '50'; ?>%">
277 <?php
278 $all_roles = \WP2FA\WP2FA::wp_2fa_get_roles();
279 $enforced_roles = WP2FA::get_wp2fa_setting( 'enforced_roles' );
280 foreach ( $all_roles as $role => $role_name ) {
281 $selected = '';
282 if ( in_array( $role, $enforced_roles, true ) ) {
283 $selected = 'selected="selected"';
284 }
285 ?>
286 <option <?php echo $selected; // phpcs:ignore ?> value="<?php echo \esc_attr( strtolower( $role ) ); ?>"><?php echo \esc_html( $role_name ); ?></option>
287 <?php
288 }
289 ?>
290 </select>
291 </p>
292 </div>
293 <?php if ( WP_Helper::is_multisite() ) { ?>
294 <p class="description">
295 <input type="checkbox" name="wp_2fa_policy[superadmins-role-add]" id="superadmins-role-add" value="yes" style="position: relative; top: -3px;"
296 <?php checked( WP2FA::get_wp2fa_setting( 'superadmins-role-add' ), 'yes' ); ?> />
297 <label for="superadmins-role-add"><?php esc_html_e( 'Also enforce 2FA on network users with super admin privileges', 'wp-2fa' ); ?></label>
298 </p>
299 <?php } ?>
300 </fieldset>
301 <?php if ( WP_Helper::is_multisite() ) { ?>
302 <div>
303 <label for="enforce-on-multisite" style="margin:.35em 0 .5em !important; display: block;">
304 <input type="radio" name="wp_2fa_policy[enforcement-policy]" id="enforce-on-multisite" value="enforce-on-multisite"
305 <?php checked( WP2FA::get_wp2fa_setting( 'enforcement-policy' ), 'enforce-on-multisite' ); ?>
306 data-unhide-when-checked=".all-sites">
307 <span><?php esc_html_e( 'These sub-sites', 'wp-2fa' ); ?></span>
308 </label>
309 <fieldset class="hidden all-sites">
310 <p>
311 <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'; ?>%">
312 <?php
313 $selected_sites = WP2FA::get_wp2fa_setting( 'included_sites' );
314 foreach ( WP_Helper::get_multi_sites() as $site ) {
315 $args = array(
316 'blog_id' => $site->blog_id,
317 );
318
319 $current_blog_details = get_blog_details( $args );
320 $selected = '';
321 if ( in_array( $site->blog_id, $selected_sites, true ) ) {
322 $selected = 'selected="selected"';
323 }
324 ?>
325 <option <?php echo $selected; // phpcs:ignore ?> value="<?php echo \esc_attr( $site->blog_id ); ?>"><?php echo \esc_html( $current_blog_details->blogname ); ?></option>
326 <?php
327 }
328 ?>
329 </select>
330 </p>
331 </fieldset>
332 </div>
333 <?php } ?>
334 <div>
335 <label for="do-not-enforce" style="margin:.35em 0 .5em !important; display: block;">
336 <input type="radio" name="wp_2fa_policy[enforcement-policy]" id="do-not-enforce" value="do-not-enforce"
337 <?php checked( WP2FA::get_wp2fa_setting( 'enforcement-policy' ), 'do-not-enforce' ); ?>
338 >
339 <span><?php esc_html_e( 'Do not enforce on any users', 'wp-2fa' ); ?></span>
340 </label>
341 </div>
342 <br/>
343 </fieldset>
344 <?php
345 if ( ! $setup_wizard ) {
346 ?>
347 </td>
348 </tr>
349 </tbody>
350 </table>
351 <?php
352 }
353 }
354
355 /**
356 * Exclude users and groups
357 *
358 * @since 1.7.0
359 *
360 * @param boolean $setup_wizard - Boolean - is that first time wizard setup or settings page call.
361 *
362 * @return void
363 */
364 public static function exclude_users( $setup_wizard = false ) {
365 ?>
366 <h3><?php esc_html_e( 'Do you want to exclude any users or roles from 2FA? ', 'wp-2fa' ); ?></h3>
367 <p class="description">
368 <?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' ); ?>
369 </p>
370 <?php
371 if ( ! $setup_wizard ) {
372 ?>
373 <table class="form-table js-enforcement-policy-section">
374 <tbody>
375 <tr>
376 <th><label id="exclude-users" for="excluded-users-multi-select"><?php esc_html_e( 'Exclude the following users', 'wp-2fa' ); ?></label></th>
377 <td>
378 <?php } else { ?>
379 <label for="excluded-users-multi-select"><?php esc_html_e( 'Exclude the following users', 'wp-2fa' ); ?>
380 <?php } ?>
381 <fieldset>
382 <div>
383 <select multiple="multiple" id="excluded-users-multi-select" name="wp_2fa_policy[excluded_users][]" style=" display:none;width:<?php echo ( $setup_wizard ) ? '100' : '50'; ?>%">
384 <?php
385 $excluded_users = WP2FA::get_wp2fa_setting( 'excluded_users' );
386 foreach ( $excluded_users as $user ) {
387 ?>
388 <option selected="selected" value="<?php echo \esc_attr( $user ); ?>"><?php echo \esc_html( $user ); ?></option>
389 <?php
390 }
391 ?>
392 </select>
393 </div>
394 <?php
395 if ( ! $setup_wizard ) {
396 ?>
397
398 </td>
399 </tr>
400 <tr>
401 <th><label for="excluded-roles-multi-select"><?php esc_html_e( 'Exclude the following roles', 'wp-2fa' ); ?></label></th>
402 <td>
403 <p>
404 <?php } else { ?>
405 <br>
406 <label for="excluded-roles-multi-select"><?php esc_html_e( 'Exclude the following roles', 'wp-2fa' ); ?></label>
407 <?php } ?>
408 <select multiple="multiple" id="excluded-roles-multi-select" name="wp_2fa_policy[excluded_roles][]" style=" display:none;width:<?php echo ( $setup_wizard ) ? '100' : '50'; ?>%">
409 <?php
410 $all_roles = \WP2FA\WP2FA::wp_2fa_get_roles();
411 $excluded_roles = WP2FA::get_wp2fa_setting( 'excluded_roles' );
412 foreach ( $all_roles as $role => $role_name ) {
413 $selected = '';
414 if ( in_array( strtolower( $role ), $excluded_roles, true ) ) {
415 $selected = 'selected="selected"';
416 }
417 ?>
418 <option <?php echo $selected; // phpcs:ignore ?> value="<?php echo \esc_attr( strtolower( $role ) ); ?>"><?php echo \esc_html( $role_name ); ?></option>
419 <?php
420 }
421 ?>
422 </select>
423 <br>
424 <?php if ( WP_Helper::is_multisite() ) { ?>
425 <div style="margin-top:10px;">
426 <input type="checkbox" name="wp_2fa_policy[superadmins-role-exclude]" id="superadmins-role-exclude" value="yes"
427 <?php checked( WP2FA::get_wp2fa_setting( 'superadmins-role-exclude' ), 'yes' ); ?> />
428 <label for="superadmins-role-exclude"><?php esc_html_e( 'Also exclude users with super admin privilege', 'wp-2fa' ); ?></label>
429 </div>
430 <?php } ?>
431 </fieldset>
432 <?php
433 if ( ! $setup_wizard ) {
434 ?>
435 </td>
436 </tr>
437 </tbody>
438 </table>
439 <?php } ?>
440 <?php
441 }
442
443 /**
444 * Which network sites to exclude (for multisite instal)
445 *
446 * @since 1.7.0
447 *
448 * @param boolean $setup_wizard - Boolean - is that first time wizard setup or settings page call.
449 *
450 * @return void
451 */
452 public static function excluded_network_sites( $setup_wizard = false ) {
453 ?>
454 <h3><?php esc_html_e( 'Do you want to exclude all the users of a site from 2FA? ', 'wp-2fa' ); ?></h3>
455 <p class="description">
456 <?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' ); ?>
457 </p>
458 <?php
459 if ( ! $setup_wizard ) {
460 ?>
461 <table class="form-table js-enforcement-policy-section">
462 <tbody>
463 <tr>
464 <th><label for="excluded-sites-multi-select"><?php esc_html_e( 'Exclude the following sites', 'wp-2fa' ); ?></label></th>
465 <td>
466 <?php } ?>
467 <fieldset>
468 <?php
469 if ( $setup_wizard ) {
470 ?>
471
472 <div class="option-pill">
473 <label for="excluded_sites_search"><?php esc_html_e( 'Exclude the following sites', 'wp-2fa' ); ?>
474 <?php } ?>
475 <select multiple="multiple" id="excluded-sites-multi-select" name="wp_2fa_policy[excluded_sites][]" style=" display:none;width:<?php echo ( $setup_wizard ) ? '100' : '50'; ?>%">
476 <?php
477 $excluded_sites = WP2FA::get_wp2fa_setting( 'excluded_sites' );
478 if ( ! empty( $excluded_sites ) ) {
479 foreach ( $excluded_sites as $site_id ) {
480 $site = get_blog_details( $site_id )->blogname;
481 ?>
482 <option selected="selected" value="<?php echo \esc_attr( $site_id ); ?>"><?php echo \esc_html( $site ); ?></option>
483 <?php
484 }
485 }
486 ?>
487 </select>
488 <?php
489 if ( $setup_wizard ) {
490 ?>
491 </label>
492 </div>
493 <?php } ?>
494 </fieldset>
495 <?php
496 if ( ! $setup_wizard ) {
497 ?>
498 </td>
499 </tr>
500 </tbody>
501 </table>
502 <?php } ?>
503 <?php
504 }
505
506 /**
507 * Set the grace period
508 *
509 * @since 1.7.0
510 *
511 * @param boolean $setup_wizard - Boolean - is that first time wizard setup or settings page call.
512 *
513 * @return void
514 */
515 public static function grace_period( $setup_wizard = false ) {
516 $grace_period = (int) WP2FA::get_wp2fa_setting( 'grace-period', true );
517 /**
518 * Via that, you can change the grace period TTL.
519 *
520 * @param bool - Default at this point is true - no method is selected.
521 */
522 $testing = apply_filters( WP_2FA_PREFIX . 'allow_grace_period_in_seconds', false );
523 if ( $testing ) {
524 $grace_max = 600;
525 } else {
526 $grace_max = 10;
527 }
528 ?>
529 <fieldset class="contains-hidden-inputs">
530 <label for="no-grace-period" style="margin-bottom: 10px; display: block;">
531 <input type="radio" name="wp_2fa_policy[grace-policy]" id="no-grace-period" value="no-grace-period"
532 <?php checked( WP2FA::get_wp2fa_setting( 'grace-policy' ), 'no-grace-period' ); ?>
533 >
534 <span><?php esc_html_e( 'Users have to configure 2FA straight away.', 'wp-2fa' ); ?></span>
535 </label>
536
537 <label for="use-grace-period">
538 <input type="radio" name="wp_2fa_policy[grace-policy]" id="use-grace-period" value="use-grace-period"
539 <?php checked( WP2FA::get_wp2fa_setting( 'grace-policy' ), 'use-grace-period' ); ?>
540 data-unhide-when-checked=".grace-period-inputs">
541 <span><?php esc_html_e( 'Give users a grace period to configure 2FA', 'wp-2fa' ); ?></span>
542 </label>
543 <fieldset class="hidden grace-period-inputs">
544 <br/>
545 <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 ); ?>">
546 <label class="radio-inline">
547 <input class="js-nested" type="radio" name="wp_2fa_policy[grace-period-denominator]" value="hours"
548 <?php checked( WP2FA::get_wp2fa_setting( 'grace-period-denominator' ), 'hours' ); ?>
549 >
550 <?php esc_html_e( 'hours', 'wp-2fa' ); ?>
551 </label>
552 <label class="radio-inline">
553 <input class="js-nested" type="radio" name="wp_2fa_policy[grace-period-denominator]" value="days"
554 <?php checked( WP2FA::get_wp2fa_setting( 'grace-period-denominator' ), 'days' ); ?>
555 >
556 <?php esc_html_e( 'days', 'wp-2fa' ); ?>
557 </label>
558 <?php
559 /**
560 * Fires after the grace period. Gives the ability to change the parsed code.
561 *
562 * @param string $content - HTML content.
563 * @param string $role - The name of the role.
564 * @param string $name_prefix - Name prefix for the input name, includes the role name if provided.
565 * @param string $data_role - Data attribute - used by the JS.
566 * @param string $role_id - The role name, used to identify the inputs.
567 *
568 * @since 2.0.0
569 */
570 $after_grace_content = \apply_filters( WP_2FA_PREFIX . 'after_grace_period', '', '', 'wp_2fa_policy' );
571 echo $after_grace_content; // phpcs:ignore
572 ?>
573 <?php
574 /**
575 * Via that, you can change the grace period TTL.
576 *
577 * @param bool - Default at this point is true - no method is selected.
578 */
579 $testing = apply_filters( WP_2FA_PREFIX . 'allow_grace_period_in_seconds', false );
580 if ( $testing ) {
581 ?>
582 <label class="radio-inline">
583 <input class="js-nested" type="radio" name="wp_2fa_policy[grace-period-denominator]" value="seconds"
584 <?php checked( WP2FA::get_wp2fa_setting( 'grace-period-denominator' ), 'seconds' ); ?>
585 >
586 <?php esc_html_e( 'Seconds', 'wp-2fa' ); ?>
587 </label>
588 <?php
589 }
590
591 if ( $setup_wizard ) {
592 $user = wp_get_current_user();
593 $last_user_to_update_settings = $user->ID;
594
595 ?>
596 <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 ); ?>">
597 <?php } else { ?>
598 <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>
599 <?php } ?>
600 </fieldset>
601 <br/>
602 </fieldset>
603 <?php
604 }
605 }
606 }
607