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 / SettingsPages / class-settings-page-white-label.php
wp-2fa / includes / classes / Admin / SettingsPages Last commit date
class-settings-page-email.php 4 years ago class-settings-page-general.php 4 years ago class-settings-page-policies.php 4 years ago class-settings-page-white-label.php 4 years ago
class-settings-page-white-label.php
200 lines
1 <?php
2 /**
3 * White label settings class.
4 *
5 * @package wp2fa
6 * @subpackage settings-pages
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\SettingsPages;
13
14 use \WP2FA\WP2FA as WP2FA;
15 use WP2FA\Utils\Debugging;
16
17 /**
18 * White labeling settings tab
19 */
20 if ( ! class_exists( '\WP2FA\Admin\SettingsPages\Settings_Page_White_Label' ) ) {
21 /**
22 * Settings_Page_White_Label - Class for handling settings
23 *
24 * @since 2.0.0
25 */
26 class Settings_Page_White_Label {
27
28 /**
29 * Render the settings
30 *
31 * @return void
32 *
33 * @since 2.0.0
34 */
35 public function render() {
36 settings_fields( WP_2FA_WHITE_LABEL_SETTINGS_NAME );
37 $this->change_default_text_area();
38 submit_button();
39 }
40
41 /**
42 * Validate options before saving
43 *
44 * @param array $input The settings array.
45 *
46 * @return array|void
47 *
48 * @since 2.0.0
49 */
50 public function validate_and_sanitize( $input ) {
51
52 // Bail if user doesn't have permissions to be here.
53 if ( ! current_user_can( 'manage_options' ) || ! isset( $_POST['action'] ) && ! check_admin_referer( 'wp2fa-step-choose-method' ) ) {
54 return;
55 }
56
57 $output['default-text-code-page'] = WP2FA::get_wp2fa_setting( 'default-text-code-page', false, true );
58
59 if ( isset( $input['default-text-code-page'] ) && '' !== trim( $input['default-text-code-page'] ) ) {
60 $output['default-text-code-page'] = \wp_strip_all_tags( $input['default-text-code-page'] );
61 }
62
63 $output['default-backup-code-page'] = WP2FA::get_wp2fa_setting( 'default-backup-code-page', false, true );
64
65 if ( isset( $input['default-backup-code-page'] ) && '' !== trim( $input['default-backup-code-page'] ) ) {
66 $output['default-backup-code-page'] = \wp_strip_all_tags( $input['default-backup-code-page'] );
67 }
68
69 // Remove duplicates from settings errors. We do this as this sanitization callback is actually fired twice, so we end up with duplicates when saving the settings for the FIRST TIME only. The issue is not present once the settings are in the DB as the sanitization wont fire again. For details on this core issue - https://core.trac.wordpress.org/ticket/21989.
70 global $wp_settings_errors;
71 if ( isset( $wp_settings_errors ) ) {
72 $errors = array_map( 'unserialize', array_unique( array_map( 'serialize', $wp_settings_errors ) ) );
73 $wp_settings_errors = $errors; // phpcs:ignore
74 }
75
76 $log_content = __( 'Settings saving processes complete', 'wp-2fa' );
77 Debugging::log( $log_content );
78
79 /**
80 * Filter the values we are about to store in the plugin settings.
81 *
82 * @param array $output - The output array with all the data we will store in the settings.
83 * @param array $input - The input array with all the data we received from the user.
84 *
85 * @since 2.0.0
86 */
87 $output = apply_filters( WP_2FA_PREFIX . 'filter_output_content', $output, $input );
88
89 return $output;
90 }
91
92 /**
93 * Updates global white label network options
94 *
95 * @return void
96 *
97 * @since 2.0.0
98 *
99 * @SuppressWarnings(PHPMD.ExitExpressions)
100 */
101 public function update_wp2fa_network_options() {
102
103 if ( isset( $_POST[ WP_2FA_WHITE_LABEL_SETTINGS_NAME ] ) ) {
104 check_admin_referer( 'wp_2fa_white_label-options' );
105 $options = $this->validate_and_sanitize( wp_unslash( $_POST[ WP_2FA_WHITE_LABEL_SETTINGS_NAME ] ) ); // phpcs:ignore
106 $settings_errors = get_settings_errors( WP_2FA_WHITE_LABEL_SETTINGS_NAME );
107 if ( ! empty( $settings_errors ) ) {
108
109 // redirect back to our options page.
110 wp_safe_redirect(
111 add_query_arg(
112 array(
113 'page' => 'wp-2fa-settings',
114 'wp_2fa_network_settings_error' => urlencode_deep( $settings_errors[0]['message'] ),
115 ),
116 network_admin_url( 'settings.php' )
117 )
118 );
119 exit;
120
121 }
122 WP2FA::update_plugin_settings( $options, false, WP_2FA_WHITE_LABEL_SETTINGS_NAME );
123
124 // redirect back to our options page.
125 wp_safe_redirect(
126 add_query_arg(
127 array(
128 'page' => 'wp-2fa-settings',
129 'tab' => 'white-label-settings',
130 'wp_2fa_network_settings_updated' => 'true',
131 ),
132 network_admin_url( 'admin.php' )
133 )
134 );
135 exit;
136 }
137 }
138
139 /**
140 * Shows default settings input to the user
141 *
142 * @return void
143 *
144 * @since 2.0.0
145 */
146 private function change_default_text_area() {
147 /**
148 * Fires right before the white label settings tab HTML rendering.
149 *
150 * @since 2.0.0
151 */
152 do_action( WP_2FA_PREFIX . 'white_labeling_settings_page_before_default_text' );
153 ?>
154 <h3><?php esc_html_e( 'Change the default text used in the 2FA code page?', 'wp-2fa' ); ?></h3>
155 <p class="description">
156 <?php esc_html_e( 'This is the text shown to the users on the page when they are asked to enter the 2FA code. To change the default text, simply type it in the below placeholder.', 'wp-2fa' ); ?>
157 </p>
158 <table class="form-table">
159 <tbody>
160 <tr>
161 <th><label for="2fa-method"><?php esc_html_e( '2FA code page text', 'wp-2fa' ); ?></label></th>
162 <td>
163 <fieldset>
164 <label for="default-text-code-page">
165 <textarea cols="70" rows="10" name="wp_2fa_white_label[default-text-code-page]" id="default-text-code-page"><?php echo \esc_html( WP2FA::get_wp2fa_white_label_setting( 'default-text-code-page', true ) ); ?></textarea>
166 <div><span><strong><i><?php esc_html_e( 'Note:', 'wp-2fa' ); ?></i></strong> <?php esc_html_e( 'Only plain text is allowed.', 'wp-2fa' ); ?></span></div>
167 </label>
168 </fieldset>
169 </td>
170 </tr>
171 <tr>
172 <th><label for="backup-method"><?php esc_html_e( 'Backup code page text', 'wp-2fa' ); ?></label></th>
173 <td>
174 <fieldset>
175 <label for="default-backup-code-page">
176 <textarea cols="70" rows="10" name="wp_2fa_white_label[default-backup-code-page]" id="default-backup-code-page"><?php echo \esc_html( WP2FA::get_wp2fa_white_label_setting( 'default-backup-code-page', true ) ); ?></textarea>
177 <div><span><strong><i><?php esc_html_e( 'Note:', 'wp-2fa' ); ?></i></strong> <?php esc_html_e( 'Only plain text is allowed.', 'wp-2fa' ); ?></span></div>
178 </label>
179 </fieldset>
180 </td>
181 </tr>
182 <?php
183 /**
184 * Gives the ability for the 3rd party extensions to add additional white label settings
185 */
186 do_action( WP_2FA_PREFIX . 'white_labeling_settings_page_after_code_page' );
187 ?>
188 </tbody>
189 </table>
190 <?php
191 /**
192 * Fires after the white label settings tab is rendered.
193 *
194 * @since 2.0.0
195 */
196 do_action( WP_2FA_PREFIX . 'white_labeling_settings_page_after_default_text' );
197 }
198 }
199 }
200