PluginProbe ʕ •ᴥ•ʔ
WP 2FA – Two-factor authentication for WordPress / 2.8.0
WP 2FA – Two-factor authentication for WordPress v2.8.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-render.php
wp-2fa / includes / classes / Admin / SettingsPages Last commit date
class-settings-page-email.php 1 year ago class-settings-page-general.php 1 year ago class-settings-page-policies.php 1 year ago class-settings-page-render.php 1 year ago class-settings-page-white-label.php 1 year ago index.php 1 year ago
class-settings-page-render.php
193 lines
1 <?php
2 /**
3 * Settings page render class.
4 *
5 * @package wp2fa
6 * @subpackage views
7 * @copyright 2024 Melapress
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;
15 use WP2FA\Admin\Helpers\WP_Helper;
16
17 if ( ! class_exists( '\WP2FA\Admin\SettingsPages\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 $main_user = get_current_user_id();
34 $current_user_id = $main_user;
35
36 if ( ! empty( WP2FA::get_wp2fa_setting( '2fa_settings_last_updated_by' ) ) ) {
37 $main_user = (int) WP2FA::get_wp2fa_setting( '2fa_settings_last_updated_by' );
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 <br>
45 <?php if ( ! empty( WP2FA::get_wp2fa_general_setting( 'limit_access' ) ) && $main_user !== $current_user_id ) { ?>
46 <?php
47 echo \esc_html__( 'These settings have been disabled by your site administrator, please contact them for further assistance.', 'wp-2fa' );
48 ?>
49 <?php } else { ?>
50 <?php
51 /**
52 * Fires before the plugin settings rendering.
53 *
54 * @since 2.0.0
55 */
56 do_action( WP_2FA_PREFIX . 'before_plugin_settings' );
57 ?>
58 <div class="nav-tab-wrapper">
59 <?php
60 $settings = self::settings_array();
61
62 /**
63 * Stores the default settings key, so there is no need to walk the entire array again to extract that value
64 */
65 $default_settings_key = 'generic-settings';
66
67 foreach ( $settings as $setting_tab => $setting_values ) {
68 $active_class = '';
69 if ( ! isset( $_REQUEST['tab'] ) && $setting_values['default'] ) { // phpcs:ignore
70 $active_class = 'nav-tab-active';
71 $default_settings_key = $setting_tab;
72 } elseif ( isset( $_REQUEST['tab'] ) && $setting_tab === $_REQUEST['tab'] ) { // phpcs:ignore
73 $active_class = 'nav-tab-active';
74 }
75 echo '<a href="' . $setting_values['url'] . '" class="nav-tab ' . $active_class . '">' . $setting_values['name'] . '</a>'; // phpcs:ignore
76 }
77 ?>
78 </div>
79 <?php
80 $show_tab = $default_settings_key;
81
82 if ( isset( $_REQUEST['tab'] ) && array_key_exists( $_REQUEST['tab'], $settings ) ) { // phpcs:ignore
83 $show_tab = \sanitize_text_field( \wp_unslash( $_REQUEST['tab'] ) ); // phpcs:ignore
84 }
85
86 if ( WP_Helper::is_multisite() ) {
87 $action = 'edit.php?action=' . $settings[ $show_tab ]['network_action'];
88 } else {
89 $action = 'options.php';
90 }
91 ?>
92 <br/>
93 <?php
94 $settings[ $show_tab ]['description'];
95 ?>
96 <br/>
97 <form id="wp-2fa-admin-settings" action='<?php echo \esc_attr( $action ); ?>' method='post' autocomplete="off" >
98 <?php
99 \call_user_func( array( $settings[ $show_tab ]['class'], $settings[ $show_tab ]['method'] ) );
100 ?>
101 </form>
102 <?php } ?>
103 </div>
104 <?php
105 }
106
107 /**
108 * Holds the array with all the settings of the plugin. Fires filter, so third parties could change these settings.
109 *
110 * @return array
111 *
112 * @since 2.2.0
113 */
114 private static function settings_array(): array {
115 $email_settings_name = \esc_html__( 'Emails & templates', 'wp-2fa' );
116 $settings_tabs = array(
117 'generic-settings' => array(
118 'url' => \esc_url(
119 add_query_arg(
120 array(
121 'page' => 'wp-2fa-settings',
122 'tab' => 'generic-settings',
123 ),
124 network_admin_url( 'admin.php' )
125 )
126 ),
127 'name' => \esc_html__( 'General settings', 'wp-2fa' ),
128 'default' => true,
129 'description' => sprintf(
130 '<p class="description">%1$s <a href="mailto:support@melapress.com">%2$s</a></p>',
131 \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' ),
132 \esc_html__( 'support@melapress.com', 'wp-2fa' )
133 ),
134 'class' => 'WP2FA\Admin\SettingsPages\Settings_Page_General',
135 'method' => 'render',
136 'network_action' => 'update_wp2fa_network_options',
137 ),
138 'email-settings' => array(
139 'url' => \esc_url(
140 add_query_arg(
141 array(
142 'page' => 'wp-2fa-settings',
143 'tab' => 'email-settings',
144 ),
145 network_admin_url( 'admin.php' )
146 )
147 ),
148 'name' => $email_settings_name,
149 'default' => false,
150 'description' => sprintf(
151 '<p class="description">%1$s <a href="mailto:support@melapress.com">%2$s</a></p>',
152 \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' ),
153 \esc_html__( 'support@melapress.com', 'wp-2fa' )
154 ),
155 'class' => 'WP2FA\Admin\SettingsPages\Settings_Page_Email',
156 'method' => 'render',
157 'network_action' => 'update_wp2fa_network_email_options',
158 ),
159 'white-label-settings' => array(
160 'url' => \esc_url(
161 add_query_arg(
162 array(
163 'page' => 'wp-2fa-settings',
164 'tab' => 'white-label-settings',
165 ),
166 network_admin_url( 'admin.php' )
167 )
168 ),
169 'name' => \esc_html__( 'White labeling', 'wp-2fa' ),
170 'default' => false,
171 'description' => sprintf(
172 '<p class="description">%1$s <a href="mailto:support@melapress.com">%2$s</a></p>',
173 \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' ),
174 \esc_html__( 'support@melapress.com', 'wp-2fa' )
175 ),
176 'class' => 'WP2FA\Admin\SettingsPages\Settings_Page_White_Label',
177 'method' => 'render',
178 'network_action' => 'update_wp2fa_network_options',
179 ),
180 );
181
182 /**
183 * Filter: `Settings tabs`
184 *
185 * Gives an option for third parties to alter the plugin settings page
186 *
187 * @param array $settings_tabs – Settings tabs.
188 */
189 return \apply_filters( WP_2FA_PREFIX . 'settings_tabs', $settings_tabs );
190 }
191 }
192 }
193