PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 2.6.2
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v2.6.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 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.6.2, at admin/admin-functions.php

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