PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 3.16.6
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v3.16.6
4.0.2 4.0.1 4.0.0 3.16.6 3.16.5 3.16.4 3.16.3 3.16.2 3.16.1 3.16.0 3.15.9 3.9.9 3.9.5 3.9.6 3.9.7 3.9.8 1.1.7 1.1.8 1.1.9 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 All 340 releases
profile-builder / admin / general-settings.php

general-settings.php in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 3.16.6, at admin/general-settings.php

1,129 lines 75.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3 /**
4 * Function that returns an array with the settings tabs(pages) and secondary tabs( can be sub-pages (we load a registered page as a secondary tab) or actual sub-tabs )
5 * @return array with the tabs
6 */
7 function wppb_get_settings_pages(){
8 $wppb_module_settings = get_option('wppb_module_settings');
9
10 $settings_pages['pages'] = array(
11 'profile-builder-general-settings' => __( 'General Settings', 'profile-builder' ),
12 'profile-builder-content_restriction' => __( 'Content Restriction', 'profile-builder' ),
13 'profile-builder-private-website' => __( 'Private Website', 'profile-builder' ),
14 'profile-builder-toolbox-settings' => __( 'Advanced Settings', 'profile-builder' ),
15 );
16
17 //add tabs here for Advanced Settings
18 $settings_pages['sub-tabs']['profile-builder-toolbox-settings']['forms'] = __( 'Forms', 'profile-builder' );
19 $settings_pages['sub-tabs']['profile-builder-toolbox-settings']['fields'] = __( 'Fields', 'profile-builder' );
20
21 if ( defined( 'WPPB_PAID_PLUGIN_DIR' ) && file_exists( WPPB_PAID_PLUGIN_DIR . '/add-ons/add-ons.php' ) && isset( $wppb_module_settings['wppb_userListing'] ) && $wppb_module_settings['wppb_userListing'] === 'show' )
22 $settings_pages['sub-tabs']['profile-builder-toolbox-settings']['userlisting'] = __( 'Userlisting', 'profile-builder' );
23
24 $settings_pages['sub-tabs']['profile-builder-toolbox-settings']['shortcodes'] = __( 'Shortcodes', 'profile-builder' );
25 $settings_pages['sub-tabs']['profile-builder-toolbox-settings']['admin'] = __( 'Admin', 'profile-builder' );
26
27 //add sub-pages here for email customizer
28 if( file_exists( WPPB_PLUGIN_DIR . '/features/email-customizer/email-customizer.php' ) ){
29
30 $settings_pages['pages']['user-email-customizer'] = __( 'Email Customizer', 'profile-builder' );
31 $settings_pages['sub-pages']['user-email-customizer']['user-email-customizer'] = __( 'User Emails', 'profile-builder' );
32 $settings_pages['sub-pages']['user-email-customizer']['admin-email-customizer'] = __( 'Administrator Emails', 'profile-builder' );
33
34 } else if ( defined( 'WPPB_PAID_PLUGIN_DIR' ) && file_exists( WPPB_PAID_PLUGIN_DIR . '/add-ons/add-ons.php' ) ) {
35 if( ( isset($wppb_module_settings['wppb_emailCustomizerAdmin']) && $wppb_module_settings['wppb_emailCustomizerAdmin'] == 'show' ) || ( isset($wppb_module_settings['wppb_emailCustomizer']) && $wppb_module_settings['wppb_emailCustomizer'] == 'show') ){
36 $settings_pages['pages']['user-email-customizer'] = __( 'Email Customizer', 'profile-builder' );
37 $settings_pages['sub-pages']['user-email-customizer']['user-email-customizer'] = __( 'User Emails', 'profile-builder' );
38 $settings_pages['sub-pages']['user-email-customizer']['admin-email-customizer'] = __( 'Administrator Emails', 'profile-builder' );
39 }
40 }
41
42 return $settings_pages;
43 }
44
45 /**
46 * Function that generates the html for the tabs and subtabs on the settings page
47 */
48 function wppb_generate_settings_tabs(){
49 ?>
50 <nav class="nav-tab-wrapper cozmoslabs-nav-tab-wrapper">
51 <?php
52 $pages = wppb_get_settings_pages();
53
54 $active_tab = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
55 //if we are on a subpage we need to change the active tab to the parent
56 if( !empty( $pages['sub-pages'] ) ) {
57 foreach ($pages['sub-pages'] as $parent_slug => $subpages) {
58 if (array_key_exists($active_tab, $subpages)) {
59 $active_tab = $parent_slug;
60 }
61 }
62 }
63
64 foreach( $pages['pages'] as $page_slug => $tab_name ){
65 echo '<a href="' . esc_url( admin_url( add_query_arg( array( 'page' => $page_slug ), 'admin.php' ) ) ) . '" class="nav-tab ' . ( $active_tab == $page_slug ? 'nav-tab-active' : '' ) . '">'. esc_html( $tab_name ) .'</a>';
66 }
67 ?>
68 </nav>
69 <?php
70
71 // this is not always the same as the active tab
72 $active_subpage = sanitize_text_field($_GET['page']);
73
74 if( !empty( $pages['sub-pages'] ) ) {
75 foreach ($pages['sub-pages'] as $parent_slug => $subpages) {
76 if (array_key_exists( sanitize_text_field( $active_subpage ), $subpages)) {
77 echo '<ul class="wppb-subtabs subsubsub cozmoslabs-nav-sub-tab-wrapper">';
78 foreach ($subpages as $subpage_slug => $subpage_name) {
79 echo '<li><a href="' . esc_url( admin_url( add_query_arg(array('page' => $subpage_slug), 'admin.php') ) ) . '" class="nav-sub-tab ' . ($active_subpage == $subpage_slug ? 'current' : '') . '">' . esc_html( $subpage_name ) . '</a></li>';
80 }
81 echo '</ul>';
82 }
83 }
84 }
85
86 if( !empty( $pages['sub-tabs'] ) ) {
87 foreach ($pages['sub-tabs'] as $parent_slug => $tabs) {
88 if ( $active_subpage == $parent_slug) {
89 echo '<ul class="wppb-subtabs subsubsub cozmoslabs-nav-sub-tab-wrapper">';
90 //determine the active tab, if no tab present then default to the first one
91 if( isset($_GET['tab']) )
92 $active_tab = sanitize_text_field( $_GET['tab'] );
93 else {
94 $keys = array_keys($tabs);
95 $active_tab = array_shift( $keys );
96 }
97 foreach ($tabs as $tab_slug => $tab_name) {
98 echo '<li><a href="' . esc_url( add_query_arg( array('tab' => $tab_slug) ) ) . '" class="nav-sub-tab ' . ( $active_tab == $tab_slug ? 'current' : '') . '">' . esc_html( $tab_name ) . '</a></li>';
99 }
100 echo '</ul>';
101 }
102 }
103 }
104 }
105
106 /**
107 * Function that creates the "General Settings" submenu page
108 *
109 * @since v.2.0
110 *
111 * @return void
112 */
113 function wppb_register_general_settings_submenu_page() {
114 add_submenu_page( 'profile-builder', __( 'Settings', 'profile-builder' ), __( 'Settings', 'profile-builder' ), 'manage_options', 'profile-builder-general-settings', 'wppb_general_settings_content' );
115 }
116 add_action( 'admin_menu', 'wppb_register_general_settings_submenu_page', 3 );
117
118
119 function wppb_generate_default_settings_defaults(){
120 add_option( 'wppb_general_settings', array( 'extraFieldsLayout' => 'default', 'automaticallyLogIn' => 'No', 'emailConfirmation' => 'no', 'activationLandingPage' => '', 'adminApproval' => 'no', 'loginWith' => 'usernameemail', 'rolesEditor' => 'no', 'conditional_fields_ajax' => 'no', 'formsDesign' => 'form-style-default', 'hide_admin_bar_for' => '' ) );
121 }
122
123
124 /**
125 * Function that adds content to the "General Settings" submenu page
126 *
127 * @since v.2.0
128 *
129 * @return string
130 */
131 function wppb_general_settings_content() {
132 wppb_generate_default_settings_defaults();
133 ?>
134 <div class="wrap wppb-wrap cozmoslabs-wrap">
135
136 <h1></h1>
137 <!-- WordPress Notices are added after the h1 tag -->
138
139 <div class="cozmoslabs-page-header">
140 <div class="cozmoslabs-section-title">
141
142 <h2 class="cozmoslabs-page-title">
143 <?php esc_html_e( 'Profile Builder Settings', 'profile-builder' ); ?>
144 <a href="https://www.cozmoslabs.com/docs/profile-builder/general-settings/?utm_source=wpbackend&utm_medium=pb-documentation&utm_campaign=PBDocs" target="_blank" data-code="f223" class="wppb-docs-link dashicons dashicons-editor-help"></a>
145 </h2>
146
147 </div>
148 </div>
149
150 <?php settings_errors(); ?>
151
152 <?php wppb_generate_settings_tabs(); ?>
153
154 <?php wppb_load_necessary_scripts(); ?>
155
156 <div class="cozmoslabs-settings-container">
157
158 <?php if ( !is_multisite() && defined( 'WPPB_PAID_PLUGIN_DIR' ) && defined( 'PROFILE_BUILDER_PAID_VERSION' ) ) : ?>
159 <div class="cozmoslabs-form-subsection-wrapper" id="wppb-register-version">
160 <?php wppb_add_register_version_form(); ?>
161 </div>
162 <?php endif; ?>
163
164 <form method="post" action="options.php#general-settings">
165 <?php $wppb_generalSettings = get_option( 'wppb_general_settings' ); ?>
166 <?php settings_fields( 'wppb_general_settings' ); ?>
167
168 <div class="cozmoslabs-settings">
169
170 <div class="cozmoslabs-form-subsection-wrapper" id="wppb-form_desings">
171 <h4 class="cozmoslabs-subsection-title"><?php esc_html_e( 'Design & User Experience', 'profile-builder' ); ?></h4>
172 <p class="cozmoslabs-description" style="margin-bottom: 5px;"><?php esc_html_e( 'Choose a style that better suits your website.', 'profile-builder' ); ?></p>
173 <p class="cozmoslabs-description"><?php esc_html_e( 'The default style is there to let you customize the CSS and in general will receive the look and feel from your own theme’s styling.', 'profile-builder' ); ?></p>
174
175 <div class="cozmoslabs-form-field-wrapper">
176 <?php
177 if ( defined( 'WPPB_PAID_PLUGIN_DIR' ) && file_exists( WPPB_PAID_PLUGIN_DIR.'/features/form-designs/form-designs.php' ) ) {
178 echo wppb_render_forms_design_selector(); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
179 }
180 elseif ( PROFILE_BUILDER == 'Profile Builder Free' ) {
181 echo wppb_display_form_designs_preview(); //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
182 }
183 ?>
184 </div>
185 </div>
186
187 <div class="cozmoslabs-form-subsection-wrapper">
188 <h4 class="cozmoslabs-subsection-title"><?php esc_html_e( 'Optimize The login and Registration flow for your members', 'profile-builder' ); ?></h4>
189
190 <div class="cozmoslabs-form-field-wrapper cozmoslabs-toggle-switch">
191 <label class="cozmoslabs-form-field-label" for="wppb_settings_automatically_log_in"><?php esc_html_e('Automatically Log In', 'profile-builder'); ?></label>
192
193 <div class="cozmoslabs-toggle-container">
194 <input type="checkbox" name="wppb_general_settings[automaticallyLogIn]" id="wppb_settings_automatically_log_in" value="Yes" <?php echo (!empty($wppb_generalSettings['automaticallyLogIn']) && $wppb_generalSettings['automaticallyLogIn'] === 'Yes') ? 'checked' : ''; ?> >
195 <label class="cozmoslabs-toggle-track" for="wppb_settings_automatically_log_in"></label>
196 </div>
197
198 <div class="cozmoslabs-toggle-description">
199 <label for="wppb_settings_automatically_log_in" class="cozmoslabs-description"><?php esc_html_e( 'Enable to automatically log in new users after successful registration.', 'profile-builder' ); ?></label>
200 </div>
201 </div>
202
203 <div class="cozmoslabs-form-field-wrapper cozmoslabs-toggle-switch">
204 <label class="cozmoslabs-form-field-label" for="wppb_settings_email_confirmation"><?php esc_html_e('Email Confirmation', 'profile-builder'); ?></label>
205
206
207 <div class="cozmoslabs-toggle-container">
208
209 <input type="checkbox" name="wppb_general_settings[emailConfirmation]" id="wppb_settings_email_confirmation" value="yes" <?php echo (!empty($wppb_generalSettings['emailConfirmation']) && $wppb_generalSettings['emailConfirmation'] === 'yes') ? 'checked' : ''; ?> >
210 <label class="cozmoslabs-toggle-track" for="wppb_settings_email_confirmation"></label>
211
212 </div>
213 <div class="cozmoslabs-toggle-description">
214 <label for="wppb_settings_email_confirmation" class="cozmoslabs-description"><?php esc_html_e( 'This works with front-end forms only. Recommended to redirect WP default registration to a Profile Builder one using "Custom Redirects" module.', 'profile-builder' ); ?></label>
215 </div>
216
217 <p class="cozmoslabs-description cozmoslabs-description-space-left" id="unconfirmed-user-emails"><?php printf( esc_html__( 'You can find a list of unconfirmed email addresses %1$sUsers > All Users > Email Confirmation%2$s.', 'profile-builder' ), '<a href="'. esc_url( get_bloginfo( 'url' ) ).'/wp-admin/users.php?page=unconfirmed_emails">', '</a>' )?></p>
218 </div>
219
220 <div class="cozmoslabs-form-field-wrapper" id="wppb-settings-activation-page">
221 <label class="cozmoslabs-form-field-label" for="wppb_settings_email_confirmation_page"><?php esc_html_e('Email Confirmation Page', 'profile-builder'); ?></label>
222
223 <select name="wppb_general_settings[activationLandingPage]" class="wppb-select" id="wppb_settings_email_confirmation_page">
224 <option value="" <?php if ( empty( $wppb_generalSettings['emailConfirmation'] ) ) echo 'selected'; ?>></option>
225 <optgroup label="<?php esc_html_e( 'Existing Pages', 'profile-builder' ); ?>">
226 <?php
227 $pages = get_pages( apply_filters( 'wppb_page_args_filter', array( 'sort_order' => 'ASC', 'sort_column' => 'post_title', 'post_type' => 'page', 'post_status' => array( 'publish' ) ) ) );
228
229 foreach ( $pages as $key => $value ){
230 echo '<option value="'.esc_attr( $value->ID ).'"';
231 if ( $wppb_generalSettings['activationLandingPage'] == $value->ID )
232 echo ' selected';
233
234 echo '>' . esc_html( $value->post_title ) . '</option>';
235 }
236 ?>
237 </optgroup>
238 </select>
239
240 <p class="cozmoslabs-description cozmoslabs-description-space-left"><?php esc_html_e( 'Specify the page where the users will be directed when confirming the email account. This page can differ from the register page(s) and can be changed at any time.', 'profile-builder' ); ?></p>
241 </div>
242
243 <?php
244 if ( PROFILE_BUILDER == 'Profile Builder Free' ) {
245 ?>
246
247 <div class="cozmoslabs-form-field-wrapper cozmoslabs-toggle-switch">
248 <label class="cozmoslabs-form-field-label"><?php esc_html_e('Admin Approval', 'profile-builder'); ?></label>
249
250 <p class="cozmoslabs-description cozmoslabs-description-align-right cozmoslabs-description-upsell">
251 <?php echo esc_html__( 'You decide who is a user on your website. Get notified via email or approve multiple users at once from the WordPress UI.', 'profile-builder' ); ?><br>
252 <?php printf( esc_html__( 'Enable Admin Approval by upgrading to %1$sBasic or PRO versions%2$s.', 'profile-builder' ),'<a href="https://www.cozmoslabs.com/wordpress-profile-builder/?utm_source=pb-general-settings&utm_medium=client-site&utm_campaign=pb-admin-approval#pricing">', '</a>' )?>
253 </p>
254 </div>
255
256 <?php } ?>
257
258
259 <?php
260 if ( defined( 'WPPB_PAID_PLUGIN_DIR' ) && file_exists( WPPB_PAID_PLUGIN_DIR.'/features/admin-approval/admin-approval.php' ) ){
261 ?>
262
263 <div class="cozmoslabs-form-field-wrapper cozmoslabs-toggle-switch">
264 <label class="cozmoslabs-form-field-label" for="adminApprovalSelect"><?php esc_html_e('Admin Approval', 'profile-builder'); ?></label>
265
266 <div class="cozmoslabs-toggle-container">
267 <input type="checkbox" name="wppb_general_settings[adminApproval]" id="adminApprovalSelect" value="yes" <?php echo (!empty($wppb_generalSettings['adminApproval']) && $wppb_generalSettings['adminApproval'] === 'yes') ? 'checked' : ''; ?> >
268 <label class="cozmoslabs-toggle-track" for="adminApprovalSelect"></label>
269 </div>
270
271 <div class="cozmoslabs-toggle-description">
272 <label for="adminApprovalSelect" class="cozmoslabs-description wppb-aa-details"><?php esc_html_e( 'Each user that registers on the website will be given a Pending status and will need to be approved or unapproved by the admin before he/she can login.', 'profile-builder' ); ?></label>
273 </div>
274
275 <p class="cozmoslabs-description cozmoslabs-description-space-left wppb-aa-user-list"><?php printf( esc_html__( 'You can find a list of users at %1$sUsers > All Users > Admin Approval%2$s.', 'profile-builder' ), '<a href="'. esc_url( get_bloginfo( 'url' ) ).'/wp-admin/users.php?page=admin_approval&orderby=registered&order=desc">', '</a>' )?></p>
276 </div>
277
278 <div class="cozmoslabs-form-field-wrapper wppb-aa-user-list">
279 <label class="cozmoslabs-form-field-label" for="adminApprovalOnUserRoleSelect"><?php esc_html_e('Admin Approval User Role', 'profile-builder'); ?></label>
280
281 <select name="wppb_general_settings[adminApprovalOnUserRole][]" class="wppb-select wppb-select2" multiple>
282 <?php
283 $wppb_userRoles = wppb_adminApproval_onUserRole();
284
285 if( ! empty( $wppb_userRoles ) ) {
286 foreach( $wppb_userRoles as $role => $role_name ) {
287
288 echo '<option value="' . esc_attr( $role ) . '"' . (( !empty( $wppb_generalSettings['adminApprovalOnUserRole'] ) && in_array( $role, $wppb_generalSettings['adminApprovalOnUserRole'] ) ) || empty( $wppb_generalSettings['adminApprovalOnUserRole']) ? ' selected' : '') . '>' . esc_html( $role_name ) . '</option>';
289
290 }
291 }
292 ?>
293 </select>
294 </div>
295
296 <?php } ?>
297
298 <div class="cozmoslabs-form-field-wrapper">
299 <label class="cozmoslabs-form-field-label" for="loginWithSelect"><?php esc_html_e( 'Allow Users to Log in With:', 'profile-builder' ); ?></label>
300
301 <select name="wppb_general_settings[loginWith]" class="wppb-select" id="loginWithSelect">
302 <option value="usernameemail" <?php if ( $wppb_generalSettings['loginWith'] == 'usernameemail' ) echo 'selected'; ?>><?php esc_html_e( 'Username and Email', 'profile-builder' ); ?></option>
303 <option value="username" <?php if ( $wppb_generalSettings['loginWith'] == 'username' ) echo 'selected'; ?>><?php esc_html_e( 'Username', 'profile-builder' ); ?></option>
304 <option value="email" <?php if ( $wppb_generalSettings['loginWith'] == 'email' ) echo 'selected'; ?>><?php esc_html_e( 'Email', 'profile-builder' ); ?></option>
305 </select>
306
307 <p class="cozmoslabs-description cozmoslabs-description-space-left"><?php esc_html_e( 'Choose what the user will be logging in with.', 'profile-builder' ); ?></p>
308 </div>
309
310 </div>
311
312 <div class="cozmoslabs-form-subsection-wrapper">
313 <h4 class="cozmoslabs-subsection-title"><?php esc_html_e( 'Security', 'profile-builder' ); ?></h4>
314
315 <div class="cozmoslabs-form-field-wrapper">
316 <label class="cozmoslabs-form-field-label" for="minimumPasswordLength"><?php esc_html_e( 'Minimum Password Length', 'profile-builder' ); ?></label>
317 <input type="text" name="wppb_general_settings[minimum_password_length]" class="wppb-text" id="minimumPasswordLength" value="<?php if( !empty( $wppb_generalSettings['minimum_password_length'] ) ) echo esc_attr( $wppb_generalSettings['minimum_password_length'] ); ?>"/>
318
319 <p class="cozmoslabs-description cozmoslabs-description-space-left"><?php esc_html_e( 'Enter the minimum characters the password should have. Leave empty for no minimum limit', 'profile-builder' ); ?></p>
320 </div>
321
322
323 <div class="cozmoslabs-form-field-wrapper">
324 <label class="cozmoslabs-form-field-label" for="minimumPasswordStrength"><?php esc_html_e( 'Minimum Password Strength', 'profile-builder' ); ?></label>
325
326 <select name="wppb_general_settings[minimum_password_strength]" class="wppb-select" id="minimumPasswordStrength">
327 <option value=""><?php esc_html_e( 'Disabled', 'profile-builder' ); ?></option>
328 <option value="short" <?php if ( !empty($wppb_generalSettings['minimum_password_strength']) && $wppb_generalSettings['minimum_password_strength'] == 'short' ) echo 'selected'; ?>><?php esc_html_e( 'Very weak', 'profile-builder' ); ?></option>
329 <option value="bad" <?php if ( !empty($wppb_generalSettings['minimum_password_strength']) && $wppb_generalSettings['minimum_password_strength'] == 'bad' ) echo 'selected'; ?>><?php esc_html_e( 'Weak', 'profile-builder' ); ?></option>
330 <option value="good" <?php if ( !empty($wppb_generalSettings['minimum_password_strength']) && $wppb_generalSettings['minimum_password_strength'] == 'good' ) echo 'selected'; ?>><?php esc_html_e( 'Medium', 'profile-builder' ); ?></option>
331 <option value="strong" <?php if ( !empty($wppb_generalSettings['minimum_password_strength']) && $wppb_generalSettings['minimum_password_strength'] == 'strong' ) echo 'selected'; ?>><?php esc_html_e( 'Strong', 'profile-builder' ); ?></option>
332 </select>
333
334 <p class="cozmoslabs-description cozmoslabs-description-space-left"><?php esc_html_e( 'A stronger password strength will probably force the user to not reuse passwords from other websites.', 'profile-builder' ); ?></p>
335 </div>
336
337
338 <div class="cozmoslabs-form-field-wrapper">
339 <label class="cozmoslabs-form-field-label" for="lostPasswordPage"><?php esc_html_e( 'Password Recovery Page', 'profile-builder' ); ?></label>
340
341 <select name="wppb_general_settings[lost_password_page]" class="wppb-select" id="lostPasswordPage">
342 <option value=""> <?php esc_html_e( 'None', 'profile-builder' ); ?></option>
343 <?php
344 $args = array(
345 'post_type' => 'page',
346 'post_status' => 'publish',
347 'numberposts' => -1,
348 'orderby' => 'name',
349 'order' => 'ASC'
350 );
351 $pages = get_posts( $args );
352
353 foreach ( $pages as $key => $value ){
354 echo '<option value="'.esc_attr( $value->guid ).'"';
355 if ( isset( $wppb_generalSettings['lost_password_page'] ) && $wppb_generalSettings['lost_password_page'] == $value->guid )
356 echo ' selected';
357
358 echo '>' . esc_html( $value->post_title ) . '</option>';
359 }
360 ?>
361 </select>
362
363 <p class="cozmoslabs-description cozmoslabs-description-space-left"><?php esc_html_e( 'Select the page which contains the "[wppb-recover-password]" shortcode.', 'profile-builder' ); ?></p>
364 </div>
365 </div>
366
367 <div class="cozmoslabs-form-subsection-wrapper">
368 <h4 class="cozmoslabs-subsection-title"><?php esc_html_e( 'Two-Factor Authentication', 'profile-builder' ); ?></h4>
369
370 <?php if( defined( 'WPPB_PAID_PLUGIN_DIR' ) && file_exists( WPPB_PAID_PLUGIN_DIR . '/features/two-factor-authentication/class-two-factor-authentication.php' ) ) : ?>
371
372 <div class="cozmoslabs-form-field-wrapper cozmoslabs-toggle-switch">
373 <?php
374 $wppb_two_factor_authentication_settings = get_option( 'wppb_two_factor_authentication_settings', 'not_found' );
375
376 $enabled = 'no';
377 if ( $wppb_two_factor_authentication_settings !== 'not_found' && is_array( $wppb_two_factor_authentication_settings ) && isset( $wppb_two_factor_authentication_settings['enabled'] ) ) {
378 $enabled = $wppb_two_factor_authentication_settings['enabled'];
379 }
380 ?>
381
382 <label class="cozmoslabs-form-field-label" for="wppb-auth-enable"><?php esc_html_e('Two-Factor Authentication', 'profile-builder'); ?></label>
383
384 <div class="cozmoslabs-toggle-container">
385 <input type="checkbox" name="wppb_two_factor_authentication_settings[enabled]" id="wppb-auth-enable" value="yes" <?php echo ($enabled === 'yes') ? 'checked' : ''; ?> >
386 <label class="cozmoslabs-toggle-track" for="wppb-auth-enable"></label>
387 </div>
388
389 <?php
390 $current_user = wp_get_current_user();
391 ?>
392
393 <script type="text/javascript">
394 jQuery(document).ready(function($) {
395 // Handle 2FA enable toggle
396 $('#wppb-auth-enable').on('change', function() {
397 if ($(this).is(':checked')) {
398 $('#wppb-auth-roles-selector').show();
399 $('#wppb-force-2fa-enable').closest('.cozmoslabs-form-field-wrapper').show();
400 $('#wppb-2fa-require-totp-profile-edit').show();
401 if ($('#wppb-force-2fa-enable').is(':checked')) {
402 $('#wppb-force-2fa-roles-selector').show();
403 $('#wppb-force-2fa-grace-period').show();
404 $('#wppb-force-2fa-edit-profile-page-selector').show();
405
406 }
407 } else {
408 $('#wppb-auth-roles-selector').hide();
409 $('#wppb-force-2fa-enable').closest('.cozmoslabs-form-field-wrapper').hide();
410 $('#wppb-force-2fa-roles-selector').hide();
411 $('#wppb-force-2fa-grace-period').hide();
412 $('#wppb-force-2fa-edit-profile-page-selector').hide();
413
414 $('#wppb-2fa-require-totp-profile-edit').hide();
415 }
416 });
417
418 // Handle force 2FA enable toggle
419 $('#wppb-force-2fa-enable').on('change', function() {
420 if ($(this).is(':checked')) {
421 $('#wppb-force-2fa-roles-selector').show();
422 $('#wppb-force-2fa-grace-period').show();
423 $('#wppb-force-2fa-edit-profile-page-selector').show();
424
425 } else {
426 $('#wppb-force-2fa-roles-selector').hide();
427 $('#wppb-force-2fa-grace-period').hide();
428 $('#wppb-force-2fa-edit-profile-page-selector').hide();
429
430 }
431 });
432
433 // Handle changes to "Enable Authenticator For" roles
434 $('#wppb-auth-enable-roles').on('change', function() {
435 updateForce2FARolesDropdown();
436 });
437
438 // Function to update the Force 2FA roles dropdown based on enabled roles
439 function updateForce2FARolesDropdown() {
440 var enabledRoles = $('#wppb-auth-enable-roles').val() || [];
441 var force2FARolesSelect = $('#wppb-force-2fa-roles');
442 var currentlySelected = force2FARolesSelect.val() || [];
443
444 // Clear current options
445 force2FARolesSelect.empty();
446
447 // Get all available roles from the original select
448 var allRoleOptions = $('#wppb-auth-enable-roles option');
449
450 // If '*' (all roles) is selected, show all roles
451 if (enabledRoles.indexOf('*') !== -1) {
452 allRoleOptions.each(function() {
453 var roleValue = $(this).val();
454 if (roleValue !== '*') { // Skip the "ALL ROLES" option
455 var option = $('<option></option>')
456 .attr('value', roleValue)
457 .text($(this).text());
458 if (currentlySelected.indexOf(roleValue) !== -1) {
459 option.prop('selected', true);
460 }
461 force2FARolesSelect.append(option);
462 }
463 });
464 } else {
465 // Only show roles that are specifically enabled for 2FA
466 enabledRoles.forEach(function(roleKey) {
467 allRoleOptions.each(function() {
468 if ($(this).val() === roleKey) {
469 var option = $('<option></option>')
470 .attr('value', roleKey)
471 .text($(this).text());
472 if (currentlySelected.indexOf(roleKey) !== -1) {
473 option.prop('selected', true);
474 }
475 force2FARolesSelect.append(option);
476 }
477 });
478 });
479 }
480
481 // Trigger select2 update
482 force2FARolesSelect.trigger('change');
483 }
484
485 // Initial state
486 $('#wppb-auth-enable').trigger('change');
487 updateForce2FARolesDropdown();
488
489 // Force 2FA Confirmation Logic
490 var currentUserRoles = <?php echo json_encode( $current_user->roles ); ?>;
491 var currentUser2FAEnabled = <?php echo ( get_user_option( 'wppb_auth_enabled', $current_user->ID ) === 'enabled' ) ? 'true' : 'false'; ?>;
492
493 // Store initial state
494 var initialForce2FAEnabled = $('#wppb-force-2fa-enable').is(':checked');
495 var initialMain2FAEnabled = $('#wppb-auth-enable').is(':checked');
496 var initialSelectedRoles = $('#wppb-force-2fa-roles').val() || [];
497 initialSelectedRoles.sort();
498
499 // Create Modal
500 $('body').append(
501 '<div id="wppb-force-2fa-modal" style="display:none; position:fixed; z-index:10000; left:0; top:0; width:100%; height:100%; overflow:auto; background-color:rgba(0,0,0,0.4);">' +
502 '<div style="background-color:#fefefe; margin:15% auto; padding:20px; border:1px solid #888; width:500px; max-width:90%; border-radius:4px; box-shadow:0 4px 6px rgba(0,0,0,0.1);">' +
503 '<h3 style="margin-top:0;">' + <?php echo json_encode( esc_html__( 'Confirm Two-Factor Authentication Enforcement', 'profile-builder' ) ); ?> + '</h3>' +
504 '<div id="wppb-force-2fa-message"></div>' +
505 '<div style="margin-top:20px; text-align:right;">' +
506 '<button type="button" id="wppb-force-2fa-cancel" class="button">' + <?php echo json_encode( esc_html__( 'Cancel', 'profile-builder' ) ); ?> + '</button> ' +
507 '<button type="button" id="wppb-force-2fa-confirm" class="button button-primary">' + <?php echo json_encode( esc_html__( 'Confirm & Save', 'profile-builder' ) ); ?> + '</button>' +
508 '</div>' +
509 '</div>' +
510 '</div>'
511 );
512
513 // Intercept form submission
514 $('form').on('submit', function(e) {
515 // Only check if we are on the general settings page and submitting the main form
516 if ($(this).find('input[name="option_page"]').val() !== 'wppb_general_settings') {
517 return;
518 }
519
520 var force2FAEnabled = $('#wppb-force-2fa-enable').is(':checked');
521 var main2FAEnabled = $('#wppb-auth-enable').is(':checked');
522 var selectedRoles = $('#wppb-force-2fa-roles').val() || [];
523 selectedRoles.sort();
524
525 // Check if settings have changed
526 var settingsChanged = false;
527
528 // Case 1: Force 2FA Enabled status changed
529 if (force2FAEnabled !== initialForce2FAEnabled) {
530 settingsChanged = true;
531 }
532
533 // Case 2: Roles selection changed (only if Force 2FA is enabled)
534 if (force2FAEnabled) {
535 if (selectedRoles.length !== initialSelectedRoles.length) {
536 settingsChanged = true;
537 } else {
538 for (var i = 0; i < selectedRoles.length; i++) {
539 if (selectedRoles[i] !== initialSelectedRoles[i]) {
540 settingsChanged = true;
541 break;
542 }
543 }
544 }
545 }
546
547 // Case 3: Main 2FA enabled status changed (only if Force 2FA is enabled)
548 // This covers the case where Force 2FA was already checked but inactive because Main 2FA was off
549 if (force2FAEnabled && main2FAEnabled !== initialMain2FAEnabled) {
550 settingsChanged = true;
551 }
552
553 // Only show popup if Force 2FA is enabled AND Main 2FA is enabled AND settings have changed
554 if (force2FAEnabled && main2FAEnabled && settingsChanged) {
555 // Check if we already confirmed
556 if ($(this).data('force-2fa-confirmed')) {
557 return;
558 }
559
560 var selectedRolesText = [];
561
562 $('#wppb-force-2fa-roles option:selected').each(function() {
563 selectedRolesText.push($(this).text());
564 });
565
566 if (selectedRoles.length > 0) {
567 e.preventDefault();
568 var form = $(this);
569
570 var message = '<p>' + <?php echo json_encode( esc_html__( 'You are enforcing 2FA for the following user roles:', 'profile-builder' ) ); ?> + ' <strong>' + selectedRolesText.join(', ') + '</strong>.</p>';
571 message += '<p>' + <?php echo json_encode( esc_html__( 'Users with these roles will be required to set up 2FA on their next login.', 'profile-builder' ) ); ?> + '</p>';
572
573 // Check if current user is affected
574 var userAffected = false;
575 for (var i = 0; i < currentUserRoles.length; i++) {
576 if (selectedRoles.indexOf(currentUserRoles[i]) !== -1) {
577 userAffected = true;
578 break;
579 }
580 }
581
582 if (userAffected && !currentUser2FAEnabled) {
583 message += '<div class="notice notice-warning inline" style="margin: 10px 0; padding: 10px; display: block !important;"><p><strong>' + <?php echo json_encode( esc_html__( 'Warning:', 'profile-builder' ) ); ?> + '</strong> ' +
584 <?php echo json_encode( esc_html__( 'Based on the configured settings, your account is also required to set up 2FA. Once you confirm this change, you will be redirected to set it up.', 'profile-builder' ) ); ?> + '</p></div>';
585 }
586
587 $('#wppb-force-2fa-message').html(message);
588 $('#wppb-force-2fa-modal').show();
589
590 // Handle Confirm
591 $('#wppb-force-2fa-confirm').off('click').on('click', function() {
592 $('#wppb-force-2fa-modal').hide();
593 form.data('force-2fa-confirmed', true);
594 form.submit();
595 });
596
597 // Handle Cancel
598 $('#wppb-force-2fa-cancel').off('click').on('click', function() {
599 $('#wppb-force-2fa-modal').hide();
600 });
601 }
602 }
603 });
604 });
605 </script>
606
607 <div class="cozmoslabs-toggle-description">
608 <label for="wppb-auth-enable" class="cozmoslabs-description"><?php esc_html_e( 'Enable the Google Authenticator functionality.', 'profile-builder' ); ?></label>
609 </div>
610 </div>
611
612 <div class="cozmoslabs-form-field-wrapper cozmoslabs-toggle-switch" id="wppb-2fa-require-totp-profile-edit" <?php echo $enabled === 'no' ? 'style="display: none;"' : '' ?> >
613 <?php
614 $require_totp_profile_edit = 'yes';
615 if ( $wppb_two_factor_authentication_settings !== 'not_found' && is_array( $wppb_two_factor_authentication_settings ) && isset( $wppb_two_factor_authentication_settings['require_totp_profile_edit'] ) ) {
616 $require_totp_profile_edit = $wppb_two_factor_authentication_settings['require_totp_profile_edit'];
617 }
618 ?>
619
620
621 <label class="cozmoslabs-form-field-label" for="wppb-require-totp-profile-edit"><?php esc_html_e('Require TOTP Verification on Profile Edit', 'profile-builder'); ?></label>
622
623 <div class="cozmoslabs-toggle-container">
624 <input type="checkbox" name="wppb_two_factor_authentication_settings[require_totp_profile_edit]" id="wppb-require-totp-profile-edit" value="yes" <?php echo ($require_totp_profile_edit === 'yes') ? 'checked' : ''; ?> >
625 <label class="cozmoslabs-toggle-track" for="wppb-require-totp-profile-edit"></label>
626 </div>
627
628 <div class="cozmoslabs-toggle-description">
629 <label for="wppb-require-totp-profile-edit" class="cozmoslabs-description"><?php esc_html_e( 'Require users with Two-Factor Authentication enabled to verify their TOTP code every time they edit their profile. This setting is enabled by default.', 'profile-builder' ); ?></label>
630 </div>
631 </div>
632
633 <div class="cozmoslabs-form-field-wrapper" id="wppb-auth-roles-selector" <?php echo $enabled === 'no' ? 'style="display: none;"' : '' ?> >
634 <?php
635 $roles = get_editable_roles( );
636 $network_roles = array( );
637 if ( !empty( $wppb_two_factor_authentication_settings['roles'] ) )
638 $network_roles = is_array( $wppb_two_factor_authentication_settings['roles'] ) ? $wppb_two_factor_authentication_settings['roles'] : array( $wppb_two_factor_authentication_settings['roles'] );
639 ?>
640
641 <label class="cozmoslabs-form-field-label" for="wppb-auth-enable-roles"><?php esc_html_e( 'Enable Authenticator For', 'profile-builder' ); ?></label>
642
643 <select name="wppb_two_factor_authentication_settings[roles][]" id="wppb-auth-enable-roles" class="wppb-select wppb-select2" multiple>
644 <?php
645 echo '<option value="*"' . (in_array('*', $network_roles, true) ? ' selected' : '') . '>'. esc_html__('ALL ROLES', 'profile-builder') .'</option>';
646
647 foreach ($roles as $role_key => $role) {
648 echo '<option value="' . esc_attr($role_key) . '"' . (in_array($role_key, $network_roles, true) ? ' selected' : '') . '>' . esc_html($role['name']) . '</option>';
649 }
650 ?>
651 </select>
652
653 <p class="cozmoslabs-description cozmoslabs-description-space-left"><?php esc_html_e( '"ALL ROLES" - Two-Factor Authentication will be enabled for all user roles.', 'profile-builder' ); ?></p>
654 </div>
655
656 <hr style="margin: 20px 0; border: 0; border-top: 1px solid #ddd;">
657
658 <div class="cozmoslabs-form-field-wrapper cozmoslabs-toggle-switch">
659 <?php
660 $force_2fa_enabled = 'no';
661 if ( $wppb_two_factor_authentication_settings !== 'not_found' && is_array( $wppb_two_factor_authentication_settings ) && isset( $wppb_two_factor_authentication_settings['force_2fa_enabled'] ) ) {
662 $force_2fa_enabled = $wppb_two_factor_authentication_settings['force_2fa_enabled'];
663 }
664 ?>
665
666 <label class="cozmoslabs-form-field-label" for="wppb-force-2fa-enable"><?php esc_html_e('Force 2FA for Selected Roles', 'profile-builder'); ?></label>
667
668 <div class="cozmoslabs-toggle-container">
669 <input type="checkbox" name="wppb_two_factor_authentication_settings[force_2fa_enabled]" id="wppb-force-2fa-enable" value="yes" <?php echo ($force_2fa_enabled === 'yes') ? 'checked' : ''; ?> >
670 <label class="cozmoslabs-toggle-track" for="wppb-force-2fa-enable"></label>
671 </div>
672
673 <div class="cozmoslabs-toggle-description">
674 <label for="wppb-force-2fa-enable" class="cozmoslabs-description"><?php esc_html_e( 'Force users with selected roles to set up Two-Factor Authentication. Users will be redirected to their profile page if 2FA is not configured.', 'profile-builder' ); ?></label>
675 </div>
676 </div>
677
678 <div class="cozmoslabs-form-field-wrapper" id="wppb-force-2fa-roles-selector" <?php echo $force_2fa_enabled === 'no' ? 'style="display: none;"' : '' ?> >
679 <?php
680 $force_2fa_roles = array( );
681 if ( !empty( $wppb_two_factor_authentication_settings['force_2fa_roles'] ) )
682 $force_2fa_roles = is_array( $wppb_two_factor_authentication_settings['force_2fa_roles'] ) ? $wppb_two_factor_authentication_settings['force_2fa_roles'] : array( $wppb_two_factor_authentication_settings['force_2fa_roles'] );
683 ?>
684
685 <label class="cozmoslabs-form-field-label" for="wppb-force-2fa-roles"><?php esc_html_e( 'Force 2FA For', 'profile-builder' ); ?></label>
686
687 <select name="wppb_two_factor_authentication_settings[force_2fa_roles][]" id="wppb-force-2fa-roles" class="wppb-select wppb-select2" multiple>
688 <?php
689 // Only show roles that are enabled for 2FA
690 $enabled_roles = isset( $wppb_two_factor_authentication_settings['roles'] ) ?
691 $wppb_two_factor_authentication_settings['roles'] : array();
692
693 // If '*' (all roles) is selected, show all roles
694 if ( in_array( '*', $enabled_roles, true ) ) {
695 foreach ($roles as $role_key => $role) {
696 echo '<option value="' . esc_attr($role_key) . '"' . (in_array($role_key, $force_2fa_roles, true) ? ' selected' : '') . '>' . esc_html($role['name']) . '</option>';
697 }
698 } else {
699 // Only show roles that are specifically enabled for 2FA
700 foreach ($enabled_roles as $enabled_role) {
701 if ( isset( $roles[$enabled_role] ) ) {
702 echo '<option value="' . esc_attr($enabled_role) . '"' . (in_array($enabled_role, $force_2fa_roles, true) ? ' selected' : '') . '>' . esc_html($roles[$enabled_role]['name']) . '</option>';
703 }
704 }
705 }
706 ?>
707 </select>
708
709 <p class="cozmoslabs-description cozmoslabs-description-space-left"><?php esc_html_e( 'Select which user roles will be forced to set up Two-Factor Authentication. Only roles that have 2FA enabled above are available.', 'profile-builder' ); ?></p>
710 </div>
711
712 <div class="cozmoslabs-form-field-wrapper" id="wppb-force-2fa-grace-period" <?php echo $force_2fa_enabled === 'no' ? 'style="display: none;"' : '' ?> >
713 <?php
714 $grace_period_days = 0;
715 if ( !empty( $wppb_two_factor_authentication_settings['grace_period_days'] ) )
716 $grace_period_days = intval( $wppb_two_factor_authentication_settings['grace_period_days'] );
717 ?>
718
719 <label class="cozmoslabs-form-field-label" for="wppb-force-2fa-grace-period-days"><?php esc_html_e( 'Grace Period', 'profile-builder' ); ?></label>
720
721 <input type="number" name="wppb_two_factor_authentication_settings[grace_period_days]" id="wppb-force-2fa-grace-period-days" class="wppb-text" min="0" max="365" value="<?php echo esc_attr( $grace_period_days ); ?>" />
722
723 <p class="cozmoslabs-description cozmoslabs-description-space-left"><?php esc_html_e( 'Number of days users have to set up Two-Factor Authentication. Set to 0 for immediate enforcement.', 'profile-builder' ); ?></p>
724 </div>
725
726 <div class="cozmoslabs-form-field-wrapper" id="wppb-force-2fa-edit-profile-page-selector" <?php echo $force_2fa_enabled === 'no' ? 'style="display: none;"' : '' ?> >
727 <?php
728 $edit_profile_page_id = 'admin';
729 if ( !empty( $wppb_two_factor_authentication_settings['edit_profile_page_id'] ) ) {
730 $edit_profile_page_id = $wppb_two_factor_authentication_settings['edit_profile_page_id'];
731 }
732
733 // Get pages with Edit Profile shortcode or block
734 $edit_profile_pages = array();
735 if ( defined( 'WPPB_PAID_PLUGIN_DIR' ) && file_exists( WPPB_PAID_PLUGIN_DIR . '/features/two-factor-authentication/class-two-factor-authentication.php' ) ) {
736 require_once( WPPB_PAID_PLUGIN_DIR . '/features/two-factor-authentication/class-two-factor-authentication.php' );
737 // The method only exists in paid add-on versions matching this base plugin; guard against a stale add-on to avoid a fatal error.
738 if ( method_exists( 'WPPB_Two_Factor_Authenticator', 'get_edit_profile_pages' ) ) {
739 $edit_profile_pages = WPPB_Two_Factor_Authenticator::get_edit_profile_pages();
740 }
741 }
742 ?>
743
744 <label class="cozmoslabs-form-field-label" for="wppb-force-2fa-edit-profile-page"><?php esc_html_e( 'Redirect to Edit Profile Page', 'profile-builder' ); ?></label>
745
746 <select name="wppb_two_factor_authentication_settings[edit_profile_page_id]" id="wppb-force-2fa-edit-profile-page" class="wppb-select">
747 <option value="admin" <?php selected( $edit_profile_page_id, 'admin' ); ?>><?php esc_html_e( 'Admin Profile Page', 'profile-builder' ); ?></option>
748 <?php
749 if ( !empty( $edit_profile_pages ) ) {
750 foreach ( $edit_profile_pages as $page ) {
751 echo '<option value="' . esc_attr( $page['ID'] ) . '" ' . selected( $edit_profile_page_id, $page['ID'], false ) . '>' . esc_html( $page['title'] ) . '</option>';
752 }
753 }
754 ?>
755 </select>
756
757 <div class="cozmoslabs-description cozmoslabs-description-space-left">
758 <?php
759 if ( empty( $edit_profile_pages ) ) {
760 echo '<div class="cozmoslabs-description cozmoslabs-description-upsell" style="margin-top: 10px;">' . esc_html__( 'No pages with Edit Profile forms found. Please create a page with the [wppb-edit-profile] shortcode or block.', 'profile-builder' ) . '</div>';
761 } else {
762 esc_html_e( 'Select which page users should be redirected to when they need to set up Two-Factor Authentication.', 'profile-builder' );
763 }
764 ?>
765 </div>
766 </div>
767
768
769
770 <?php else : ?>
771
772 <div class="cozmoslabs-form-field-wrapper cozmoslabs-toggle-switch">
773
774 <label class="cozmoslabs-form-field-label" for="wppb-2fa-enable"><?php esc_html_e('Two-Factor Authentication', 'profile-builder'); ?></label>
775
776 <div class="cozmoslabs-toggle-container">
777 <input type="checkbox" name="wppb_two_factor_authentication_free" id="wppb-2fa-enable" value="yes">
778 <label class="cozmoslabs-toggle-track" for="wppb-2fa-enable"></label>
779 </div>
780
781 <div class="cozmoslabs-toggle-description">
782 <label for="wppb-2fa-enable" class="cozmoslabs-description"><?php esc_html_e( 'Enable the Google Authenticator functionality.', 'profile-builder' ); ?></label>
783 </div>
784
785 <p class="cozmoslabs-description cozmoslabs-description-upsell" id="wppb-2fa-upgrade-notice" style="display: none;">
786 <?php printf( esc_html__( 'Increase the security of your user accounts with 2 Factor Authentication by upgrading to %1$sBasic or Pro%2$s versions.', 'profile-builder' ), '<a href="https://www.cozmoslabs.com/wordpress-profile-builder/?utm_source=wpbackend&utm_medium=clientsite&utm_content=settings-2fa&utm_campaign=PBFree#pricing" target="_blank">', '</a>' );?>
787 </p>
788
789 </div>
790
791 <?php endif; ?>
792 </div>
793
794 <div class="cozmoslabs-form-subsection-wrapper">
795 <h4 class="cozmoslabs-subsection-title"><?php esc_html_e( 'Other features', 'profile-builder' ); ?></h4>
796
797 <div class="cozmoslabs-form-field-wrapper">
798 <label class="cozmoslabs-form-field-label" for="hideAdminBarFor"><?php esc_html_e( 'Hide Admin Bar for User Roles', 'profile-builder' ); ?></label>
799
800 <select name="wppb_general_settings[hide_admin_bar_for][]" class="wppb-select wppb-select2" id="hideAdminBarFor" multiple>
801 <?php
802 global $wp_roles;
803 $general_settings = get_option( 'wppb_general_settings' );
804 $selected_roles = isset($general_settings['hide_admin_bar_for']) ? $general_settings['hide_admin_bar_for'] : '';
805
806 echo '<option value="allUserRoles"' . ( ( !empty( $selected_roles ) && in_array( 'allUserRoles', $selected_roles ) ) ? ' selected' : '' ) . '>' . esc_html__( 'All User Roles', 'profile-builder' ) . '</option>';
807 echo '<option value="allUserRolesExceptAdmin"' . ( ( !empty( $selected_roles ) && in_array( 'allUserRolesExceptAdmin', $selected_roles ) ) ? ' selected' : '' ) . '>' . esc_html__( 'All User Roles Except Admin', 'profile-builder' ) . '</option>';
808
809 foreach ( $wp_roles->roles as $role ) {
810 $key = $role['name'];
811
812 echo '<option value="'.esc_attr( $key ).'"' . ( ( !empty( $selected_roles ) && in_array( $key, $selected_roles ) ) ? ' selected' : '' ) . '>' . esc_html( translate_user_role( $key ) ) . '</option>';
813 }
814
815 ?>
816 </select>
817
818 <p class="cozmoslabs-description cozmoslabs-description-space-left"><?php esc_html_e( 'Hide the WordPress Admin Bar for these user roles. You can select multiple roles to hide it for.', 'profile-builder' ); ?></p>
819 </div>
820
821 <?php
822 if( file_exists( WPPB_PLUGIN_DIR.'/features/roles-editor/roles-editor.php' ) ) {
823 ?>
824
825 <div class="cozmoslabs-form-field-wrapper cozmoslabs-toggle-switch">
826 <label class="cozmoslabs-form-field-label" for="rolesEditorSelect"><?php esc_html_e('Roles Editor', 'profile-builder'); ?></label>
827
828 <div class="cozmoslabs-toggle-container">
829 <input type="checkbox" name="wppb_general_settings[rolesEditor]" id="rolesEditorSelect" value="yes" <?php echo (!empty($wppb_generalSettings['rolesEditor']) && $wppb_generalSettings['rolesEditor'] === 'yes') ? 'checked' : ''; ?> >
830 <label class="cozmoslabs-toggle-track" for="rolesEditorSelect"></label>
831 </div>
832
833 <div class="cozmoslabs-toggle-description">
834 <label for="rolesEditorSelect" class="cozmoslabs-description wppb-roles-editor-details"><?php esc_html_e( 'Easily create new custom user roles or customize any existing user role capabilities.', 'profile-builder' ); ?></label>
835 </div>
836
837 <p class="cozmoslabs-description cozmoslabs-description-space-left wppb-roles-editor-link"><?php printf( esc_html__( 'You can add / edit user roles at %1$sUsers > Roles Editor%2$s.', 'profile-builder' ), '<a href="'. esc_url( get_bloginfo( 'url' ) ).'/wp-admin/edit.php?post_type=wppb-roles-editor">', '</a>' )?></p>
838 </div>
839
840 <?php } ?>
841
842 <div class="cozmoslabs-form-field-wrapper cozmoslabs-toggle-switch">
843 <label class="cozmoslabs-form-field-label" for="extraFieldsLayout"><?php esc_html_e('Load CSS', 'profile-builder'); ?></label>
844
845 <div class="cozmoslabs-toggle-container">
846 <input type="checkbox" id="extraFieldsLayout" name="wppb_general_settings[extraFieldsLayout]"<?php echo ( ( isset( $wppb_generalSettings['extraFieldsLayout'] ) && ( $wppb_generalSettings['extraFieldsLayout'] == 'default' ) ) ? ' checked' : '' ); ?> value="default">
847 <label class="cozmoslabs-toggle-track" for="extraFieldsLayout"></label>
848 </div>
849 <div class="cozmoslabs-toggle-description">
850 <label for="extraFieldsLayout" class="cozmoslabs-description"><?php printf( esc_html__( 'You can find the default file here: %1$s', 'profile-builder' ), '<a href="'.dirname( plugin_dir_url( __FILE__ ) ).'/assets/css/style-front-end.css" target="_blank">'.dirname( dirname( plugin_basename( __FILE__ ) ) ).'/assets/css/style-front-end.css</a>' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></label>
851 </div>
852 </div>
853
854 </div>
855
856 <?php do_action( 'wppb_extra_general_settings', $wppb_generalSettings ); ?>
857
858 <input type="hidden" name="action" value="update" />
859
860 </div>
861
862 <div class="submit cozmoslabs-submit">
863 <h3 class="cozmoslabs-subsection-title"><?php esc_html_e( 'Update Settings', 'profile-builder' ) ?></h3>
864 <div class="cozmoslabs-publish-button-group">
865 <p class="submit">
866 <input type="submit" class="button-primary" value="<?php esc_html_e( 'Save Changes', 'profile-builder' ); ?>" />
867 </p>
868 </div>
869 </div>
870
871 </form>
872
873 </div>
874
875 </div>
876
877 <?php
878 }
879
880
881 /*
882 * Function that sanitizes the general settings
883 *
884 * @param array $wppb_generalSettings
885 *
886 * @since v.2.0.7
887 */
888 function wppb_general_settings_sanitize( $wppb_generalSettings ) {
889 $wppb_generalSettings = apply_filters( 'wppb_general_settings_sanitize_extra', $wppb_generalSettings );
890
891 if( !empty( $wppb_generalSettings ) ){
892 foreach( $wppb_generalSettings as $settings_name => $settings_value ){
893 if( $settings_name == "minimum_password_length" || $settings_name == "activationLandingPage" )
894 $wppb_generalSettings[$settings_name] = absint( $settings_value );
895 elseif( $settings_name == "extraFieldsLayout" || $settings_name == "emailConfirmation" || $settings_name == "adminApproval" || $settings_name == "loginWith" || $settings_name == "minimum_password_strength" )
896 $wppb_generalSettings[$settings_name] = sanitize_text_field( $settings_value );
897 elseif( $settings_name == "adminApprovalOnUserRole" ){
898 if( is_array( $settings_value ) && !empty( $settings_value ) ){
899 foreach( $settings_value as $key => $value ){
900 $wppb_generalSettings[$settings_name][$key] = sanitize_text_field( $value );
901 }
902 }
903 }
904 }
905 }
906
907 return $wppb_generalSettings;
908 }
909
910
911 /*
912 * Function that pushes settings errors to the user
913 *
914 * @since v.2.0.7
915 */
916 function wppb_general_settings_admin_notices() {
917 settings_errors( 'wppb_general_settings' );
918 }
919 add_action( 'admin_notices', 'wppb_general_settings_admin_notices' );
920
921
922 /*
923 * Function that return user roles
924 *
925 * @since v.2.2.0
926 *
927 * @return array
928 */
929 function wppb_adminApproval_onUserRole() {
930 global $wp_roles;
931
932 $wp_roles = new WP_Roles();
933
934 $roles = $wp_roles->get_names();
935
936 unset( $roles['administrator'] );
937
938 return $roles;
939 }
940
941
942
943 /*
944 * Generate the Form Designs Preview Showcase
945 *
946 */
947 function wppb_display_form_designs_preview() {
948 $form_designs_data = array(
949 array(
950 'id' => 'form-style-default',
951 'name' => 'Default',
952 'images' => array(
953 'main' => WPPB_PLUGIN_URL.'assets/images/pb-default-forms.jpg',
954 ),
955 ),
956 array(
957 'id' => 'form-style-1',
958 'name' => 'Sublime',
959 'images' => array(
960 'main' => WPPB_PLUGIN_URL.'assets/images/style1-slide1.jpg',
961 'slide1' => WPPB_PLUGIN_URL.'assets/images/style1-slide2.jpg',
962 'slide2' => WPPB_PLUGIN_URL.'assets/images/style1-slide3.jpg',
963 ),
964 ),
965 array(
966 'id' => 'form-style-2',
967 'name' => 'Greenery',
968 'images' => array(
969 'main' => WPPB_PLUGIN_URL.'assets/images/style2-slide1.jpg',
970 'slide1' => WPPB_PLUGIN_URL.'assets/images/style2-slide2.jpg',
971 'slide2' => WPPB_PLUGIN_URL.'assets/images/style2-slide3.jpg',
972 ),
973 ),
974 array(
975 'id' => 'form-style-3',
976 'name' => 'Slim',
977 'images' => array(
978 'main' => WPPB_PLUGIN_URL.'assets/images/style3-slide1.jpg',
979 'slide1' => WPPB_PLUGIN_URL.'assets/images/style3-slide2.jpg',
980 'slide2' => WPPB_PLUGIN_URL.'assets/images/style3-slide3.jpg',
981 ),
982 )
983 );
984
985 $output = '<div id="wppb-forms-design-browser">';
986
987 foreach ( $form_designs_data as $form_design ) {
988
989 if ( $form_design['id'] != 'form-style-default' ) {
990 $preview_button = '<div class="wppb-forms-design-preview button-secondary" id="' . $form_design['id'] . '-info">Preview</div>';
991 $title = esc_html__( 'Available in the Pro versions of the plugin', 'profile-builder' );
992 }
993 else {
994 $preview_button = '';
995 $title = '';
996 }
997
998 $output .= '<div class="wppb-forms-design" id="'. $form_design['id'] .'" title="'. $title .'">
999 <label>
1000 <input type="radio" id="wppb-fd-option-' . $form_design['id'] . '" value="' . $form_design['id'] . '" name="" disabled ' . ( $form_design['id'] == 'form-style-default' ? 'checked' : '' ) .'>
1001 ' . $form_design['name'] . '</label>
1002 <div class="wppb-forms-design-screenshot">
1003 <img src="' . $form_design['images']['main'] . '" alt="Form Design">
1004 '. $preview_button .'
1005 </div>
1006 </div>';
1007
1008 $img_count = 0;
1009 $image_list = '';
1010 foreach ( $form_design['images'] as $image ) {
1011 $img_count++;
1012 $active_img = ( $img_count == 1 ) ? ' active' : '';
1013 $image_list .= '<img class="wppb-forms-design-preview-image'. $active_img .'" src="'. $image .'">';
1014 }
1015
1016 if ( $img_count > 1 ) {
1017 $previous_button = '<div class="wppb-slideshow-button wppb-forms-design-sildeshow-previous disabled" data-theme-id="'. $form_design['id'] .'" data-slideshow-direction="previous"> < </div>';
1018 $next_button = '<div class="wppb-slideshow-button wppb-forms-design-sildeshow-next" data-theme-id="'. $form_design['id'] .'" data-slideshow-direction="next"> > </div>';
1019 $justify_content = 'space-between';
1020 }
1021 else {
1022 $previous_button = $next_button = '';
1023 $justify_content = 'center';
1024 }
1025
1026 $output .= '<div id="modal-'. $form_design['id'] .'" class="wppb-forms-design-modal" title="'. $form_design['name'] .'">
1027 <div class="wppb-forms-design-modal-slideshow" style="justify-content: '. $justify_content .'">
1028 '. $previous_button .'
1029 <div class="wppb-forms-design-modal-images">
1030 '. $image_list .'
1031 </div>
1032 '. $next_button .'
1033 </div>
1034 </div>';
1035
1036 }
1037
1038 $output .= '</div>';
1039
1040 $output .= '<p class="cozmoslabs-description cozmoslabs-description-upsell">'. sprintf( esc_html__( 'You can now beautify your forms using pre-made templates. Enable %3$sForm Designs%4$s by upgrading to %1$sBasic or PRO versions%2$s.', 'profile-builder' ), '<a href="https://www.cozmoslabs.com/wordpress-profile-builder/?utm_source=pb-general-settings&utm_medium=client-site&utm_campaign=pb-form-design-templates#pricing" target="_blank">', '</a>', '<strong>', '</strong>' ) .'</p>';
1041
1042 return $output;
1043 }
1044
1045
1046 /*
1047 * Generate the Register Version Form
1048 *
1049 */
1050 function wppb_add_register_version_form() {
1051 $status = wppb_get_serial_number_status();
1052 $license = wppb_get_serial_number();
1053 $license_details = get_option( 'wppb_license_details', false );
1054
1055 if( !empty( $license ) ){
1056 // process license so it doesn't get displayed in back-end
1057 $license_length = strlen( $license );
1058 $license = substr_replace( $license, '***************', 7, $license_length - 14 );
1059 }
1060 ?>
1061
1062 <h4 class="cozmoslabs-subsection-title"><?php esc_html_e( 'Register Website', 'profile-builder' ) ?></h4>
1063
1064 <form method="post" action="<?php echo !is_multisite() ? 'options.php' : 'edit.php'; ?>">
1065 <?php settings_fields( 'wppb_license_key' ); ?>
1066
1067 <div class="cozmoslabs-form-field-wrapper cozmoslabs-form-field-serial-number">
1068
1069 <label class="cozmoslabs-form-field-label" for="wppb_license_key"><?php esc_html_e( 'License key', 'profile-builder' ); ?></label>
1070
1071 <div class="cozmoslabs-serial-wrap__holder">
1072 <input id="wppb_license_key" name="wppb_license_key" type="text" class="regular-text" value="<?php echo esc_attr( $license ); ?>" />
1073 <?php wp_nonce_field( 'wppb_license_nonce', 'wppb_license_nonce' ); ?>
1074
1075 <?php if( $status !== false && $status == 'valid' ) {
1076 $button_name = 'wppb_edd_license_deactivate';
1077 $button_value = __('Deactivate License', 'profile-builder' );
1078
1079 if( empty( $details['invalid'] ) )
1080 echo '<span title="'. esc_html__( 'Active on this site', 'profile-builder' ) .'" class="wppb-active-license dashicons dashicons-yes"></span>';
1081 else
1082 echo '<span title="'. esc_html__( 'Your license is invalid', 'profile-builder' ) .'" class="wppb-invalid-license dashicons dashicons-warning"></span>';
1083
1084 } else {
1085 $button_name = 'wppb_edd_license_activate';
1086 $button_value = __('Activate License', 'profile-builder');
1087 }
1088 ?>
1089 <input type="submit" class="button-secondary" name="<?php echo esc_attr( $button_name ); ?>" value="<?php echo esc_attr( $button_value ); ?>"/>
1090 </div>
1091
1092 <?php if( $status != 'expired' && ( !empty( $license_details ) && !empty( $license_details->expires ) && $license_details->expires !== 'lifetime' ) && ( ( !isset( $license_details->subscription_status ) || $license_details->subscription_status != 'active' ) && strtotime( $license_details->expires ) < strtotime( '+14 days' ) ) ) : ?>
1093 <div class="cozmoslabs-description-container yellow">
1094 <p class="cozmoslabs-description"><?php echo wp_kses_post( sprintf( __( 'Your %s license is about to expire on %s', 'profile-builder' ), '<strong>' . PROFILE_BUILDER . '</strong>', '<strong>' . date_i18n( get_option( 'date_format' ), strtotime( $license_details->expires ) ) . '</strong>' ) ); ?>
1095 <p class="cozmoslabs-description"><?php echo wp_kses_post( sprintf( __( 'Please %sRenew Your Licence%s to continue receiving access to new features, premium addons, product downloads & automatic updates — including important security patches and WordPress compatibility.', 'profile-builder' ), "<a href='https://www.cozmoslabs.com/account/?utm_source=wpbackend&utm_medium=clientsite&utm_campaign=PBPro&utm_content=license-about-to-expire' target='_blank'>", "</a>" ) ); ?></p>
1096 </div>
1097 <?php elseif( $status == 'expired' ) : ?>
1098 <div class="cozmoslabs-description-container red">
1099 <p class="cozmoslabs-description"><?php echo wp_kses_post( sprintf( __( 'Your %s license has expired.', 'profile-builder' ), '<strong>' . PROFILE_BUILDER . '</strong>' ) ); ?>
1100 <p class="cozmoslabs-description"><?php echo wp_kses_post( sprintf( __( 'Please %1$sRenew Your Licence%2$s to continue receiving access to new features, premium addons, product downloads & automatic updates — including important security patches and WordPress compatibility.', 'profile-builder' ), '<a href="https://www.cozmoslabs.com/account/?utm_source=wpbackend&utm_medium=clientsite&utm_campaign=PBPro&utm_content=license-expired" target="_blank">', '</a>' ) ); ?></p>
1101 </div>
1102 <?php elseif( $status == 'no_activations_left' ) : ?>
1103 <div class="cozmoslabs-description-container red">
1104 <p class="cozmoslabs-description"><?php echo wp_kses_post( sprintf( __( 'Your %s license has reached its activation limit.', 'profile-builder' ), '<strong>' . PROFILE_BUILDER . '</strong>' ) ); ?>
1105 <p class="cozmoslabs-description"><?php echo wp_kses_post( sprintf( __( '%sUpgrade now%s for unlimited activations and extra features like multiple registration and edit profile forms, userlisting, custom redirects and more.', 'profile-builder' ), '<a href="https://www.cozmoslabs.com/account/?utm_source=wpbackend&utm_medium=clientsite&utm_campaign=PBPro&utm_content=license-activation-limit" target="_blank">', '</a>' ) ); ?>
1106 </div>
1107 <?php elseif( empty( $license ) || $status != 'valid' ) : ?>
1108 <div class="cozmoslabs-description-container">
1109 <p class="cozmoslabs-description"><?php echo wp_kses_post( sprintf( __( 'Enter your license key. Your license key can be found in your %sCozmoslabs account%s. ', 'profile-builder' ), '<a href="https://www.cozmoslabs.com/account/?utm_source=wpbackend&utm_medium=clientsite&utm_campaign=PBPro&utm_content=license-missing" target="_blank">', '</a>' ) ); ?></p>
1110 <p class="cozmoslabs-description"><?php echo wp_kses_post( sprintf( __( 'You can use this core version of Profile Builder for free. For priority support and advanced functionality, %sa license key is required%s.', 'profile-builder' ), '<a href="https://www.cozmoslabs.com/wordpress-profile-builder/?utm_source=wpbackend&utm_medium=clientsite&utm_campaign=PBPro&utm_content=license-missing#pricing" target="_blank">', '</a>' ) ); ?></p>
1111 </div>
1112 <?php endif; ?>
1113
1114 </div>
1115 </form>
1116
1117 <?php
1118 }
1119
1120
1121 /*
1122 * Load scripts and styles we need on the page ( ex. Select2 )
1123 *
1124 */
1125 function wppb_load_necessary_scripts() {
1126 wp_enqueue_script( 'wppb-select2', WPPB_PLUGIN_URL . 'assets/js/select2/select2.min.js', array(), PROFILE_BUILDER_VERSION );
1127 wp_enqueue_script( 'wppb-select2-compat', WPPB_PLUGIN_URL . 'assets/js/select2-compat.js', array(), PROFILE_BUILDER_VERSION );
1128 wp_enqueue_style( 'wppb_select2_css', WPPB_PLUGIN_URL .'assets/css/select2/select2.min.css', array(), PROFILE_BUILDER_VERSION );
1129 }