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

717 lines 31.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Functions Load
4 *
5 */
6
7 // whitelist options, you can add more register_settings changing the second parameter
8 function wppb_register_settings() {
9 register_setting( 'wppb_option_group', 'wppb_default_settings' );
10 register_setting( 'wppb_general_settings', 'wppb_general_settings', 'wppb_general_settings_sanitize' );
11 register_setting( 'wppb_display_admin_settings', 'wppb_display_admin_settings' );
12 register_setting( 'wppb_profile_builder_pro_serial', 'wppb_profile_builder_pro_serial' );
13 register_setting( 'wppb_profile_builder_hobbyist_serial', 'wppb_profile_builder_hobbyist_serial' );
14 register_setting( 'wppb_module_settings', 'wppb_module_settings' );
15 register_setting( 'wppb_module_settings_description', 'wppb_module_settings_description' );
16 register_setting( 'customRedirectSettings', 'customRedirectSettings' );
17 register_setting( 'customUserListingSettings', 'customUserListingSettings' );
18 register_setting( 'reCaptchaSettings', 'reCaptchaSettings' );
19 register_setting( 'emailCustomizer', 'emailCustomizer' );
20 }
21
22
23
24
25 // WPML support
26 function wppb_icl_t($context, $name, $value){
27 if( function_exists( 'icl_t' ) )
28 return icl_t( $context, $name, $value );
29
30 else
31 return $value;
32 }
33
34
35 function wppb_add_plugin_stylesheet() {
36 $wppb_generalSettings = get_option( 'wppb_general_settings' );
37
38 if ( ( file_exists( WPPB_PLUGIN_DIR . '/assets/css/style-front-end.css' ) ) && ( isset( $wppb_generalSettings['extraFieldsLayout'] ) && ( $wppb_generalSettings['extraFieldsLayout'] == 'default' ) ) ){
39 wp_register_style( 'wppb_stylesheet', WPPB_PLUGIN_URL . 'assets/css/style-front-end.css' );
40 wp_enqueue_style( 'wppb_stylesheet' );
41 }
42 if( is_rtl() ) {
43 if ( ( file_exists( WPPB_PLUGIN_DIR . '/assets/css/rtl.css' ) ) && ( isset( $wppb_generalSettings['extraFieldsLayout'] ) && ( $wppb_generalSettings['extraFieldsLayout'] == 'default' ) ) ){
44 wp_register_style( 'wppb_stylesheet_rtl', WPPB_PLUGIN_URL . 'assets/css/rtl.css' );
45 wp_enqueue_style( 'wppb_stylesheet_rtl' );
46 }
47 }
48 }
49
50
51 function wppb_show_admin_bar($content){
52 global $current_user;
53
54 $adminSettingsPresent = get_option('wppb_display_admin_settings','not_found');
55 $show = null;
56
57 if ($adminSettingsPresent != 'not_found' && $current_user->ID)
58 foreach ($current_user->roles as $role_key) {
59 if (empty($GLOBALS['wp_roles']->roles[$role_key]))
60 continue;
61 $role = $GLOBALS['wp_roles']->roles[$role_key];
62 if (isset($adminSettingsPresent[$role['name']])) {
63 if ($adminSettingsPresent[$role['name']] == 'show')
64 $show = true;
65 if ($adminSettingsPresent[$role['name']] == 'hide' && $show === null)
66 $show = false;
67 }
68 }
69 return $show === null ? $content : $show;
70 }
71
72
73 if(!function_exists('wppb_curpageurl')){
74 function wppb_curpageurl() {
75 $pageURL = 'http';
76
77 if ((isset($_SERVER["HTTPS"])) && ($_SERVER["HTTPS"] == "on"))
78 $pageURL .= "s";
79
80 $pageURL .= "://";
81
82 if ($_SERVER["SERVER_PORT"] != "80")
83 $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
84
85 else
86 $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
87
88 if ( function_exists('apply_filters') ) apply_filters('wppb_curpageurl', $pageURL);
89
90 return $pageURL;
91 }
92 }
93
94
95 if ( is_admin() ){
96
97 // register the settings for the menu only display sidebar menu for a user with a certain capability, in this case only the "admin"
98 add_action( 'admin_init', 'wppb_register_settings' );
99
100 // display the same extra profile fields in the admin panel also
101 if ( file_exists ( WPPB_PLUGIN_DIR.'/front-end/extra-fields/extra-fields.php' ) ){
102 require_once( WPPB_PLUGIN_DIR.'/front-end/extra-fields/extra-fields.php' );
103
104 add_action( 'show_user_profile', 'display_profile_extra_fields_in_admin', 10 );
105 add_action( 'edit_user_profile', 'display_profile_extra_fields_in_admin', 10 );
106 global $pagenow;
107 if( $pagenow != 'user-new.php' )
108 add_action( 'user_profile_update_errors', 'wppb_validate_backend_fields', 10, 3 );
109 add_action( 'personal_options_update', 'save_profile_extra_fields_in_admin', 10 );
110 add_action( 'edit_user_profile_update', 'save_profile_extra_fields_in_admin', 10 );
111 }
112
113 }else if ( !is_admin() ){
114 // include the stylesheet
115 add_action( 'wp_print_styles', 'wppb_add_plugin_stylesheet' );
116
117 // include the menu file for the profile informations
118 include_once( WPPB_PLUGIN_DIR.'/front-end/edit-profile.php' );
119 include_once( WPPB_PLUGIN_DIR.'/front-end/class-formbuilder.php' );
120 add_shortcode( 'wppb-edit-profile', 'wppb_front_end_profile_info' );
121
122 // include the menu file for the login screen
123 include_once( WPPB_PLUGIN_DIR.'/front-end/login.php' );
124 add_shortcode( 'wppb-login', 'wppb_front_end_login' );
125
126 // include the menu file for the logout screen
127 include_once( WPPB_PLUGIN_DIR.'/front-end/logout.php' );
128 add_shortcode( 'wppb-logout', 'wppb_front_end_logout' );
129
130 // include the menu file for the register screen
131 include_once( WPPB_PLUGIN_DIR.'/front-end/register.php' );
132 add_shortcode( 'wppb-register', 'wppb_front_end_register_handler' );
133
134 // include the menu file for the recover password screen
135 include_once( WPPB_PLUGIN_DIR.'/front-end/recover.php' );
136 add_shortcode( 'wppb-recover-password', 'wppb_front_end_password_recovery' );
137
138 // set the front-end admin bar to show/hide
139 add_filter( 'show_admin_bar' , 'wppb_show_admin_bar');
140
141 // Shortcodes used for the widget area
142 add_filter( 'widget_text', 'do_shortcode', 11 );
143 }
144
145
146 /**
147 * Function that overwrites the default wp_mail function and sends out emails
148 *
149 * @since v.2.0
150 *
151 * @param string $to
152 * @param string $subject
153 * @param string $message
154 * @param string $message_from
155 *
156 */
157 function wppb_mail( $to, $subject, $message, $message_from, $context = null ) {
158 $to = apply_filters( 'wppb_send_email_to', $to );
159 $send_email = apply_filters( 'wppb_send_email', true, $to, $subject, $message, $context );
160
161 $message = apply_filters( 'wppb_email_message', $message );
162
163 do_action( 'wppb_before_sending_email', $to, $subject, $message, $send_email );
164
165 if ( $send_email ) {
166 //we add this filter to enable html encoding
167 add_filter( 'wp_mail_content_type', create_function( '', 'return "text/html"; ' ) );
168
169 $sent = wp_mail( $to , $subject, $message );
170 }
171
172 do_action( 'wppb_after_sending_email', $sent, $to, $subject, $message, $send_email );
173
174 return $sent;
175 }
176
177 function wppb_activate_account_check(){
178 if ( ( isset( $_GET['activation_key'] ) ) && ( trim( $_GET['activation_key'] ) != '' ) ){
179 global $post;
180
181 $wppb_generalSettings = get_option( 'wppb_general_settings' );
182 $activation_landing_page_id = ( ( isset( $wppb_generalSettings['activationLandingPage'] ) && ( trim( $wppb_generalSettings['activationLandingPage'] ) != '' ) ) ? $wppb_generalSettings['activationLandingPage'] : 'not_set' );
183
184 if ( $activation_landing_page_id != 'not_set' ){
185 //an activation page was selected, but we still need to check if the current page doesn't already have the registration shortcode
186 if ( strpos( $post->post_content, '[wppb-register' ) === false )
187 add_filter( 'the_content', 'wppb_add_activation_message' );
188
189 }elseif ( strpos( $post->post_content, '[wppb-register' ) === false ){
190 //no activation page was selected, and the sent link pointed to the home url
191 wp_redirect( apply_filters( 'wppb_activatate_account_redirect_url', WPPB_PLUGIN_URL.'assets/misc/fallback-page.php?activation_key='.urlencode( $_GET['activation_key'] ).'&site_name='.urlencode( get_bloginfo( 'name' ) ).'&site_url='.urlencode( get_bloginfo( 'url' ) ).'&message='.urlencode( $activation_message = wppb_activate_signup( $_GET['activation_key'] ) ), $_GET['activation_key'], $activation_message ) );
192 exit;
193 }
194 }
195 }
196 add_action( 'template_redirect', 'wppb_activate_account_check' );
197
198
199 function wppb_add_activation_message( $content ){
200
201 return wppb_activate_signup( $_GET['activation_key'] ) . $content;
202 }
203
204
205 // Create a new, top-level page
206 $args = array(
207 'page_title' => 'Profile Builder',
208 'menu_title' => 'Profile Builder',
209 'capability' => 'manage_options',
210 'menu_slug' => 'profile-builder',
211 'page_type' => 'menu_page',
212 'position' => '70,69',
213 'priority' => 1,
214 'icon_url' => WPPB_PLUGIN_URL . 'assets/images/pb_menu_icon.png'
215 );
216 new WCK_Page_Creator_PB( $args );
217
218 /**
219 * Remove the automatically created submenu page
220 *
221 * @since v.2.0
222 *
223 * @return void
224 */
225 function wppb_remove_main_menu_page(){
226 remove_submenu_page( 'profile-builder', 'profile-builder' );
227 }
228 add_action( 'admin_menu', 'wppb_remove_main_menu_page', 11 );
229
230 /**
231 * Add scripts to the back-end CPT's to remove the slug from the edit page
232 *
233 * @since v.2.0
234 *
235 * @return void
236 */
237 function wppb_print_cpt_script( $hook ){
238 wp_enqueue_script( 'jquery-ui-dialog' );
239 wp_enqueue_style( 'wp-jquery-ui-dialog' );
240
241 if ( $hook == 'profile-builder_page_manage-fields' ){
242 wp_enqueue_script( 'wppb-manage-fields-live-change', WPPB_PLUGIN_URL . 'assets/js/jquery-manage-fields-live-change.js', array(), PROFILE_BUILDER_VERSION, true );
243 }
244
245 if (( $hook == 'profile-builder_page_manage-fields' ) ||
246 ( $hook == 'profile-builder_page_profile-builder-basic-info' ) ||
247 ( $hook == 'profile-builder_page_profile-builder-modules' ) ||
248 ( $hook == 'profile-builder_page_profile-builder-general-settings' ) ||
249 ( $hook == 'profile-builder_page_profile-builder-admin-bar-settings' ) ||
250 ( $hook == 'profile-builder_page_profile-builder-register' ) ||
251 ( $hook == 'profile-builder_page_profile-builder-wppb_userListing' ) ||
252 ( $hook == 'profile-builder_page_custom-redirects' ) ||
253 ( $hook == 'profile-builder_page_profile-builder-wppb_emailCustomizer' ) ||
254 ( $hook == 'profile-builder_page_profile-builder-wppb_emailCustomizerAdmin' ) ||
255 ( $hook == 'profile-builder_page_profile-builder-add-ons' ) ||
256 ( $hook == 'profile-builder_page_profile-builder-woocommerce-sync') ||
257 ( $hook == 'admin_page_profile-builder-pms-promo') ) {
258 wp_enqueue_style( 'wppb-back-end-style', WPPB_PLUGIN_URL . 'assets/css/style-back-end.css', false, PROFILE_BUILDER_VERSION );
259 }
260
261 if ( $hook == 'profile-builder_page_profile-builder-general-settings' )
262 wp_enqueue_script( 'wppb-manage-fields-live-change', WPPB_PLUGIN_URL . 'assets/js/jquery-email-confirmation.js', array(), PROFILE_BUILDER_VERSION, true );
263
264 if( ($hook == 'profile-builder_page_profile-builder-add-ons' ) ||
265 ($hook == 'admin_page_profile-builder-pms-promo' ) ) {
266 wp_enqueue_script('wppb-add-ons', WPPB_PLUGIN_URL . 'assets/js/jquery-pb-add-ons.js', array(), PROFILE_BUILDER_VERSION, true);
267 wp_enqueue_style( 'thickbox' );
268 wp_enqueue_script( 'thickbox' );
269 }
270
271 if ( isset( $_GET['post_type'] ) || isset( $_GET['post'] ) ){
272 if ( isset( $_GET['post_type'] ) )
273 $post_type = $_GET['post_type'];
274
275 elseif ( isset( $_GET['post'] ) )
276 $post_type = get_post_type( $_GET['post'] );
277
278 if ( ( 'wppb-epf-cpt' == $post_type ) || ( 'wppb-rf-cpt' == $post_type ) || ( 'wppb-ul-cpt' == $post_type ) ){
279 wp_enqueue_style( 'wppb-back-end-style', WPPB_PLUGIN_URL . 'assets/css/style-back-end.css', false, PROFILE_BUILDER_VERSION );
280 wp_enqueue_script( 'wppb-epf-rf', WPPB_PLUGIN_URL . 'assets/js/jquery-epf-rf.js', array(), PROFILE_BUILDER_VERSION, true );
281 }
282 }
283 if ( file_exists ( WPPB_PLUGIN_DIR.'/update/update-checker.php' ) ) {
284 wp_enqueue_script( 'wppb-sitewide', WPPB_PLUGIN_URL . 'assets/js/jquery-pb-sitewide.js', array(), PROFILE_BUILDER_VERSION, true );
285 }
286 wp_enqueue_style( 'wppb-serial-notice-css', WPPB_PLUGIN_URL . 'assets/css/serial-notice.css', false, PROFILE_BUILDER_VERSION );
287 }
288 add_action( 'admin_enqueue_scripts', 'wppb_print_cpt_script' );
289
290
291 // Set up the AJAX hooks
292 function wppb_delete(){
293 if ( isset( $_POST['_ajax_nonce'] ) ){
294
295 if ( ( isset( $_POST['what'] ) ) && ( $_POST['what'] == 'avatar' ) ){
296 if ( !wp_verify_nonce( $_POST['_ajax_nonce'], 'user'.base64_decode( $_POST['currentUser'] ).'_nonce_avatar' ) ){
297 echo __( 'The user-validation has failed - the avatar was not deleted!', 'profile-builder' );
298 die();
299
300 }else{
301 update_user_meta( base64_decode( $_POST['currentUser'] ), base64_decode( $_POST['customFieldName'] ), '');
302 update_user_meta( base64_decode( $_POST['currentUser'] ), 'resized_avatar_'.base64_decode( $_POST['customFieldID'] ), '' );
303 echo 'done';
304 die();
305 }
306 }elseif ( ( isset( $_POST['what'] ) ) && ( $_POST['what'] == 'attachment' ) ){
307 if ( !wp_verify_nonce( $_POST['_ajax_nonce'], 'user'.base64_decode( $_POST['currentUser'] ).'_nonce_upload' ) ){
308 echo __( 'The user-validation has failed - the attachment was not deleted!', 'profile-builder' );
309 die();
310
311 }else{
312 update_user_meta( base64_decode( $_POST['currentUser'] ), base64_decode( $_POST['customFieldName'] ), '');
313 echo 'done';
314 die();
315 }
316 }
317 }
318 }
319 add_action( 'wp_ajax_hook_wppb_delete', 'wppb_delete' );
320
321
322 //the function used to overwrite the avatar across the wp installation
323 function wppb_changeDefaultAvatar( $avatar, $id_or_email, $size, $default, $alt ){
324 /* Get user info. */
325 if(is_object($id_or_email)){
326 $my_user_id = $id_or_email->user_id;
327
328 }elseif(is_numeric($id_or_email)){
329 $my_user_id = $id_or_email;
330
331 }elseif(!is_integer($id_or_email)){
332 $user_info = get_user_by( 'email', $id_or_email );
333 $my_user_id = ( is_object( $user_info ) ? $user_info->ID : '' );
334 }else
335 $my_user_id = $id_or_email;
336
337 $wppb_manage_fields = get_option( 'wppb_manage_fields', 'not_found' );
338
339 if ( $wppb_manage_fields != 'not_found' ){
340 foreach( $wppb_manage_fields as $value ){
341 if ( $value['field'] == 'Avatar'){
342
343 $customUserAvatar = get_user_meta( $my_user_id, $value['meta-name'], true );
344 if( !empty( $customUserAvatar ) ){
345 if( is_numeric( $customUserAvatar ) ){
346 $img_attr = wp_get_attachment_image_src( $customUserAvatar, 'wppb-avatar-size-'.$size );
347 if( $img_attr[3] === false ){
348 $img_attr = wp_get_attachment_image_src( $customUserAvatar, 'thumbnail' );
349 $avatar = "<img alt='{$alt}' src='{$img_attr[0]}' class='avatar avatar-{$size} photo avatar-default' height='{$size}' width='{$size}' />";
350 }
351 else
352 $avatar = "<img alt='{$alt}' src='{$img_attr[0]}' class='avatar avatar-{$size} photo avatar-default' height='{$img_attr[2]}' width='{$img_attr[1]}' />";
353 }
354 else {
355 $customUserAvatar = get_user_meta($my_user_id, 'resized_avatar_' . $value['id'], true);
356 $customUserAvatarRelativePath = get_user_meta($my_user_id, 'resized_avatar_' . $value['id'] . '_relative_path', true);
357
358 if ((($customUserAvatar != '') || ($customUserAvatar != null)) && file_exists($customUserAvatarRelativePath)) {
359 $avatar = "<img alt='{$alt}' src='{$customUserAvatar}' class='avatar avatar-{$size} photo avatar-default' height='{$size}' width='{$size}' />";
360 }
361 }
362 }
363 }
364 }
365 }
366
367 return $avatar;
368 }
369 add_filter( 'get_avatar', 'wppb_changeDefaultAvatar', 21, 5 );
370
371
372 //the function used to resize the avatar image; the new function uses a user ID as parameter to make pages load faster
373 function wppb_resize_avatar( $userID, $userlisting_size = null, $userlisting_crop = null ){
374 // include the admin image API
375 require_once( ABSPATH . '/wp-admin/includes/image.php' );
376
377 // retrieve first a list of all the current custom fields
378 $wppb_manage_fields = get_option( 'wppb_manage_fields' );
379
380 foreach ( $wppb_manage_fields as $key => $value ){
381 if ( $value['field'] == 'Avatar' ){
382
383 // retrieve width and height of the image
384 $width = $height = '';
385
386 //this checks if it only has 1 component
387 if ( is_numeric( $value['avatar-size'] ) ){
388 $width = $height = $value['avatar-size'];
389
390 }else{
391 //this checks if the entered value has 2 components
392 $sentValue = explode( ',', $value['avatar-size'] );
393 $width = $sentValue[0];
394 $height = $sentValue[1];
395 }
396
397 $width = ( !empty( $userlisting_size ) ? $userlisting_size : $width );
398 $height = ( !empty( $userlisting_size ) ? $userlisting_size : $height );
399
400 if( !strpos( get_user_meta( $userID, 'resized_avatar_'.$value['id'], true ), $width . 'x' . $height ) ) {
401 // retrieve the original image (in original size)
402 $avatar_directory_path = get_user_meta( $userID, 'avatar_directory_path_'.$value['id'], true );
403
404 $image = wp_get_image_editor( $avatar_directory_path );
405 if ( !is_wp_error( $image ) ) {
406 do_action( 'wppb_before_avatar_resizing', $image, $userID, $value['meta-name'], $value['avatar-size'] );
407
408 $crop = apply_filters( 'wppb_avatar_crop_resize', ( !empty( $userlisting_crop ) ? $userlisting_crop : false ) );
409
410 $resize = $image->resize( $width, $height, $crop );
411
412 if ($resize !== FALSE) {
413 do_action( 'wppb_avatar_resizing', $image, $resize );
414
415 $fileType = apply_filters( 'wppb_resized_file_extension', 'png' );
416
417 $wp_upload_array = wp_upload_dir(); // Array of key => value pairs
418
419 //create file(name); both with directory and url
420 $fileName_dir = $image->generate_filename( NULL, $wp_upload_array['basedir'].'/profile_builder/avatars/', $fileType );
421
422 if ( PHP_OS == "WIN32" || PHP_OS == "WINNT" )
423 $fileName_dir = str_replace( '\\', '/', $fileName_dir );
424
425 $fileName_url = str_replace( str_replace( '\\', '/', $wp_upload_array['basedir'] ), $wp_upload_array['baseurl'], $fileName_dir );
426
427 //save the newly created (resized) avatar on the disc
428 $saved_image = $image->save( $fileName_dir );
429
430 /* the image save sometimes doesn't save with the desired extension so we need to see with what extension it saved it with and
431 if it differs replace the extension in the path and url that we save as meta */
432 $validate_saved_image = wp_check_filetype_and_ext( $saved_image['path'], $saved_image['path'] );
433 $ext = substr( $fileName_dir,strrpos( $fileName_dir, '.', -1 ), strlen($fileName_dir) );
434 if( !empty( $validate_saved_image['ext'] ) && $validate_saved_image['ext'] != $ext ){
435 $fileName_url = str_replace( $ext, '.'.$validate_saved_image['ext'], $fileName_url );
436 $fileName_dir = str_replace( $ext, '.'.$validate_saved_image['ext'], $fileName_dir );
437 }
438
439 update_user_meta( $userID, 'resized_avatar_'.$value['id'], $fileName_url );
440 update_user_meta( $userID, 'resized_avatar_'.$value['id'].'_relative_path', $fileName_dir );
441
442 do_action( 'wppb_after_avatar_resizing', $image, $fileName_dir, $fileName_url );
443 }
444 }
445 }
446 }
447 }
448 }
449
450
451 if ( is_admin() ){
452 // add a hook to delete the user from the _signups table if either the email confirmation is activated, or it is a wpmu installation
453 function wppb_delete_user_from_signups_table($user_id) {
454 global $wpdb;
455
456 $userLogin = $wpdb->get_var( $wpdb->prepare( "SELECT user_login, user_email FROM " . $wpdb->users . " WHERE ID = %d LIMIT 1", $user_id ) );
457 if ( is_multisite() )
458 $delete = $wpdb->delete( $wpdb->signups, array( 'user_login' => $userLogin ) );
459 else
460 $delete = $wpdb->delete( $wpdb->prefix.'signups', array( 'user_login' => $userLogin ) );
461 }
462
463 $wppb_generalSettings = get_option( 'wppb_general_settings' );
464 if ( $wppb_generalSettings['emailConfirmation'] == 'yes' ) {
465 if( is_multisite() )
466 add_action( 'wpmu_delete_user', 'wppb_delete_user_from_signups_table' );
467 else
468 add_action('delete_user', 'wppb_delete_user_from_signups_table');
469 }
470 }
471
472
473
474 // This function offers compatibility with the all in one event calendar plugin
475 function wppb_aioec_compatibility(){
476
477 wp_deregister_script( 'jquery.tools-form');
478 }
479 add_action('admin_print_styles-users_page_ProfileBuilderOptionsAndSettings', 'wppb_aioec_compatibility');
480
481
482 function wppb_user_meta_exists( $id, $meta_name ){
483 global $wpdb;
484
485 return $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->usermeta WHERE user_id = %d AND meta_key = %s", $id, $meta_name ) );
486 }
487
488
489 // function to check if there is a need to add the http:// prefix
490 function wppb_check_missing_http( $redirectLink ) {
491 return preg_match( '#^(?:[a-z\d]+(?:-+[a-z\d]+)*\.)+[a-z]+(?::\d+)?(?:/|$)#i', $redirectLink );
492 }
493
494
495
496 //function to output the password strength checker on frontend forms
497 function wppb_password_strength_checker_html(){
498 $wppb_generalSettings = get_option( 'wppb_general_settings' );
499 if( !empty( $wppb_generalSettings['minimum_password_strength'] ) ){
500 $password_strength = '<span id="pass-strength-result">'.__('Strength indicator', 'profile-builder' ).'</span>
501 <input type="hidden" value="" name="wppb_password_strength" id="wppb_password_strength"/>';
502 return $password_strength;
503 }
504 return '';
505 }
506
507 //function to check password length check
508 function wppb_check_password_length( $password ){
509 $wppb_generalSettings = get_option( 'wppb_general_settings' );
510 if( !empty( $wppb_generalSettings['minimum_password_length'] ) ){
511 if( strlen( $password ) < $wppb_generalSettings['minimum_password_length'] ){
512 return true;
513 }
514 else
515 return false;
516 }
517 return false;
518 }
519
520 //function to check password strength
521 function wppb_check_password_strength(){
522 $wppb_generalSettings = get_option( 'wppb_general_settings' );
523 if( isset( $_POST['wppb_password_strength'] ) && !empty( $wppb_generalSettings['minimum_password_strength'] ) ){
524 $password_strength_array = array( 'short' => 0, 'bad' => 1, 'good' => 2, 'strong' => 3 );
525 $password_strength_text = array( 'short' => __( 'Very Weak', 'profile-builder' ), 'bad' => __( 'Weak', 'profile-builder' ), 'good' => __( 'Medium', 'profile-builder' ), 'strong' => __( 'Strong', 'profile-builder' ) );
526 if( $password_strength_array[$_POST['wppb_password_strength']] < $password_strength_array[$wppb_generalSettings['minimum_password_strength']] ){
527 return $password_strength_text[$wppb_generalSettings['minimum_password_strength']];
528 }
529 else
530 return false;
531 }
532 return false;
533 }
534
535 /* function to output password length requirements text */
536 function wppb_password_length_text(){
537 $wppb_generalSettings = get_option( 'wppb_general_settings' );
538 if( !empty( $wppb_generalSettings['minimum_password_length'] ) ){
539 return sprintf(__('Minimum length of %d characters', 'profile-builder'), $wppb_generalSettings['minimum_password_length']);
540 }
541 return '';
542 }
543
544 /**
545 * Include password strength check scripts on frontend where we have shortoces present
546 */
547 add_action( 'wp_footer', 'wppb_enqueue_password_strength_check' );
548 function wppb_enqueue_password_strength_check() {
549 global $wppb_shortcode_on_front;
550 if( $wppb_shortcode_on_front ){
551 $wppb_generalSettings = get_option( 'wppb_general_settings' );
552 if( !empty( $wppb_generalSettings['minimum_password_strength'] ) ){
553 wp_enqueue_script( 'password-strength-meter' );
554 }
555 }
556 }
557 add_action( 'wp_footer', 'wppb_password_strength_check', 102 );
558 function wppb_password_strength_check(){
559 global $wppb_shortcode_on_front;
560 if( $wppb_shortcode_on_front ){
561 $wppb_generalSettings = get_option( 'wppb_general_settings' );
562 if( !empty( $wppb_generalSettings['minimum_password_strength'] ) ){
563 ?>
564 <script type="text/javascript">
565 function check_pass_strength() {
566 var pass1 = jQuery('#passw1').val(), pass2 = jQuery('#passw2').val(), strength;
567
568 jQuery('#pass-strength-result').removeClass('short bad good strong');
569 if ( ! pass1 ) {
570 jQuery('#pass-strength-result').html( pwsL10n.empty );
571 return;
572 }
573
574 strength = wp.passwordStrength.meter( pass1, wp.passwordStrength.userInputBlacklist(), pass2 );
575
576 switch ( strength ) {
577 case 2:
578 jQuery('#pass-strength-result').addClass('bad').html( pwsL10n.bad );
579 jQuery('#wppb_password_strength').val('bad');
580 break;
581 case 3:
582 jQuery('#pass-strength-result').addClass('good').html( pwsL10n.good );
583 jQuery('#wppb_password_strength').val('good');
584 break;
585 case 4:
586 jQuery('#pass-strength-result').addClass('strong').html( pwsL10n.strong );
587 jQuery('#wppb_password_strength').val('strong');
588 break;
589 case 5:
590 jQuery('#pass-strength-result').addClass('short').html( pwsL10n.mismatch );
591 jQuery('#wppb_password_strength').val('short');
592 break;
593 default:
594 jQuery('#pass-strength-result').addClass('short').html( pwsL10n['short'] );
595 jQuery('#wppb_password_strength').val('short');
596 }
597 }
598 jQuery( document ).ready( function() {
599 // Binding to trigger checkPasswordStrength
600 jQuery('#passw1').val('').keyup( check_pass_strength );
601 jQuery('#passw2').val('').keyup( check_pass_strength );
602 jQuery('#pass-strength-result').show();
603 });
604 </script>
605 <?php
606 }
607 }
608 }
609 /**
610 * Create functions for repeating error messages in front-end forms
611 */
612 function wppb_required_field_error($field_title='') {
613 $required_error = apply_filters('wppb_required_error' , __('This field is required','profile-builder') , $field_title);
614
615 return $required_error;
616
617 }
618 /* Function for displaying reCAPTCHA error on Login and Recover Password forms */
619 function wppb_recaptcha_field_error($field_title='') {
620 $recaptcha_error = apply_filters('wppb_recaptcha_error' , __('Please enter a (valid) reCAPTCHA value','profile-builder') , $field_title);
621
622 return $recaptcha_error;
623
624 }
625
626 /* Create a wrapper function for get_query_var */
627 function wppb_get_query_var( $varname ){
628 return apply_filters( 'wppb_get_query_var_'.$varname, get_query_var( $varname ) );
629 }
630
631 /*Filter the "Save Changes" button text, to make it translatable*/
632 function wppb_change_save_changes_button($value){
633 $value = __('Save Changes','profile-builder');
634 return $value;
635 }
636 add_filter( 'wck_save_changes_button', 'wppb_change_save_changes_button', 10, 2);
637
638 /*Filter the "Cancel" button text, to make it translatable*/
639 function wppb_change_cancel_button($value){
640 $value = __('Cancel','profile-builder');
641 return $value;
642 }
643 add_filter( 'wck_cancel_button', 'wppb_change_cancel_button', 10, 2);
644
645 /*Filter the "Delete" button text, to make it translatable*/
646 function wppb_change_delete_button($value){
647 $value = __('Delete','profile-builder');
648 return $value;
649 }
650 add_filter( 'wck_delete_button', 'wppb_change_delete_button', 10, 2);
651
652 /*Filter the "Edit" button text, to make it translatable*/
653 function wppb_change_edit_button($value){
654 $value = __('Edit','profile-builder');
655 return $value;
656 }
657 add_filter( 'wck_edit_button', 'wppb_change_edit_button', 10, 2);
658
659 /*Filter the User Listing, Register Forms and Edit Profile forms metabox header content, to make it translatable*/
660 function wppb_change_metabox_content_header(){
661 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>';
662 }
663 add_filter('wck_metabox_content_header_wppb_ul_page_settings', 'wppb_change_metabox_content_header', 1);
664 add_filter('wck_metabox_content_header_wppb_rf_page_settings', 'wppb_change_metabox_content_header', 1);
665 add_filter('wck_metabox_content_header_wppb_epf_page_settings', 'wppb_change_metabox_content_header', 1);
666
667
668 /* Add a notice if people are not able to register via Profile Builder; Membership -> "Anyone can register" checkbox is not checked under WordPress admin UI -> Settings -> General tab */
669 if ( (get_option('users_can_register') == false) && (!class_exists('PMS_Add_General_Notices')) ) {
670 if( is_multisite() ) {
671 new WPPB_Add_General_Notices('wppb_anyone_can_register',
672 sprintf(__('To allow users to register for your website via Profile Builder, you first must enable user registration. Go to %1$sNetwork Settings%2$s, and under Registration Settings make sure to check “User accounts may be registered”. %3$sDismiss%4$s', 'profile-builder'), "<a href='" . network_admin_url('settings.php') . "'>", "</a>", "<a href='" . esc_url( add_query_arg('wppb_anyone_can_register_dismiss_notification', '0') ) . "'>", "</a>"),
673 'update-nag');
674 }else{
675 new WPPB_Add_General_Notices('wppb_anyone_can_register',
676 sprintf(__('To allow users to register for your website via Profile Builder, you first must enable user registration. Go to %1$sSettings -> General%2$s tab, and under Membership make sure to check “Anyone can register”. %3$sDismiss%4$s', 'profile-builder'), "<a href='" . admin_url('options-general.php') . "'>", "</a>", "<a href='" . esc_url( add_query_arg('wppb_anyone_can_register_dismiss_notification', '0') ) . "'>", "</a>"),
677 'update-nag');
678 }
679 }
680
681 /*Filter default WordPress notices ("Post published. Post updated."), add post type name for User Listing, Registration Forms and Edit Profile Forms*/
682 function wppb_change_default_post_updated_messages($messages){
683 global $post;
684 $post_type = get_post_type($post->ID);
685 $object = get_post_type_object($post_type);
686
687 if ( ($post_type == 'wppb-rf-cpt')||($post_type == 'wppb-epf-cpt')||($post_type == 'wppb-ul-cpt') ){
688 $messages['post'][1] = $object->labels->name . ' updated.';
689 $messages['post'][6] = $object->labels->name . ' published.';
690 }
691 return $messages;
692 }
693 add_filter('post_updated_messages','wppb_change_default_post_updated_messages', 2);
694
695
696 /* for meta-names with spaces in them PHP converts the space to underline in the $_POST */
697 function wppb_handle_meta_name( $meta_name ){
698 $meta_name = str_replace( ' ', '_', $meta_name );
699 return $meta_name;
700 }
701
702
703 // change User Registered date and time according to timezone selected in WordPress settings
704 function wppb_get_date_by_timezone() {
705 $wppb_wp_timezone = get_option( 'timezone_string' );
706
707 if( ! empty( $wppb_wp_timezone ) ) {
708 date_default_timezone_set( $wppb_wp_timezone );
709 $wppb_get_date = date( "Y-m-d G:i:s" );
710 } else {
711 $wppb_wp_gmt_offset = get_option( 'gmt_offset' );
712 $wppb_gmt_offset = $wppb_wp_gmt_offset * 60 * 60;
713 $wppb_get_date = gmdate( "Y-m-d G:i:s", time() + $wppb_gmt_offset );
714 }
715
716 return $wppb_get_date;
717 }