PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 3.6.2
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v3.6.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 3.6.2, at features/functions.php

1,759 lines 69.3 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){
32 if( function_exists( 'icl_t' ) )
33 return icl_t( $context, $name, $value );
34
35 else
36 return $value;
37 }
38
39
40 function wppb_add_plugin_stylesheet() {
41 $wppb_generalSettings = get_option( 'wppb_general_settings' );
42
43 if ( ( file_exists( WPPB_PLUGIN_DIR . '/assets/css/style-front-end.css' ) ) && ( isset( $wppb_generalSettings['extraFieldsLayout'] ) && ( $wppb_generalSettings['extraFieldsLayout'] == 'default' ) ) ){
44 wp_register_style( 'wppb_stylesheet', WPPB_PLUGIN_URL . 'assets/css/style-front-end.css', array(), PROFILE_BUILDER_VERSION );
45 wp_enqueue_style( 'wppb_stylesheet' );
46 }
47 if( is_rtl() ) {
48 if ( ( file_exists( WPPB_PLUGIN_DIR . '/assets/css/rtl.css' ) ) && ( isset( $wppb_generalSettings['extraFieldsLayout'] ) && ( $wppb_generalSettings['extraFieldsLayout'] == 'default' ) ) ){
49 wp_register_style( 'wppb_stylesheet_rtl', WPPB_PLUGIN_URL . 'assets/css/rtl.css', array(), PROFILE_BUILDER_VERSION );
50 wp_enqueue_style( 'wppb_stylesheet_rtl' );
51 }
52 }
53 }
54
55
56 function wppb_show_admin_bar($content){
57 global $current_user;
58
59 $adminSettingsPresent = get_option('wppb_display_admin_settings','not_found');
60 $show = null;
61
62 if ($adminSettingsPresent != 'not_found' && $current_user->ID)
63 foreach ($current_user->roles as $role_key) {
64 if (empty($GLOBALS['wp_roles']->roles[$role_key]))
65 continue;
66 $role = $GLOBALS['wp_roles']->roles[$role_key];
67 if (isset($adminSettingsPresent[$role['name']])) {
68 if ($adminSettingsPresent[$role['name']] == 'show')
69 $show = true;
70 if ($adminSettingsPresent[$role['name']] == 'hide' && $show === null)
71 $show = false;
72 }
73 }
74 return $show === null ? $content : $show;
75 }
76
77
78 if(!function_exists('wppb_curpageurl')){
79 function wppb_curpageurl(){
80 $req_uri = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( $_SERVER['REQUEST_URI'] ) : '';
81
82 if( function_exists('wppb_get_abs_home') ) {
83 $home_path = trim(parse_url(wppb_get_abs_home(), PHP_URL_PATH), '/');
84 $home_path_regex = sprintf('|^%s|i', preg_quote($home_path, '|'));
85
86 // Trim path info from the end and the leading home path from the front.
87 $req_uri = ltrim($req_uri, '/');
88 $req_uri = preg_replace($home_path_regex, '', $req_uri);
89 $req_uri = trim(wppb_get_abs_home(), '/') . '/' . ltrim($req_uri, '/');
90 }
91
92 if ( function_exists('apply_filters') ) $req_uri = apply_filters('wppb_curpageurl', $req_uri);
93
94 return $req_uri;
95 }
96 }
97
98 /**
99 * Return absolute home url as stored in database, unfiltered.
100 *
101 * @return string
102 */
103 if(!function_exists('wppb_get_abs_home')) {
104 function wppb_get_abs_home(){
105 global $wpdb;
106 global $wppb_absolute_home;
107
108 if( isset($wppb_absolute_home) ) {
109 return $wppb_absolute_home;
110 }
111
112 // returns the unfiltered home_url by directly retrieving it from wp_options.
113 $wppb_absolute_home = (!is_multisite() && defined('WP_HOME')
114 ? WP_HOME
115 : (is_multisite() && !is_main_site()
116 ? (preg_match('/^(https)/', get_option('home')) === 1 ? 'https://'
117 : 'http://') . $wpdb->get_var(" SELECT CONCAT(b.domain, b.path)
118 FROM {$wpdb->blogs} b
119 WHERE blog_id = {$wpdb->blogid}
120 LIMIT 1")
121
122 : $wpdb->get_var(" SELECT option_value
123 FROM {$wpdb->options}
124 WHERE option_name = 'home'
125 LIMIT 1"))
126 );
127
128 if (empty($wppb_absolute_home)) {
129 $wppb_absolute_home = get_option("siteurl");
130 }
131
132 // always return absolute_home based on the http or https version of the current page request. This means no more redirects.
133 if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
134 $wppb_absolute_home = str_replace('http://', 'https://', $wppb_absolute_home);
135 } else {
136 $wppb_absolute_home = str_replace('https://', 'http://', $wppb_absolute_home);
137 }
138
139 return $wppb_absolute_home;
140 }
141 }
142
143
144 if ( is_admin() ){
145
146 // register the settings for the menu only display sidebar menu for a user with a certain capability, in this case only the "admin"
147 add_action( 'admin_init', 'wppb_register_settings' );
148
149 // display the same extra profile fields in the admin panel also
150 if ( file_exists ( WPPB_PLUGIN_DIR.'/front-end/extra-fields/extra-fields.php' ) ){
151 require_once( WPPB_PLUGIN_DIR.'/front-end/extra-fields/extra-fields.php' );
152
153 add_action( 'show_user_profile', 'display_profile_extra_fields_in_admin', 10 );
154 add_action( 'edit_user_profile', 'display_profile_extra_fields_in_admin', 10 );
155 global $pagenow;
156 if( $pagenow != 'user-new.php' )
157 add_action( 'user_profile_update_errors', 'wppb_validate_backend_fields', 10, 3 );
158 add_action( 'personal_options_update', 'save_profile_extra_fields_in_admin', 10 );
159 add_action( 'edit_user_profile_update', 'save_profile_extra_fields_in_admin', 10 );
160 }
161
162 /* we need to include the fields here for conditional fields when they run through ajax, the extra-fields were already included above for backend forms */
163 $wppb_generalSettings = get_option( 'wppb_general_settings' );
164 if( wp_doing_ajax() && wppb_conditional_fields_exists() && isset( $wppb_generalSettings['conditional_fields_ajax'] ) && $wppb_generalSettings['conditional_fields_ajax'] === 'yes' ) {
165 if (file_exists(WPPB_PLUGIN_DIR . '/front-end/default-fields/default-fields.php'))
166 require_once(WPPB_PLUGIN_DIR . '/front-end/default-fields/default-fields.php');
167 }
168
169 }else if ( !is_admin() ){
170 // include the stylesheet
171 add_action( 'wp_print_styles', 'wppb_add_plugin_stylesheet' );
172
173 // include the menu file for the profile informations
174 include_once( WPPB_PLUGIN_DIR.'/front-end/edit-profile.php' );
175 include_once( WPPB_PLUGIN_DIR.'/front-end/class-formbuilder.php' );
176 add_shortcode( 'wppb-edit-profile', 'wppb_front_end_profile_info' );
177
178 // include the menu file for the login screen
179 include_once( WPPB_PLUGIN_DIR.'/front-end/login.php' );
180 add_shortcode( 'wppb-login', 'wppb_front_end_login' );
181
182 // include the menu file for the logout screen
183 include_once( WPPB_PLUGIN_DIR.'/front-end/logout.php' );
184 add_shortcode( 'wppb-logout', 'wppb_front_end_logout' );
185
186 // include the menu file for the register screen
187 include_once( WPPB_PLUGIN_DIR.'/front-end/register.php' );
188 add_shortcode( 'wppb-register', 'wppb_front_end_register_handler' );
189
190 // include the menu file for the recover password screen
191 include_once( WPPB_PLUGIN_DIR.'/front-end/recover.php' );
192 add_shortcode( 'wppb-recover-password', 'wppb_front_end_password_recovery' );
193
194 // set the front-end admin bar to show/hide
195 add_filter( 'show_admin_bar' , 'wppb_show_admin_bar');
196
197 // Shortcodes used for the widget area
198 add_filter( 'widget_text', 'do_shortcode', 11 );
199 }
200
201
202 /**
203 * Function that overwrites the default wp_mail function and sends out emails
204 *
205 * @since v.2.0
206 *
207 * @param string $to
208 * @param string $subject
209 * @param string $message
210 * @param string $message_from
211 *
212 */
213 function wppb_mail( $to, $subject, $message, $message_from = null, $context = null, $headers = '' ) {
214 $to = apply_filters( 'wppb_send_email_to', $to, $context );
215 $send_email = apply_filters( 'wppb_send_email', true, $to, $subject, $message, $context );
216
217 $message = apply_filters( 'wppb_email_message', $message, $context );
218
219 $message = wppb_maybe_add_propper_html_tags_to_email( $message );
220
221 do_action( 'wppb_before_sending_email', $to, $subject, $message, $send_email, $context );
222
223 if ( $send_email ) {
224 //we add this filter to enable html encoding
225 add_filter('wp_mail_content_type', 'wppb_html_content_type' );
226
227 $atts = apply_filters( 'wppb_mail', compact( 'to', 'subject', 'message', 'headers' ), $context );
228
229 $sent = wp_mail( $atts['to'] , html_entity_decode( htmlspecialchars_decode( $atts['subject'], ENT_QUOTES ), ENT_QUOTES ), $atts['message'], $atts['headers'] );
230
231 do_action( 'wppb_after_sending_email', $sent, $to, $subject, $message, $send_email, $context );
232
233 return $sent;
234 }
235
236 return '';
237 }
238
239 /* return text/html as email content type. used in wp_mail_content_type filter */
240 function wppb_html_content_type( $content_type ){
241 return 'text/html';
242 }
243
244 /*
245 * function that adds proper html tags to a html email message if they are missing
246 */
247 function wppb_maybe_add_propper_html_tags_to_email( $message ){
248
249 //check if we have html content
250 if( $message !== wp_strip_all_tags( $message ) ){
251 if( strpos( html_entity_decode( $message ), '<html' ) === false && strpos( html_entity_decode( $message ), '<body' ) === false ){
252 $message = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body>'. $message . '</body></html>';
253 }
254 }
255
256 return $message;
257 }
258
259 function wppb_activate_account_check(){
260 if ( ( isset( $_GET['activation_key'] ) ) && ( sanitize_text_field( $_GET['activation_key'] ) != '' ) ){
261 global $post;
262 $activation_key = sanitize_text_field( $_GET['activation_key'] );
263
264 $wppb_generalSettings = get_option( 'wppb_general_settings' );
265 $activation_landing_page_id = ( ( isset( $wppb_generalSettings['activationLandingPage'] ) && ( trim( $wppb_generalSettings['activationLandingPage'] ) != '' ) ) ? $wppb_generalSettings['activationLandingPage'] : 'not_set' );
266
267 if ( $activation_landing_page_id != 'not_set' ){
268 //an activation page was selected, but we still need to check if the current page doesn't already have the registration shortcode
269 if ( strpos( $post->post_content, '[wppb-register' ) === false )
270 add_filter( 'the_content', 'wppb_add_activation_message' );
271
272 }elseif ( strpos( $post->post_content, '[wppb-register' ) === false ){
273 //no activation page was selected, and the sent link pointed to the home url
274 nocache_headers();
275 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 ) );
276 exit;
277 }
278 }
279 }
280 add_action( 'template_redirect', 'wppb_activate_account_check' );
281
282
283 function wppb_add_activation_message( $content ){
284 if( isset( $_GET['activation_key'] ) )
285 return wppb_activate_signup( sanitize_text_field( $_GET['activation_key'] ) ) . $content;
286 else
287 return $content;
288 }
289
290
291 // Create a new, top-level page
292 $args = array(
293 'page_title' => 'Profile Builder',
294 'menu_title' => 'Profile Builder',
295 'capability' => 'manage_options',
296 'menu_slug' => 'profile-builder',
297 'page_type' => 'menu_page',
298 'position' => '70,69',
299 'priority' => 1,
300 'icon_url' => WPPB_PLUGIN_URL . 'assets/images/pb-menu-icon.png'
301 );
302 new WCK_Page_Creator_PB( $args );
303
304 /**
305 * Remove the automatically created submenu page
306 *
307 * @since v.2.0
308 *
309 * @return void
310 */
311 function wppb_remove_main_menu_page(){
312 remove_submenu_page( 'profile-builder', 'profile-builder' );
313 }
314 add_action( 'admin_menu', 'wppb_remove_main_menu_page', 11 );
315
316 /**
317 * Add scripts to the back-end CPT's to remove the slug from the edit page
318 *
319 * @since v.2.0
320 *
321 * @return void
322 */
323 function wppb_print_cpt_script( $hook ){
324 wp_enqueue_script( 'jquery-ui-dialog' );
325 wp_enqueue_style( 'wp-jquery-ui-dialog' );
326
327 if ( $hook == 'profile-builder_page_manage-fields' ){
328 wp_enqueue_script( 'wppb-manage-fields-live-change', WPPB_PLUGIN_URL . 'assets/js/jquery-manage-fields-live-change.js', array(), PROFILE_BUILDER_VERSION, true );
329 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' ) ) );
330
331 wp_enqueue_script( 'wppb-select2', WPPB_PLUGIN_URL . 'assets/js/select2/select2.min.js', array(), PROFILE_BUILDER_VERSION, true );
332 wp_enqueue_style( 'wppb-select2-style', WPPB_PLUGIN_URL . 'assets/css/select2/select2.min.css', false, PROFILE_BUILDER_VERSION );
333 }
334
335 if ( $hook == 'admin_page_profile-builder-private-website' ){
336 wp_enqueue_script( 'wppb-select2', WPPB_PLUGIN_URL . 'assets/js/select2/select2.min.js', array(), PROFILE_BUILDER_VERSION, true );
337 wp_enqueue_style( 'wppb-select2-style', WPPB_PLUGIN_URL . 'assets/css/select2/select2.min.css', false, PROFILE_BUILDER_VERSION );
338 }
339
340 if (( $hook == 'profile-builder_page_manage-fields' ) ||
341 ( $hook == 'profile-builder_page_profile-builder-basic-info' ) ||
342 ( $hook == 'profile-builder_page_profile-builder-add-ons' ) ||
343 ( $hook == 'profile-builder_page_profile-builder-general-settings' ) ||
344 ( $hook == 'profile-builder_page_profile-builder-admin-bar-settings' ) ||
345 ( $hook == 'profile-builder_page_profile-builder-register' ) ||
346 ( $hook == 'profile-builder_page_profile-builder-wppb_userListing' ) ||
347 ( $hook == 'profile-builder_page_custom-redirects' ) ||
348 ( $hook == 'profile-builder_page_profile-builder-wppb_emailCustomizer' ) ||//?what is this
349 ( $hook == 'profile-builder_page_profile-builder-wppb_emailCustomizerAdmin' ) ||//?what is this
350 ( $hook == 'profile-builder_page_profile-builder-add-ons' ) ||
351 ( $hook == 'profile-builder_page_profile-builder-woocommerce-sync' ) ||
352 ( $hook == 'profile-builder_page_profile-builder-bbpress') ||
353 ( $hook == 'profile-builder_page_admin-email-customizer') ||
354 ( $hook == 'profile-builder_page_user-email-customizer') ||
355 ( $hook == 'profile-builder_page_profile-builder-content_restriction' ) ||
356 ( strpos( $hook, 'profile-builder_page_' ) === 0 ) ||
357 ( $hook == 'edit.php' && ( isset( $_GET['post_type'] ) && $_GET['post_type'] === 'wppb-roles-editor' ) ) ||
358 ( $hook == 'admin_page_profile-builder-pms-promo') ||
359 ( $hook == 'admin_page_profile-builder-private-website') ) {
360 wp_enqueue_style( 'wppb-back-end-style', WPPB_PLUGIN_URL . 'assets/css/style-back-end.css', false, PROFILE_BUILDER_VERSION );
361 }
362
363 if ( $hook == 'profile-builder_page_profile-builder-general-settings' )
364 wp_enqueue_script( 'wppb-manage-fields-live-change', WPPB_PLUGIN_URL . 'assets/js/jquery-email-confirmation.js', array(), PROFILE_BUILDER_VERSION, true );
365
366 if( ($hook == 'profile-builder_page_profile-builder-add-ons' ) ||
367 ($hook == 'admin_page_profile-builder-pms-promo' ) ) {
368 wp_enqueue_script('wppb-add-ons', WPPB_PLUGIN_URL . 'assets/js/jquery-pb-add-ons.js', array(), PROFILE_BUILDER_VERSION, true);
369 wp_enqueue_style( 'thickbox' );
370 wp_enqueue_script( 'thickbox' );
371 }
372
373 if ( isset( $_GET['post_type'] ) || isset( $_GET['post'] ) ){
374 if ( isset( $_GET['post_type'] ) )
375 $post_type = sanitize_text_field( $_GET['post_type'] );
376
377 elseif ( isset( $_GET['post'] ) )
378 $post_type = get_post_type( absint( $_GET['post'] ) );
379
380 if ( ( 'wppb-epf-cpt' == $post_type ) || ( 'wppb-rf-cpt' == $post_type ) || ( 'wppb-ul-cpt' == $post_type ) ){
381 wp_enqueue_style( 'wppb-back-end-style', WPPB_PLUGIN_URL . 'assets/css/style-back-end.css', false, PROFILE_BUILDER_VERSION );
382 wp_enqueue_script( 'wppb-epf-rf', WPPB_PLUGIN_URL . 'assets/js/jquery-epf-rf.js', array(), PROFILE_BUILDER_VERSION, true );
383 }
384 else if( 'wppb-roles-editor' == $post_type ){
385 wp_enqueue_style( 'wppb-back-end-style', WPPB_PLUGIN_URL . 'assets/css/style-back-end.css', array(), PROFILE_BUILDER_VERSION );
386 }
387 }
388
389 wp_enqueue_script( 'wppb-sitewide', WPPB_PLUGIN_URL . 'assets/js/jquery-pb-sitewide.js', array(), PROFILE_BUILDER_VERSION, true );
390
391 wp_enqueue_style( 'wppb-serial-notice-css', WPPB_PLUGIN_URL . 'assets/css/serial-notice.css', false, PROFILE_BUILDER_VERSION );
392 }
393 add_action( 'admin_enqueue_scripts', 'wppb_print_cpt_script' );
394
395 /**
396 * Highlight the settings page under Profile Builder in the admin menu for these pages
397 */
398 //add add_action( "admin_footer-$hook", "wppb_make_setting_menu_item_highlighted" ); for other pages that don't have a parent
399 add_action( "admin_footer-admin_page_profile-builder-private-website", "wppb_make_setting_menu_item_highlighted" );
400 add_action( "admin_footer-profile-builder_page_profile-builder-admin-bar-settings", "wppb_make_setting_menu_item_highlighted" );
401 add_action( "admin_footer-profile-builder_page_profile-builder-content_restriction", "wppb_make_setting_menu_item_highlighted" );
402 add_action( "admin_footer-profile-builder_page_profile-builder-content_restriction", "wppb_make_setting_menu_item_highlighted" );
403 add_action( "admin_footer-profile-builder_page_admin-email-customizer", "wppb_make_setting_menu_item_highlighted" );
404 add_action( "admin_footer-profile-builder_page_user-email-customizer", "wppb_make_setting_menu_item_highlighted" );
405 add_action( "admin_footer-profile-builder_page_profile-builder-toolbox-settings", "wppb_make_setting_menu_item_highlighted" );
406 add_action( "admin_footer-profile-builder_page_profile-builder-two-factor-authentication", "wppb_make_setting_menu_item_highlighted" );
407 function wppb_make_setting_menu_item_highlighted(){
408 echo'<script type="text/javascript">
409 jQuery(document).ready( function($) {
410 $("#toplevel_page_profile-builder").addClass("current wp-has-current-submenu wp-menu-open");
411 $("a[href=\'admin.php?page=profile-builder-general-settings\']").closest("li").addClass("current");
412 });
413 </script>';
414 }
415
416
417 //the function used to overwrite the avatar across the wp installation
418 function wppb_changeDefaultAvatar( $avatar, $id_or_email, $size, $default, $alt ){
419 /* Get user info. */
420 if(is_object($id_or_email)){
421 $my_user_id = $id_or_email->user_id;
422
423 if ($id_or_email instanceof WP_User){
424 $my_user_id = $id_or_email->ID;
425 }
426
427 }elseif(is_numeric($id_or_email)){
428 $my_user_id = $id_or_email;
429
430 }elseif(!is_integer($id_or_email)){
431 $user_info = get_user_by( 'email', $id_or_email );
432 $my_user_id = ( is_object( $user_info ) ? $user_info->ID : '' );
433 }else
434 $my_user_id = $id_or_email;
435
436 $wppb_manage_fields = get_option( 'wppb_manage_fields', 'not_found' );
437 if ( $wppb_manage_fields != 'not_found' ){
438 foreach( $wppb_manage_fields as $value ){
439 if ( $value['field'] == 'Avatar'){
440 $avatar_field = $value;
441 }
442 }
443 }
444
445 /* for multisite if we don't have an avatar try to get it from the main blog */
446 if( is_multisite() && empty( $avatar_field ) ){
447 switch_to_blog(1);
448 $wppb_switched_blog = true;
449 $wppb_manage_fields = get_option( 'wppb_manage_fields', 'not_found' );
450 if ( $wppb_manage_fields != 'not_found' ){
451 foreach( $wppb_manage_fields as $value ){
452 if ( $value['field'] == 'Avatar'){
453 $avatar_field = $value;
454 }
455 }
456 }
457 }
458
459 if ( !empty( $avatar_field ) ){
460
461 $customUserAvatar = get_user_meta( $my_user_id, Wordpress_Creation_Kit_PB::wck_generate_slug( $avatar_field['meta-name'] ), true );
462 if( !empty( $customUserAvatar ) ){
463 if( is_numeric( $customUserAvatar ) ){
464 $img_attr = wp_get_attachment_image_src( $customUserAvatar, 'wppb-avatar-size-'.$size );
465 if( $img_attr[3] === false ){
466 $img_attr = wp_get_attachment_image_src( $customUserAvatar, 'thumbnail' );
467 $avatar = "<img alt='{$alt}' src='{$img_attr[0]}' class='avatar avatar-{$size} photo avatar-default' height='{$size}' width='{$size}' />";
468 }
469 else
470 $avatar = "<img alt='{$alt}' src='{$img_attr[0]}' class='avatar avatar-{$size} photo avatar-default' height='{$img_attr[2]}' width='{$img_attr[1]}' />";
471 }
472 else {
473 $customUserAvatar = get_user_meta($my_user_id, 'resized_avatar_' . $avatar_field['id'], true);
474 $customUserAvatarRelativePath = get_user_meta($my_user_id, 'resized_avatar_' . $avatar_field['id'] . '_relative_path', true);
475
476 if ((($customUserAvatar != '') || ($customUserAvatar != null)) && file_exists($customUserAvatarRelativePath)) {
477 $avatar = "<img alt='{$alt}' src='{$customUserAvatar}' class='avatar avatar-{$size} photo avatar-default' height='{$size}' width='{$size}' />";
478 }
479 }
480 }
481
482 }
483
484 /* if we switched the blog restore it */
485 if( is_multisite() && !empty( $wppb_switched_blog ) && $wppb_switched_blog )
486 restore_current_blog();
487
488 return $avatar;
489 }
490 add_filter( 'get_avatar', 'wppb_changeDefaultAvatar', 21, 5 );
491
492
493 //the function used to overwrite the avatar across the wp installation
494 function wppb_changeDefaultAvatarUrl( $url, $id_or_email, $args ){
495 /* Get user info. */
496 if(is_object($id_or_email)){
497 $my_user_id = $id_or_email->user_id;
498
499 if ($id_or_email instanceof WP_User){
500 $my_user_id = $id_or_email->ID;
501 }
502
503 }elseif(is_numeric($id_or_email)){
504 $my_user_id = $id_or_email;
505
506 }elseif(!is_integer($id_or_email)){
507 $user_info = get_user_by( 'email', $id_or_email );
508 $my_user_id = ( is_object( $user_info ) ? $user_info->ID : '' );
509 }else
510 $my_user_id = $id_or_email;
511
512 $wppb_manage_fields = get_option( 'wppb_manage_fields', 'not_found' );
513 if ( $wppb_manage_fields != 'not_found' ){
514 foreach( $wppb_manage_fields as $value ){
515 if ( $value['field'] == 'Avatar'){
516 $avatar_field = $value;
517 }
518 }
519 }
520
521 /* for multisite if we don't have an avatar try to get it from the main blog */
522 if( is_multisite() && empty( $avatar_field ) ){
523 switch_to_blog(1);
524 $wppb_switched_blog = true;
525 $wppb_manage_fields = get_option( 'wppb_manage_fields', 'not_found' );
526 if ( $wppb_manage_fields != 'not_found' ){
527 foreach( $wppb_manage_fields as $value ){
528 if ( $value['field'] == 'Avatar'){
529 $avatar_field = $value;
530 }
531 }
532 }
533 }
534
535 $avatar_url = $url;
536
537 if ( !empty( $avatar_field ) ){
538
539 $customUserAvatar = get_user_meta( $my_user_id, Wordpress_Creation_Kit_PB::wck_generate_slug( $avatar_field['meta-name'] ), true );
540 if( !empty( $customUserAvatar ) ){
541 if( is_numeric( $customUserAvatar ) ){
542 if( $img_attr = wp_get_attachment_image_src( $customUserAvatar, 'wppb-avatar-size-'.$args['size'] ) ) {
543 if ( $img_attr[3] === false ) {
544 $img_attr = wp_get_attachment_image_src( $customUserAvatar, 'thumbnail' );
545 }
546 $avatar_url = $img_attr[0];
547 }
548 }
549 else {
550 $customUserAvatar = get_user_meta($my_user_id, 'resized_avatar_' . $avatar_field['id'], true);
551 $customUserAvatarRelativePath = get_user_meta($my_user_id, 'resized_avatar_' . $avatar_field['id'] . '_relative_path', true);
552
553 if ((($customUserAvatar != '') || ($customUserAvatar != null)) && file_exists($customUserAvatarRelativePath)) {
554 $avatar_url = $customUserAvatar;
555 }
556 }
557 }
558
559 }
560
561 /* if we switched the blog restore it */
562 if( is_multisite() && !empty( $wppb_switched_blog ) && $wppb_switched_blog )
563 restore_current_blog();
564
565 return $avatar_url;
566 }
567 add_filter( 'get_avatar_url', 'wppb_changeDefaultAvatarUrl', 21, 5 );
568
569
570 //the function used to resize the avatar image; the new function uses a user ID as parameter to make pages load faster
571 function wppb_resize_avatar( $userID, $userlisting_size = null, $userlisting_crop = null ){
572 // include the admin image API
573 require_once( ABSPATH . '/wp-admin/includes/image.php' );
574
575 // retrieve first a list of all the current custom fields
576 $wppb_manage_fields = get_option( 'wppb_manage_fields', 'not_found' );
577 if ( $wppb_manage_fields != 'not_found' ){
578 foreach( $wppb_manage_fields as $value ){
579 if ( $value['field'] == 'Avatar'){
580 $avatar_field = $value;
581 }
582 }
583 }
584
585 /* for multisite if we don't have an avatar try to get it from the main blog */
586 if( is_multisite() && empty( $avatar_field ) ){
587 switch_to_blog(1);
588 $wppb_switched_blog = true;
589 $wppb_manage_fields = get_option( 'wppb_manage_fields', 'not_found' );
590 if ( $wppb_manage_fields != 'not_found' ){
591 foreach( $wppb_manage_fields as $value ){
592 if ( $value['field'] == 'Avatar'){
593 $avatar_field = $value;
594 }
595 }
596 }
597 }
598
599
600 if ( !empty( $avatar_field ) ){
601
602 // retrieve width and height of the image
603 $width = $height = '';
604
605 //this checks if it only has 1 component
606 if ( is_numeric( $avatar_field['avatar-size'] ) ){
607 $width = $height = $avatar_field['avatar-size'];
608
609 }else{
610 //this checks if the entered value has 2 components
611 $sentValue = explode( ',', $avatar_field['avatar-size'] );
612 $width = $sentValue[0];
613 $height = $sentValue[1];
614 }
615
616 $width = ( !empty( $userlisting_size ) ? $userlisting_size : $width );
617 $height = ( !empty( $userlisting_size ) ? $userlisting_size : $height );
618
619 if( !strpos( get_user_meta( $userID, 'resized_avatar_'.$avatar_field['id'], true ), $width . 'x' . $height ) ) {
620 // retrieve the original image (in original size)
621 $avatar_directory_path = get_user_meta( $userID, 'avatar_directory_path_'.$avatar_field['id'], true );
622
623 $image = wp_get_image_editor( $avatar_directory_path );
624 if ( !is_wp_error( $image ) ) {
625 do_action( 'wppb_before_avatar_resizing', $image, $userID, Wordpress_Creation_Kit_PB::wck_generate_slug( $avatar_field['meta-name'] ), $avatar_field['avatar-size'] );
626
627 $crop = apply_filters( 'wppb_avatar_crop_resize', ( !empty( $userlisting_crop ) ? $userlisting_crop : false ) );
628
629 $resize = $image->resize( $width, $height, $crop );
630
631 if ($resize !== FALSE) {
632 do_action( 'wppb_avatar_resizing', $image, $resize );
633
634 $fileType = apply_filters( 'wppb_resized_file_extension', 'png' );
635
636 $wp_upload_array = wp_upload_dir(); // Array of key => value pairs
637
638 //create file(name); both with directory and url
639 $fileName_dir = $image->generate_filename( NULL, $wp_upload_array['basedir'].'/profile_builder/avatars/', $fileType );
640
641 if ( PHP_OS == "WIN32" || PHP_OS == "WINNT" )
642 $fileName_dir = str_replace( '\\', '/', $fileName_dir );
643
644 $fileName_url = str_replace( str_replace( '\\', '/', $wp_upload_array['basedir'] ), $wp_upload_array['baseurl'], $fileName_dir );
645
646 //save the newly created (resized) avatar on the disc
647 $saved_image = $image->save( $fileName_dir );
648
649 if ( !is_wp_error( $saved_image ) ) {
650 /* the image save sometimes doesn't save with the desired extension so we need to see with what extension it saved it with and
651 if it differs replace the extension in the path and url that we save as meta */
652 $validate_saved_image = wp_check_filetype_and_ext( $saved_image['path'], $saved_image['path'] );
653 $ext = substr( $fileName_dir,strrpos( $fileName_dir, '.', -1 ), strlen($fileName_dir) );
654 if( !empty( $validate_saved_image['ext'] ) && $validate_saved_image['ext'] != $ext ){
655 $fileName_url = str_replace( $ext, '.'.$validate_saved_image['ext'], $fileName_url );
656 $fileName_dir = str_replace( $ext, '.'.$validate_saved_image['ext'], $fileName_dir );
657 }
658
659 update_user_meta( $userID, 'resized_avatar_'.$avatar_field['id'], $fileName_url );
660 update_user_meta( $userID, 'resized_avatar_'.$avatar_field['id'].'_relative_path', $fileName_dir );
661
662 do_action( 'wppb_after_avatar_resizing', $image, $fileName_dir, $fileName_url );
663 }
664 }
665 }
666 }
667 }
668
669 /* if we switched the blog restore it */
670 if( is_multisite() && !empty( $wppb_switched_blog ) && $wppb_switched_blog )
671 restore_current_blog();
672
673 }
674
675
676 if ( is_admin() ){
677 // add a hook to delete the user from the _signups table if either the email confirmation is activated, or it is a wpmu installation
678 function wppb_delete_user_from_signups_table($user_id) {
679 global $wpdb;
680
681 $userLogin = $wpdb->get_var( $wpdb->prepare( "SELECT user_login, user_email FROM " . $wpdb->users . " WHERE ID = %d LIMIT 1", $user_id ) );
682 if ( is_multisite() )
683 $delete = $wpdb->delete( $wpdb->signups, array( 'user_login' => $userLogin ) );
684 else {
685 $table_name = $wpdb->prefix . 'signups';
686 $val = $wpdb->get_var( $wpdb->prepare( "SHOW TABLES LIKE %s", $table_name ) );
687 if ( $val ){
688 $delete = $wpdb->delete($wpdb->prefix . 'signups', array('user_login' => $userLogin));
689 }
690 }
691 }
692
693 $wppb_generalSettings = get_option( 'wppb_general_settings' );
694 if ( !empty( $wppb_generalSettings['emailConfirmation'] ) && ( $wppb_generalSettings['emailConfirmation'] == 'yes' ) ) {
695 if( is_multisite() )
696 add_action( 'wpmu_delete_user', 'wppb_delete_user_from_signups_table' );
697 else
698 add_action('delete_user', 'wppb_delete_user_from_signups_table');
699 }
700 }
701
702
703
704 // This function offers compatibility with the all in one event calendar plugin
705 function wppb_aioec_compatibility(){
706
707 wp_deregister_script( 'jquery.tools-form');
708 }
709 add_action('admin_print_styles-users_page_ProfileBuilderOptionsAndSettings', 'wppb_aioec_compatibility');
710
711
712 function wppb_user_meta_exists( $id, $meta_name ){
713 global $wpdb;
714
715 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 );
716 }
717
718
719 // function to check if there is a need to add the http:// prefix
720 function wppb_check_missing_http( $redirectLink ) {
721 return preg_match( '#^(?:[a-z\d]+(?:-+[a-z\d]+)*\.)+[a-z]+(?::\d+)?(?:/|$)#i', $redirectLink );
722 }
723
724 //function that adds missing http to a link
725 function wppb_add_missing_http( $link ){
726 $http = '';
727 if ( wppb_check_missing_http( $link ) ) { //if missing http(s)
728 $http = 'http';
729 if ((isset($_SERVER["HTTPS"])) && ($_SERVER["HTTPS"] == "on"))
730 $http .= "s";
731 $http .= "://";
732 }
733
734 return $http . $link;
735 }
736
737
738 //function to output the password strength checker on frontend forms
739 function wppb_password_strength_checker_html(){
740 $wppb_generalSettings = get_option( 'wppb_general_settings' );
741 if( !empty( $wppb_generalSettings['minimum_password_strength'] ) ){
742 $password_strength = '<span id="pass-strength-result">'.__('Strength indicator', 'profile-builder' ).'</span>
743 <input type="hidden" value="" name="wppb_password_strength" id="wppb_password_strength"/>';
744 return $password_strength;
745 }
746 return '';
747 }
748
749 //function to check password length check
750 function wppb_check_password_length( $password ){
751 $wppb_generalSettings = get_option( 'wppb_general_settings' );
752 if( !empty( $wppb_generalSettings['minimum_password_length'] ) ){
753 if( strlen( $password ) < $wppb_generalSettings['minimum_password_length'] ){
754 return true;
755 }
756 else
757 return false;
758 }
759 return false;
760 }
761
762 //function to check password strength
763 function wppb_check_password_strength(){
764 $wppb_generalSettings = get_option( 'wppb_general_settings' );
765 if( isset( $_POST['wppb_password_strength'] ) && !empty( $wppb_generalSettings['minimum_password_strength'] ) ){
766 $wppb_password_strength = sanitize_text_field( $_POST['wppb_password_strength'] );
767 $password_strength_array = array( 'short' => 0, 'bad' => 1, 'good' => 2, 'strong' => 3 );
768 $password_strength_text = array( 'short' => __( 'Very Weak', 'profile-builder' ), 'bad' => __( 'Weak', 'profile-builder' ), 'good' => __( 'Medium', 'profile-builder' ), 'strong' => __( 'Strong', 'profile-builder' ) );
769 if( $password_strength_array[$wppb_password_strength] < $password_strength_array[$wppb_generalSettings['minimum_password_strength']] ){
770 return $password_strength_text[$wppb_generalSettings['minimum_password_strength']];
771 }
772 else
773 return false;
774 }
775 return false;
776 }
777
778 /* function to output password length requirements text */
779 function wppb_password_length_text(){
780 $wppb_generalSettings = get_option( 'wppb_general_settings' );
781 if( !empty( $wppb_generalSettings['minimum_password_length'] ) ){
782 return sprintf(__('Minimum length of %d characters.', 'profile-builder'), $wppb_generalSettings['minimum_password_length']);
783 }
784 return '';
785 }
786
787 /* function to output password strength requirements text */
788 function wppb_password_strength_description() {
789 $wppb_generalSettings = get_option( 'wppb_general_settings' );
790
791 if( ! empty( $wppb_generalSettings['minimum_password_strength'] ) ) {
792 $password_strength_text = array( 'short' => __( 'Very Weak', 'profile-builder' ), 'bad' => __( 'Weak', 'profile-builder' ), 'good' => __( 'Medium', 'profile-builder' ), 'strong' => __( 'Strong', 'profile-builder' ) );
793 $password_strength_description = '<br>'. sprintf( __( 'The password must have a minimum strength of %s', 'profile-builder' ), $password_strength_text[$wppb_generalSettings['minimum_password_strength']] );
794
795 return $password_strength_description;
796 } else {
797 return '';
798 }
799 }
800
801 /**
802 * Include password strength check scripts on frontend where we have shortcodes present
803 */
804 add_action( 'wp_footer', 'wppb_enqueue_password_strength_check' );
805 function wppb_enqueue_password_strength_check() {
806 global $wppb_shortcode_on_front;
807 if( $wppb_shortcode_on_front ){
808 $wppb_generalSettings = get_option( 'wppb_general_settings' );
809 if( !empty( $wppb_generalSettings['minimum_password_strength'] ) ){
810 wp_enqueue_script( 'password-strength-meter' );
811 }
812 }
813 }
814 add_action( 'wp_footer', 'wppb_password_strength_check', 102 );
815 function wppb_password_strength_check(){
816 global $wppb_shortcode_on_front;
817 if( $wppb_shortcode_on_front ){
818 $wppb_generalSettings = get_option( 'wppb_general_settings' );
819 if( !empty( $wppb_generalSettings['minimum_password_strength'] ) ){
820 ?>
821 <script type="text/javascript">
822 function check_pass_strength() {
823 var pass1 = jQuery('#passw1').val(), pass2 = jQuery('#passw2').val(), strength;
824
825 jQuery('#pass-strength-result').removeClass('short bad good strong');
826 if ( ! pass1 ) {
827 jQuery('#pass-strength-result').html( pwsL10n.empty );
828 return;
829 }
830
831 strength = wp.passwordStrength.meter( pass1, wp.passwordStrength.userInputDisallowedList(), pass2 );
832
833 switch ( strength ) {
834 case 2:
835 jQuery('#pass-strength-result').addClass('bad').html( pwsL10n.bad );
836 jQuery('#wppb_password_strength').val('bad');
837 break;
838 case 3:
839 jQuery('#pass-strength-result').addClass('good').html( pwsL10n.good );
840 jQuery('#wppb_password_strength').val('good');
841 break;
842 case 4:
843 jQuery('#pass-strength-result').addClass('strong').html( pwsL10n.strong );
844 jQuery('#wppb_password_strength').val('strong');
845 break;
846 case 5:
847 jQuery('#pass-strength-result').addClass('short').html( pwsL10n.mismatch );
848 jQuery('#wppb_password_strength').val('short');
849 break;
850 default:
851 jQuery('#pass-strength-result').addClass('short').html( pwsL10n['short'] );
852 jQuery('#wppb_password_strength').val('short');
853 }
854 }
855 jQuery( document ).ready( function() {
856 // Binding to trigger checkPasswordStrength
857 jQuery('#passw1').val('').on( 'keyup', check_pass_strength );
858 jQuery('#passw2').val('').on( 'keyup', check_pass_strength );
859 jQuery('#pass-strength-result').show();
860 });
861 </script>
862 <?php
863 }
864 }
865 }
866
867 /**
868 * Include toggle password visibility script on frontend where we have shortcodes present
869 */
870 function wppb_password_visibility_toggle_html(){
871 if( apply_filters( 'wppb_show_password_visibility_toggle', false ) ){
872 return '
873 <button type="button" class="wppb-toggle-pw wppb-show-pw hide-if-no-js" data-toggle="0" aria-label="Show password" tabindex="-1">
874 <img src="'.WPPB_PLUGIN_URL.'/assets/images/eye-outline.svg"/>
875 </button>';
876 }
877 return '';
878 }
879
880 /**
881 * Include toggle password visibility script on frontend where we have shortcodes present
882 */
883 add_action( 'wp_footer', 'wppb_enqueue_password_visibility_toggle' );
884 function wppb_enqueue_password_visibility_toggle() {
885 global $wppb_shortcode_on_front;
886 if( $wppb_shortcode_on_front && apply_filters( 'wppb_show_password_visibility_toggle', false ) ){
887 ?>
888 <script type="text/javascript">
889 jQuery( document ).ready( function() {
890
891 jQuery( "button.wppb-toggle-pw" ).on( "click", wppb_password_visibility_toggle );
892
893 jQuery( 'button.wppb-toggle-pw' ).each( function( index, toggle ){
894
895 var parent = jQuery( toggle ).parent()
896
897 if( parent.hasClass( 'wppb-form-field' ) && jQuery( '.wppb-description-delimiter', parent ) ){
898
899 jQuery( toggle ).css( 'top', parseInt( jQuery( toggle ).css('top') ) - ( jQuery( '.wppb-description-delimiter', parent ).outerHeight() / 2 ) )
900
901 }
902
903 })
904
905 });
906 function wppb_password_visibility_toggle() {
907 var target_form_id = "#" + jQuery(this).closest('form').attr("id") + " ";
908
909 var password_inputs = [ ".login-password input#user_pass", "input#passw1", "input#passw2" ]
910
911 for ( var password_input of password_inputs ){
912 var input = jQuery( target_form_id + password_input );
913 var button = jQuery( target_form_id + "button.wppb-toggle-pw" );
914 var icon = jQuery( target_form_id + "button.wppb-toggle-pw img" );
915
916 if ( input.length ) {
917 if ("password" === input.attr("type")) {
918 input.attr("type", "text");
919 button.toggleClass("wppb-show-pw").toggleClass("wppb-hide-pw");
920 icon.attr("src", "<?php echo esc_attr( WPPB_PLUGIN_URL ); ?>/assets/images/eye-off-outline.svg");
921 } else {
922 input.attr("type", "password");
923 button.toggleClass("wppb-show-pw").toggleClass("wppb-hide-pw");
924 icon.attr("src", "<?php echo esc_attr( WPPB_PLUGIN_URL ); ?>/assets/images/eye-outline.svg");
925 }
926 }
927 }
928 }
929 </script>
930 <?php
931 }
932 }
933
934 /**
935 * Create functions for repeating error messages in front-end forms
936 */
937 function wppb_required_field_error($field_title='') {
938 $required_error = apply_filters('wppb_required_error' , __('This field is required','profile-builder') , $field_title);
939
940 return $required_error;
941
942 }
943
944 /**
945 * Function that returns a certain field (from manage_fields) by a given id or meta_name
946 */
947 function wppb_get_field_by_id_or_meta( $id_or_meta ){
948
949 $id = 0;
950 $meta = '';
951
952 if ( is_numeric($id_or_meta) )
953 $id = $id_or_meta;
954 else
955 $meta = $id_or_meta;
956
957 $fields = get_option('wppb_manage_fields', 'not_found');
958
959 if ($fields != 'not_found') {
960
961 foreach ($fields as $key => $field) {
962 if ( (!empty($id)) && ($field['id'] == $id) )
963 return $field;
964 if ( (!empty($meta)) && ($field['meta-name'] == $meta) )
965 return $field;
966 }
967
968 }
969
970 return '';
971 }
972
973
974 /* Function for displaying reCAPTCHA error on Login and Recover Password forms */
975 function wppb_recaptcha_field_error($field_title='') {
976 $recaptcha_error = apply_filters('wppb_recaptcha_error' , __('Please enter a (valid) reCAPTCHA value','profile-builder') , $field_title);
977
978 return $recaptcha_error;
979
980 }
981 /* Function for displaying phone field error */
982 function wppb_phone_field_error( $field_title = '' ) {
983 $phone_error = apply_filters( 'wppb_phone_error' , __( 'Incorrect phone number', 'profile-builder' ) , $field_title );
984
985 return $phone_error;
986 }
987
988 /* Create a wrapper function for get_query_var */
989 function wppb_get_query_var( $varname ){
990 //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
991 if($varname === 'username' && !get_query_var( $varname ) && isset($_GET['wppb_username'])){
992 return apply_filters( 'wppb_get_query_var_'.$varname, sanitize_user( $_GET['wppb_username'] ) );
993 }
994
995 return apply_filters( 'wppb_get_query_var_'.$varname, get_query_var( $varname ) );
996 }
997
998 /** @param string|array $key Query key or keys to remove.
999 */
1000 function wppb_remove_query_arg( $key, $url = false ){
1001 $striped_url = remove_query_arg( $key, $url);
1002
1003 //treat page key on frontpage case where it is transformed into a pretty permalink
1004 if( ( is_array($key) && in_array('wppb_page', $key) ) || ( !is_array($key) && 'wppb_page' === $key ) ){
1005 $striped_url = preg_replace( '/\/'.wppb_get_users_pagination_slug().'\/\d+\//', '/', $striped_url );
1006 $striped_url = preg_replace( '/\/'.wppb_get_users_pagination_slug().'\//', '/', $striped_url );
1007 }
1008
1009 return $striped_url;
1010 }
1011
1012 //function that generates tha pagination slug for userlisting
1013 function wppb_get_users_pagination_slug(){
1014 return apply_filters('wppb_users_pagination_slug', 'users-page');
1015 }
1016
1017 /* Filter the "Save Changes" button text, to make it translatable */
1018 function wppb_change_save_changes_button($value){
1019 $value = __('Save Changes','profile-builder');
1020 return $value;
1021 }
1022 add_filter( 'wck_save_changes_button', 'wppb_change_save_changes_button', 10, 2);
1023
1024 /* Filter the "Cancel" button text, to make it translatable */
1025 function wppb_change_cancel_button($value){
1026 $value = __('Cancel','profile-builder');
1027 return $value;
1028 }
1029 add_filter( 'wck_cancel_button', 'wppb_change_cancel_button', 10, 2);
1030
1031 /* ilter the "Delete" button text, to make it translatable */
1032 function wppb_change_delete_button($value){
1033 $value = __('Delete','profile-builder');
1034 return $value;
1035 }
1036 add_filter( 'wck_delete_button', 'wppb_change_delete_button', 10, 2);
1037
1038 /*Filter the "Edit" button text, to make it translatable*/
1039 function wppb_change_edit_button($value){
1040 $value = __('Edit','profile-builder');
1041 return $value;
1042 }
1043 add_filter( 'wck_edit_button', 'wppb_change_edit_button', 10, 2);
1044
1045 /*Filter the User Listing, Register Forms and Edit Profile forms metabox header content, to make it translatable*/
1046 function wppb_change_metabox_content_header(){
1047 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>';
1048 }
1049 add_filter('wck_metabox_content_header_wppb_ul_page_settings', 'wppb_change_metabox_content_header', 1);
1050 add_filter('wck_metabox_content_header_wppb_rf_page_settings', 'wppb_change_metabox_content_header', 1);
1051 add_filter('wck_metabox_content_header_wppb_epf_page_settings', 'wppb_change_metabox_content_header', 1);
1052
1053
1054 /*Filter default WordPress notices ("Post published. Post updated."), add post type name for User Listing, Registration Forms and Edit Profile Forms*/
1055 function wppb_change_default_post_updated_messages($messages){
1056 global $post;
1057 $post_type = get_post_type($post->ID);
1058 $object = get_post_type_object($post_type);
1059
1060 if ( ($post_type == 'wppb-rf-cpt')||($post_type == 'wppb-epf-cpt')||($post_type == 'wppb-ul-cpt') ){
1061 $messages['post'][1] = $object->labels->name . ' updated.';
1062 $messages['post'][6] = $object->labels->name . ' published.';
1063 }
1064 return $messages;
1065 }
1066 add_filter('post_updated_messages','wppb_change_default_post_updated_messages', 2);
1067
1068
1069 /* for meta-names with spaces in them PHP converts the space to underline in the $_POST */
1070 function wppb_handle_meta_name( $meta_name ){
1071 $meta_name = trim( $meta_name );
1072 $meta_name = str_replace( ' ', '_', $meta_name );
1073 $meta_name = str_replace( '.', '_', $meta_name );
1074 return $meta_name;
1075 }
1076
1077 /**
1078 * Function that checks if a field type exists in a form
1079 * @return bool
1080 */
1081 function wppb_field_exists_in_form( $field_type, $form_args ){
1082 if( !empty( $form_args ) && !empty( $form_args['form_fields'] ) ){
1083 foreach( $form_args['form_fields'] as $field ){
1084 if( $field['field'] === $field_type ){
1085 return true;
1086 }
1087 }
1088 }
1089
1090 return false;
1091 }
1092
1093 // change User Registered date and time according to timezone selected in WordPress settings
1094 function wppb_get_register_date() {
1095
1096 $time_format = "Y-m-d G:i:s";
1097 $wppb_get_date = date_i18n( $time_format, false, true );
1098
1099 if( apply_filters( 'wppb_return_local_time_for_register', false ) ){
1100 $wppb_get_date = date_i18n( $time_format );
1101 }
1102
1103 return $wppb_get_date;
1104 }
1105
1106 /**
1107 * Function that ads the gmt offset from the general settings to a unix timestamp
1108 * @param $timestamp
1109 * @return mixed
1110 */
1111 function wppb_add_gmt_offset( $timestamp ) {
1112 if( apply_filters( 'wppb_add_gmt_offset', true ) ){
1113 $timestamp = $timestamp + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
1114 }
1115 return $timestamp;
1116 }
1117
1118 /**
1119 * Add HTML tag 'required' to fields
1120 *
1121 * 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.
1122 * Field type 'Checkbox' is explicitly excluded because there is no HTML support to check if at least one option is selected.
1123 * Other fields excluded are Avatar, Upload, Heading, ReCaptcha, WYSIWYG, Map.
1124 *
1125 * @since
1126 *
1127 * @param string $extra_attributes Extra attributes attached to the field HTML tag.
1128 * @param array $field Field description.
1129 * @return string $extra_attributes
1130 */
1131 function wppb_add_html_tag_required_to_fields( $extra_attributes, $field, $form_location = '' ) {
1132 if ( $field['field'] != "Checkbox" && isset( $field['required'] ) && $field['required'] == 'Yes' ){
1133 if( !( ( $field['field'] == "Default - Password" || $field['field'] == "Default - Repeat Password" ) && $form_location == 'edit_profile' ) )
1134 $extra_attributes .= ' required ';
1135 }
1136 return $extra_attributes;
1137 }
1138 add_filter( 'wppb_extra_attribute', 'wppb_add_html_tag_required_to_fields', 10, 3 );
1139
1140 /**
1141 * Add HTML tag 'required' to WooCommerce fields
1142 *
1143 * 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.
1144 * Does not work on 'State / County' field, if it becomes required later depending on the Country Value
1145 *
1146 * @since
1147 *
1148 * @param string $extra_attributes Extra attributes attached to the field HTML tag.
1149 * @param array $field Field description.
1150 * @return string $extra_attributes
1151 */
1152 function wppb_add_html_tag_required_to_woo_fields( $extra_attributes, $field ) {
1153 if ( isset( $field['required'] ) && $field['required'] == 'Yes' ){
1154 $extra_attributes .= ' required ';
1155 }
1156 return $extra_attributes;
1157 }
1158 add_filter( 'wppb_woo_extra_attribute', 'wppb_add_html_tag_required_to_woo_fields', 10, 2 );
1159
1160
1161 /**
1162 * Add jQuery script to remove required attribute for hidden fields
1163 *
1164 * 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.
1165 * If a field is made visible again, add the required field back again.
1166 *
1167 * @since
1168 *
1169 * @param string $extra_attributes Extra attributes attached to the field HTML tag.
1170 * @param array $field Field description.
1171 * @return string $extra_attributes
1172 */
1173 function wppb_manage_required_attribute() {
1174 global $wppb_shortcode_on_front;
1175 if ($wppb_shortcode_on_front) {
1176 //check if jquery has been loaded yet because we need it at this point
1177 // we're checking if it's not admin because it brakes elementor otherwise.
1178 if( !wp_script_is('jquery', 'done') && !is_admin() ){
1179 wp_print_scripts('jquery');
1180 }
1181 ?>
1182 <script type="text/javascript">
1183 jQuery(document).on( "wppbAddRequiredAttributeEvent", wppbAddRequired );
1184 function wppbAddRequired(event) {
1185 var element = wppbEventTargetRequiredElement( event.target );
1186 if( jQuery( element ).attr( "wppb_cf_temprequired" ) ){
1187 jQuery( element ).removeAttr( "wppb_cf_temprequired" );
1188 jQuery( element ).attr( "required", "required" );
1189 }
1190 }
1191
1192 jQuery(document).on( "wppbRemoveRequiredAttributeEvent", wppbRemoveRequired );
1193 function wppbRemoveRequired(event) {
1194 var element = wppbEventTargetRequiredElement( event.target );
1195 if ( jQuery( element ).attr( "required" ) ) {
1196 jQuery( element ).removeAttr( "required" );
1197 jQuery( element ).attr( "wppb_cf_temprequired", "wppb_cf_temprequired" );
1198 }
1199 }
1200
1201 jQuery(document).on( "wppbToggleRequiredAttributeEvent", wppbToggleRequired );
1202 function wppbToggleRequired(event) {
1203 if ( jQuery( event.target ).attr( "required" ) ) {
1204 jQuery( event.target ).removeAttr( "required" );
1205 jQuery( event.target ).attr( "wppb_cf_temprequired", "wppb_cf_temprequired" );
1206 }else if( jQuery( event.target ).attr( "wppb_cf_temprequired" ) ){
1207 jQuery( event.target ).removeAttr( "wppb_cf_temprequired" );
1208 jQuery( event.target ).attr( "required", "required" );
1209 }
1210 }
1211
1212 function wppbEventTargetRequiredElement( htmlElement ){
1213 if ( htmlElement.nodeName == "OPTION" ){
1214 // <option> is the target element, so we need to get the parent <select>, in order to apply the required attribute
1215 return htmlElement.parentElement;
1216 }else{
1217 return htmlElement;
1218 }
1219 }
1220
1221 </script>
1222 <?php
1223 }
1224 }
1225 add_action( 'wp_footer', 'wppb_manage_required_attribute', 99 );
1226
1227 function wpbb_specify_blog_details_on_signup_email( $message, $user_email, $user, $activation_key, $registration_page_url, $meta, $from_name, $context ){
1228 $meta = unserialize($meta);
1229
1230 if ( is_multisite() && isset( $meta['wppb_create_new_site_checkbox'] ) && $meta['wppb_create_new_site_checkbox'] == 'yes' ) {
1231 $blog_details = wpmu_validate_blog_signup( $meta['wppb_blog_url'], $meta['wppb_blog_title'] );
1232
1233 if ( empty($blog_details['errors']->errors['blogname']) && empty($blog_details['errors']->errors['blog_title'])) {
1234 $blog_path = $blog_details['domain'] . $blog_details['path'];
1235 $message .= __( '<br><br>Also, you will be able to visit your site at ', 'profile-builder' ) . '<a href="' . $blog_path . '">' . $blog_path . '</a>.';
1236 }
1237 }
1238 return $message;
1239 }
1240 add_filter( 'wppb_signup_user_notification_email_content', 'wpbb_specify_blog_details_on_signup_email', 5, 8 );
1241
1242 function wpbb_specify_blog_details_on_registration_email( $user_message_content, $email, $password, $user_message_subject, $context ){
1243
1244 if ( is_multisite() ) {
1245 $user = get_user_by( 'email', $email );
1246 $blog_path = wppb_get_blog_url_of_user_id( $user->ID );
1247 if ( ! empty ( $blog_path ) ) {
1248 $user_message_content .= __( '<br><br>You can visit your site at ', 'profile-builder' ) . '<a href="' . $blog_path . '">' . $blog_path . '</a>.';
1249 }
1250 }
1251 return $user_message_content;
1252
1253 }
1254 add_filter( 'wppb_register_user_email_message_without_admin_approval', 'wpbb_specify_blog_details_on_registration_email', 5, 5 );
1255 add_filter( 'wppb_register_user_email_message_with_admin_approval', 'wpbb_specify_blog_details_on_registration_email', 5, 5 );
1256
1257
1258 function wppb_get_blog_url_of_user_id( $user_id, $ignore_privacy = true ){
1259 $blog_id = get_user_meta( $user_id, 'primary_blog', true );
1260 if ( is_multisite() && !empty( $blog_id ) ){
1261 $blog_details = get_blog_details( $blog_id );
1262 if ( $ignore_privacy || $blog_details->public ) {
1263 return $blog_details->domain . $blog_details->path;
1264 }
1265 }
1266 return '';
1267 }
1268
1269 function wppb_can_users_signup_blog(){
1270 if ( ! is_multisite() )
1271 return false;
1272 global $wpdb;
1273 $current_site = get_current_site();
1274 $sitemeta_options_query = $wpdb->prepare( "SELECT meta_value FROM {$wpdb->sitemeta} WHERE meta_key = 'registration' AND site_id = %d", $current_site->id );
1275 $network_options_meta = $wpdb->get_results( $sitemeta_options_query );
1276
1277 if ( $network_options_meta[0]->meta_value == 'all' ){
1278 return true;
1279 }
1280 return false;
1281 }
1282
1283 /**
1284 * Function that handle redirect URL
1285 *
1286 * @param string $redirect_priority - it can be normal or top priority
1287 * @param string $redirect_type - type of the redirect
1288 * @param null|string $redirect_url - redirect URL if already set
1289 * @param null|string|object $user - username, user email or user data
1290 * @param null|string $user_role - user role
1291 *
1292 * @return null|string $redirect_url
1293 */
1294 function wppb_get_redirect_url( $redirect_priority, $redirect_type, $redirect_url = NULL, $user = NULL, $user_role = NULL ) {
1295 if( empty($redirect_priority) ) {
1296 $redirect_priority = 'normal';
1297 }
1298
1299 if( PROFILE_BUILDER == 'Profile Builder Pro' ) {
1300 $wppb_module_settings = get_option( 'wppb_module_settings' );
1301
1302 if( isset( $wppb_module_settings['wppb_customRedirect'] ) && $wppb_module_settings['wppb_customRedirect'] == 'show' && $redirect_priority != 'top' && function_exists( 'wppb_custom_redirect_url' ) ) {
1303 $redirect_url = wppb_custom_redirect_url( $redirect_type, $redirect_url, $user, $user_role );
1304 }
1305 }
1306
1307 if( ! empty( $redirect_url ) ) {
1308 $redirect_url = ( wppb_check_missing_http( $redirect_url ) ? 'http://'. $redirect_url : $redirect_url );
1309 }
1310
1311 return $redirect_url;
1312 }
1313
1314 /**
1315 * Function that builds the redirect
1316 *
1317 * @param string $redirect_url - redirect URL
1318 * @param int $redirect_delay - redirect delay in seconds
1319 * @param null|string $redirect_type - the type of the redirect
1320 * @param null|array $form_args - form args if set
1321 *
1322 * @return string $redirect_message
1323 */
1324 function wppb_build_redirect( $redirect_url, $redirect_delay, $redirect_type = NULL, $form_args = NULL ) {
1325 if( isset( $redirect_type ) ) {
1326 $redirect_url = apply_filters( 'wppb_'. $redirect_type .'_redirect', $redirect_url );
1327 }
1328
1329 $redirect_message = '';
1330
1331 if( ! empty( $redirect_url ) ) {
1332 $redirect_url = ( wppb_check_missing_http( $redirect_url ) ? 'http://'. $redirect_url : $redirect_url );
1333
1334 if( $redirect_delay == 0 ) {
1335 $redirect_message = '<meta http-equiv="Refresh" content="'. $redirect_delay .';url='. $redirect_url .'" />';
1336 } else {
1337 $redirect_url_href = apply_filters( 'wppb_redirect_url', '<a href="'. $redirect_url .'">'. __( 'here', 'profile-builder' ) .'</a>', $redirect_url, $redirect_type, $form_args );
1338 $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 );
1339 }
1340 }
1341
1342 return $redirect_message;
1343 }
1344
1345 /**
1346 * Function that strips the script tags from an input
1347 * @param $string
1348 * @return mixed
1349 */
1350 function wppb_sanitize_value( $string ){
1351 return preg_replace( '/<script\b[^>]*>(.*?)<\/script>/is', '', $string );
1352 }
1353
1354 /**
1355 * Function that receives a user role and returns its label.
1356 * Returns the original role if not found.
1357 *
1358 * @since v.2.7.1
1359 *
1360 * @param string $role
1361 *
1362 * @return string
1363 */
1364 function wppb_get_role_name($role){
1365 global $wp_roles;
1366
1367 if ( array_key_exists( $role, $wp_roles->role_names ) )
1368 return $wp_roles->role_names[$role];
1369
1370 return $role;
1371 }
1372
1373 /**
1374 * Function that receives a user role label and returns its slug.
1375 * Returns the original role label if not found.
1376 *
1377 * @since v.3.5.6
1378 *
1379 * @param string $role
1380 *
1381 * @return string
1382 */
1383 function wppb_get_role_slug($role) {
1384 global $wp_roles;
1385
1386 foreach ( $wp_roles->role_names as $slug => $label ) {
1387 if ( $label === $role) {
1388 return $slug;
1389 }
1390 }
1391
1392 return $role;
1393 }
1394
1395 /**
1396 * Functionality for Private Website start
1397 */
1398 add_action( 'template_redirect', 'wppb_private_website_functionality' );
1399 add_action( 'login_init', 'wppb_private_website_functionality', 1 );
1400 function wppb_private_website_functionality(){
1401 $wppb_private_website_settings = get_option( 'wppb_private_website_settings', 'not_found' );
1402 if( $wppb_private_website_settings != 'not_found' ){
1403 if( $wppb_private_website_settings['private_website'] == 'yes' ){
1404 if( !is_user_logged_in() ){
1405
1406 //force wp-login.php if you accidentally get locked out
1407 global $pagenow;
1408 if( $pagenow === 'wp-login.php' && isset( $_GET['wppb_force_wp_login'] ) )
1409 return;
1410
1411 //go through paths first if they are set
1412 if( isset( $wppb_private_website_settings['allowed_paths'] ) && !empty( $wppb_private_website_settings['allowed_paths'] ) ){
1413 $allowed_paths = explode( "\r\n", $wppb_private_website_settings['allowed_paths'] );
1414 $parsed_url = wp_parse_url( wppb_curpageurl() );
1415 if( !empty( $parsed_url['path'] ) ) {
1416 $path = $parsed_url['path'];
1417
1418 foreach ($allowed_paths as $allowed_path) {
1419 if (strpos($allowed_path, '*') === false) {
1420 if (trim($path, "/") === trim($allowed_path, "/")) {
1421 return;
1422 }
1423 } else {
1424 if (strpos(ltrim($path, "/"), trailingslashit(trim(str_replace('*', '', $allowed_path), "/"))) === 0) {
1425 return;
1426 }
1427 }
1428 }
1429 }
1430 }
1431
1432 if( isset( $wppb_private_website_settings['allowed_pages'] ) )
1433 $allowed_pages = $wppb_private_website_settings['allowed_pages'];
1434 else{
1435 $allowed_pages = array();
1436 }
1437
1438 $redirect_to_id = $wppb_private_website_settings['redirect_to'];
1439 if( !empty( $redirect_to_id ) ) {
1440 $redirect_url = get_permalink($redirect_to_id);
1441 $allowed_pages[] = $redirect_to_id;
1442 }
1443 else {
1444 //don't redirect if we are already on the wp-login.php page
1445 if( $pagenow === 'wp-login.php' ){
1446 return;
1447 }
1448 else
1449 $redirect_url = wp_login_url(wppb_curpageurl());
1450 }
1451
1452 $redirect_url = apply_filters( 'wppb_private_website_redirect_url', $redirect_url );
1453 $allowed_pages = apply_filters( 'wppb_private_website_allowed_pages', $allowed_pages );
1454
1455 global $post;
1456 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
1457 if( function_exists('url_to_postid') ) {
1458 $post_id = url_to_postid(wppb_curpageurl());//try to get the id from the actual url
1459 }else {
1460 $post_id = 0;
1461 }
1462 }
1463 else
1464 $post_id = $post->ID;
1465
1466 if( ( !in_array( $post_id, $allowed_pages ) && $redirect_url !== strtok( wppb_curpageurl(), '?' ) ) || is_search() ){
1467 nocache_headers();
1468 if( apply_filters( 'wppb_private_website_redirect_add_query_args', true ) && current_filter() == 'template_redirect' ) {
1469 $redirect_url = add_query_arg( 'wppb_referer_url', urlencode( esc_url( wppb_curpageurl() ) ), $redirect_url );
1470 }
1471 wp_safe_redirect( $redirect_url );
1472 exit;
1473 }
1474
1475 }
1476 }
1477 }
1478 }
1479
1480 //add classes on the body to know if we have enabled private website options
1481 add_filter( 'body_class', 'wppb_private_website_body_classes' );
1482 function wppb_private_website_body_classes( $classes ){
1483 $wppb_private_website_settings = get_option( 'wppb_private_website_settings', 'not_found' );
1484 if( $wppb_private_website_settings != 'not_found' ) {
1485 if ($wppb_private_website_settings['private_website'] == 'yes') {
1486 if (!is_user_logged_in()) {
1487 $classes[] = 'wppb-private-website';
1488 if ($wppb_private_website_settings['hide_menus'] == 'yes') {
1489 $classes[] = 'wppb-private-website-hide-menus';
1490 }
1491 }
1492 }
1493 }
1494
1495 return $classes;
1496 }
1497
1498
1499 /**
1500 * Disable RSS
1501 */
1502 add_action('do_feed', 'wppb_disable_feed', 1);
1503 add_action('do_feed_rdf', 'wppb_disable_feed', 1);
1504 add_action('do_feed_rss', 'wppb_disable_feed', 1);
1505 add_action('do_feed_rss2', 'wppb_disable_feed', 1);
1506 add_action('do_feed_atom', 'wppb_disable_feed', 1);
1507 add_action('do_feed_rss2_comments', 'wppb_disable_feed', 1);
1508 add_action('do_feed_atom_comments', 'wppb_disable_feed', 1);
1509 function wppb_disable_feed() {
1510 $wppb_private_website_settings = get_option( 'wppb_private_website_settings', 'not_found' );
1511 if( $wppb_private_website_settings != 'not_found' ) {
1512 if ($wppb_private_website_settings['private_website'] == 'yes') {
1513 if (!is_user_logged_in()) {
1514 wp_die( wp_kses_post( sprintf( __('No feed available,please visit our <a href="%s">homepage</a>!', 'profile-builder' ), get_bloginfo('url') ) ) );
1515 }
1516 }
1517 }
1518 }
1519
1520
1521 /**
1522 * Disable REST
1523 */
1524 //add_filter('rest_enabled', 'wppb_disable_rest'); // this is depracated
1525 add_filter('rest_jsonp_enabled', 'wppb_disable_rest');
1526 function wppb_disable_rest( $bool ){
1527 $wppb_private_website_settings = get_option( 'wppb_private_website_settings', 'not_found' );
1528 if( $wppb_private_website_settings != 'not_found' ) {
1529 if ($wppb_private_website_settings['private_website'] == 'yes') {
1530 if ( isset( $wppb_private_website_settings[ 'disable_rest_api' ] ) && $wppb_private_website_settings[ 'disable_rest_api' ] == 'no' ) {
1531 return $bool;
1532 }
1533 if (!is_user_logged_in()) {
1534 return false;
1535 }
1536 }
1537 }
1538 return $bool;
1539 }
1540
1541 /* I should test this to not create any problems */
1542 add_filter('rest_authentication_errors', 'wppb_disable_rest_api_authentication', 10, 1 );
1543 function wppb_disable_rest_api_authentication($result) {
1544 if (!empty($result)) {
1545 return $result;
1546 }
1547
1548 $wppb_private_website_settings = get_option( 'wppb_private_website_settings', 'not_found' );
1549 if( $wppb_private_website_settings != 'not_found' ) {
1550 if ($wppb_private_website_settings['private_website'] == 'yes') {
1551 if ( isset( $wppb_private_website_settings[ 'disable_rest_api' ] ) && $wppb_private_website_settings[ 'disable_rest_api' ] == 'no' ) {
1552 return $result;
1553 }
1554 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") {
1555 return new WP_Error('rest_not_logged_in', __( 'You are not currently logged in.', 'profile-builder' ), array('status' => 401));
1556 }
1557 }
1558 }
1559
1560 return $result;
1561 }
1562
1563 /**
1564 * We can hide all menu items
1565 */
1566 add_filter('wp_nav_menu', 'wppb_hide_menus');
1567 add_filter('wp_page_menu', 'wppb_hide_menus');
1568 function wppb_hide_menus( $menu ){
1569 $wppb_private_website_settings = get_option( 'wppb_private_website_settings', 'not_found' );
1570 if( $wppb_private_website_settings != 'not_found' ) {
1571 if ($wppb_private_website_settings['private_website'] == 'yes') {
1572 if ( !is_user_logged_in() && ( !empty($wppb_private_website_settings['hide_menus']) && $wppb_private_website_settings['hide_menus'] == 'yes' ) ) {
1573 return '';
1574 }
1575 }
1576 }
1577 return $menu;
1578 }
1579
1580 /**
1581 * Functionality for Private Website end
1582 */
1583
1584 /**
1585 * Functionality GDPR compliance start
1586 */
1587
1588 //hook into the wp export compatibility
1589 add_filter( 'wp_privacy_personal_data_exporters', 'wppb_register_profile_builder_wp_exporter', 10 );
1590 function wppb_register_profile_builder_wp_exporter( $exporters ) {
1591 $exporters['profile-builder'] = array(
1592 'exporter_friendly_name' => __( 'Profile Builder', 'profile-builder' ),
1593 'callback' => 'wppb_profile_builder_wp_exporter',
1594 );
1595 return $exporters;
1596 }
1597 /* function to add aour user meta to wp exporter */
1598 function wppb_profile_builder_wp_exporter( $email_address, $page = 1 ) {
1599
1600 $export_items = array();
1601
1602 $form_fields = get_option( 'wppb_manage_fields' );
1603
1604 if( !empty( $form_fields ) ) {
1605 $user = get_user_by( 'email', $email_address );
1606 if( $user ) {
1607
1608 $item_id = "user-meta-{$user->ID}";
1609 $group_id = 'user-meta';
1610 $group_label = __('User Meta' , 'profile-builder' );
1611 $data = array();
1612
1613 $all_meta_for_user = get_user_meta( $user->ID );
1614 if( !empty( $all_meta_for_user ) ) {
1615 foreach ($form_fields as $form_field) {
1616
1617 if (!empty($form_field['meta-name']) && strpos($form_field['field'], 'Default') === false) {
1618 $user_meta_value = $all_meta_for_user[$form_field['meta-name']][0];
1619 if( !empty( $user_meta_value ) ){
1620
1621
1622 $data[] = array(
1623 'name' => $form_field['field-title'],
1624 'value' => $user_meta_value
1625 );
1626 }
1627 }
1628 }
1629
1630 $export_items[] = array(
1631 'group_id' => $group_id,
1632 'group_label' => $group_label,
1633 'item_id' => $item_id,
1634 'data' => $data,
1635 );
1636
1637 }
1638 }
1639 }
1640
1641
1642 return array(
1643 'data' => $export_items,
1644 'done' => true,
1645 );
1646 }
1647
1648 /**
1649 * Hook to delete a user through the GDPR Delete button
1650 */
1651 add_action( 'template_redirect', 'wppb_gdpr_delete_user') ;
1652 function wppb_gdpr_delete_user() {
1653
1654 if( isset( $_GET['wppb_user'] ) && ! empty( $_GET['wppb_user'] ) ) {
1655
1656 $edited_user_id = get_current_user_id();
1657 if ( ( !is_multisite() && current_user_can('edit_users') ) || ( is_multisite() && current_user_can('manage_network') ) ) {
1658 $edited_user_id = absint($_GET['wppb_user']);
1659 }
1660
1661 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']) {
1662 require_once(ABSPATH . 'wp-admin/includes/user.php');
1663 $user = new WP_User( absint( $_REQUEST['wppb_user'] ) );
1664
1665 if (!empty($user->roles)) {
1666 foreach ($user->roles as $role) {
1667 if ($role != 'administrator') {
1668 wp_delete_user( absint( $_REQUEST['wppb_user'] ) );
1669 }
1670 }
1671 }
1672
1673 $args = array('wppb_user', 'wppb_action', 'wppb_nonce');
1674 nocache_headers();
1675 wp_redirect(remove_query_arg($args));
1676 }
1677 }
1678 }
1679
1680
1681 /**
1682 * Functionality GDPR compliance end
1683 */
1684
1685 /**
1686 * Function that checks if Admin Approval is enabled
1687 */
1688 function wppb_get_admin_approval_option_value(){
1689 $wppb_general_settings = get_option( 'wppb_general_settings', 'not_found' );
1690 if( file_exists(WPPB_PLUGIN_DIR . '/features/admin-approval/admin-approval.php') && $wppb_general_settings != 'not_found' && !empty( $wppb_general_settings['adminApproval'] ) && $wppb_general_settings['adminApproval'] === 'yes' )
1691 return 'yes';
1692 else
1693 return 'no';
1694 }
1695
1696 /**
1697 * Function that checks if conditional fields feature exists
1698 * @return bool
1699 */
1700 function wppb_conditional_fields_exists(){
1701 if (file_exists(WPPB_PLUGIN_DIR . '/features/conditional-fields/conditional-fields.php'))
1702 return true;
1703 else
1704 return false;
1705 }
1706
1707 /**
1708 * Add support for [wppb-embed] shortcode inside userlisting as the default [embed] is weird and doesn't work outside the_content
1709 */
1710 add_shortcode('wppb-embed', 'wppb_embed');
1711 function wppb_embed($atts, $content){
1712 $atts = shortcode_atts( array(
1713 'width' => '',
1714 'height' => ''
1715 ), $atts, 'wppb-embed' );
1716
1717 global $wp_embed;
1718 if(empty($atts['width']) || empty($atts['height'])){
1719 $content = $wp_embed->run_shortcode('[embed]'.$content.'[/embed]');
1720 } else {
1721 $content = $wp_embed->run_shortcode('[embed width="'.$atts['width'].'" height="'.$atts['height'].'"]'.$content.'[/embed]');
1722 }
1723
1724 return $content;
1725 }
1726
1727 /**
1728 * Function to determine if an add-on is active
1729 */
1730
1731 function wppb_check_if_add_on_is_active( $slug ){
1732 //the old modulse part
1733 if (file_exists(WPPB_PLUGIN_DIR . '/add-ons/add-ons.php')) {
1734 $wppb_module_settings = get_option('wppb_module_settings', 'not_found');
1735 if ($wppb_module_settings != 'not_found') {
1736 foreach ($wppb_module_settings as $add_on_slug => $status) {
1737 if ($slug == $add_on_slug) {
1738 if ($status === 'hide')
1739 return false;
1740 elseif ($status === 'show')
1741 return true;
1742 }
1743 }
1744 }
1745 }
1746
1747 //the free addons part
1748 $wppb_free_add_ons_settings = get_option( 'wppb_free_add_ons_settings', array() );
1749 if ( !empty( $wppb_free_add_ons_settings ) ){
1750 foreach( $wppb_free_add_ons_settings as $add_on_slug => $status ){
1751 if( $slug == $add_on_slug ){
1752 return $status;
1753 }
1754 }
1755 }
1756
1757 return false;
1758 }
1759