PluginProbe ʕ •ᴥ•ʔ
WP 2FA – Two-factor authentication for WordPress / 2.5.0
WP 2FA – Two-factor authentication for WordPress v2.5.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 2 years ago class-settings-page-general.php 2 years ago class-settings-page-policies.php 2 years ago class-settings-page-render.php 2 years ago class-settings-page-white-label.php 2 years ago index.php 2 years ago
class-settings-page-render.php
192 lines
1 <?php
2 /**
3 * Settings page render class.
4 *
5 * @package wp2fa
6 * @subpackage views
7 * @copyright %%YEAR%% 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 $settings_tabs = array(
116 'generic-settings' => array(
117 'url' => esc_url(
118 add_query_arg(
119 array(
120 'page' => 'wp-2fa-settings',
121 'tab' => 'generic-settings',
122 ),
123 network_admin_url( 'admin.php' )
124 )
125 ),
126 'name' => esc_html__( 'General settings', 'wp-2fa' ),
127 'default' => true,
128 'description' => sprintf(
129 '<p class="description">%1$s <a href="mailto:support@melapress.com">%2$s</a></p>',
130 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' ),
131 esc_html__( 'support@melapress.com', 'wp-2fa' )
132 ),
133 'class' => 'WP2FA\Admin\SettingsPages\Settings_Page_General',
134 'method' => 'render',
135 'network_action' => 'update_wp2fa_network_options',
136 ),
137 'email-settings' => array(
138 'url' => esc_url(
139 add_query_arg(
140 array(
141 'page' => 'wp-2fa-settings',
142 'tab' => 'email-settings',
143 ),
144 network_admin_url( 'admin.php' )
145 )
146 ),
147 'name' => esc_html__( 'Emails & templates', 'wp-2fa' ),
148 'default' => false,
149 'description' => sprintf(
150 '<p class="description">%1$s <a href="mailto:support@melapress.com">%2$s</a></p>',
151 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' ),
152 esc_html__( 'support@melapress.com', 'wp-2fa' )
153 ),
154 'class' => 'WP2FA\Admin\SettingsPages\Settings_Page_Email',
155 'method' => 'render',
156 'network_action' => 'update_wp2fa_network_email_options',
157 ),
158 'white-label-settings' => array(
159 'url' => esc_url(
160 add_query_arg(
161 array(
162 'page' => 'wp-2fa-settings',
163 'tab' => 'white-label-settings',
164 ),
165 network_admin_url( 'admin.php' )
166 )
167 ),
168 'name' => esc_html__( 'White labeling', 'wp-2fa' ),
169 'default' => false,
170 'description' => sprintf(
171 '<p class="description">%1$s <a href="mailto:support@melapress.com">%2$s</a></p>',
172 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' ),
173 esc_html__( 'support@melapress.com', 'wp-2fa' )
174 ),
175 'class' => 'WP2FA\Admin\SettingsPages\Settings_Page_White_Label',
176 'method' => 'render',
177 'network_action' => 'update_wp2fa_network_options',
178 ),
179 );
180
181 /**
182 * Filter: `Settings tabs`
183 *
184 * Gives an option for third parties to alter the plugin settings page
185 *
186 * @param array $settings_tabs – Settings tabs.
187 */
188 return apply_filters( WP_2FA_PREFIX . 'settings_tabs', $settings_tabs );
189 }
190 }
191 }
192