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