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

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

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