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 / admin / admin-functions.php

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

168 lines 7.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Function which returns the same field-format over and over again.
4 *
5 * @since v.2.0
6 *
7 * @param string $field
8 * @param string $field_title
9 *
10 * @return string
11 */
12 function wppb_field_format ( $field_title, $field ){
13
14 return trim( $field_title ).' ( '.trim( $field ).' )';
15 }
16
17
18 /**
19 * Add a notification for either the Username or the Email field letting the user know that, even though it is there, it won't do anything
20 *
21 * @since v.2.0
22 *
23 * @param string $form
24 * @param integer $id
25 * @param string $value
26 *
27 * @return string $form
28 */
29 function wppb_manage_fields_display_field_title_slug( $form, $i, $value ){
30 $wppb_generalSettings = get_option( 'wppb_general_settings', 'not_found' );
31 if ( $wppb_generalSettings != 'not_found' ){
32 if ( $wppb_generalSettings['loginWith'] == 'email' )
33 if ( ( $value == 'Username ( Default - Username )' ) || ( $value == 'Username' ) )
34 $form .= '<div id="wppb-login-email-nag" class="wppb-backend-notice">' . sprintf( __( 'Login is set to be done using the E-mail. This field will NOT appear in the front-end! ( you can change these settings under the "%s" tab )', 'profilebuilder' ), '<a href="'.admin_url( 'admin.php?page=profile-builder-general-settings' ).'" target="_blank">' . __('General Settings', 'profilebuilder') . '</a>' ) . '</div>';
35 }
36
37 return $form;
38 }
39 add_filter( "wck_before_listed_wppb_manage_fields_element_0", 'wppb_manage_fields_display_field_title_slug', 10, 3 );
40 add_filter( "wck_before_listed_wppb_epf_fields_element_0", 'wppb_manage_fields_display_field_title_slug', 10, 3 );
41 add_filter( "wck_before_listed_wppb_rf_fields_element_0", 'wppb_manage_fields_display_field_title_slug', 10, 3 );
42
43
44
45
46
47 /**
48 * Function that adds a custom class to the existing container
49 *
50 * @since v.2.0
51 *
52 * @param string $update_container_class - the new class name
53 * @param string $meta - the name of the meta
54 * @param array $results
55 * @param integer $element_id - the ID of the element
56 *
57 * @return string
58 */
59 function wppb_update_container_class( $update_container_class, $meta, $results, $element_id ) {
60 $wppb_element_type = Wordpress_Creation_Kit_PB::wck_generate_slug( $results[$element_id]["field"] );
61
62 return "class='update_container_$meta update_container_$wppb_element_type element_type_$wppb_element_type'";
63 }
64 add_filter( 'wck_update_container_class_wppb_manage_fields', 'wppb_update_container_class', 10, 4 );
65
66
67 /**
68 * Function that adds a custom class to the existing element
69 *
70 * @since v.2.0
71 *
72 * @param string $element_class - the new class name
73 * @param string $meta - the name of the meta
74 * @param array $results
75 * @param integer $element_id - the ID of the element
76 *
77 * @return string
78 */
79 function wppb_element_class( $element_class, $meta, $results, $element_id ){
80 $wppb_element_type = Wordpress_Creation_Kit_PB::wck_generate_slug( $results[$element_id]["field"] );
81
82 return "class='element_type_$wppb_element_type added_fields_list'";
83 }
84 add_filter( 'wck_element_class_wppb_manage_fields', 'wppb_element_class', 10, 4 );
85
86 /**
87 * Functions to check password length and strength
88 *
89 * @since v.2.0
90 */
91 /* on add user and update profile from WP admin area */
92 add_action( 'user_profile_update_errors', 'wppb_password_check_on_profile_update', 0, 3 );
93 function wppb_password_check_on_profile_update( $errors, $update, $user ){
94 wppb_password_check_extra_conditions( $errors, $user );
95 }
96
97 /* on reset password */
98 add_action( 'validate_password_reset', 'wppb_password_check_extra_conditions', 10, 2 );
99 function wppb_password_check_extra_conditions( $errors, $user ){
100 $password = ( isset( $_POST[ 'pass1' ] ) && trim( $_POST[ 'pass1' ] ) ) ? $_POST[ 'pass1' ] : false;
101
102 if( $password ){
103 $wppb_generalSettings = get_option( 'wppb_general_settings' );
104 if( !empty( $wppb_generalSettings['minimum_password_length'] ) ){
105 if( strlen( $password ) < $wppb_generalSettings['minimum_password_length'] )
106 $errors->add( 'pass', __( '<strong>ERROR</strong>: The password must have the minimum length of '. $wppb_generalSettings['minimum_password_length'] .' characters', 'profilebuilder' ) );
107 }
108
109 if( isset( $_POST['wppb_password_strength'] ) && !empty( $wppb_generalSettings['minimum_password_strength'] ) ){
110
111 $password_strength_array = array( 'short' => 0, 'bad' => 1, 'good' => 2, 'strong' => 3 );
112 $password_strength_text = array( 'short' => __( 'Very weak', 'profilebuilder' ), 'bad' => __( 'Weak', 'profilebuilder' ), 'good' => __( 'Medium', 'profilebuilder' ), 'strong' => __( 'Strong', 'profilebuilder' ) );
113
114 foreach( $password_strength_text as $psr_key => $psr_text ){
115 if( $psr_text == $_POST['wppb_password_strength'] ){
116 $password_strength_result_slug = $psr_key;
117 break;
118 }
119 }
120
121 if( !empty( $password_strength_result_slug ) ){
122 if( $password_strength_array[$password_strength_result_slug] < $password_strength_array[$wppb_generalSettings['minimum_password_strength']] )
123 $errors->add( 'pass', __( '<strong>ERROR</strong>: The password must have a minimum strength of '. $password_strength_text[$wppb_generalSettings['minimum_password_strength']], 'profilebuilder' ) );
124 }
125 }
126 }
127
128 return $errors;
129 }
130
131 /* we need to create a hidden field that contains the results of the password strength from the js strength tester */
132 add_action( 'admin_footer', 'wppb_add_hidden_password_strength_on_backend' );
133 add_action( 'login_footer', 'wppb_add_hidden_password_strength_on_backend' );
134 function wppb_add_hidden_password_strength_on_backend(){
135 if( $GLOBALS['pagenow'] == 'profile.php' || $GLOBALS['pagenow'] == 'user-new.php' || ( $GLOBALS['pagenow'] == 'wp-login.php' && isset( $_GET['action'] ) && ( $_GET['action'] == 'rp' || $_GET['action'] == 'resetpass' ) ) ){
136 $wppb_generalSettings = get_option( 'wppb_general_settings' );
137 if( !empty( $wppb_generalSettings['minimum_password_strength'] ) ){
138 ?>
139 <script type="text/javascript">
140 jQuery( document ).ready( function() {
141 var passswordStrengthResult = jQuery( '#pass-strength-result' );
142 // Check for password strength meter
143 if ( passswordStrengthResult.length ) {
144 // Attach submit event to form
145 passswordStrengthResult.parents( 'form' ).on( 'submit', function() {
146 // Store check results in hidden field
147 jQuery( this ).append( '<input type="hidden" name="wppb_password_strength" value="' + passswordStrengthResult.text() + '">' );
148 });
149 }
150 });
151 </script>
152 <?php
153 }
154 }
155 }
156
157
158 /* Modify the Add Entry buttons for WCK metaboxes according to context */
159 add_filter( 'wck_add_entry_button', 'wppb_change_add_entry_button', 10, 2 );
160 function wppb_change_add_entry_button( $string, $meta ){
161 if( $meta == 'wppb_manage_fields' || $meta == 'wppb_epf_fields' || $meta == 'wppb_rf_fields' ){
162 return __( "Add Field", 'profilebuilder' );
163 }elseif( $meta == 'wppb_epf_page_settings' || $meta == 'wppb_rf_page_settings' || $meta == 'wppb_ul_page_settings' ){
164 return __( "Save Settings", 'profilebuilder' );
165 }
166
167 return $string;
168 }