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 / Utils / class-white-label.php
wp-2fa / includes / classes / Utils Last commit date
class-abstract-migration.php 11 months ago class-date-time-utils.php 11 months ago class-debugging.php 11 months ago class-generate-modal.php 11 months ago class-migration.php 11 months ago class-request-utils.php 11 months ago class-settings-utils.php 11 months ago class-user-utils.php 11 months ago class-validator.php 11 months ago class-white-label.php 11 months ago index.php 11 months ago
class-white-label.php
219 lines
1 <?php
2 /**
3 * Responsible for white labeling functionality.
4 *
5 * @package wp2fa
6 * @subpackage white-label
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\Utils;
17
18 use WP2FA\WP2FA;
19 use WP2FA\Admin\Controllers\Methods;
20
21 if ( ! class_exists( '\WP2FA\Utils\White_Label' ) ) {
22 /**
23 * Utility class for white labeling.
24 *
25 * @package WP2FA\Utils
26 *
27 * @since 2.8.0
28 */
29 class White_Label {
30
31 /**
32 * Local static cache for plugins settings.
33 *
34 * @var array
35 *
36 * @since 2.8.0
37 */
38 private static $plugin_settings = array();
39
40 /**
41 * Class cache to store the default white label settings.
42 *
43 * @var array
44 *
45 * @since 3.0.0
46 */
47 private static $default_settings = array();
48
49 /**
50 * Inits the plugin related classes and settings
51 *
52 * @return void
53 *
54 * @since 2.8.0
55 */
56 public static function init() {
57
58 \add_filter( WP_2FA_PREFIX . 'default_settings', array( __CLASS__, 'merge_settings' ) );
59
60 \add_filter( WP_2FA_PREFIX . 'whitelabel_settings', array( __CLASS__, 'fill_settings_array' ) );
61
62 \add_filter( 'login_headerurl', array( __CLASS__, 'set_logo_url' ) );
63 }
64
65 /**
66 * Changes the default logo URL to the white label's custom URL.
67 *
68 * @param string $logo_url - The current logo URL.
69 *
70 * @return string
71 *
72 * @since 3.0.0
73 */
74 public static function set_logo_url( $logo_url ) {
75 $custom_url = esc_url( WP2FA::get_wp2fa_white_label_setting( 'logo-code-page-url' ) );
76
77 if ( ! empty( $custom_url ) ) {
78 // Change the header title as well.
79 \add_filter(
80 'login_headertext',
81 function() use ( $custom_url ) {
82 return esc_html( $custom_url );
83 }
84 );
85
86 return $custom_url;
87 }
88
89 return $logo_url;
90 }
91
92 /**
93 * Merges the default settings with the stored settings.
94 *
95 * @param array $settings_array - Collected settings.
96 *
97 * @since 3.0.0
98 */
99 public static function fill_settings_array( $settings_array ) {
100 $settings_array = array_merge( self::get_default_settings(), $settings_array );
101
102 return $settings_array;
103 }
104
105 /**
106 * Util function to grab white label settings or apply defaults if no settings are saved into the db.
107 *
108 * @param string $setting_name Settings to grab value of.
109 * @param boolean $get_default_on_empty return default setting value if current one is empty.
110 *
111 * @return string|array Settings value or default value.
112 *
113 * @since 2.8.0
114 */
115 public static function get_setting( $setting_name = '', $get_default_on_empty = false ) {
116 $default_settings = self::get_default_settings( array() );
117
118 $white_label_setting = self::$plugin_settings[ WP_2FA_WHITE_LABEL_SETTINGS_NAME ];
119
120 // If we have no setting name, return them all.
121 if ( empty( $setting_name ) ) {
122 return $white_label_setting;
123 }
124
125 // First lets check if any options have been saved.
126 if ( empty( $white_label_setting ) || ! isset( $white_label_setting ) ) {
127 $apply_defaults = true;
128 }
129
130 if ( $apply_defaults ) {
131 return isset( $default_settings[ $setting_name ] ) ? $default_settings[ $setting_name ] : '';
132 } elseif ( ! isset( $white_label_setting[ $setting_name ] ) ) {
133 if ( true === $get_default_on_empty ) {
134 if ( isset( $default_settings[ $setting_name ] ) ) {
135 return $default_settings[ $setting_name ];
136 }
137 }
138
139 return '';
140 } else {
141 return $white_label_setting[ $setting_name ];
142 }
143 }
144
145 /**
146 * Array with all the plugin default settings.
147 *
148 * @return array
149 *
150 * @since 2.8.0
151 */
152 public static function get_default_settings() {
153
154 if ( empty( self::$default_settings ) ) {
155 self::$default_settings = array(
156 'default-text-code-page' => '<p>' . esc_html__( 'Please enter the two-factor authentication (2FA) verification code below to login. Depending on your 2FA setup, you can get the code from the 2FA app or it was sent to you by email.', 'wp-2fa' ) . '</p><p><strong>' . esc_html__( 'Note: if you are supposed to receive an email but did not receive any, please click the Resend Code button to request another code.', 'wp-2fa' ) . '</strong></p>',
157 'default-text-pw-reset-code-page' => '<p>' . esc_html__( 'You have been sent a one-time code via email. Please enter the code below and then click Get New Password to proceed with the password reset.', 'wp-2fa' ) . '</p><br><p><strong>' . esc_html__( 'Note: If you have not received the code please click the button Resend Code. If you still do not get the code after pressing the button, please contact the website\'s administrator.', 'wp-2fa' ) . '</strong></p>',
158 'default-2fa-required-notice' => '<p>' . esc_html__( 'This website\'s administrator requires you to enable two-factor authentication (2FA) {grace_period_remaining}.', 'wp-2fa' ) . '</p><br><p>' . esc_html__( 'Failing to configure 2FA within this time period will result in a locked account. For more information, please contact your website administrator.', 'wp-2fa' ) . '</p>',
159 'default-2fa-resetup-required-notice' => '<p>' . esc_html__( 'This website\'s administrator requires you to enable two-factor authentication (2FA) {grace_period_remaining}.', 'wp-2fa' ) . '</p><br><p>' . esc_html__( 'Failing to configure 2FA within this time period will result in a locked account. For more information, please contact your website administrator.', 'wp-2fa' ) . '</p>',
160
161 'custom-text-app-code-page' => '<p>' . esc_html__( 'Please enter the two-factor authentication (2FA) verification code below to login. Depending on your 2FA setup, you can get the code from the 2FA app or it was sent to you by email.', 'wp-2fa' ) . '</p><p><strong>' . esc_html__( 'Note: if you are supposed to receive an email but did not receive any, please click the Resend Code button to request another code.', 'wp-2fa' ) . '</strong></p>',
162 'custom-text-email-code-page' => '<p>' . esc_html__( 'Please enter the two-factor authentication (2FA) verification code below to login. Depending on your 2FA setup, you can get the code from the 2FA app or it was sent to you by email.', 'wp-2fa' ) . '</p><p><strong>' . esc_html__( 'Note: if you are supposed to receive an email but did not receive any, please click the Resend Code button to request another code.', 'wp-2fa' ) . '</strong></p>',
163
164 'default-backup-code-page' => esc_html__( 'Enter a backup verification code.', 'wp-2fa' ),
165 'enable_wizard_styling' => 'enable_wizard_styling',
166 'show_help_text' => 'show_help_text',
167 'enable_wizard_logo' => '',
168 'hide_page_generated_by' => false,
169 'enable_welcome' => '',
170 'welcome' => '',
171 'method_selection' => '<h3>' . esc_html__( 'Choose the 2FA method', 'wp-2fa' ) . '</h3>' . Methods::get_number_of_methods_text(),
172 // 'method_selection_single' => '<h3>' . esc_html__( 'Choose the 2FA method', 'wp-2fa' ) . '</h3><p>' . esc_html__( 'Only the below 2FA method is allowed on this website:', 'wp-2fa' ) . '</p>',
173
174 'no_further_action' => '<h3>' . esc_html__( 'Congratulations! You are all set.', 'wp-2fa' ),
175 '2fa_required_intro' => '<h3>' . esc_html__( 'You are required to configure 2FA.', 'wp-2fa' ) . '</h3><p>' . esc_html__( 'In order to keep this site - and your details secure, this website’s administrator requires you to enable 2FA authentication to continue.', 'wp-2fa' ) . '</p><p>' . esc_html__( 'Two factor authentication ensures only you have access to your account by creating an added layer of security when logging in -', 'wp-2fa' ) . ' <a href="https://melapress.com/wordpress-2fa/?&utm_source=plugin&utm_medium=wp2fa&utm_campaign=learn_more" target="_blank" rel="noopener">' . esc_html__( 'Learn more', 'wp-2fa' ) . '</a></p>',
176
177 'custom_css' => '',
178 'login_custom_css' => '',
179 'logo-code-page' => '',
180 'logo-code-page-url' => '',
181 'disable_login_css' => '',
182 'login-to-view-area' => '<p>' . esc_html__( 'You must be logged in to view this page. {login_url}', 'wp-2fa' ) . '</p>',
183
184 'user-profile-form-preamble-title' => esc_html__( 'Two-factor authentication settings', 'wp-2fa' ),
185 'user-profile-form-preamble-desc' => esc_html__( 'Add two-factor authentication to strengthen the security of your user account.', 'wp-2fa' ),
186 'use_custom_2fa_message' => 'use-defaults',
187 );
188
189 /**
190 * Gives the ability to filter the default settings array of the plugin
191 *
192 * @param array $settings - The array with all the default settings.
193 *
194 * @since 2.0.0
195 */
196 self::$default_settings = \apply_filters( WP_2FA_PREFIX . 'white_label_default_settings', self::$default_settings );
197 }
198
199 return self::$default_settings;
200 }
201
202 /**
203 * Array with all the plugin default settings.
204 *
205 * @param array $settings - Currently collected settings.
206 *
207 * @return array
208 *
209 * @since 3.0.0
210 */
211 public static function merge_settings( $settings ) {
212
213 $settings[ WP_2FA_WHITE_LABEL_SETTINGS_NAME ] = self::get_default_settings();
214
215 return $settings;
216 }
217 }
218 }
219