PluginProbe ʕ •ᴥ•ʔ
WP 2FA – Two-factor authentication for WordPress / 2.1.0
WP 2FA – Two-factor authentication for WordPress v2.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
185 lines
1 <?php
2 /**
3 * White label settings class.
4 *
5 * @package wp2fa
6 * @copyright 2021 WP White Security
7 * @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
8 * @link https://wordpress.org/plugins/wp-2fa/
9 */
10
11 namespace WP2FA\Admin\SettingsPages;
12
13 use \WP2FA\WP2FA as WP2FA;
14 use WP2FA\Utils\Debugging;
15
16 /**
17 * Settings_Page_White_Label - Class for handling settings
18 *
19 * @since 2.0.0
20 */
21 class Settings_Page_White_Label {
22
23 /**
24 * Render the settings
25 *
26 * @return void
27 *
28 * @since 2.0.0
29 */
30 public function render() {
31 settings_fields( WP_2FA_WHITE_LABEL_SETTINGS_NAME );
32 $this->change_default_text_area();
33 submit_button();
34 }
35
36 /**
37 * Validate options before saving
38 *
39 * @param array $input The settings array.
40 *
41 * @return array|void
42 *
43 * @since 2.0.0
44 */
45 public function validate_and_sanitize( $input ) {
46
47 // Bail if user doesn't have permissions to be here.
48 if ( ! current_user_can( 'manage_options' ) || ! isset( $_POST['action'] ) && ! check_admin_referer( 'wp2fa-step-choose-method' ) ) {
49 return;
50 }
51
52 $output['default-text-code-page'] = WP2FA::get_wp2fa_setting( 'default-text-code-page', false, true );
53
54 if ( isset( $input['default-text-code-page'] ) && '' !== trim( $input['default-text-code-page'] ) ) {
55 $output['default-text-code-page'] = \wp_strip_all_tags( $input['default-text-code-page'] );
56 }
57
58 $output['default-backup-code-page'] = WP2FA::get_wp2fa_setting( 'default-backup-code-page', false, true );
59
60 if ( isset( $input['default-backup-code-page'] ) && '' !== trim( $input['default-backup-code-page'] ) ) {
61 $output['default-backup-code-page'] = \wp_strip_all_tags( $input['default-backup-code-page'] );
62 }
63
64 // 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.
65 global $wp_settings_errors;
66 if ( isset( $wp_settings_errors ) ) {
67 $errors = array_map( 'unserialize', array_unique( array_map( 'serialize', $wp_settings_errors ) ) );
68 $wp_settings_errors = $errors; // @codingStandardsIgnoreLine WP $wp_settings_errors assignment
69 }
70
71 $log_content = __( 'Settings saving processes complete', 'wp-2fa' );
72 Debugging::log( $log_content );
73
74 /**
75 * Filter the values we are about to store in the plugin settings.
76 *
77 * @param array $output - The output array with all the data we will store in the settings.
78 * @param array $input - The input array with all the data we received from the user.
79 *
80 * @since 2.0.0
81 */
82 $output = apply_filters( 'wp_2fa_filter_output_content', $output, $input );
83
84 return $output;
85 }
86
87 /**
88 * Updates global white label network options
89 *
90 * @return void
91 *
92 * @since 2.0.0
93 *
94 * @SuppressWarnings(PHPMD.ExitExpressions)
95 */
96 public function update_wp2fa_network_options() {
97
98 if ( isset( $_POST[ WP_2FA_WHITE_LABEL_SETTINGS_NAME ] ) ) {
99 check_admin_referer( 'wp_2fa_white_label-options' );
100 $options = $this->validate_and_sanitize( wp_unslash( $_POST[ WP_2FA_WHITE_LABEL_SETTINGS_NAME ] ) ); // @codingStandardsIgnoreLine - Not sanitized warning
101 $settings_errors = get_settings_errors( WP_2FA_WHITE_LABEL_SETTINGS_NAME );
102 if ( ! empty( $settings_errors ) ) {
103
104 // redirect back to our options page.
105 wp_safe_redirect(
106 add_query_arg(
107 array(
108 'page' => 'wp-2fa-settings',
109 'wp_2fa_network_settings_error' => urlencode_deep( $settings_errors[0]['message'] ),
110 ),
111 network_admin_url( 'settings.php' )
112 )
113 );
114 exit;
115
116 }
117 WP2FA::updatePluginSettings( $options, false, WP_2FA_WHITE_LABEL_SETTINGS_NAME );
118
119 // redirect back to our options page.
120 wp_safe_redirect(
121 add_query_arg(
122 array(
123 'page' => 'wp-2fa-settings',
124 'tab' => 'white-label-settings',
125 'wp_2fa_network_settings_updated' => 'true',
126 ),
127 network_admin_url( 'admin.php' )
128 )
129 );
130 exit;
131 }
132 }
133
134 /**
135 * Shows default settings input to the user
136 *
137 * @return void
138 *
139 * @since 2.0.0
140 */
141 private function change_default_text_area() {
142 do_action( WP_2FA_PREFIX . 'white_labeling_settings_page_before_default_text' );
143 ?>
144 <h3><?php esc_html_e( 'Change the default text used in the 2FA code page?', 'wp-2fa' ); ?></h3>
145 <p class="description">
146 <?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' ); ?>
147 </p>
148 <table class="form-table">
149 <tbody>
150 <tr>
151 <th><label for="2fa-method"><?php esc_html_e( '2FA code page text', 'wp-2fa' ); ?></label></th>
152 <td>
153 <fieldset>
154 <label for="default-text-code-page">
155 <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>
156 <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>
157 </label>
158 </fieldset>
159 </td>
160 </tr>
161 <tr>
162 <th><label for="backup-method"><?php esc_html_e( 'Backup code page text', 'wp-2fa' ); ?></label></th>
163 <td>
164 <fieldset>
165 <label for="default-backup-code-page">
166 <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>
167 <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>
168 </label>
169 </fieldset>
170 </td>
171 </tr>
172 <?php
173 /**
174 * Gives the ability for the 3rd party extensions to add additional white label settings
175 */
176 do_action( WP_2FA_PREFIX . 'white_labeling_settings_page_after_code_page' );
177 ?>
178 </tbody>
179 </table>
180 <?php
181
182 do_action( WP_2FA_PREFIX . 'white_labeling_settings_page_after_default_text' );
183 }
184 }
185