PluginProbe ʕ •ᴥ•ʔ
WP 2FA – Two-factor authentication for WordPress / 2.4.2
WP 2FA – Two-factor authentication for WordPress v2.4.2
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-settings-page-render.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-settings-page-render.php
191 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
17 if ( ! class_exists( '\WP2FA\Admin\Views\Settings_Page_Render' ) ) {
18 /**
19 * Settings_Page_Render - Class for rendering the plugin settings settings
20 *
21 * @since 2.0.0
22 */
23 class Settings_Page_Render {
24
25 /**
26 * Render the settings
27 */
28 public static function render() {
29 if ( ! current_user_can( 'manage_options' ) ) {
30 return;
31 }
32
33 $user = wp_get_current_user();
34 if ( ! empty( WP2FA::get_wp2fa_setting( '2fa_settings_last_updated_by' ) ) ) {
35 $main_user = (int) WP2FA::get_wp2fa_setting( '2fa_settings_last_updated_by' );
36 } else {
37 $main_user = get_current_user_id();
38 }
39 ?>
40
41 <div class="wrap wp-2fa-settings-wrapper wp2fa-form-styles">
42 <h2><?php esc_html_e( 'WP 2FA Settings', 'wp-2fa' ); ?></h2>
43 <hr>
44 <?php if ( ! empty( WP2FA::get_wp2fa_general_setting( 'limit_access' ) ) && $main_user !== $user->ID ) { ?>
45 <?php
46 echo esc_html__( 'These settings have been disabled by your site administrator, please contact them for further assistance.', 'wp-2fa' );
47 ?>
48 <?php } else { ?>
49 <?php
50 /**
51 * Fires before the plugin settings rendering.
52 *
53 * @since 2.0.0
54 */
55 do_action( WP_2FA_PREFIX . 'before_plugin_settings' );
56 ?>
57 <div class="nav-tab-wrapper">
58 <?php
59 $settings = self::settings_array();
60
61 /**
62 * Stores the default settings key, so there is no need to walk the entire array again to extract that value
63 */
64 $default_settings_key = 'generic-settings';
65
66 foreach ( $settings as $setting_tab => $setting_values ) {
67 $active_class = '';
68 if ( ! isset( $_REQUEST['tab'] ) && $setting_values['default'] ) { // phpcs:ignore
69 $active_class = 'nav-tab-active';
70 $default_settings_key = $setting_tab;
71 } elseif ( isset( $_REQUEST['tab'] ) && $setting_tab === $_REQUEST['tab'] ) { // phpcs:ignore
72 $active_class = 'nav-tab-active';
73 }
74 echo '<a href="' . $setting_values['url'] . '" class="nav-tab ' . $active_class . '">' . $setting_values['name'] . '</a>'; // phpcs:ignore
75 }
76 ?>
77 </div>
78 <?php
79 $show_tab = $default_settings_key;
80
81 if ( isset( $_REQUEST['tab'] ) && array_key_exists( $_REQUEST['tab'], $settings ) ) { // phpcs:ignore
82 $show_tab = \sanitize_text_field( \wp_unslash( $_REQUEST['tab'] ) ); // phpcs:ignore
83 }
84
85 if ( WP_Helper::is_multisite() ) {
86 $action = 'edit.php?action=' . $settings[ $show_tab ]['network_action'];
87 } else {
88 $action = 'options.php';
89 }
90 ?>
91 <br/>
92 <?php
93 $settings[ $show_tab ]['description'];
94 ?>
95 <br/>
96 <form id="wp-2fa-admin-settings" action='<?php echo esc_attr( $action ); ?>' method='post' autocomplete="off" >
97 <?php
98 \call_user_func( array( $settings[ $show_tab ]['class'], $settings[ $show_tab ]['method'] ) );
99 ?>
100 </form>
101 <?php } ?>
102 </div>
103 <?php
104 }
105
106 /**
107 * Holds the array with all the settings of the plugin. Fires filter, so third parties could change these settings.
108 *
109 * @return array
110 *
111 * @since 2.2.0
112 */
113 private static function settings_array(): array {
114 $settings_tabs = array(
115 'generic-settings' => array(
116 'url' => esc_url(
117 add_query_arg(
118 array(
119 'page' => 'wp-2fa-settings',
120 'tab' => 'generic-settings',
121 ),
122 network_admin_url( 'admin.php' )
123 )
124 ),
125 'name' => esc_html__( 'General settings', 'wp-2fa' ),
126 'default' => true,
127 'description' => sprintf(
128 '<p class="description">%1$s <a href="mailto:support@wpwhitesecurity.com">%2$s</a></p>',
129 esc_html__( 'Use the settings below to configure the properties of the two-factor authentication on your website and how users use it. If you have any questions send us an email at', 'wp-2fa' ),
130 esc_html__( 'support@wpwhitesecurity.com', 'wp-2fa' )
131 ),
132 'class' => 'WP2FA\Admin\SettingsPages\Settings_Page_General',
133 'method' => 'render',
134 'network_action' => 'update_wp2fa_network_options',
135 ),
136 'email-settings' => array(
137 'url' => esc_url(
138 add_query_arg(
139 array(
140 'page' => 'wp-2fa-settings',
141 'tab' => 'email-settings',
142 ),
143 network_admin_url( 'admin.php' )
144 )
145 ),
146 'name' => esc_html__( 'Emails & templates', 'wp-2fa' ),
147 'default' => false,
148 'description' => sprintf(
149 '<p class="description">%1$s <a href="mailto:support@wpwhitesecurity.com">%2$s</a></p>',
150 esc_html__( 'Use the settings below to configure the properties of the two-factor authentication on your website and how users use it. If you have any questions send us an email at', 'wp-2fa' ),
151 esc_html__( 'support@wpwhitesecurity.com', 'wp-2fa' )
152 ),
153 'class' => 'WP2FA\Admin\SettingsPages\Settings_Page_Email',
154 'method' => 'render',
155 'network_action' => 'update_wp2fa_network_email_options',
156 ),
157 'white-label-settings' => array(
158 'url' => esc_url(
159 add_query_arg(
160 array(
161 'page' => 'wp-2fa-settings',
162 'tab' => 'white-label-settings',
163 ),
164 network_admin_url( 'admin.php' )
165 )
166 ),
167 'name' => esc_html__( 'White labeling', 'wp-2fa' ),
168 'default' => false,
169 'description' => sprintf(
170 '<p class="description">%1$s <a href="mailto:support@wpwhitesecurity.com">%2$s</a></p>',
171 esc_html__( 'Use the settings below to configure the emails which are sent to users as part of the 2FA plugin. If you have any questions send us an email at', 'wp-2fa' ),
172 esc_html__( 'support@wpwhitesecurity.com', 'wp-2fa' )
173 ),
174 'class' => 'WP2FA\Admin\SettingsPages\Settings_Page_White_Label',
175 'method' => 'render',
176 'network_action' => 'update_wp2fa_network_options',
177 ),
178 );
179
180 /**
181 * Filter: `Settings tabs`
182 *
183 * Gives an option for third parties to alter the plugin settings page
184 *
185 * @param array $settings_tabs – Settings tabs.
186 */
187 return apply_filters( WP_2FA_PREFIX . 'settings_tabs', $settings_tabs );
188 }
189 }
190 }
191