'; $form_part .= ''; $form_part .= ''; } return $form_part; } add_filter( 'login_form_bottom', 'wppb_login_form_bottom', 10, 2 ); // when email login is enabled we need to change the post data for the username function wppb_change_login_with_email(){ if( !empty( $_POST['log'] ) ){ // only do this for our form if( isset( $_POST['wppb_login'] ) ){ global $wpdb, $_POST; $wppb_generalSettings = get_option( 'wppb_general_settings' ); // if this setting is active, the posted username is, in fact the user's email if( isset( $wppb_generalSettings['loginWith'] ) && ( $wppb_generalSettings['loginWith'] == 'email' ) ){ $username = $wpdb->get_var( $wpdb->prepare( "SELECT user_login FROM $wpdb->users WHERE user_email= %s LIMIT 1", trim( $_POST['log'] ) ) ); if( !empty( $username ) ) $_POST['log'] = $username; else{ // 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 $_POST['log'] = 'this_is_an_invalid_email'.time(); } } } } } add_action( 'login_init', 'wppb_change_login_with_email' ); // login redirect filter. used to redirect from wp-login.php if it errors out function wppb_login_redirect( $redirect_to, $redirect_url, $user ){ // if login action initialized by our form if( isset( $_POST['wppb_login'] ) ){ if( is_wp_error( $user ) ){ // if we don't have a succesfull login we must redirect to the url of the form, so make sure this happens $redirect_to = $_POST['wppb_request_url']; $request_form_location = $_POST['wppb_form_location']; $error_string = $user->get_error_message(); // if login with email is enabled change the word username with email $wppb_generalSettings = get_option('wppb_general_settings'); if( isset( $wppb_generalSettings['loginWith'] ) && ( $wppb_generalSettings['loginWith'] == 'email' ) ){ $siteURL = home_url( '/wp-login.php?action=lostpassword' ); $siteURL = apply_filters( 'wppb_pre_login_url_filter', $siteURL ); if( $user->get_error_code() == 'incorrect_password' ){ $error_string = ''. __( 'ERROR', 'profilebuilder' ) .': '. __( 'The password you entered is incorrect.', 'profilebuilder' ) .' '; $error_string .= ''. __( 'Lost your password', 'profilebuilder' ) .'?'; } /* maybe also change the recover password link */ $error_string = str_replace( home_url( '/wp-login.php?action=lostpassword' ), $siteURL, $error_string ); $error_string = str_replace( 'username', 'email', $error_string ); } // if the error string is empty it means that none of the fields were completed if( empty( $error_string ) ){ $error_string = ''. __( 'ERROR', 'profilebuilder' ) .': '. __( 'Both fields are empty.', 'profilebuilder' ) .' '; $error_string = apply_filters( 'wppb_login_empty_fields_error_message', $error_string ); } $error_string = apply_filters( 'wppb_login_wp_error_message', $error_string, $user ); // encode the error string and send it as a GET parameter $arr_params = array ( 'loginerror' => urlencode( base64_encode( $error_string ) ), 'request_form_location' => $request_form_location ); $redirect_to = add_query_arg( $arr_params, $redirect_to ); wp_safe_redirect( $redirect_to ); } else{ // we don't have an error make sure to remove the error from the query arg $redirect_to = remove_query_arg( 'loginerror', $redirect_to ); } } return $redirect_to; } add_filter( 'login_redirect', 'wppb_login_redirect', 10, 3 ); /* shortcode function */ function wppb_front_end_login( $atts ){ extract( shortcode_atts( array( 'display' => true, 'redirect' => '' ), $atts ) ); $wppb_generalSettings = get_option('wppb_general_settings'); if( !is_user_logged_in() ){ // set up the form arguments $form_args = array( 'echo' => false, 'id_submit' => 'wppb-submit' ); // maybe set up the redirect argument if( empty( $redirect ) ){ $wppb_module_settings = get_option( 'wppb_module_settings' ); if( $wppb_module_settings['wppb_customRedirect'] == 'show' ){ //check to see if the redirect location is not an empty string and is activated $login_redirect_settings = get_option( 'customRedirectSettings' ); // set up the redirect argument to our redirect page if( ( trim( $login_redirect_settings['afterLoginTarget'] ) != '' ) && ( $login_redirect_settings['afterLogin'] == 'yes' ) ){ $redirect_to = trim( $login_redirect_settings['afterLoginTarget'] ); if( wppb_check_missing_http( $redirect_to ) ) $redirect_to = 'http://'. $redirect_to; $form_args['redirect'] = $redirect_to; } } } else $form_args['redirect'] = trim( $redirect ); // change the label argument for username is login with email is enabled if ( isset( $wppb_generalSettings['loginWith'] ) && ( $wppb_generalSettings['loginWith'] == 'email' ) ) $form_args['label_username'] = __( 'Email', 'profilebuilder' ); // initialize our form variable $login_form = ''; // display our login errors if( isset( $_GET['loginerror'] ) || isset( $_POST['loginerror'] ) ){ $loginerror = isset( $_GET['loginerror'] ) ? $_GET['loginerror'] : $_POST['loginerror']; $loginerror = '
'.urldecode( base64_decode( $loginerror ) ).'
'; if( isset( $_GET['request_form_location'] ) ){ if( $_GET['request_form_location'] == 'widget' && !in_the_loop() ){ $login_form .= $loginerror; } elseif( $_GET['request_form_location'] == 'page' && in_the_loop() ){ $login_form .= $loginerror; } } } // build our form $login_form .= ''.sprintf(__( 'You are currently logged in as %1$s. %2$s', 'profilebuilder' ), ''.$display_name.'', ''. __( 'Log out', 'profilebuilder').' »' ) . '
'; return apply_filters( 'wppb_login_message', $loged_in_message, $wppb_user->ID, $display_name ); } }