PluginProbe ʕ •ᴥ•ʔ
WP 2FA – Two-factor authentication for WordPress / 2.9.0
WP 2FA – Two-factor authentication for WordPress v2.9.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-passord-reset-2fa.php
wp-2fa / includes / classes / Admin / Views Last commit date
class-first-time-wizard-steps.php 11 months ago class-grace-period-notifications.php 11 months ago class-passord-reset-2fa.php 11 months ago class-re-login-2fa.php 11 months ago class-wizard-steps.php 11 months ago index.php 11 months ago
class-passord-reset-2fa.php
149 lines
1 <?php
2 /**
3 * Roles and main settings password reset class.
4 *
5 * @package wp2fa
6 * @subpackage views
7 *
8 * @copyright 2025 Melapress
9 * @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
10 *
11 * @see https://wordpress.org/plugins/wp-2fa/
12 */
13
14 declare(strict_types=1);
15
16 namespace WP2FA\Admin\Views;
17
18 use WP2FA\Utils\Settings_Utils;
19
20 if ( ! class_exists( '\WP2FA\Admin\Views\Password_Reset_2FA' ) ) {
21 /**
22 * Password_Reset_2FA - Class for rendering the plugin settings related to 2fa when user resets the password.
23 *
24 * @since 2.5.0
25 */
26 class Password_Reset_2FA {
27 public const PASSWORD_RESET_SETTINGS_NAME = 'password-reset-2fa-show';
28
29 public const ENABLED_SETTING_VALUE = 'password-reset-2fa';
30
31 /**
32 * Inits all the class related hooks.
33 *
34 * @return void
35 *
36 * @since 2.5.0
37 */
38 public static function init() {
39 // phpcs:disable
40 // phpcs:enable
41 }
42
43 /**
44 * Shows the settings for the grace period notifications behavior.
45 *
46 * @param string $role - The name of the role.
47 * @param string $name_prefix - Name prefix for the input name, includes the role name if provided.
48 * @param string $data_role - Data attribute - used by the JS.
49 * @param string $role_id - The role name, used to identify the inputs.
50 *
51 * @return string
52 *
53 * @since 2.5.0
54 */
55 public static function reset_settings( string $role = '', string $name_prefix = '', string $data_role = '', string $role_id = '' ): string {
56 ob_start();
57
58 $password_reset_action = Settings_Utils::get_setting_role( $role, self::PASSWORD_RESET_SETTINGS_NAME, true );
59
60 ?>
61 <div class="sub-setting-indent">
62 <fieldset>
63 <label for="<?php echo \esc_attr( self::ENABLED_SETTING_VALUE . $role_id ); ?>" style="margin-bottom: 10px; display: inline-block;">
64 <input type="checkbox" name="<?php echo \esc_attr( $name_prefix . '[' . self::PASSWORD_RESET_SETTINGS_NAME . ']' ); ?>"
65 id="<?php echo \esc_attr( self::ENABLED_SETTING_VALUE . $role_id ); ?>"
66 <?php echo $data_role; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
67 value="<?php echo \esc_attr( self::ENABLED_SETTING_VALUE ); ?>" <?php checked( $password_reset_action, self::ENABLED_SETTING_VALUE ); ?> class="js-nested">
68 <span><?php echo \esc_html__( 'Require 2FA on password reset', 'wp-2fa' ); ?></span>
69 </label>
70 </fieldset>
71 </div>
72 <?php
73 $html_content = ob_get_clean();
74
75 return $html_content;
76 }
77
78 /**
79 * Adds global plugin setting options.
80 *
81 * @param array $loop_settings - Array with current plugin settings.
82 *
83 * @return array
84 *
85 * @since 2.5.0
86 */
87 public static function add_setting_value( array $loop_settings ): array {
88 $loop_settings[] = self::PASSWORD_RESET_SETTINGS_NAME;
89
90 return $loop_settings;
91 }
92
93 /**
94 * Adds the extension default settings to the main plugin settings.
95 *
96 * @param array $default_settings - array with plugin default settings.
97 *
98 * @return array
99 *
100 * @since 2.5.0
101 */
102 public static function add_default_settings( array $default_settings ): array {
103 $default_settings[ self::PASSWORD_RESET_SETTINGS_NAME ] = self::PASSWORD_RESET_SETTINGS_NAME;
104
105 return $default_settings;
106 }
107
108 /**
109 * Password reset settings.
110 *
111 * @param string $content - HTML content.
112 * @param string $role - The name of the role.
113 * @param string $name_prefix - Name prefix for the input name, includes the role name if provided.
114 * @param string $data_role - Data attribute - used by the JS.
115 * @param string $role_id - The role name, used to identify the inputs.
116 *
117 * @return string
118 *
119 * @since 2.5.0
120 */
121 public static function password_reset_setting( string $content, string $role = '', string $name_prefix = '', string $data_role = '', string $role_id = '' ): string {
122 ob_start();
123 ?>
124 <h3><?php \esc_html_e( 'Do you want to require 2FA when users reset their password?', 'wp-2fa' ); ?></h3>
125 <p class="description">
126 <?php \esc_html_e( 'When you enable this setting users will be required to enter a one-time code sent to them via email when resetting the password.', 'wp-2fa' ); ?>
127 </p>
128
129 <table class="form-table">
130 <tbody>
131 <tr>
132 <th><label for="<?php echo \esc_attr( self::ENABLED_SETTING_VALUE . $role_id ); ?>"><?php \esc_html_e( 'Password reset', 'wp-2fa' ); ?></label></th>
133 <td>
134 <fieldset class="contains-hidden-inputs">
135 <?php echo self::reset_settings( $role, $name_prefix, $data_role, $role_id ); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
136 </fieldset>
137 </td>
138 </tr>
139 </tbody>
140 </table>
141 <?php
142
143 $content .= ob_get_clean();
144
145 return $content;
146 }
147 }
148 }
149