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 / front-end / login.php

login.php in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 2.0.6, at front-end/login.php

204 lines 10.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // add hidden input to our form to identify that is a profile builder form
3 function wppb_login_form_bottom( $form_part, $args ){
4 // we set this id in the wp_login_form() function
5 if( $args['id_submit'] == 'wppb-submit' ){
6 if( in_the_loop() )
7 $form_location = 'page';
8 else
9 $form_location = 'widget';
10
11 $form_part = '<input type="hidden" name="wppb_login" value="true"/>';
12 $form_part .= '<input type="hidden" name="wppb_form_location" value="'. $form_location .'"/>';
13 $form_part .= '<input type="hidden" name="wppb_request_url" value="'.wppb_curpageurl().'"/>';
14 $form_part .= '<input type="hidden" name="wppb_lostpassword_url" value="'.$args['lostpassword_url'].'"/>';
15 }
16
17 return $form_part;
18 }
19 add_filter( 'login_form_bottom', 'wppb_login_form_bottom', 10, 2 );
20
21 // when email login is enabled we need to change the post data for the username
22 function wppb_change_login_with_email(){
23 if( !empty( $_POST['log'] ) ){
24 // only do this for our form
25 if( isset( $_POST['wppb_login'] ) ){
26 global $wpdb, $_POST;
27
28 $wppb_generalSettings = get_option( 'wppb_general_settings' );
29
30 // if this setting is active, the posted username is, in fact the user's email
31 if( isset( $wppb_generalSettings['loginWith'] ) && ( $wppb_generalSettings['loginWith'] == 'email' ) ){
32 $username = $wpdb->get_var( $wpdb->prepare( "SELECT user_login FROM $wpdb->users WHERE user_email= %s LIMIT 1", trim( $_POST['log'] ) ) );
33
34 if( !empty( $username ) )
35 $_POST['log'] = $username;
36
37 else{
38 // if we don't have a username for the email entered we can't have an empty username because we will receive a field empty error
39 $_POST['log'] = 'this_is_an_invalid_email'.time();
40 }
41 }
42 }
43 }
44 }
45 add_action( 'login_init', 'wppb_change_login_with_email' );
46
47 // login redirect filter. used to redirect from wp-login.php if it errors out
48 function wppb_login_redirect( $redirect_to, $redirect_url, $user ){
49 // if login action initialized by our form
50 if( isset( $_POST['wppb_login'] ) ){
51 if( is_wp_error( $user ) ) {
52 // if we don't have a successful login we must redirect to the url of the form, so make sure this happens
53 $redirect_to = $_POST['wppb_request_url'];
54 $request_form_location = $_POST['wppb_form_location'];
55 $error_string = $user->get_error_message();
56
57 $wppb_generalSettings = get_option('wppb_general_settings');
58
59 if (isset($wppb_generalSettings['loginWith'])) {
60 $LostPassURL = home_url('/wp-login.php?action=lostpassword');
61
62 // if the Login shortcode has a lostpassword argument set, give the lost password error link that value
63 if (!empty($_POST['wppb_lostpassword_url'])) {
64 if ( wppb_check_missing_http( $_POST['wppb_lostpassword_url'] ) ) $LostPassURL = "http://" . $_POST['wppb_lostpassword_url'];
65 else $LostPassURL = $_POST['wppb_lostpassword_url'];
66 }
67
68 //apply filter to allow changing Lost your Password link
69 $LostPassURL = apply_filters('wppb_pre_login_url_filter', $LostPassURL);
70
71 if ($user->get_error_code() == 'incorrect_password') {
72 $error_string = '<strong>' . __('ERROR', 'profilebuilder') . '</strong>: ' . __('The password you entered is incorrect.', 'profilebuilder') . ' ';
73 $error_string .= '<a href="' . $LostPassURL . '" title="' . __('Password Lost and Found.', 'profilebuilder') . '">' . __('Lost your password', 'profilebuilder') . '</a>?';
74
75 // change the recover password link
76 $error_string = str_replace(home_url('/wp-login.php?action=lostpassword'), $LostPassURL, $error_string);
77 }
78 if ($user->get_error_code() == 'invalid_username') {
79 $error_string = '<strong>' . __('ERROR', 'profilebuilder') . '</strong>: ' . __('Invalid username.', 'profilebuilder') . ' ';
80 $error_string .= '<a href="' . $LostPassURL . '" title="' . __('Password Lost and Found.', 'profilebuilder') . '">' . __('Lost your password', 'profilebuilder') . '</a>?';
81 }
82 // if login with email is enabled change the word username with email
83 if ($wppb_generalSettings['loginWith'] == 'email')
84 $error_string = str_replace( __('username','profilebuilder'), __('email','profilebuilder'), $error_string);
85
86 }
87 // if the error string is empty it means that none of the fields were completed
88 if (empty($error_string)) {
89 $error_string = '<strong>' . __('ERROR', 'profilebuilder') . '</strong>: ' . __('Both fields are empty.', 'profilebuilder') . ' ';
90 $error_string = apply_filters('wppb_login_empty_fields_error_message', $error_string);
91 }
92
93 $error_string = apply_filters('wppb_login_wp_error_message', $error_string, $user);
94
95 // encode the error string and send it as a GET parameter
96 $arr_params = array('loginerror' => urlencode(base64_encode($error_string)), 'request_form_location' => $request_form_location);
97 $redirect_to = add_query_arg($arr_params, $redirect_to);
98 wp_safe_redirect($redirect_to);
99 }
100 else{
101 // we don't have an error make sure to remove the error from the query arg
102 $redirect_to = remove_query_arg( 'loginerror', $redirect_to );
103 }
104 }
105
106 return $redirect_to;
107 }
108 add_filter( 'login_redirect', 'wppb_login_redirect', 10, 3 );
109
110
111 /* shortcode function */
112 function wppb_front_end_login( $atts ){
113
114 extract( shortcode_atts( array( 'display' => true, 'redirect' =>'', 'register_url'=>'', 'lostpassword_url'=>'' ), $atts ) );
115
116 $wppb_generalSettings = get_option('wppb_general_settings');
117
118 if( !is_user_logged_in() ){
119 // set up the form arguments
120 $form_args = array( 'echo' => false, 'id_submit' => 'wppb-submit' );
121
122 // maybe set up the redirect argument
123 if( empty( $redirect ) ){
124 $wppb_module_settings = get_option( 'wppb_module_settings' );
125 if( $wppb_module_settings['wppb_customRedirect'] == 'show' ){
126 //check to see if the redirect location is not an empty string and is activated
127 $login_redirect_settings = get_option( 'customRedirectSettings' );
128
129 // set up the redirect argument to our redirect page
130 if( ( trim( $login_redirect_settings['afterLoginTarget'] ) != '' ) && ( $login_redirect_settings['afterLogin'] == 'yes' ) ){
131 $redirect_to = trim( $login_redirect_settings['afterLoginTarget'] );
132 if( wppb_check_missing_http( $redirect_to ) )
133 $redirect_to = 'http://'. $redirect_to;
134
135 $form_args['redirect'] = $redirect_to;
136 }
137 }
138 }
139 else
140 $form_args['redirect'] = trim( $redirect );
141
142 // change the label argument for username is login with email is enabled
143 if ( isset( $wppb_generalSettings['loginWith'] ) && ( $wppb_generalSettings['loginWith'] == 'email' ) )
144 $form_args['label_username'] = __( 'Email', 'profilebuilder' );
145
146 // initialize our form variable
147 $login_form = '';
148
149 // display our login errors
150 if( isset( $_GET['loginerror'] ) || isset( $_POST['loginerror'] ) ){
151 $loginerror = isset( $_GET['loginerror'] ) ? $_GET['loginerror'] : $_POST['loginerror'];
152 $loginerror = '<p class="wppb-error">'.urldecode( base64_decode( $loginerror ) ).'</p><!-- .error -->';
153 if( isset( $_GET['request_form_location'] ) ){
154 if( $_GET['request_form_location'] == 'widget' && !in_the_loop() ){
155 $login_form .= $loginerror;
156 }
157 elseif( $_GET['request_form_location'] == 'page' && in_the_loop() ){
158 $login_form .= $loginerror;
159 }
160 }
161 }
162 // build our form
163 $login_form .= '<div id="wppb-login-wrap" class="wppb-user-forms">';
164 $form_args['lostpassword_url'] = $lostpassword_url;
165 $login_form .= wp_login_form( $form_args );
166
167 if ((!empty($register_url)) || (!empty($lostpassword_url))) {
168 $login_form .= '<p class="login-register-lost-password">';
169 $i = 0;
170 if (!empty($register_url)) {
171 if ( wppb_check_missing_http( $register_url ) ) $register_url = "http://" . $register_url;
172 $login_form .= '<a href="' . esc_url($register_url) . '">'. apply_filters('wppb_login_register_text', __('Register','profilebuilder')) .'</a>';
173 $i++;
174 }
175 if (!empty($lostpassword_url)) {
176 if ($i != 0) $login_form .= ' | ';
177 if ( wppb_check_missing_http( $lostpassword_url ) ) $lostpassword_url = "http://" . $lostpassword_url;
178 $login_form .= '<a href="'. esc_url($lostpassword_url) .'">'. apply_filters('wppb_login_lostpass_text', __('Lost your password?','profilebuilder')) .'</a>';
179 }
180 $login_form .= '</p>';
181 }
182
183 $login_form .= '</div>';
184 return $login_form;
185
186 }else{
187 $user_ID = get_current_user_id();
188 $wppb_user = get_userdata( $user_ID );
189
190 if( isset( $wppb_generalSettings['loginWith'] ) && ( $wppb_generalSettings['loginWith'] == 'email' ) )
191 $display_name = $wppb_user->user_email;
192
193 elseif($wppb_user->display_name !== '')
194 $display_name = $wppb_user->user_login;
195
196 else
197 $display_name = $wppb_user->display_name;
198
199 $loged_in_message = '<p class="wppb-alert">'.sprintf(__( 'You are currently logged in as %1$s. %2$s', 'profilebuilder' ), '<a href="'.$authorPostsUrl = get_author_posts_url( $wppb_user->ID ).'" title="'.$display_name.'">'.$display_name.'</a>', '<a href="'.wp_logout_url( $redirectTo = wppb_curpageurl() ).'" title="'.__( 'Log out of this account', 'profilebuilder' ).'">'. __( 'Log out', 'profilebuilder').' &raquo;</a>' ) . '</p><!-- .alert-->';
200
201 return apply_filters( 'wppb_login_message', $loged_in_message, $wppb_user->ID, $display_name );
202
203 }
204 }