PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 4.0.2
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v4.0.2
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 / features / functions.php

functions.php in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 4.0.2, at features/functions.php

2,144 lines 85.5 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 /**
5 * Functions Load
6 *
7 */
8
9 // whitelist options, you can add more register_settings changing the second parameter
10 function wppb_register_settings() {
11 register_setting( 'wppb_option_group', 'wppb_default_settings' );
12 register_setting( 'wppb_general_settings', 'wppb_general_settings', 'wppb_general_settings_sanitize' );
13 // register_setting( 'wppb_display_admin_settings', 'wppb_display_admin_settings' );
14 register_setting( 'wppb_profile_builder_pro_serial', 'wppb_profile_builder_pro_serial' );
15 register_setting( 'wppb_profile_builder_hobbyist_serial', 'wppb_profile_builder_hobbyist_serial' );
16 register_setting( 'wppb_module_settings', 'wppb_module_settings' );
17 register_setting( 'wppb_module_settings_description', 'wppb_module_settings_description' );
18 register_setting( 'customRedirectSettings', 'customRedirectSettings' );
19 register_setting( 'customUserListingSettings', 'customUserListingSettings' );
20 register_setting( 'reCaptchaSettings', 'reCaptchaSettings' );
21 register_setting( 'emailCustomizer', 'emailCustomizer' );
22 register_setting( 'wppb_content_restriction_settings', 'wppb_content_restriction_settings' );
23 register_setting( 'wppb_private_website_settings', 'wppb_private_website_settings' );
24 register_setting( 'wppb_two_factor_authentication_settings', 'wppb_two_factor_authentication_settings' );
25 }
26
27
28
29
30 // WPML support
31 function wppb_icl_t( $context, $name, $value, $kses = false ){
32
33 if( $kses === false ){
34 if( function_exists( 'icl_t' ) )
35 return icl_t( $context, $name, $value );
36 else
37 return $value;
38 } else {
39 if( function_exists( 'icl_t' ) )
40 return wp_kses_post( icl_t( $context, $name, $value ) );
41 else
42 return wp_kses_post( $value );
43 }
44
45 }
46
47 function wppb_icl_register_string( $context, $name, $value ) {
48 if( function_exists( 'icl_register_string' )) {
49 if ( $name === 'msf_previous_button_text_translation' || $name === 'msf_next_button_text_translation' )
50 $wpml_default_lang = 'en';
51 else
52 $wpml_default_lang = apply_filters('wpml_default_language', NULL );
53 $allow_empty_value = false;
54 icl_register_string($context, $name , $value , $allow_empty_value , $wpml_default_lang );
55 }
56 }
57
58
59 /**
60 * Whether Profile Builder should load style-block-themes-front-end.css.
61 */
62 function wppb_should_load_block_theme_stylesheet() {
63 $is_block_theme_context = version_compare( get_bloginfo( 'version' ), '5.9', '>=' )
64 && function_exists( 'wp_is_block_theme' )
65 && wp_is_block_theme();
66
67 /**
68 * Filter whether to load the block theme front-end stylesheet.
69 *
70 * @param bool $load_block_theme_stylesheet True when WordPress is 5.9+ and the active theme is a block theme.
71 */
72 return (bool) apply_filters( 'wppb_load_block_theme_stylesheet', $is_block_theme_context );
73 }
74
75 function wppb_add_plugin_stylesheet() {
76 $wppb_generalSettings = get_option( 'wppb_general_settings' );
77
78 if ( ( file_exists( WPPB_PLUGIN_DIR . '/assets/css/style-front-end.css' ) ) && ( isset( $wppb_generalSettings['extraFieldsLayout'] ) && ( $wppb_generalSettings['extraFieldsLayout'] == 'default' ) ) ){
79 wp_register_style( 'wppb_stylesheet', WPPB_PLUGIN_URL . 'assets/css/style-front-end.css', array(), PROFILE_BUILDER_VERSION );
80 wp_enqueue_style( 'wppb_stylesheet' );
81 }
82
83 if( is_rtl() ) {
84 if ( ( file_exists( WPPB_PLUGIN_DIR . '/assets/css/rtl.css' ) ) && ( isset( $wppb_generalSettings['extraFieldsLayout'] ) && ( $wppb_generalSettings['extraFieldsLayout'] == 'default' ) ) ){
85 wp_register_style( 'wppb_stylesheet_rtl', WPPB_PLUGIN_URL . 'assets/css/rtl.css', array(), PROFILE_BUILDER_VERSION );
86 wp_enqueue_style( 'wppb_stylesheet_rtl' );
87 }
88 }
89
90 if ( wppb_should_load_block_theme_stylesheet() ) {
91 $active_design = function_exists( 'wppb_get_active_form_design' ) ? wppb_get_active_form_design() : 'form-style-default';
92
93 if ( $active_design === 'form-style-default' && file_exists( WPPB_PLUGIN_DIR . 'assets/css/style-block-themes-front-end.css' ) ) {
94 wp_register_style( 'wppb_block_themes_front_end_stylesheet', WPPB_PLUGIN_URL . 'assets/css/style-block-themes-front-end.css', array(), PROFILE_BUILDER_VERSION );
95 wp_enqueue_style( 'wppb_block_themes_front_end_stylesheet' );
96 }
97 }
98 }
99
100
101 function wppb_show_admin_bar($content){
102 global $current_user;
103
104 $general_settings = get_option( 'wppb_general_settings' );
105 $selected_roles = isset( $general_settings['hide_admin_bar_for'] ) ? $general_settings['hide_admin_bar_for'] : '';
106
107 $show = null;
108
109 if ( $general_settings != 'not_found' && $current_user->ID && !empty( $selected_roles ) )
110 foreach ( $current_user->roles as $role_key ) {
111 if( $role_key == 'administrator' && current_user_can( 'manage_options' ) && !in_array( 'allUserRoles', $selected_roles ) )
112 break;
113 else if ( empty( $GLOBALS['wp_roles']->roles[$role_key] ) )
114 continue;
115
116 $role = $GLOBALS['wp_roles']->roles[$role_key];
117
118 if ( !empty( $selected_roles ) && ( in_array( $role['name'], $selected_roles ) || in_array( 'allUserRoles', $selected_roles ) || in_array( 'allUserRolesExceptAdmin', $selected_roles ) ) && $show === null )
119 $show = false;
120 }
121 return $show === null ? $content : $show;
122 }
123
124 function wppb_has_international_tel_input_field() {
125 $manage_fields = get_option( 'wppb_manage_fields', array() );
126
127 if ( ! is_array( $manage_fields ) ) {
128 return false;
129 }
130
131 foreach ( $manage_fields as $field ) {
132 if ( ! empty( $field['field'] ) && $field['field'] === 'International Telephone Input' ) {
133 return true;
134 }
135 }
136
137 return false;
138 }
139
140 function wppb_maybe_add_international_tel_input_notice() {
141 if ( ! class_exists( 'WPPB_Plugin_Notifications' ) ) {
142 return;
143 }
144
145 if ( ! wppb_has_international_tel_input_field() ) {
146 return;
147 }
148
149 if ( function_exists( 'wppb_international_tel_input_handler' ) ) {
150 return;
151 }
152
153 $notification_id = 'wppb_intl_tel_input_paid_update_notice';
154 $message = '<p>';
155 $message .= __( 'The <strong>International Telephone Input</strong> field is currently used on this site, but it now requires the <strong>paid Profile Builder plugin</strong> to be updated as well.', 'profile-builder' );
156 $message .= ' ';
157 $message .= __( 'Please update the paid plugin to the latest version so this field can continue to load and validate correctly.', 'profile-builder' );
158 $message .= '</p>';
159 $message .= '<a href="' . wp_nonce_url( add_query_arg( array( 'wppb_dismiss_admin_notification' => $notification_id ) ), 'wppb_plugin_notice_dismiss' ) . '" type="button" class="notice-dismiss"><span class="screen-reader-text">' . __( 'Dismiss this notice.', 'profile-builder' ) . '</span></a>';
160
161 WPPB_Plugin_Notifications::get_instance()->add_notification( $notification_id, $message, 'wppb-notice notice notice-warning is-dismissible', false, array(), true );
162 }
163
164 add_action( 'admin_init', 'wppb_maybe_add_international_tel_input_notice' );
165
166 if(!function_exists('wppb_curpageurl')){
167 function wppb_curpageurl(){
168 $req_uri = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( $_SERVER['REQUEST_URI'] ) : '';
169
170 if( function_exists('wppb_get_abs_home') ) {
171 $url = parse_url( wppb_get_abs_home(), PHP_URL_PATH );
172
173 $home_path = !empty( $url ) ? trim( $url, '/' ) : $url;
174
175 if( $home_path === null || $home_path === false )
176 $home_path = '';
177
178 $home_path_regex = sprintf('|^%s|i', preg_quote($home_path, '|'));
179
180 // Trim path info from the end and the leading home path from the front.
181 $req_uri = ltrim($req_uri, '/');
182 $req_uri = preg_replace($home_path_regex, '', $req_uri);
183 $req_uri = trim(wppb_get_abs_home(), '/') . '/' . ltrim($req_uri, '/');
184 }
185
186 if ( function_exists('apply_filters') ) $req_uri = apply_filters('wppb_curpageurl', $req_uri);
187
188 return $req_uri;
189 }
190 }
191
192 /**
193 * Return absolute home url as stored in database, unfiltered.
194 *
195 * @return string
196 */
197 if(!function_exists('wppb_get_abs_home')) {
198 function wppb_get_abs_home(){
199 global $wpdb;
200 global $wppb_absolute_home;
201
202 if( isset($wppb_absolute_home) ) {
203 return $wppb_absolute_home;
204 }
205
206 // returns the unfiltered home_url by directly retrieving it from wp_options.
207 $wppb_absolute_home = (!is_multisite() && defined('WP_HOME')
208 ? WP_HOME
209 : (is_multisite() && !is_main_site()
210 ? (preg_match('/^(https)/', get_option('home')) === 1 ? 'https://'
211 : 'http://') . $wpdb->get_var(" SELECT CONCAT(b.domain, b.path)
212 FROM {$wpdb->blogs} b
213 WHERE blog_id = {$wpdb->blogid}
214 LIMIT 1")
215
216 : $wpdb->get_var(" SELECT option_value
217 FROM {$wpdb->options}
218 WHERE option_name = 'home'
219 LIMIT 1"))
220 );
221
222 if (empty($wppb_absolute_home)) {
223 $wppb_absolute_home = get_option("siteurl");
224 }
225
226 // always return absolute_home based on the http or https version of the current page request. This means no more redirects.
227 if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
228 $wppb_absolute_home = str_replace('http://', 'https://', $wppb_absolute_home);
229 } else {
230 $wppb_absolute_home = str_replace('https://', 'http://', $wppb_absolute_home);
231 }
232
233 return $wppb_absolute_home;
234 }
235 }
236
237
238 if ( is_admin() ){
239
240 // register the settings for the menu only display sidebar menu for a user with a certain capability, in this case only the "admin"
241 add_action( 'admin_init', 'wppb_register_settings' );
242
243 // display the same extra profile fields in the admin panel also
244 if ( file_exists ( WPPB_PLUGIN_DIR.'/front-end/default-fields/fields-functions.php' ) ){
245 require_once( WPPB_PLUGIN_DIR.'/front-end/default-fields/fields-functions.php' );
246
247 add_action( 'show_user_profile', 'wppb_display_fields_in_admin', 10 );
248 add_action( 'edit_user_profile', 'wppb_display_fields_in_admin', 10 );
249 global $pagenow;
250 if( $pagenow != 'user-new.php' )
251 add_action( 'user_profile_update_errors', 'wppb_validate_fields_in_admin', 10, 3 );
252 add_action( 'personal_options_update', 'wppb_save_fields_in_admin', 10 );
253 add_action( 'edit_user_profile_update', 'wppb_save_fields_in_admin', 10 );
254 }
255
256 // Since 3.8.1 fields are loaded in the back-end all the time: for conditional logic, simple uploads, display fields in admin functionalities
257 if (file_exists(WPPB_PLUGIN_DIR . '/front-end/default-fields/default-fields.php'))
258 require_once(WPPB_PLUGIN_DIR . '/front-end/default-fields/default-fields.php');
259
260 if ( defined( 'WPPB_PAID_PLUGIN_DIR' ) && file_exists( WPPB_PAID_PLUGIN_DIR . '/front-end/extra-fields/extra-fields.php'))
261 require_once(WPPB_PAID_PLUGIN_DIR . '/front-end/extra-fields/extra-fields.php');
262
263
264 }else if ( !is_admin() ){
265 // include the stylesheet
266 add_action( 'wp_print_styles', 'wppb_add_plugin_stylesheet' );
267
268 // include the menu file for the profile informations
269 include_once( WPPB_PLUGIN_DIR.'/front-end/edit-profile.php' );
270 include_once( WPPB_PLUGIN_DIR.'/front-end/class-formbuilder.php' );
271 add_shortcode( 'wppb-edit-profile', 'wppb_front_end_profile_info' );
272
273 // include the menu file for the login screen
274 include_once( WPPB_PLUGIN_DIR.'/front-end/login.php' );
275 add_shortcode( 'wppb-login', 'wppb_front_end_login' );
276
277 // include the menu file for the logout screen
278 include_once( WPPB_PLUGIN_DIR.'/front-end/logout.php' );
279 add_shortcode( 'wppb-logout', 'wppb_front_end_logout' );
280
281 // include the menu file for the register screen
282 include_once( WPPB_PLUGIN_DIR.'/front-end/register.php' );
283 add_shortcode( 'wppb-register', 'wppb_front_end_register_handler' );
284
285 // include the menu file for the recover password screen
286 include_once( WPPB_PLUGIN_DIR.'/front-end/recover.php' );
287 add_shortcode( 'wppb-recover-password', 'wppb_front_end_password_recovery' );
288
289 // set the front-end admin bar to show/hide
290 add_filter( 'show_admin_bar' , 'wppb_show_admin_bar');
291
292 // Shortcodes used for the widget area
293 add_filter( 'widget_text', 'do_shortcode', 11 );
294 }
295
296
297 /**
298 * Function that overwrites the default wp_mail function and sends out emails
299 *
300 * @since v.2.0
301 *
302 * @param string $to
303 * @param string $subject
304 * @param string $message
305 * @param string $message_from
306 *
307 */
308 function wppb_mail( $to, $subject, $message, $message_from = null, $context = null, $headers = '' ) {
309 $to = apply_filters( 'wppb_send_email_to', $to, $context );
310 $send_email = apply_filters( 'wppb_send_email', true, $to, $subject, $message, $context );
311
312 $message = apply_filters( 'wppb_email_message', $message, $context );
313
314 $message = wppb_maybe_add_propper_html_tags_to_email( $message );
315
316 do_action( 'wppb_before_sending_email', $to, $subject, $message, $send_email, $context );
317
318 if ( $send_email ) {
319 //we add this filter to enable html encoding
320 if( apply_filters( 'wppb_mail_enable_html', true, $context, $to, $subject, $message ) )
321 add_filter('wp_mail_content_type', 'wppb_html_content_type' );
322
323 $atts = apply_filters( 'wppb_mail', compact( 'to', 'subject', 'message', 'headers' ), $context );
324
325 $sent = wp_mail( $atts['to'] , html_entity_decode( htmlspecialchars_decode( $atts['subject'], ENT_QUOTES ), ENT_QUOTES ), $atts['message'], $atts['headers'] );
326
327 do_action( 'wppb_after_sending_email', $sent, $to, $subject, $message, $send_email, $context );
328
329 return $sent;
330 }
331
332 return '';
333 }
334
335 /* return text/html as email content type. used in wp_mail_content_type filter */
336 function wppb_html_content_type( $content_type ){
337 return 'text/html';
338 }
339
340 /*
341 * function that adds proper html tags to a html email message if they are missing
342 */
343 function wppb_maybe_add_propper_html_tags_to_email( $message ){
344
345 //check if we have html content
346 if( $message !== wp_strip_all_tags( $message ) ){
347 if( strpos( html_entity_decode( $message ), '<html' ) === false && strpos( html_entity_decode( $message ), '<body' ) === false ){
348 $message = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body>'. $message . '</body></html>';
349 }
350 }
351
352 return $message;
353 }
354
355 function wppb_activate_account_check(){
356 if ( ( isset( $_GET['activation_key'] ) ) && ( sanitize_text_field( $_GET['activation_key'] ) != '' ) ){
357 global $post;
358 $activation_key = sanitize_text_field( $_GET['activation_key'] );
359
360 $wppb_generalSettings = get_option( 'wppb_general_settings' );
361 $activation_landing_page_id = ( ( isset( $wppb_generalSettings['activationLandingPage'] ) && ( trim( $wppb_generalSettings['activationLandingPage'] ) != '' ) ) ? $wppb_generalSettings['activationLandingPage'] : 'not_set' );
362
363 if ( $activation_landing_page_id != 'not_set' ){
364 //an activation page was selected, but we still need to check if the current page doesn't already have the registration shortcode
365 if ( strpos( $post->post_content, '[wppb-register' ) === false && !has_block( 'wppb/register', $post->post_content ) )
366 add_filter( 'the_content', 'wppb_add_activation_message' );
367
368 }elseif ( strpos( $post->post_content, '[wppb-register' ) === false && !has_block( 'wppb/register', $post->post_content ) ){
369 //no activation page was selected, and the sent link pointed to the home url
370 nocache_headers();
371 wp_redirect( apply_filters( 'wppb_activatate_account_redirect_url', WPPB_PLUGIN_URL.'assets/misc/fallback-page.php?activation_key='.urlencode( $activation_key ).'&site_name='.urlencode( get_bloginfo( 'name' ) ).'&message='.urlencode( $activation_message = wppb_activate_signup( $activation_key ) ), $activation_key, $activation_message ) );
372 exit;
373 }
374 }
375 }
376 add_action( 'template_redirect', 'wppb_activate_account_check' );
377
378
379 function wppb_add_activation_message( $content ){
380 if( isset( $_GET['activation_key'] ) )
381 return wppb_activate_signup( sanitize_text_field( $_GET['activation_key'] ) ) . $content;
382 else
383 return $content;
384 }
385
386
387 // Create a new, top-level page
388 $args = array(
389 'page_title' => 'Profile Builder',
390 'menu_title' => 'Profile Builder',
391 'capability' => 'manage_options',
392 'menu_slug' => 'profile-builder',
393 'page_type' => 'menu_page',
394 'position' => '70.69',
395 'priority' => 1,
396 'icon_url' => WPPB_PLUGIN_URL . 'assets/images/pb-menu-icon.svg'
397 );
398 new WCK_Page_Creator_PB( $args );
399
400 /**
401 * Remove the automatically created submenu page
402 *
403 * @since v.2.0
404 *
405 * @return void
406 */
407 function wppb_remove_main_menu_page(){
408 remove_submenu_page( 'profile-builder', 'profile-builder' );
409 }
410 add_action( 'admin_menu', 'wppb_remove_main_menu_page', 11 );
411
412 /**
413 * Add scripts to the back-end CPT's to remove the slug from the edit page
414 *
415 * @since v.2.0
416 *
417 * @return void
418 */
419 function wppb_print_cpt_script( $hook ){
420 wp_enqueue_script( 'jquery-ui-dialog' );
421 wp_enqueue_style( 'wp-jquery-ui-dialog' );
422
423 if ( $hook == 'profile-builder_page_manage-fields' ){
424 wp_enqueue_script( 'wppb-manage-fields-live-change', WPPB_PLUGIN_URL . 'assets/js/jquery-manage-fields-live-change.js', array(), PROFILE_BUILDER_VERSION, true );
425 wp_localize_script( 'wppb-manage-fields-live-change', 'wppb_fields_strings', array( 'gdpr_title' => __( 'GDPR Checkbox', 'profile-builder' ), 'gdpr_description' => __( 'I allow the website to collect and store the data I submit through this form.', 'profile-builder' ), 'honeypot_title' => __( 'Honeypot', 'profile-builder' ) ) );
426
427 wp_enqueue_script( 'wppb-select2', WPPB_PLUGIN_URL . 'assets/js/select2/select2.min.js', array(), PROFILE_BUILDER_VERSION, true );
428 wp_enqueue_style( 'wppb-select2-style', WPPB_PLUGIN_URL . 'assets/css/select2/select2.min.css', false, PROFILE_BUILDER_VERSION );
429 }
430
431 if ( $hook == 'profile-builder_page_profile-builder-private-website' ){
432 wp_enqueue_script( 'wppb-select2', WPPB_PLUGIN_URL . 'assets/js/select2/select2.min.js', array(), PROFILE_BUILDER_VERSION, true );
433 wp_enqueue_script( 'wppb-select2-compat', WPPB_PLUGIN_URL . 'assets/js/select2-compat.js', array(), PROFILE_BUILDER_VERSION, true );
434 wp_enqueue_style( 'wppb-select2-style', WPPB_PLUGIN_URL . 'assets/css/select2/select2.min.css', false, PROFILE_BUILDER_VERSION );
435 }
436
437 if (( $hook == 'profile-builder_page_manage-fields' ) ||
438 ( $hook == 'profile-builder_page_profile-builder-basic-info' ) ||
439 ( $hook == 'profile-builder_page_profile-builder-add-ons' ) ||
440 ( $hook == 'profile-builder_page_profile-builder-general-settings' ) ||
441 ( $hook == 'profile-builder_page_profile-builder-admin-bar-settings' ) ||
442 ( $hook == 'profile-builder_page_profile-builder-register' ) ||
443 ( $hook == 'profile-builder_page_profile-builder-wppb_userListing' ) ||
444 ( $hook == 'profile-builder_page_custom-redirects' ) ||
445 ( $hook == 'profile-builder_page_profile-builder-wppb_emailCustomizer' ) ||//?what is this
446 ( $hook == 'profile-builder_page_profile-builder-wppb_emailCustomizerAdmin' ) ||//?what is this
447 ( $hook == 'profile-builder_page_profile-builder-add-ons' ) ||
448 ( $hook == 'profile-builder_page_profile-builder-woocommerce-sync' ) ||
449 ( $hook == 'profile-builder_page_profile-builder-bbpress') ||
450 ( $hook == 'profile-builder_page_admin-email-customizer') ||
451 ( $hook == 'profile-builder_page_user-email-customizer') ||
452 ( $hook == 'profile-builder_page_profile-builder-content_restriction' ) ||
453 ( strpos( $hook, 'profile-builder_page_' ) === 0 ) ||
454 ( $hook == 'edit.php' && ( isset( $_GET['post_type'] ) && $_GET['post_type'] === 'wppb-roles-editor' ) ) ||
455 ( $hook == 'toplevel_page_profile-builder-register') || //multisite register version page
456 ( $hook == 'admin_page_profile-builder-pms-promo') ) {
457 wp_enqueue_style( 'wppb-back-end-style', WPPB_PLUGIN_URL . 'assets/css/style-back-end.css', false, PROFILE_BUILDER_VERSION );
458 }
459
460 if ( $hook == 'profile-builder_page_profile-builder-general-settings' )
461 wp_enqueue_script( 'wppb-manage-fields-live-change', WPPB_PLUGIN_URL . 'assets/js/jquery-email-confirmation.js', array(), PROFILE_BUILDER_VERSION, true );
462
463 if( ($hook == 'profile-builder_page_profile-builder-add-ons' ) ||
464 ($hook == 'admin_page_profile-builder-pms-promo' ) ) {
465 wp_enqueue_script('wppb-add-ons', WPPB_PLUGIN_URL . 'assets/js/jquery-pb-add-ons.js', array(), PROFILE_BUILDER_VERSION, true);
466 wp_enqueue_style( 'thickbox' );
467 wp_enqueue_script( 'thickbox' );
468 }
469
470 if ( $hook == 'profile-builder_page_profile-builder-dashboard' )
471 wp_enqueue_script( 'jquery-pb-dashboard', WPPB_PLUGIN_URL . 'assets/js/jquery-pb-dashboard.js', array(), PROFILE_BUILDER_VERSION, true );
472
473 if ( isset( $_GET['post_type'] ) || isset( $_GET['post'] ) ){
474 if ( isset( $_GET['post_type'] ) )
475 $post_type = sanitize_text_field( $_GET['post_type'] );
476
477 elseif ( isset( $_GET['post'] ) )
478 $post_type = get_post_type( absint( $_GET['post'] ) );
479
480 if ( ( 'wppb-epf-cpt' == $post_type ) || ( 'wppb-rf-cpt' == $post_type ) || ( 'wppb-ul-cpt' == $post_type ) ){
481 wp_enqueue_style( 'wppb-back-end-style', WPPB_PLUGIN_URL . 'assets/css/style-back-end.css', false, PROFILE_BUILDER_VERSION );
482 wp_enqueue_script( 'wppb-epf-rf', WPPB_PLUGIN_URL . 'assets/js/jquery-epf-rf.js', array(), PROFILE_BUILDER_VERSION, true );
483 wp_localize_script( 'wppb-epf-rf', 'wppbEpfRf', array( 'nonce' => wp_create_nonce( 'wppb-epf-rf-id-change' ) ) );
484 }
485 else if( 'wppb-roles-editor' == $post_type ){
486 wp_enqueue_style( 'wppb-back-end-style', WPPB_PLUGIN_URL . 'assets/css/style-back-end.css', array(), PROFILE_BUILDER_VERSION );
487 }
488 }
489 else if ( isset( $_GET['page'] ) ) {
490 wp_enqueue_style( 'wppb-back-end-style', WPPB_PLUGIN_URL . 'assets/css/style-back-end.css', array(), PROFILE_BUILDER_VERSION );
491 }
492
493 if ( $hook == 'user-edit.php' ) {
494 wp_enqueue_style( 'wppb-back-end-edit-user-style', WPPB_PLUGIN_URL . 'assets/css/style-back-end-edit-user.css', array(), PROFILE_BUILDER_VERSION );
495 }
496
497 wp_enqueue_script( 'wppb-sitewide', WPPB_PLUGIN_URL . 'assets/js/jquery-pb-sitewide.js', array(), PROFILE_BUILDER_VERSION, true );
498 wp_localize_script( 'wppb-sitewide', 'wppbDeactivationData', array(
499 'deactivationReasonNonce' => wp_create_nonce( 'wppb_deactivation_reason' ),
500 'deactivationReasonRequired' => __( 'Please select a reason before deactivating.', 'profile-builder' ),
501 'deactivationReasonInput' => __( 'Please complete the required field before deactivating.', 'profile-builder' ),
502 'deactivationReasonSaveError' => __( 'We could not save your feedback. Please try again.', 'profile-builder' ),
503 ) );
504
505 wp_enqueue_style( 'wppb-serial-notice-css', WPPB_PLUGIN_URL . 'assets/css/serial-notice.css', false, PROFILE_BUILDER_VERSION );
506 }
507 add_action( 'admin_enqueue_scripts', 'wppb_print_cpt_script', 9 );
508
509 /**
510 * Highlight the settings page under Profile Builder in the admin menu for these pages
511 */
512 //add add_action( "admin_footer-$hook", "wppb_make_setting_menu_item_highlighted" ); for other pages that don't have a parent
513 add_action( "admin_footer-profile-builder_page_profile-builder-private-website", "wppb_make_setting_menu_item_highlighted" );
514 add_action( "admin_footer-profile-builder_page_profile-builder-admin-bar-settings", "wppb_make_setting_menu_item_highlighted" );
515 add_action( "admin_footer-profile-builder_page_profile-builder-content_restriction", "wppb_make_setting_menu_item_highlighted" );
516 add_action( "admin_footer-profile-builder_page_admin-email-customizer", "wppb_make_setting_menu_item_highlighted" );
517 add_action( "admin_footer-profile-builder_page_user-email-customizer", "wppb_make_setting_menu_item_highlighted" );
518 add_action( "admin_footer-profile-builder_page_profile-builder-toolbox-settings", "wppb_make_setting_menu_item_highlighted" );
519 add_action( "admin_footer-profile-builder_page_profile-builder-two-factor-authentication", "wppb_make_setting_menu_item_highlighted" );
520 function wppb_make_setting_menu_item_highlighted(){
521 echo'<script type="text/javascript">
522 jQuery(document).ready( function($) {
523 $("#toplevel_page_profile-builder").addClass("current wp-has-current-submenu wp-menu-open");
524 $("a[href=\'admin.php?page=profile-builder-general-settings\']").closest("li").addClass("current");
525 });
526 </script>';
527 }
528
529
530 //the function used to overwrite the avatar across the wp installation
531 function wppb_changeDefaultAvatar( $avatar, $id_or_email, $size, $default, $alt ){
532 /* Get user info. */
533 if(is_object($id_or_email)){
534 $my_user_id = $id_or_email->user_id;
535
536 if ($id_or_email instanceof WP_User){
537 $my_user_id = $id_or_email->ID;
538 }
539
540 }elseif(is_numeric($id_or_email)){
541 $my_user_id = $id_or_email;
542
543 }elseif(!is_integer($id_or_email)){
544 $user_info = get_user_by( 'email', $id_or_email );
545 $my_user_id = ( is_object( $user_info ) ? $user_info->ID : '' );
546 }else
547 $my_user_id = $id_or_email;
548
549 $wppb_manage_fields = get_option( 'wppb_manage_fields', 'not_found' );
550 if ( $wppb_manage_fields != 'not_found' ){
551 foreach( $wppb_manage_fields as $value ){
552 if ( $value['field'] == 'Avatar'){
553 $avatar_field = $value;
554 }
555 }
556 }
557
558 /* for multisite if we don't have an avatar try to get it from the main blog */
559 if( is_multisite() && empty( $avatar_field ) ){
560 switch_to_blog(1);
561 $wppb_switched_blog = true;
562 $wppb_manage_fields = get_option( 'wppb_manage_fields', 'not_found' );
563 if ( $wppb_manage_fields != 'not_found' ){
564 foreach( $wppb_manage_fields as $value ){
565 if ( $value['field'] == 'Avatar'){
566 $avatar_field = $value;
567 }
568 }
569 }
570 }
571
572 if ( !empty( $avatar_field ) ){
573
574 $customUserAvatar = get_user_meta( $my_user_id, Wordpress_Creation_Kit_PB::wck_generate_slug( $avatar_field['meta-name'] ), true );
575 if( !empty( $customUserAvatar ) ){
576 if( is_numeric( $customUserAvatar ) ){
577 $img_attr = wp_get_attachment_image_src( $customUserAvatar, 'wppb-avatar-size-'.$size );
578
579 if( is_array( $img_attr ) ){
580 if( $img_attr[3] === false ){
581 $img_attr = wp_get_attachment_image_src( $customUserAvatar, 'thumbnail' );
582 $avatar = "<img alt='{$alt}' src='{$img_attr[0]}' class='avatar avatar-{$size} photo avatar-default' height='{$size}' width='{$size}' />";
583 }
584 else
585 $avatar = "<img alt='{$alt}' src='{$img_attr[0]}' class='avatar avatar-{$size} photo avatar-default' height='{$img_attr[2]}' width='{$img_attr[1]}' />";
586 }
587 }
588 else {
589 $customUserAvatar = get_user_meta($my_user_id, 'resized_avatar_' . $avatar_field['id'], true);
590 $customUserAvatarRelativePath = get_user_meta($my_user_id, 'resized_avatar_' . $avatar_field['id'] . '_relative_path', true);
591
592 if ((($customUserAvatar != '') || ($customUserAvatar != null)) && file_exists($customUserAvatarRelativePath)) {
593 $avatar = "<img alt='{$alt}' src='{$customUserAvatar}' class='avatar avatar-{$size} photo avatar-default' height='{$size}' width='{$size}' />";
594 }
595 }
596 }
597
598 }
599
600 /* if we switched the blog restore it */
601 if( is_multisite() && !empty( $wppb_switched_blog ) && $wppb_switched_blog )
602 restore_current_blog();
603
604 return $avatar;
605 }
606 add_filter( 'get_avatar', 'wppb_changeDefaultAvatar', 21, 5 );
607
608
609 //the function used to overwrite the avatar across the wp installation
610 function wppb_changeDefaultAvatarUrl( $url, $id_or_email, $args ){
611 /* Get user info. */
612 if(is_object($id_or_email)){
613 $my_user_id = $id_or_email->user_id;
614
615 if ($id_or_email instanceof WP_User){
616 $my_user_id = $id_or_email->ID;
617 }
618
619 }elseif(is_numeric($id_or_email)){
620 $my_user_id = $id_or_email;
621
622 }elseif(!is_integer($id_or_email)){
623 $user_info = get_user_by( 'email', $id_or_email );
624 $my_user_id = ( is_object( $user_info ) ? $user_info->ID : '' );
625 }else
626 $my_user_id = $id_or_email;
627
628 $wppb_manage_fields = get_option( 'wppb_manage_fields', 'not_found' );
629 if ( $wppb_manage_fields != 'not_found' ){
630 foreach( $wppb_manage_fields as $value ){
631 if ( $value['field'] == 'Avatar'){
632 $avatar_field = $value;
633 }
634 }
635 }
636
637 /* for multisite if we don't have an avatar try to get it from the main blog */
638 if( is_multisite() && empty( $avatar_field ) ){
639 switch_to_blog(1);
640 $wppb_switched_blog = true;
641 $wppb_manage_fields = get_option( 'wppb_manage_fields', 'not_found' );
642 if ( $wppb_manage_fields != 'not_found' ){
643 foreach( $wppb_manage_fields as $value ){
644 if ( $value['field'] == 'Avatar'){
645 $avatar_field = $value;
646 }
647 }
648 }
649 }
650
651 $avatar_url = $url;
652
653 if ( !empty( $avatar_field ) ){
654
655 $customUserAvatar = get_user_meta( $my_user_id, Wordpress_Creation_Kit_PB::wck_generate_slug( $avatar_field['meta-name'] ), true );
656 if( !empty( $customUserAvatar ) ){
657 if( is_numeric( $customUserAvatar ) ){
658 if( $img_attr = wp_get_attachment_image_src( $customUserAvatar, 'wppb-avatar-size-'.$args['size'] ) ) {
659 if ( $img_attr[3] === false ) {
660 $img_attr = wp_get_attachment_image_src( $customUserAvatar, 'thumbnail' );
661 }
662 $avatar_url = $img_attr[0];
663 }
664 }
665 else {
666 $customUserAvatar = get_user_meta($my_user_id, 'resized_avatar_' . $avatar_field['id'], true);
667 $customUserAvatarRelativePath = get_user_meta($my_user_id, 'resized_avatar_' . $avatar_field['id'] . '_relative_path', true);
668
669 if ((($customUserAvatar != '') || ($customUserAvatar != null)) && file_exists($customUserAvatarRelativePath)) {
670 $avatar_url = $customUserAvatar;
671 }
672 }
673 }
674
675 }
676
677 /* if we switched the blog restore it */
678 if( is_multisite() && !empty( $wppb_switched_blog ) && $wppb_switched_blog )
679 restore_current_blog();
680
681 return $avatar_url;
682 }
683 add_filter( 'get_avatar_url', 'wppb_changeDefaultAvatarUrl', 21, 5 );
684
685
686 //the function used to resize the avatar image; the new function uses a user ID as parameter to make pages load faster
687 function wppb_resize_avatar( $userID, $userlisting_size = null, $userlisting_crop = null ){
688 // include the admin image API
689 require_once( ABSPATH . '/wp-admin/includes/image.php' );
690
691 // retrieve first a list of all the current custom fields
692 $wppb_manage_fields = get_option( 'wppb_manage_fields', 'not_found' );
693 if ( $wppb_manage_fields != 'not_found' ){
694 foreach( $wppb_manage_fields as $value ){
695 if ( $value['field'] == 'Avatar'){
696 $avatar_field = $value;
697 }
698 }
699 }
700
701 /* for multisite if we don't have an avatar try to get it from the main blog */
702 if( is_multisite() && empty( $avatar_field ) ){
703 switch_to_blog(1);
704 $wppb_switched_blog = true;
705 $wppb_manage_fields = get_option( 'wppb_manage_fields', 'not_found' );
706 if ( $wppb_manage_fields != 'not_found' ){
707 foreach( $wppb_manage_fields as $value ){
708 if ( $value['field'] == 'Avatar'){
709 $avatar_field = $value;
710 }
711 }
712 }
713 }
714
715
716 if ( !empty( $avatar_field ) ){
717
718 // retrieve width and height of the image
719 $width = $height = '';
720
721 //this checks if it only has 1 component
722 if ( is_numeric( $avatar_field['avatar-size'] ) ){
723 $width = $height = $avatar_field['avatar-size'];
724
725 }else{
726 //this checks if the entered value has 2 components
727 $sentValue = explode( ',', $avatar_field['avatar-size'] );
728 $width = $sentValue[0];
729 $height = $sentValue[1];
730 }
731
732 $width = ( !empty( $userlisting_size ) ? $userlisting_size : $width );
733 $height = ( !empty( $userlisting_size ) ? $userlisting_size : $height );
734
735 if( !strpos( get_user_meta( $userID, 'resized_avatar_'.$avatar_field['id'], true ), $width . 'x' . $height ) ) {
736 // retrieve the original image (in original size)
737 $avatar_directory_path = get_user_meta( $userID, 'avatar_directory_path_'.$avatar_field['id'], true );
738
739 $image = wp_get_image_editor( $avatar_directory_path );
740 if ( !is_wp_error( $image ) ) {
741 do_action( 'wppb_before_avatar_resizing', $image, $userID, Wordpress_Creation_Kit_PB::wck_generate_slug( $avatar_field['meta-name'] ), $avatar_field['avatar-size'] );
742
743 $crop = apply_filters( 'wppb_avatar_crop_resize', ( !empty( $userlisting_crop ) ? $userlisting_crop : false ) );
744
745 $resize = $image->resize( $width, $height, $crop );
746
747 if ($resize !== FALSE) {
748 do_action( 'wppb_avatar_resizing', $image, $resize );
749
750 $fileType = apply_filters( 'wppb_resized_file_extension', 'png' );
751
752 $wp_upload_array = wp_upload_dir(); // Array of key => value pairs
753
754 //create file(name); both with directory and url
755 $fileName_dir = $image->generate_filename( NULL, $wp_upload_array['basedir'].'/profile_builder/avatars/', $fileType );
756
757 if ( PHP_OS == "WIN32" || PHP_OS == "WINNT" )
758 $fileName_dir = str_replace( '\\', '/', $fileName_dir );
759
760 $fileName_url = str_replace( str_replace( '\\', '/', $wp_upload_array['basedir'] ), $wp_upload_array['baseurl'], $fileName_dir );
761
762 //save the newly created (resized) avatar on the disc
763 $saved_image = $image->save( $fileName_dir );
764
765 if ( !is_wp_error( $saved_image ) ) {
766 /* the image save sometimes doesn't save with the desired extension so we need to see with what extension it saved it with and
767 if it differs replace the extension in the path and url that we save as meta */
768 $validate_saved_image = wp_check_filetype_and_ext( $saved_image['path'], $saved_image['path'] );
769 $ext = substr( $fileName_dir,strrpos( $fileName_dir, '.', -1 ), strlen($fileName_dir) );
770 if( !empty( $validate_saved_image['ext'] ) && $validate_saved_image['ext'] != $ext ){
771 $fileName_url = str_replace( $ext, '.'.$validate_saved_image['ext'], $fileName_url );
772 $fileName_dir = str_replace( $ext, '.'.$validate_saved_image['ext'], $fileName_dir );
773 }
774
775 update_user_meta( $userID, 'resized_avatar_'.$avatar_field['id'], $fileName_url );
776 update_user_meta( $userID, 'resized_avatar_'.$avatar_field['id'].'_relative_path', $fileName_dir );
777
778 do_action( 'wppb_after_avatar_resizing', $image, $fileName_dir, $fileName_url );
779 }
780 }
781 }
782 }
783 }
784
785 /* if we switched the blog restore it */
786 if( is_multisite() && !empty( $wppb_switched_blog ) && $wppb_switched_blog )
787 restore_current_blog();
788
789 }
790
791
792 // add a hook to delete the user from the _signups table if either the email confirmation is activated, or it is a wpmu installation
793 function wppb_delete_user_from_signups_table($user_id) {
794 global $wpdb;
795
796 $user = get_userdata( $user_id );
797
798 if ( empty( $user ) ) {
799 return;
800 }
801
802 // Delete signup rows by both email and login so activated entries do not remain orphaned in the signups table
803 // - the signup row can preserve the originally submitted username, while the actual WP user_login may be regenerated from the submitted email address on activation
804 // - the signup row can also preserve the email address used at registration time, while the actual WP user_email may later change after activation
805 // - deleting by both keys covers both mismatch cases and keeps stale signups rows from blocking future registrations or other flows
806 if ( is_multisite() ) {
807 $wpdb->delete( $wpdb->signups, array( 'user_email' => $user->user_email ), array( '%s' ) );
808 $wpdb->delete( $wpdb->signups, array( 'user_login' => $user->user_login ), array( '%s' ) );
809 } else {
810 $table_name = $wpdb->prefix . 'signups';
811 $val = $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE %s", $table_name ) );
812 if ( $val ) {
813 $wpdb->delete( $table_name, array( 'user_email' => $user->user_email ), array( '%s' ) );
814 $wpdb->delete( $table_name, array( 'user_login' => $user->user_login ), array( '%s' ) );
815 }
816 }
817 }
818
819 $wppb_generalSettings = get_option( 'wppb_general_settings' );
820 if ( !empty( $wppb_generalSettings['emailConfirmation'] ) && ( $wppb_generalSettings['emailConfirmation'] == 'yes' ) ) {
821 if( is_multisite() )
822 add_action( 'wpmu_delete_user', 'wppb_delete_user_from_signups_table' );
823 else
824 add_action('delete_user', 'wppb_delete_user_from_signups_table');
825 }
826
827
828
829 // This function offers compatibility with the all in one event calendar plugin
830 function wppb_aioec_compatibility(){
831
832 wp_deregister_script( 'jquery.tools-form');
833 }
834 add_action('admin_print_styles-users_page_ProfileBuilderOptionsAndSettings', 'wppb_aioec_compatibility');
835
836
837 function wppb_user_meta_exists( $id, $meta_name ){
838 global $wpdb;
839
840 return apply_filters( 'wppb_user_meta_exists_meta_name', $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->usermeta WHERE user_id = %d AND meta_key = %s", $id, $meta_name ) ), $id, $meta_name );
841 }
842
843
844 /**
845 * Sanitize a URL from request input. Non-string values (e.g. arrays from bracket notation) return ''.
846 *
847 * @param mixed $url Candidate URL.
848 * @return string
849 */
850 function wppb_sanitize_request_url( $url ) {
851 if ( ! is_string( $url ) || $url === '' ) {
852 return '';
853 }
854
855 return esc_url_raw( wp_unslash( $url ) );
856 }
857
858 // function to check if there is a need to add the http:// prefix
859 function wppb_check_missing_http( $redirectLink ) {
860 return preg_match( '#^(?:[a-z\d]+(?:-+[a-z\d]+)*\.)+[a-z]+(?::\d+)?(?:/|$)#i', $redirectLink );
861 }
862
863 //function that adds missing http to a link
864 function wppb_add_missing_http( $link ){
865 $http = '';
866 if ( wppb_check_missing_http( $link ) ) { //if missing http(s)
867 $http = 'http';
868 if ((isset($_SERVER["HTTPS"])) && ($_SERVER["HTTPS"] == "on"))
869 $http .= "s";
870 $http .= "://";
871 }
872
873 return $http . $link;
874 }
875
876
877 //function to output the password strength checker on frontend forms
878 function wppb_password_strength_checker_html(){
879 $wppb_generalSettings = get_option( 'wppb_general_settings' );
880 if( !empty( $wppb_generalSettings['minimum_password_strength'] ) ){
881 $password_strength = '<span id="pass-strength-result">'.__('Strength indicator', 'profile-builder' ).'</span>
882 <input type="hidden" value="" name="wppb_password_strength" id="wppb_password_strength"/>';
883 return $password_strength;
884 }
885 return '';
886 }
887
888 //function to check password length check
889 function wppb_check_password_length( $password ){
890 $wppb_generalSettings = get_option( 'wppb_general_settings' );
891 if( !empty( $wppb_generalSettings['minimum_password_length'] ) ){
892 if( strlen( $password ) < $wppb_generalSettings['minimum_password_length'] ){
893 return true;
894 }
895 else
896 return false;
897 }
898 return false;
899 }
900
901 //function to check password strength
902 function wppb_check_password_strength(){
903 $wppb_generalSettings = get_option( 'wppb_general_settings' );
904 if( isset( $_POST['wppb_password_strength'] ) && sanitize_text_field( $_POST['wppb_password_strength'] ) != '' && !empty( $wppb_generalSettings['minimum_password_strength'] ) ){
905 $wppb_password_strength = sanitize_text_field( $_POST['wppb_password_strength'] );
906 $password_strength_array = array( 'short' => 0, 'bad' => 1, 'good' => 2, 'strong' => 3 );
907 $password_strength_text = array( 'short' => __( 'Very Weak', 'profile-builder' ), 'bad' => __( 'Weak', 'profile-builder' ), 'good' => __( 'Medium', 'profile-builder' ), 'strong' => __( 'Strong', 'profile-builder' ) );
908 if( $password_strength_array[$wppb_password_strength] < $password_strength_array[$wppb_generalSettings['minimum_password_strength']] ){
909 return $password_strength_text[$wppb_generalSettings['minimum_password_strength']];
910 }
911 else
912 return false;
913 }
914 return false;
915 }
916
917 /* function to output password length requirements text */
918 function wppb_password_length_text(){
919 $wppb_generalSettings = get_option( 'wppb_general_settings' );
920 if( !empty( $wppb_generalSettings['minimum_password_length'] ) ){
921 return sprintf(__('Minimum length of %d characters.', 'profile-builder'), $wppb_generalSettings['minimum_password_length']);
922 }
923 return '';
924 }
925
926 /* function to output password strength requirements text */
927 function wppb_password_strength_description() {
928 $wppb_generalSettings = get_option( 'wppb_general_settings' );
929
930 if( ! empty( $wppb_generalSettings['minimum_password_strength'] ) ) {
931 $password_strength_text = array( 'short' => __( 'Very Weak', 'profile-builder' ), 'bad' => __( 'Weak', 'profile-builder' ), 'good' => __( 'Medium', 'profile-builder' ), 'strong' => __( 'Strong', 'profile-builder' ) );
932 $password_strength_description = '<br>'. sprintf( __( 'The password must have a minimum strength of %s', 'profile-builder' ), $password_strength_text[$wppb_generalSettings['minimum_password_strength']] );
933
934 return $password_strength_description;
935 } else {
936 return '';
937 }
938 }
939
940 /**
941 * Include password strength check scripts on frontend where we have shortcodes present
942 */
943 add_action( 'elementor/frontend/after_enqueue_scripts', 'wppb_enqueue_password_strength_check' );
944 add_action( 'wp_footer', 'wppb_enqueue_password_strength_check' );
945 function wppb_enqueue_password_strength_check() {
946 global $wppb_shortcode_on_front;
947 if( $wppb_shortcode_on_front ){
948 $wppb_generalSettings = get_option( 'wppb_general_settings' );
949 if( !empty( $wppb_generalSettings['minimum_password_strength'] ) ){
950 wp_enqueue_script( 'password-strength-meter' );
951 }
952 }
953 }
954 add_action( 'wp_footer', 'wppb_password_strength_check', 102 );
955 function wppb_password_strength_check(){
956 global $wppb_shortcode_on_front;
957 if( $wppb_shortcode_on_front ){
958 $wppb_generalSettings = get_option( 'wppb_general_settings' );
959 if( !empty( $wppb_generalSettings['minimum_password_strength'] ) ){
960 ?>
961 <script type="text/javascript">
962 function check_pass_strength(form) {
963 var pass1 = jQuery(form).find('#passw1').val(),
964 pass2 = jQuery(form).find('#passw2').val(),
965 strength;
966
967 jQuery(form).find('#pass-strength-result').removeClass('short bad good strong');
968 if (!pass1) {
969 jQuery(form).find('#pass-strength-result').html(pwsL10n.empty);
970 return;
971 }
972 <?php
973 global $wp_version;
974
975 if ( version_compare( $wp_version, "4.9.0", ">=" ) ) {
976 ?>
977 strength = wp.passwordStrength.meter( pass1, wp.passwordStrength.userInputDisallowedList(), pass2 );
978 <?php
979 }
980 else {
981 ?>
982 strength = wp.passwordStrength.meter( pass1, wp.passwordStrength.userInputBlacklist(), pass2);
983 <?php
984 }
985 ?>
986 switch ( strength ) {
987 case 2:
988 jQuery(form).find('#pass-strength-result').addClass('bad').html( pwsL10n.bad );
989 jQuery(form).find('#wppb_password_strength').val('bad');
990 break;
991 case 3:
992 jQuery(form).find('#pass-strength-result').addClass('good').html( pwsL10n.good );
993 jQuery(form).find('#wppb_password_strength').val('good');
994 break;
995 case 4:
996 jQuery(form).find('#pass-strength-result').addClass('strong').html( pwsL10n.strong );
997 jQuery(form).find('#wppb_password_strength').val('strong');
998 break;
999 case 5:
1000 jQuery(form).find('#pass-strength-result').addClass('short').html( pwsL10n.mismatch );
1001 jQuery(form).find('#wppb_password_strength').val('short');
1002 break;
1003 default:
1004 jQuery(form).find('#pass-strength-result').addClass('short').html( pwsL10n['short'] );
1005 jQuery(form).find('#wppb_password_strength').val('short');
1006 }
1007 }
1008 jQuery( document ).ready( function() {
1009 // Binding to trigger checkPasswordStrength
1010 jQuery('.wppb-user-forms').each(function() {
1011 var form = this;
1012 jQuery(form).find('#passw1, #passw2').val('').on('keyup change', function() {
1013 check_pass_strength(form);
1014 });
1015 jQuery(form).find('#pass-strength-result').show();
1016 });
1017 });
1018 </script>
1019 <?php
1020 }
1021 }
1022 }
1023
1024 /**
1025 * Include toggle password visibility script on frontend where we have shortcodes present
1026 */
1027 function wppb_password_visibility_toggle_html(){
1028 if( apply_filters( 'wppb_show_password_visibility_toggle', false ) ){
1029 return '
1030 <button type="button" class="wppb-toggle-pw wppb-show-pw hide-if-no-js" data-toggle="0" aria-label="Show password" tabindex="-1">
1031 <img src="'.WPPB_PLUGIN_URL.'/assets/images/eye-outline.svg" title="'. esc_html__( 'Show password', 'profile-builder' ) .'" width="20px" height="20px" />
1032 </button>';
1033 }
1034 return '';
1035 }
1036
1037 /**
1038 * Include toggle password visibility script on frontend where we have shortcodes present
1039 */
1040 add_action( 'elementor/frontend/after_enqueue_scripts', 'wppb_enqueue_password_visibility_toggle' );
1041 add_action( 'wp_footer', 'wppb_enqueue_password_visibility_toggle' );
1042 function wppb_enqueue_password_visibility_toggle() {
1043 global $wppb_shortcode_on_front;
1044 static $enqueued = false;
1045 if( $wppb_shortcode_on_front && apply_filters( 'wppb_show_password_visibility_toggle', false ) && !$enqueued ){
1046
1047 //load jQuery if needed
1048 if( !wp_script_is('jquery', 'done') ){
1049 wp_print_scripts('jquery');
1050 }
1051
1052 ?>
1053 <script type="text/javascript">
1054 jQuery( document ).ready( function() {
1055
1056 jQuery( "button.wppb-toggle-pw" ).on( "click", wppb_password_visibility_toggle );
1057
1058 jQuery( 'button.wppb-toggle-pw' ).each( function( index, toggle ){
1059
1060 var parent = jQuery( toggle ).parent()
1061
1062 if( parent.hasClass( 'wppb-form-field' ) && jQuery( '.wppb-description-delimiter', parent ) ){
1063
1064 jQuery( toggle ).css( 'top', parseInt( jQuery( toggle ).css('top') ) - ( jQuery( '.wppb-description-delimiter', parent ).outerHeight() / 2 ) )
1065
1066 }
1067
1068 })
1069
1070 });
1071 function wppb_password_visibility_toggle() {
1072 var button = jQuery( this );
1073 var container = button.closest( '.wppb-password-field-container' );
1074 var input = container.find( 'input' ).first();
1075 var icon = button.find( 'img' );
1076
1077 if ( ! input.length ) {
1078 return;
1079 }
1080
1081 if ( "password" === input.attr( "type" ) ) {
1082 input.attr( "type", "text" );
1083 button.removeClass( "wppb-show-pw" ).addClass( "wppb-hide-pw" );
1084 icon.attr( "src", "<?php echo esc_attr( WPPB_PLUGIN_URL ); ?>/assets/images/eye-off-outline.svg" );
1085 icon.attr( "title", "<?php esc_html_e( 'Hide password', 'profile-builder' ); ?>" );
1086 } else {
1087 input.attr( "type", "password" );
1088 button.removeClass( "wppb-hide-pw" ).addClass( "wppb-show-pw" );
1089 icon.attr( "src", "<?php echo esc_attr( WPPB_PLUGIN_URL ); ?>/assets/images/eye-outline.svg" );
1090 icon.attr( "title", "<?php esc_html_e( 'Show password', 'profile-builder' ); ?>" );
1091 }
1092 }
1093 </script>
1094 <?php
1095 $enqueued = true;
1096 }
1097 }
1098
1099 /**
1100 * Create functions for repeating error messages in front-end forms
1101 */
1102 function wppb_required_field_error($field_title='') {
1103 $required_error = apply_filters('wppb_required_error' , __('This field is required','profile-builder') , $field_title);
1104
1105 return $required_error;
1106
1107 }
1108
1109 /**
1110 * Function that returns a certain field (from manage_fields) by a given id or meta_name
1111 */
1112 function wppb_get_field_by_id_or_meta( $id_or_meta ){
1113
1114 $id = 0;
1115 $meta = '';
1116
1117 if ( is_numeric($id_or_meta) )
1118 $id = $id_or_meta;
1119 else
1120 $meta = $id_or_meta;
1121
1122 $fields = get_option('wppb_manage_fields', 'not_found');
1123
1124 if ($fields != 'not_found') {
1125
1126 foreach ($fields as $key => $field) {
1127 if ( (!empty($id)) && ($field['id'] == $id) )
1128 return $field;
1129 if ( (!empty($meta)) && ($field['meta-name'] == $meta) )
1130 return $field;
1131 }
1132
1133 }
1134
1135 return '';
1136 }
1137
1138
1139 /**
1140 * Returns the AJAX actions that check the login/checkout credentials before the real form submission is sent.
1141 *
1142 * Those requests run the whole authentication stack, so our CAPTCHA check runs too and the token gets spent
1143 * with the CAPTCHA provider, but they never log the user in - the browser still submits the form afterwards
1144 * with the very same token. CAPTCHA tokens are single use, so verifying one a second time comes back as a
1145 * duplicate and the login fails. For these actions we remember the successful verification and reuse it once,
1146 * when the actual form submission arrives.
1147 */
1148 function wppb_get_captcha_prevalidation_actions() {
1149 return apply_filters( 'wppb_captcha_prevalidation_actions', array(
1150 'pms_validate_checkout', // Paid Member Subscriptions checkout validation
1151 'wordfence_ls_authenticate', // Wordfence Login Security login pre-flight, used to decide if it needs to ask for a 2FA code
1152 ) );
1153 }
1154
1155 /* Whether the current request is one of the CAPTCHA pre-validation AJAX calls above */
1156 function wppb_is_captcha_prevalidation_request() {
1157 if ( ! wp_doing_ajax() || empty( $_POST['action'] ) || ! is_string( $_POST['action'] ) ) /* phpcs:ignore WordPress.Security.NonceVerification.Missing */
1158 return false;
1159
1160 return in_array( sanitize_text_field( $_POST['action'] ), wppb_get_captcha_prevalidation_actions(), true ); /* phpcs:ignore WordPress.Security.NonceVerification.Missing */
1161 }
1162
1163 /**
1164 * Drops pre-validated CAPTCHA tokens that were never claimed by a form submission.
1165 *
1166 * A pre-validation that is not followed by a submission (wrong password, abandoned login, bots) leaves its
1167 * entry behind, so without this the option would keep growing on sites where every login is pre-validated.
1168 */
1169 function wppb_prune_captcha_prevalidations( $saved ) {
1170 if ( ! is_array( $saved ) )
1171 return array();
1172
1173 $lifetime = apply_filters( 'wppb_captcha_prevalidation_lifetime', 15 * MINUTE_IN_SECONDS );
1174
1175 foreach ( $saved as $token => $validated_at ) {
1176 if ( ! is_int( $validated_at ) || ( time() - $validated_at ) > $lifetime )
1177 unset( $saved[ $token ] );
1178 }
1179
1180 return $saved;
1181 }
1182
1183 /* Function for displaying reCAPTCHA error on Login and Recover Password forms */
1184 function wppb_recaptcha_field_error($field_title='') {
1185
1186 $recaptcha_field = wppb_get_recaptcha_field();
1187
1188 if( $recaptcha_field['recaptcha-type'] === 'v2' ) {
1189 $recaptcha_error = apply_filters('wppb_recaptcha_error' , __('Please enter a (valid) reCAPTCHA value','profile-builder') , $field_title);
1190 } else {
1191 $recaptcha_error = apply_filters('wppb_recaptcha_error' , __('reCaptcha could not be verified. Please try again.','profile-builder') , $field_title);
1192 }
1193
1194 return $recaptcha_error;
1195
1196 }
1197 /* Function for displaying phone field error */
1198 function wppb_phone_field_error( $field_title = '' ) {
1199 $phone_error = apply_filters( 'wppb_phone_error' , __( 'Incorrect phone number', 'profile-builder' ) , $field_title );
1200
1201 return $phone_error;
1202 }
1203
1204 /* Create a wrapper function for get_query_var */
1205 function wppb_get_query_var( $varname ){
1206 //if we want the userlisting on front page ( is_front_page() ) apparently the way we register query vars does not work so we will just use a simple GET var
1207 if($varname === 'username' && !get_query_var( $varname ) && isset($_GET['wppb_username'])){
1208 return apply_filters( 'wppb_get_query_var_'.$varname, sanitize_user( $_GET['wppb_username'] ) );
1209 }
1210
1211 return apply_filters( 'wppb_get_query_var_'.$varname, get_query_var( $varname ) );
1212 }
1213
1214 /** @param string|array $key Query key or keys to remove.
1215 */
1216 function wppb_remove_query_arg( $key, $url = false ){
1217 $striped_url = remove_query_arg( $key, $url);
1218
1219 //treat page key on frontpage case where it is transformed into a pretty permalink
1220 if( ( is_array($key) && in_array('wppb_page', $key) ) || ( !is_array($key) && 'wppb_page' === $key ) ){
1221 $striped_url = preg_replace( '/\/'.wppb_get_users_pagination_slug().'\/\d+\//', '/', $striped_url );
1222 $striped_url = preg_replace( '/\/'.wppb_get_users_pagination_slug().'\//', '/', $striped_url );
1223 }
1224
1225 return $striped_url;
1226 }
1227
1228 //function that generates tha pagination slug for userlisting
1229 function wppb_get_users_pagination_slug(){
1230 return apply_filters('wppb_users_pagination_slug', 'users-page');
1231 }
1232
1233 /* Filter the "Save Changes" button text, to make it translatable */
1234 function wppb_change_save_changes_button($value){
1235 $value = __('Save Changes','profile-builder');
1236 return $value;
1237 }
1238 add_filter( 'wck_save_changes_button', 'wppb_change_save_changes_button', 10, 2);
1239
1240 /* Filter the "Cancel" button text, to make it translatable */
1241 function wppb_change_cancel_button($value){
1242 $value = __('Cancel','profile-builder');
1243 return $value;
1244 }
1245 add_filter( 'wck_cancel_button', 'wppb_change_cancel_button', 10, 2);
1246
1247 /* ilter the "Delete" button text, to make it translatable */
1248 function wppb_change_delete_button($value){
1249 $value = __('Delete','profile-builder');
1250 return $value;
1251 }
1252 add_filter( 'wck_delete_button', 'wppb_change_delete_button', 10, 2);
1253
1254 /*Filter the "Edit" button text, to make it translatable*/
1255 function wppb_change_edit_button($value){
1256 $value = __('Edit','profile-builder');
1257 return $value;
1258 }
1259 add_filter( 'wck_edit_button', 'wppb_change_edit_button', 10, 2);
1260
1261 /*Filter the User Listing, Register Forms and Edit Profile forms metabox header content, to make it translatable*/
1262 function wppb_change_metabox_content_header(){
1263 return '<thead><tr><th class="wck-number">#</th><th class="wck-content">'. __( 'Content', 'profile-builder' ) .'</th><th class="wck-edit">'. __( 'Edit', 'profile-builder' ) .'</th><th class="wck-delete">'. __( 'Delete', 'profile-builder' ) .'</th></tr></thead>';
1264 }
1265 add_filter('wck_metabox_content_header_wppb_ul_page_settings', 'wppb_change_metabox_content_header', 1);
1266 add_filter('wck_metabox_content_header_wppb_rf_page_settings', 'wppb_change_metabox_content_header', 1);
1267 add_filter('wck_metabox_content_header_wppb_epf_page_settings', 'wppb_change_metabox_content_header', 1);
1268
1269
1270 /*Filter default WordPress notices ("Post published. Post updated."), add post type name for User Listing, Registration Forms and Edit Profile Forms*/
1271 function wppb_change_default_post_updated_messages($messages){
1272 global $post;
1273 $post_type = get_post_type($post->ID);
1274 $object = get_post_type_object($post_type);
1275
1276 if ( ($post_type == 'wppb-rf-cpt')||($post_type == 'wppb-epf-cpt')||($post_type == 'wppb-ul-cpt') ){
1277 $messages['post'][1] = $object->labels->name . ' updated.';
1278 $messages['post'][6] = $object->labels->name . ' published.';
1279 }
1280 return $messages;
1281 }
1282 add_filter('post_updated_messages','wppb_change_default_post_updated_messages', 2);
1283
1284
1285 /* for meta-names with spaces in them PHP converts the space to underline in the $_POST */
1286 function wppb_handle_meta_name( $meta_name ){
1287 $meta_name = trim( $meta_name );
1288 $meta_name = str_replace( ' ', '_', $meta_name );
1289 $meta_name = str_replace( '.', '_', $meta_name );
1290 return $meta_name;
1291 }
1292
1293 /**
1294 * Function that checks if a field type exists in a form
1295 * @return bool
1296 */
1297 function wppb_field_exists_in_form( $field_type, $form_args ){
1298 if( !empty( $form_args ) && !empty( $form_args['form_fields'] ) ){
1299 foreach( $form_args['form_fields'] as $field ){
1300 if( $field['field'] === $field_type ){
1301 return true;
1302 }
1303 }
1304 }
1305
1306 return false;
1307 }
1308
1309 // change User Registered date and time according to timezone selected in WordPress settings
1310 function wppb_get_register_date() {
1311
1312 $time_format = "Y-m-d G:i:s";
1313 $wppb_get_date = date_i18n( $time_format, false, true );
1314
1315 if( apply_filters( 'wppb_return_local_time_for_register', false ) ){
1316 $wppb_get_date = date_i18n( $time_format );
1317 }
1318
1319 return $wppb_get_date;
1320 }
1321
1322 /**
1323 * Function that ads the gmt offset from the general settings to a unix timestamp
1324 * @param $timestamp
1325 * @return mixed
1326 */
1327 function wppb_add_gmt_offset( $timestamp ) {
1328 if( apply_filters( 'wppb_add_gmt_offset', true ) ){
1329 $timestamp = $timestamp + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
1330 }
1331 return $timestamp;
1332 }
1333
1334 /**
1335 * Add HTML tag 'required' to fields
1336 *
1337 * Add HTML tag 'required' for each field if the field is required. For browsers that don't support this HTML tag, we will still have the fallback.
1338 * Field type 'Checkbox' is explicitly excluded because there is no HTML support to check if at least one option is selected.
1339 * Other fields excluded are Avatar, Upload, Heading, ReCaptcha, WYSIWYG, Map.
1340 *
1341 * @since
1342 *
1343 * @param string $extra_attributes Extra attributes attached to the field HTML tag.
1344 * @param array $field Field description.
1345 * @return string $extra_attributes
1346 */
1347 function wppb_add_html_tag_required_to_fields( $extra_attributes, $field, $form_location = '' ) {
1348 if ( isset( $field['required'] ) && $field['required'] == 'Yes' ){
1349
1350 if( !in_array( $field['field'], array( 'Checkbox', 'Default - Password', 'Default - Repeat Password', 'GDPR Communication Preferences' ) ) && $form_location == 'edit_profile' )
1351 $extra_attributes .= ' required ';
1352
1353 }
1354 return $extra_attributes;
1355 }
1356 add_filter( 'wppb_extra_attribute', 'wppb_add_html_tag_required_to_fields', 10, 3 );
1357
1358 /**
1359 * Add HTML tag 'required' to WooCommerce fields
1360 *
1361 * Add HTML tag 'required' for each WooCommerce field if the field is required. For browsers that don't support this HTML tag, we will still have the fallback.
1362 * Does not work on 'State / County' field, if it becomes required later depending on the Country Value
1363 *
1364 * @since
1365 *
1366 * @param string $extra_attributes Extra attributes attached to the field HTML tag.
1367 * @param array $field Field description.
1368 * @return string $extra_attributes
1369 */
1370 function wppb_add_html_tag_required_to_woo_fields( $extra_attributes, $field ) {
1371 if ( isset( $field['required'] ) && $field['required'] == 'Yes' ){
1372 $extra_attributes .= ' required ';
1373 }
1374 return $extra_attributes;
1375 }
1376 add_filter( 'wppb_woo_extra_attribute', 'wppb_add_html_tag_required_to_woo_fields', 10, 2 );
1377
1378
1379 /**
1380 * Add jQuery script to remove required attribute for hidden fields
1381 *
1382 * If a field is hidden dynamically via conditional fields or WooSync 'Ship to a different address' checkbox, then the required field needs to be removed.
1383 * If a field is made visible again, add the required field back again.
1384 *
1385 * @since
1386 *
1387 * @param string $extra_attributes Extra attributes attached to the field HTML tag.
1388 * @param array $field Field description.
1389 * @return string $extra_attributes
1390 */
1391 function wppb_manage_required_attribute() {
1392 global $wppb_shortcode_on_front;
1393 if ($wppb_shortcode_on_front) {
1394 //check if jquery has been loaded yet because we need it at this point
1395 // we're checking if it's not admin because it brakes elementor otherwise.
1396 if( !wp_script_is('jquery', 'done') && !is_admin() ){
1397 wp_print_scripts('jquery');
1398 }
1399 ?>
1400 <script type="text/javascript">
1401 jQuery(document).on( "wppbAddRequiredAttributeEvent", wppbAddRequired );
1402 function wppbAddRequired(event) {
1403 var element = wppbEventTargetRequiredElement( event.target );
1404 if( jQuery( element ).attr( "wppb_cf_temprequired" ) ){
1405 jQuery( element ).removeAttr( "wppb_cf_temprequired" );
1406 jQuery( element ).attr( "required", "required" );
1407 }
1408 }
1409
1410 jQuery(document).on( "wppbRemoveRequiredAttributeEvent", wppbRemoveRequired );
1411 function wppbRemoveRequired(event) {
1412 var element = wppbEventTargetRequiredElement( event.target );
1413 if ( jQuery( element ).attr( "required" ) ) {
1414 jQuery( element ).removeAttr( "required" );
1415 jQuery( element ).attr( "wppb_cf_temprequired", "wppb_cf_temprequired" );
1416 }
1417 }
1418
1419 jQuery(document).on( "wppbToggleRequiredAttributeEvent", wppbToggleRequired );
1420 function wppbToggleRequired(event) {
1421 if ( jQuery( event.target ).attr( "required" ) ) {
1422 jQuery( event.target ).removeAttr( "required" );
1423 jQuery( event.target ).attr( "wppb_cf_temprequired", "wppb_cf_temprequired" );
1424 }else if( jQuery( event.target ).attr( "wppb_cf_temprequired" ) ){
1425 jQuery( event.target ).removeAttr( "wppb_cf_temprequired" );
1426 jQuery( event.target ).attr( "required", "required" );
1427 }
1428 }
1429
1430 function wppbEventTargetRequiredElement( htmlElement ){
1431 if ( htmlElement.nodeName == "OPTION" ){
1432 // <option> is the target element, so we need to get the parent <select>, in order to apply the required attribute
1433 return htmlElement.parentElement;
1434 }else{
1435 return htmlElement;
1436 }
1437 }
1438
1439 </script>
1440 <?php
1441 }
1442 }
1443 add_action( 'wp_footer', 'wppb_manage_required_attribute', 99 );
1444
1445 function wpbb_specify_blog_details_on_signup_email( $message, $user_email, $user, $activation_key, $registration_page_url, $meta, $from_name, $context ){
1446 $meta = unserialize($meta);
1447
1448 if ( is_multisite() && isset( $meta['wppb_create_new_site_checkbox'] ) && $meta['wppb_create_new_site_checkbox'] == 'yes' ) {
1449 $blog_details = wpmu_validate_blog_signup( $meta['wppb_blog_url'], $meta['wppb_blog_title'] );
1450
1451 if ( empty($blog_details['errors']->errors['blogname']) && empty($blog_details['errors']->errors['blog_title'])) {
1452 $blog_path = $blog_details['domain'] . $blog_details['path'];
1453 $message .= __( '<br><br>Also, you will be able to visit your site at ', 'profile-builder' ) . '<a href="' . $blog_path . '">' . $blog_path . '</a>.';
1454 }
1455 }
1456 return $message;
1457 }
1458 add_filter( 'wppb_signup_user_notification_email_content', 'wpbb_specify_blog_details_on_signup_email', 5, 8 );
1459
1460 function wpbb_specify_blog_details_on_registration_email( $user_message_content, $email, $password, $user_message_subject, $context ){
1461
1462 if ( is_multisite() ) {
1463 $user = get_user_by( 'email', $email );
1464 $blog_path = wppb_get_blog_url_of_user_id( $user->ID );
1465 if ( ! empty ( $blog_path ) ) {
1466 $user_message_content .= __( '<br><br>You can visit your site at ', 'profile-builder' ) . '<a href="' . $blog_path . '">' . $blog_path . '</a>.';
1467 }
1468 }
1469 return $user_message_content;
1470
1471 }
1472 add_filter( 'wppb_register_user_email_message_without_admin_approval', 'wpbb_specify_blog_details_on_registration_email', 5, 5 );
1473 add_filter( 'wppb_register_user_email_message_with_admin_approval', 'wpbb_specify_blog_details_on_registration_email', 5, 5 );
1474
1475
1476 function wppb_get_blog_url_of_user_id( $user_id, $ignore_privacy = true ){
1477 $blog_id = get_user_meta( $user_id, 'primary_blog', true );
1478 if ( is_multisite() && !empty( $blog_id ) ){
1479 $blog_details = get_blog_details( $blog_id );
1480 if ( $ignore_privacy || $blog_details->public ) {
1481 return $blog_details->domain . $blog_details->path;
1482 }
1483 }
1484 return '';
1485 }
1486
1487 function wppb_can_users_signup_blog(){
1488 if ( ! is_multisite() )
1489 return false;
1490 global $wpdb;
1491 $current_site = get_current_site();
1492 $sitemeta_options_query = $wpdb->prepare( "SELECT meta_value FROM {$wpdb->sitemeta} WHERE meta_key = 'registration' AND site_id = %d", $current_site->id );
1493 $network_options_meta = $wpdb->get_results( $sitemeta_options_query );
1494
1495 if ( $network_options_meta[0]->meta_value == 'all' ){
1496 return true;
1497 }
1498 return false;
1499 }
1500
1501 /**
1502 * Function that handle redirect URL
1503 *
1504 * @param string $redirect_priority - it can be normal or top priority
1505 * @param string $redirect_type - type of the redirect
1506 * @param null|string $redirect_url - redirect URL if already set
1507 * @param null|string|object $user - username, user email or user data
1508 * @param null|string $user_role - user role
1509 *
1510 * @return null|string $redirect_url
1511 */
1512 function wppb_get_redirect_url( $redirect_priority, $redirect_type, $redirect_url = NULL, $user = NULL, $user_role = NULL ) {
1513 if( empty($redirect_priority) ) {
1514 $redirect_priority = 'normal';
1515 }
1516
1517 $versions = array( 'Profile Builder Pro', 'Profile Builder Agency', 'Profile Builder Unlimited', 'Profile Builder Dev' );
1518
1519 if( in_array( PROFILE_BUILDER, $versions ) ) {
1520 $wppb_module_settings = get_option( 'wppb_module_settings' );
1521
1522 if( isset( $wppb_module_settings['wppb_customRedirect'] ) && $wppb_module_settings['wppb_customRedirect'] == 'show' && $redirect_priority != 'top' && function_exists( 'wppb_custom_redirect_url' ) ) {
1523 $redirect_url = wppb_custom_redirect_url( $redirect_type, $redirect_url, $user, $user_role );
1524 }
1525 }
1526
1527 if( ! empty( $redirect_url ) ) {
1528 $redirect_url = ( wppb_check_missing_http( $redirect_url ) ? wppb_add_missing_http( $redirect_url ) : $redirect_url );
1529 }
1530
1531 return $redirect_url;
1532 }
1533
1534 /**
1535 * Bind an autologin nonce to a user ID server-side (one-time use).
1536 *
1537 * @param int $user_id User ID to log in.
1538 * @param string $nonce Autologin nonce.
1539 */
1540 function wppb_store_autologin_user( $user_id, $nonce ) {
1541 $user_id = absint( $user_id );
1542
1543 if ( ! $user_id || empty( $nonce ) ) {
1544 return;
1545 }
1546
1547 set_transient( 'wppb_autologin_' . md5( $nonce ), $user_id, 2 * MINUTE_IN_SECONDS );
1548 }
1549
1550 /**
1551 * Resolve the user bound to an autologin nonce.
1552 *
1553 * @param string $nonce Autologin nonce.
1554 * @param bool $consume Whether to delete the stored mapping.
1555 *
1556 * @return int User ID, or 0 when not found.
1557 */
1558 function wppb_get_autologin_user_id( $nonce, $consume = true ) {
1559 if ( empty( $nonce ) ) {
1560 return 0;
1561 }
1562
1563 $key = 'wppb_autologin_' . md5( $nonce );
1564 $user_id = absint( get_transient( $key ) );
1565
1566 if ( $user_id && $consume ) {
1567 delete_transient( $key );
1568 }
1569
1570 return $user_id;
1571 }
1572
1573 /**
1574 * Build autologin query args for a user.
1575 *
1576 * @param int $user_id User ID to log in.
1577 *
1578 * @return array Query args for add_query_arg().
1579 */
1580 function wppb_get_autologin_query_args( $user_id ) {
1581 $user_id = absint( $user_id );
1582 $nonce = wp_create_nonce( 'autologin-' . $user_id . '-' . (int) ( time() / 60 ) );
1583
1584 wppb_store_autologin_user( $user_id, $nonce );
1585
1586 return array(
1587 'autologin' => 'true',
1588 '_wpnonce' => $nonce,
1589 );
1590 }
1591
1592 /**
1593 * Verify an autologin nonce for the given user ID.
1594 *
1595 * @param string $nonce Autologin nonce.
1596 * @param int $user_id User ID bound to the nonce.
1597 *
1598 * @return bool
1599 */
1600 function wppb_verify_autologin_nonce( $nonce, $user_id ) {
1601 $user_id = absint( $user_id );
1602
1603 if ( ! $user_id || empty( $nonce ) ) {
1604 return false;
1605 }
1606
1607 $nonce_action = 'autologin-' . $user_id . '-';
1608
1609 return wp_verify_nonce( $nonce, $nonce_action . (int) ( time() / 60 ) )
1610 || wp_verify_nonce( $nonce, $nonce_action . (int) ( time() / 60 - 1 ) );
1611 }
1612
1613 /**
1614 * Function that builds the redirect
1615 *
1616 * @param string $redirect_url - redirect URL
1617 * @param int $redirect_delay - redirect delay in seconds
1618 * @param null|string $redirect_type - the type of the redirect
1619 * @param null|array $form_args - form args if set
1620 *
1621 * @return string $redirect_message
1622 */
1623 function wppb_build_redirect( $redirect_url, $redirect_delay, $redirect_type = NULL, $form_args = NULL ) {
1624 if( isset( $redirect_type ) ) {
1625 $redirect_url = apply_filters( 'wppb_'. $redirect_type .'_redirect', $redirect_url );
1626 }
1627
1628 $redirect_message = '';
1629
1630 if( ! empty( $redirect_url ) ) {
1631 $redirect_url = ( wppb_check_missing_http( $redirect_url ) ? wppb_add_missing_http( $redirect_url ) : $redirect_url );
1632
1633 if( $redirect_delay == 0 ) {
1634 $redirect_message = '<meta http-equiv="Refresh" content="'. $redirect_delay .';url='. $redirect_url .'" />';
1635 } else {
1636 $redirect_url_href = apply_filters( 'wppb_redirect_url', '<a href="'. esc_url( $redirect_url ) .'">'. __( 'here', 'profile-builder' ) .'</a>', $redirect_url, $redirect_type, $form_args );
1637 $redirect_message = apply_filters( 'wppb_redirect_message_before_returning', '<p class="redirect_message">'. sprintf( wp_slash( __( 'You will soon be redirected automatically. If you see this page for more than %1$d seconds, please click %2$s.%3$s', 'profile-builder' ) ), $redirect_delay, $redirect_url_href, '<meta http-equiv="Refresh" content="'. $redirect_delay .';url='. $redirect_url .'" />' ) .'</p>', $redirect_url, $redirect_delay, $redirect_url_href, $redirect_type, $form_args );
1638 }
1639 }
1640
1641 return $redirect_message;
1642 }
1643
1644 /**
1645 * Function that strips the script tags from an input
1646 * @param $string
1647 * @return mixed
1648 */
1649 function wppb_sanitize_value( $string ){
1650 return preg_replace( '/<script\b[^>]*>(.*?)<\/script>/is', '', $string );
1651 }
1652
1653 /**
1654 * Function that receives a user role and returns its label.
1655 * Returns the original role if not found.
1656 *
1657 * @since v.2.7.1
1658 *
1659 * @param string $role
1660 *
1661 * @return string
1662 */
1663 function wppb_get_role_name($role){
1664 global $wp_roles;
1665
1666 if ( array_key_exists( $role, $wp_roles->role_names ) )
1667 return $wp_roles->role_names[$role];
1668
1669 return $role;
1670 }
1671
1672 /**
1673 * Function that receives a user role label and returns its slug.
1674 * Returns the original role label if not found.
1675 *
1676 * @since v.3.5.6
1677 *
1678 * @param string $role
1679 *
1680 * @return string
1681 */
1682 function wppb_get_role_slug($role) {
1683 global $wp_roles;
1684
1685 foreach ( $wp_roles->role_names as $slug => $label ) {
1686 if ( $label === $role) {
1687 return $slug;
1688 }
1689 }
1690
1691 return $role;
1692 }
1693
1694 /**
1695 * Functionality for Private Website start
1696 */
1697 add_action( 'template_redirect', 'wppb_private_website_functionality' );
1698 add_action( 'login_init', 'wppb_private_website_functionality', 1 );
1699 function wppb_private_website_functionality(){
1700 $wppb_private_website_settings = get_option( 'wppb_private_website_settings', 'not_found' );
1701 if( $wppb_private_website_settings != 'not_found' ){
1702 if( !empty( $wppb_private_website_settings['private_website'] ) && $wppb_private_website_settings['private_website'] == 'yes' ){
1703 if( !is_user_logged_in() ){
1704
1705 if( is_404() )
1706 return;
1707
1708 // force wp-login.php if you accidentally get locked out
1709 global $pagenow;
1710 if( $pagenow === 'wp-login.php' && ( isset( $_GET['wppb_force_wp_login'] ) || ( isset( $_SERVER['HTTP_REFERER'] ) && strpos( esc_url_raw( $_SERVER['HTTP_REFERER'] ), 'wppb_force_wp_login=true' ) !== false ) || ( isset($_REQUEST['redirect_to']) && strpos( sanitize_text_field( $_REQUEST['redirect_to'] ), 'wppb_force_wp_login=true' ) !== false ) ) )
1711 return;
1712
1713 // bypass requests that enter the password of a password protected post
1714 if( $pagenow === 'wp-login.php' && isset( $_GET['action'] ) && $_GET['action'] == 'postpass' && isset( $_POST['post_password'] ) )
1715 return;
1716
1717 // go through paths first if they are set
1718 if( isset( $wppb_private_website_settings['allowed_paths'] ) && !empty( $wppb_private_website_settings['allowed_paths'] ) ){
1719 $allowed_paths = explode( "\r\n", $wppb_private_website_settings['allowed_paths'] );
1720 $parsed_url = wp_parse_url( wppb_curpageurl() );
1721 if( !empty( $parsed_url['path'] ) ) {
1722 $path = $parsed_url['path'];
1723
1724 foreach ($allowed_paths as $allowed_path) {
1725 if (strpos($allowed_path, '*') === false) {
1726 if (trim($path, "/") === trim($allowed_path, "/")) {
1727 return;
1728 }
1729 } else {
1730 if (strpos(ltrim($path, "/"), trailingslashit(trim(str_replace('*', '', $allowed_path), "/"))) === 0) {
1731 return;
1732 }
1733 }
1734 }
1735 }
1736 }
1737
1738 if( isset( $wppb_private_website_settings['allowed_query_strings'] ) && !empty( $wppb_private_website_settings['allowed_query_strings'] ) ){
1739 $allowed_query_strings = explode( "\r\n", $wppb_private_website_settings['allowed_query_strings'] );
1740 $parsed_url_parameters = wp_parse_url( wppb_curpageurl() );
1741
1742 if( !empty( $parsed_url_parameters['query'] ) ) {
1743 parse_str( $parsed_url_parameters['query'], $query_params );
1744
1745 foreach ( $allowed_query_strings as $allowed_query ) {
1746 if ( array_key_exists( $allowed_query, $query_params ) ) {
1747 return;
1748 }
1749 }
1750 }
1751 }
1752
1753 if( isset( $wppb_private_website_settings['allowed_pages'] ) )
1754 $allowed_pages = $wppb_private_website_settings['allowed_pages'];
1755 else{
1756 $allowed_pages = array();
1757 }
1758
1759 $redirect_to_id = $wppb_private_website_settings['redirect_to'];
1760 if( !empty( $redirect_to_id ) ) {
1761 $redirect_url = get_permalink($redirect_to_id);
1762 $allowed_pages[] = $redirect_to_id;
1763 }
1764 else {
1765 //don't redirect if we are already on the wp-login.php page
1766 if( $pagenow === 'wp-login.php' ){
1767 return;
1768 }
1769 else
1770 $redirect_url = wp_login_url(wppb_curpageurl());
1771 }
1772
1773 $redirect_url = apply_filters( 'wppb_private_website_redirect_url', $redirect_url );
1774 $allowed_pages = apply_filters( 'wppb_private_website_allowed_pages', $allowed_pages );
1775
1776 global $post;
1777 if( !isset( $post ) || ( isset($post) && $post->ID == 0 ) ) {//added || ( isset($post) && $post->ID == 0 ) for a compatibility issue with BuddyPress where the ID was 0 for a page
1778 if( function_exists('url_to_postid') ) {
1779 $post_id = url_to_postid(wppb_curpageurl());//try to get the id from the actual url
1780 }else {
1781 $post_id = 0;
1782 }
1783 }
1784 else
1785 $post_id = $post->ID;
1786
1787 if( ( !in_array( $post_id, $allowed_pages ) && $redirect_url !== strtok( wppb_curpageurl(), '?' ) ) || is_search() ){
1788 nocache_headers();
1789 if( apply_filters( 'wppb_private_website_redirect_add_query_args', true ) && current_filter() == 'template_redirect' ) {
1790 $redirect_url = add_query_arg( 'wppb_referer_url', urlencode( esc_url( wppb_curpageurl() ) ), $redirect_url );
1791 }
1792 wp_safe_redirect( $redirect_url );
1793 exit;
1794 }
1795
1796 }
1797 }
1798 }
1799
1800 }
1801
1802 //add classes on the body to know if we have enabled private website options
1803 add_filter( 'body_class', 'wppb_private_website_body_classes' );
1804 function wppb_private_website_body_classes( $classes ){
1805 $wppb_private_website_settings = get_option( 'wppb_private_website_settings', 'not_found' );
1806 if( $wppb_private_website_settings != 'not_found' ) {
1807 if ( !empty( $wppb_private_website_settings['private_website'] ) && $wppb_private_website_settings['private_website'] == 'yes' ) {
1808 if (!is_user_logged_in()) {
1809 $classes[] = 'wppb-private-website';
1810 if ( !empty( $wppb_private_website_settings['hide_menus'] ) && $wppb_private_website_settings['hide_menus'] == 'yes' ) {
1811 $classes[] = 'wppb-private-website-hide-menus';
1812 }
1813 }
1814 }
1815 }
1816
1817 return $classes;
1818 }
1819
1820
1821 /**
1822 * Disable RSS
1823 */
1824 add_action('do_feed', 'wppb_disable_feed', 1);
1825 add_action('do_feed_rdf', 'wppb_disable_feed', 1);
1826 add_action('do_feed_rss', 'wppb_disable_feed', 1);
1827 add_action('do_feed_rss2', 'wppb_disable_feed', 1);
1828 add_action('do_feed_atom', 'wppb_disable_feed', 1);
1829 add_action('do_feed_rss2_comments', 'wppb_disable_feed', 1);
1830 add_action('do_feed_atom_comments', 'wppb_disable_feed', 1);
1831 function wppb_disable_feed() {
1832 $wppb_private_website_settings = get_option( 'wppb_private_website_settings', 'not_found' );
1833 if( $wppb_private_website_settings != 'not_found' ) {
1834 if ( !empty( $wppb_private_website_settings['private_website'] ) && $wppb_private_website_settings['private_website'] == 'yes' ) {
1835 if (!is_user_logged_in()) {
1836 wp_die( wp_kses_post( sprintf( __('No feed available,please visit our <a href="%s">homepage</a>!', 'profile-builder' ), get_bloginfo('url') ) ) );
1837 }
1838 }
1839 }
1840 }
1841
1842
1843 /**
1844 * Disable REST
1845 */
1846 //add_filter('rest_enabled', 'wppb_disable_rest'); // this is depracated
1847 add_filter('rest_jsonp_enabled', 'wppb_disable_rest');
1848 function wppb_disable_rest( $bool ){
1849 $wppb_private_website_settings = get_option( 'wppb_private_website_settings', 'not_found' );
1850 if( $wppb_private_website_settings != 'not_found' ) {
1851 if ( !empty( $wppb_private_website_settings['private_website'] ) && $wppb_private_website_settings['private_website'] == 'yes' ) {
1852 if ( !isset( $wppb_private_website_settings[ 'disable_rest_api' ] ) || $wppb_private_website_settings[ 'disable_rest_api' ] !== 'yes' ) {
1853 return $bool;
1854 }
1855 if (!is_user_logged_in()) {
1856 return false;
1857 }
1858 }
1859 }
1860 return $bool;
1861 }
1862
1863 /* I should test this to not create any problems */
1864 add_filter('rest_authentication_errors', 'wppb_disable_rest_api_authentication', 10, 1 );
1865 function wppb_disable_rest_api_authentication($result) {
1866 if (!empty($result)) {
1867 return $result;
1868 }
1869
1870 $wppb_private_website_settings = get_option( 'wppb_private_website_settings', 'not_found' );
1871 if( $wppb_private_website_settings != 'not_found' ) {
1872 if ( !empty( $wppb_private_website_settings['private_website'] ) && $wppb_private_website_settings['private_website'] == 'yes' ) {
1873 if ( !isset( $wppb_private_website_settings[ 'disable_rest_api' ] ) || $wppb_private_website_settings[ 'disable_rest_api' ] !== 'yes' ) {
1874 return $result;
1875 }
1876
1877 // THE EVENTS CALENDAR EXCEPTION
1878 // They do some rest API calls in the front-end for their event view but due to their usage, they are breaking the authenticated user
1879 // and WordPress thinks the user is not authenticated (is_user_logged_in() == false)
1880 // This makes things break for logged in users whe the Private Website + Rest API functionality is enabled
1881 // We are going to ignore requests that contain their nonces so we can exlude them from our restrictions
1882 if( isset( $_REQUEST['_tec_view_rest_nonce_primary'] ) || isset( $_REQUEST['_tec_view_rest_nonce_secondary'] ) )
1883 return $result;
1884
1885 if (!is_user_logged_in() && isset( $_SERVER['REQUEST_URI'] ) && $_SERVER['REQUEST_URI'] !== "/wp-json/jwt-auth/v1/token" && $_SERVER['REQUEST_URI'] !== "/wp-json/jwt-auth/v1/token/validate") {
1886 return new WP_Error('rest_not_logged_in', __( 'You are not currently logged in.', 'profile-builder' ), array('status' => 401));
1887 }
1888 }
1889 }
1890
1891 return $result;
1892 }
1893
1894 /**
1895 * We can hide all menu items
1896 */
1897 add_filter('wp_nav_menu', 'wppb_hide_menus');
1898 add_filter('wp_page_menu', 'wppb_hide_menus');
1899 function wppb_hide_menus( $menu ){
1900 $wppb_private_website_settings = get_option( 'wppb_private_website_settings', 'not_found' );
1901 if( $wppb_private_website_settings != 'not_found' ) {
1902 if ( !empty( $wppb_private_website_settings['private_website'] ) && $wppb_private_website_settings['private_website'] == 'yes' ) {
1903 if ( !is_user_logged_in() && ( !empty($wppb_private_website_settings['hide_menus']) && $wppb_private_website_settings['hide_menus'] == 'yes' ) ) {
1904 return '';
1905 }
1906 }
1907 }
1908 return $menu;
1909 }
1910
1911 /**
1912 * Functionality for Private Website end
1913 */
1914
1915 /**
1916 * Functionality GDPR compliance start
1917 */
1918
1919 //hook into the wp export compatibility
1920 add_filter( 'wp_privacy_personal_data_exporters', 'wppb_register_profile_builder_wp_exporter', 10 );
1921 function wppb_register_profile_builder_wp_exporter( $exporters ) {
1922 $exporters['profile-builder'] = array(
1923 'exporter_friendly_name' => __( 'Profile Builder', 'profile-builder' ),
1924 'callback' => 'wppb_profile_builder_wp_exporter',
1925 );
1926 return $exporters;
1927 }
1928 /* function to add aour user meta to wp exporter */
1929 function wppb_profile_builder_wp_exporter( $email_address, $page = 1 ) {
1930
1931 $export_items = array();
1932
1933 $form_fields = get_option( 'wppb_manage_fields' );
1934
1935 if( !empty( $form_fields ) ) {
1936 $user = get_user_by( 'email', $email_address );
1937 if( $user ) {
1938
1939 $item_id = "user-meta-{$user->ID}";
1940 $group_id = 'user-meta';
1941 $group_label = __('User Meta' , 'profile-builder' );
1942 $data = array();
1943
1944 $all_meta_for_user = get_user_meta( $user->ID );
1945 if( !empty( $all_meta_for_user ) ) {
1946 foreach ($form_fields as $form_field) {
1947
1948 if (!empty($form_field['meta-name']) && strpos($form_field['field'], 'Default') === false) {
1949 $user_meta_value = $all_meta_for_user[$form_field['meta-name']][0];
1950 if( !empty( $user_meta_value ) ){
1951
1952
1953 $data[] = array(
1954 'name' => $form_field['field-title'],
1955 'value' => $user_meta_value
1956 );
1957 }
1958 }
1959 }
1960
1961 $export_items[] = array(
1962 'group_id' => $group_id,
1963 'group_label' => $group_label,
1964 'item_id' => $item_id,
1965 'data' => $data,
1966 );
1967
1968 }
1969 }
1970 }
1971
1972
1973 return array(
1974 'data' => $export_items,
1975 'done' => true,
1976 );
1977 }
1978
1979 /**
1980 * Hook to delete a user through the GDPR Delete button
1981 */
1982 add_action( 'template_redirect', 'wppb_gdpr_delete_user') ;
1983 function wppb_gdpr_delete_user() {
1984
1985 if( isset( $_GET['wppb_user'] ) && ! empty( $_GET['wppb_user'] ) ) {
1986 $edited_user_id = get_current_user_id();
1987 if ( ( ! is_multisite() && current_user_can( 'edit_users' ) ) || ( is_multisite() && current_user_can( 'manage_network' ) ) ) {
1988 $edited_user_id = absint( $_GET['wppb_user'] );
1989 }
1990
1991 if ( isset( $_REQUEST['wppb_action'] ) && $_REQUEST['wppb_action'] == 'wppb_delete_user' && isset( $_REQUEST['wppb_nonce'] ) && wp_verify_nonce( sanitize_text_field( $_REQUEST['wppb_nonce'] ), 'wppb-user-own-account-deletion' ) && isset( $_REQUEST['wppb_user'] ) && $edited_user_id == $_REQUEST['wppb_user'] ) {
1992 require_once( ABSPATH . 'wp-admin/includes/user.php' );
1993 $user = new WP_User( absint( $_REQUEST['wppb_user'] ) );
1994
1995 if ( ! empty( $user->roles ) ) {
1996 if ( ! in_array( 'administrator', $user->roles ) ) {
1997 wp_delete_user( absint( $_REQUEST['wppb_user'] ) );
1998
1999 do_action( 'wppb_gdpr_user_deleted', absint( $_REQUEST['wppb_user'] ) );
2000 }
2001 }
2002
2003 $args = array( 'wppb_user', 'wppb_action', 'wppb_nonce' );
2004 nocache_headers();
2005 wp_redirect( remove_query_arg( $args ) );
2006 }
2007 }
2008 }
2009
2010 /**
2011 * Function that removes user information from comments when the User Account is deleted using Edit Profile Form
2012 */
2013 function wppb_gdpr_remove_user_info_from_comments( $user_id ) {
2014 $user_comments = get_comments('user_id='.$user_id);
2015 foreach ( $user_comments as $comment ) {
2016 $comment_data = array();
2017 $comment_data['comment_ID'] = $comment->comment_ID;
2018 $comment_data['comment_author'] = '';
2019 $comment_data['comment_author_email'] = '';
2020 $comment_data['comment_author_url'] = '';
2021 wp_update_comment( $comment_data );
2022 }
2023 }
2024 add_action( 'wppb_gdpr_user_deleted', 'wppb_gdpr_remove_user_info_from_comments' );
2025
2026
2027 /**
2028 * Functionality GDPR compliance end
2029 */
2030
2031 /**
2032 * Function that checks if Admin Approval is enabled
2033 */
2034 function wppb_get_admin_approval_option_value(){
2035 $wppb_general_settings = get_option( 'wppb_general_settings', 'not_found' );
2036 if( defined( 'WPPB_PAID_PLUGIN_DIR' ) && file_exists( WPPB_PAID_PLUGIN_DIR . '/features/admin-approval/admin-approval.php' ) && $wppb_general_settings != 'not_found' && !empty( $wppb_general_settings['adminApproval'] ) && $wppb_general_settings['adminApproval'] === 'yes' )
2037 return 'yes';
2038 else
2039 return 'no';
2040 }
2041
2042 /**
2043 * Function that checks if conditional fields feature exists
2044 * @return bool
2045 */
2046 function wppb_conditional_fields_exists(){
2047 if ( defined( 'WPPB_PAID_PLUGIN_DIR' ) && file_exists( WPPB_PAID_PLUGIN_DIR . '/features/conditional-fields/conditional-fields.php' ) )
2048 return true;
2049 else
2050 return false;
2051 }
2052
2053 /**
2054 * Add support for [wppb-embed] shortcode inside userlisting as the default [embed] is weird and doesn't work outside the_content
2055 */
2056 add_shortcode('wppb-embed', 'wppb_embed');
2057 function wppb_embed($atts, $content){
2058 $atts = shortcode_atts( array(
2059 'width' => '',
2060 'height' => ''
2061 ), $atts, 'wppb-embed' );
2062
2063 global $wp_embed;
2064 if(empty($atts['width']) || empty($atts['height'])){
2065 $content = $wp_embed->run_shortcode('[embed]'.$content.'[/embed]');
2066 } else {
2067 $content = $wp_embed->run_shortcode('[embed width="'.esc_attr($atts['width']).'" height="'.esc_attr($atts['height']).'"]'.$content.'[/embed]');
2068 }
2069
2070 return $content;
2071 }
2072
2073 /**
2074 * Function to determine if an add-on is active
2075 */
2076
2077 function wppb_check_if_add_on_is_active( $slug ){
2078 //the old modules part
2079 if ( defined( 'WPPB_PAID_PLUGIN_DIR' ) && file_exists(WPPB_PAID_PLUGIN_DIR . '/add-ons/add-ons.php')) {
2080 $wppb_module_settings = get_option('wppb_module_settings', 'not_found');
2081 if ($wppb_module_settings != 'not_found') {
2082 foreach ($wppb_module_settings as $add_on_slug => $status) {
2083 if ($slug == $add_on_slug) {
2084 if ($status === 'hide')
2085 return false;
2086 elseif ($status === 'show')
2087 return true;
2088 }
2089 }
2090 }
2091 }
2092
2093 //the free addons part
2094 $wppb_free_add_ons_settings = get_option( 'wppb_free_add_ons_settings', array() );
2095 if ( !empty( $wppb_free_add_ons_settings ) ){
2096 foreach( $wppb_free_add_ons_settings as $add_on_slug => $status ){
2097 if( $slug == $add_on_slug ){
2098 return $status;
2099 }
2100 }
2101 }
2102
2103 //the advanced addons part
2104 $wppb_advanced_add_ons_settings = get_option( 'wppb_advanced_add_ons_settings', array() );
2105 if ( !empty( $wppb_advanced_add_ons_settings ) ){
2106 foreach( $wppb_advanced_add_ons_settings as $add_on_slug => $status ){
2107 if( $slug == $add_on_slug ){
2108 return $status;
2109 }
2110 }
2111 }
2112
2113 return false;
2114 }
2115
2116 /**
2117 * Function that checks if Two-Factor Authentication is active
2118 */
2119
2120 function wppb_is_2fa_active(){
2121 $wppb_two_factor_authentication_settings = get_option( 'wppb_two_factor_authentication_settings', 'not_found' );
2122 if( isset( $wppb_two_factor_authentication_settings['enabled'] ) && $wppb_two_factor_authentication_settings['enabled'] === 'yes' ) {
2123 return true;
2124 }
2125
2126 return false;
2127 }
2128
2129 /**
2130 * Function that returns an array containing the User Listing names
2131 */
2132
2133 function wppb_get_userlisting_names(){
2134 $ul_names = array();
2135 $userlisting_posts = get_posts( array( 'posts_per_page' => -1, 'post_status' =>'publish', 'post_type' => 'wppb-ul-cpt', 'orderby' => 'post_date', 'order' => 'ASC' ) );
2136 if( !empty( $userlisting_posts ) ){
2137 foreach ( $userlisting_posts as $post ){
2138 $ul_names[ $post->post_name ] = $post->post_title;
2139 }
2140 }
2141 reset($ul_names);
2142 return $ul_names;
2143 }
2144