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