PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 2.4.9
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v2.4.9
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 2.0.8 All 339 releases
profile-builder / admin / admin-functions.php

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

206 lines 9.1 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 )', 'profile-builder' ), '<a href="'.admin_url( 'admin.php?page=profile-builder-general-settings' ).'" target="_blank">' . __('General Settings', 'profile-builder') . '</a>' ) . '</div>';
35 }
36
37 // add a notice to 'Default - Display name publicly as' field
38 global $wppb_results_field;
39 if ( $wppb_results_field == 'Default - Display name publicly as' )
40 $form .= '<div id="wppb-display-name-nag" class="wppb-backend-notice">' . __( 'Display name publicly as - only appears on the Edit Profile page!', 'profile-builder' ) . '</div>';
41
42 return $form;
43 }
44 add_filter( "wck_before_listed_wppb_manage_fields_element_0", 'wppb_manage_fields_display_field_title_slug', 10, 3 );
45 add_filter( "wck_before_listed_wppb_epf_fields_element_0", 'wppb_manage_fields_display_field_title_slug', 10, 3 );
46 add_filter( "wck_before_listed_wppb_rf_fields_element_0", 'wppb_manage_fields_display_field_title_slug', 10, 3 );
47
48
49 /**
50 * Check if field type is 'Default - Display name publicly as' so we can add a notification for it
51 *
52 * @since v.2.2
53 *
54 * @param string $wck_element_class
55 * @param string $meta
56 * @param array $results
57 * @param integer $element_id
58 *
59 */
60 function wppb_manage_fields_display_name_notice( $wck_element_class, $meta, $results, $element_id ) {
61 global $wppb_results_field;
62
63 $wppb_results_field = $results[$element_id]['field'];
64 }
65 add_filter( 'wck_element_class_wppb_manage_fields', 'wppb_manage_fields_display_name_notice', 10, 4 );
66
67
68
69 /**
70 * Function that adds a custom class to the existing container
71 *
72 * @since v.2.0
73 *
74 * @param string $update_container_class - the new class name
75 * @param string $meta - the name of the meta
76 * @param array $results
77 * @param integer $element_id - the ID of the element
78 *
79 * @return string
80 */
81 function wppb_update_container_class( $update_container_class, $meta, $results, $element_id ) {
82 $wppb_element_type = Wordpress_Creation_Kit_PB::wck_generate_slug( $results[$element_id]["field"] );
83
84 return "class='update_container_$meta update_container_$wppb_element_type element_type_$wppb_element_type'";
85 }
86 add_filter( 'wck_update_container_class_wppb_manage_fields', 'wppb_update_container_class', 10, 4 );
87
88
89 /**
90 * Function that adds a custom class to the existing element
91 *
92 * @since v.2.0
93 *
94 * @param string $element_class - the new class name
95 * @param string $meta - the name of the meta
96 * @param array $results
97 * @param integer $element_id - the ID of the element
98 *
99 * @return string
100 */
101 function wppb_element_class( $element_class, $meta, $results, $element_id ){
102 $wppb_element_type = Wordpress_Creation_Kit_PB::wck_generate_slug( $results[$element_id]["field"] );
103
104 return "class='element_type_$wppb_element_type added_fields_list'";
105 }
106 add_filter( 'wck_element_class_wppb_manage_fields', 'wppb_element_class', 10, 4 );
107
108 /**
109 * Functions to check password length and strength
110 *
111 * @since v.2.0
112 */
113 /* on add user and update profile from WP admin area */
114 add_action( 'user_profile_update_errors', 'wppb_password_check_on_profile_update', 0, 3 );
115 function wppb_password_check_on_profile_update( $errors, $update, $user ){
116 wppb_password_check_extra_conditions( $errors, $user );
117 }
118
119 /* on reset password */
120 add_action( 'validate_password_reset', 'wppb_password_check_extra_conditions', 10, 2 );
121 function wppb_password_check_extra_conditions( $errors, $user ){
122 $password = ( isset( $_POST[ 'pass1' ] ) && trim( $_POST[ 'pass1' ] ) ) ? $_POST[ 'pass1' ] : false;
123
124 if( $password ){
125 $wppb_generalSettings = get_option( 'wppb_general_settings' );
126 if( !empty( $wppb_generalSettings['minimum_password_length'] ) ){
127 if( strlen( $password ) < $wppb_generalSettings['minimum_password_length'] )
128 $errors->add( 'pass', sprintf( __( '<strong>ERROR</strong>: The password must have the minimum length of %s characters', 'profile-builder' ), $wppb_generalSettings['minimum_password_length'] ) );
129 }
130
131 if( isset( $_POST['wppb_password_strength'] ) && !empty( $wppb_generalSettings['minimum_password_strength'] ) ){
132
133 $password_strength_array = array( 'short' => 0, 'bad' => 1, 'good' => 2, 'strong' => 3 );
134 $password_strength_text = array( 'short' => __( 'Very weak', 'profile-builder' ), 'bad' => __( 'Weak', 'profile-builder' ), 'good' => __( 'Medium', 'profile-builder' ), 'strong' => __( 'Strong', 'profile-builder' ) );
135
136 foreach( $password_strength_text as $psr_key => $psr_text ){
137 if( $psr_text == $_POST['wppb_password_strength'] ){
138 $password_strength_result_slug = $psr_key;
139 break;
140 }
141 }
142
143 if( !empty( $password_strength_result_slug ) ){
144 if( $password_strength_array[$password_strength_result_slug] < $password_strength_array[$wppb_generalSettings['minimum_password_strength']] )
145 $errors->add( 'pass', sprintf( __( '<strong>ERROR</strong>: The password must have a minimum strength of %s', 'profile-builder' ), $password_strength_text[$wppb_generalSettings['minimum_password_strength']] ) );
146 }
147 }
148 }
149
150 return $errors;
151 }
152
153 /* we need to create a hidden field that contains the results of the password strength from the js strength tester */
154 add_action( 'admin_footer', 'wppb_add_hidden_password_strength_on_backend' );
155 add_action( 'login_footer', 'wppb_add_hidden_password_strength_on_backend' );
156 function wppb_add_hidden_password_strength_on_backend(){
157 if( $GLOBALS['pagenow'] == 'profile.php' || $GLOBALS['pagenow'] == 'user-new.php' || ( $GLOBALS['pagenow'] == 'wp-login.php' && isset( $_GET['action'] ) && ( $_GET['action'] == 'rp' || $_GET['action'] == 'resetpass' ) ) ){
158 $wppb_generalSettings = get_option( 'wppb_general_settings' );
159 if( !empty( $wppb_generalSettings['minimum_password_strength'] ) ){
160 ?>
161 <script type="text/javascript">
162 jQuery( document ).ready( function() {
163 var passswordStrengthResult = jQuery( '#pass-strength-result' );
164 // Check for password strength meter
165 if ( passswordStrengthResult.length ) {
166 // Attach submit event to form
167 passswordStrengthResult.parents( 'form' ).on( 'submit', function() {
168 // Store check results in hidden field
169 jQuery( this ).append( '<input type="hidden" name="wppb_password_strength" value="' + passswordStrengthResult.text() + '">' );
170 });
171 }
172 });
173 </script>
174 <?php
175 }
176 }
177 }
178
179
180 /* Modify the Add Entry buttons for WCK metaboxes according to context */
181 add_filter( 'wck_add_entry_button', 'wppb_change_add_entry_button', 10, 2 );
182 function wppb_change_add_entry_button( $string, $meta ){
183 if( $meta == 'wppb_manage_fields' || $meta == 'wppb_epf_fields' || $meta == 'wppb_rf_fields' ){
184 return __( "Add Field", 'profile-builder' );
185 }elseif( $meta == 'wppb_epf_page_settings' || $meta == 'wppb_rf_page_settings' || $meta == 'wppb_ul_page_settings' ){
186 return __( "Save Settings", 'profile-builder' );
187 }
188
189 return $string;
190 }
191
192 /* Add admin footer text for encouraging users to leave a review of the plugin on wordpress.org */
193 function wppb_admin_rate_us( $footer_text ) {
194 global $current_screen;
195
196 if ($current_screen->parent_base == 'profile-builder'){
197 $rate_text = sprintf( __( 'If you enjoy using <strong> %1$s </strong> please <a href="%2$s" target="_blank">rate us on WordPress.org</a>. More happy users means more features, less bugs and better support for everyone. ', 'profile-builder' ),
198 PROFILE_BUILDER,
199 'https://wordpress.org/support/view/plugin-reviews/profile-builder?filter=5#postform'
200 );
201 return '<span id="footer-thankyou">' .$rate_text . '</span>';
202 } else {
203 return $footer_text;
204 }
205 }
206 add_filter('admin_footer_text','wppb_admin_rate_us');