__( 'Display a login/register form on the sidebar.','realistic' ) ) ); } public function form( $instance ){ $defaults = array( 'title' => 'Login', 'show_avatar' => 1, 'show_user' => 1, 'show_remember' => 1, 'show_register' => 1, 'show_forgot' => 1, 'show_dash' => 1, 'show_profile' => 1 ); $instance = wp_parse_args((array) $instance, $defaults); $title = isset( $instance[ 'title' ] ) ? $instance[ 'title' ] : __( 'Login','realistic' ); $show_avatar = isset( $instance[ 'show_avatar' ] ) ? esc_attr( $instance[ 'show_avatar' ] ) : 1; $show_user = isset( $instance[ 'show_user' ] ) ? esc_attr( $instance[ 'show_user' ] ) : 1; $show_remember = isset( $instance[ 'show_remember' ] ) ? esc_attr( $instance[ 'show_remember' ] ) : 1; $show_register = isset( $instance[ 'show_register' ] ) ? esc_attr( $instance[ 'show_register' ] ) : 1; $show_forgot = isset( $instance[ 'show_forgot' ] ) ? esc_attr( $instance[ 'show_forgot' ] ) : 1; $show_dash = isset( $instance[ 'show_dash' ] ) ? esc_attr( $instance[ 'show_dash' ] ) : 1; $show_profile = isset( $instance[ 'show_profile' ] ) ? esc_attr( $instance[ 'show_profile' ] ) : 1; ?>

first_name ) || !empty( $user_info->last_name) )? __('Welcome','realistic')." ".$user_info->first_name." ".$user_info->last_name : __('Welcome','realistic')." ".$user_login; } echo $before_widget; echo $before_title; echo $title; echo $after_title; echo '
'; $redirect = site_url(); if ( isset( $_GET['login'] ) ) { $login = $_GET['login']; // This variable is used when login failure occurs $current_error = $_GET['errcode']; // This variable is used to display the type of error during login if ( $login == 'failed' ){ if ( $current_error == "empty_username" || $current_error == "empty_password" ){ $error_msg = __( 'Enter both Username and Password', 'realistic' ); } elseif( $current_error == 'invalid_username' ){ $error_msg = __( 'Username is not registered', 'realistic' ); } elseif( $current_error == 'incorrect_password' ){ $error_msg = __( 'Incorrect Password', 'realistic' ); } echo "

".$error_msg."

"; } } // Check if user is logged in then show user information and logout,dashboard and profile link if ( is_user_logged_in() ) { if ( $show_avatar == 1 ) { echo '
' . get_avatar( $user_info->ID, apply_filters( 'login_widget_avatar_size', 80 ) ) . '
'; } echo '
'; if( $show_user == 1 ){ _e( 'Logged in as ', 'realistic' ); echo '' . ucfirst( implode(', ', $user_info->roles)) . '
'; } ?> "; } // If user is not logged in then show login form else { $remember_val = ( $show_remember == 1 ) ? true : false; wp_login_form(array( 'value_remember' => 0, 'redirect' => $redirect, 'label_username' => __( 'Username', 'realistic' ), 'label_password' => __( 'Password', 'realistic' ), 'remember' => $remember_val )); ?>

'.__('Register', 'realistic').''; if ( $show_register == 1 && $show_forgot == 1 )echo " | "; if ( $show_forgot == 1 ) echo '' . __('Forgot Password?','realistic') . ''; ?>

'; echo $after_widget; } } add_action( 'widgets_init', create_function( '', 'register_widget( "realistic_login_widget" );' ) ); add_action('wp_login_failed', 'handle_login_failure'); // This method will handle the login failure process. function handle_login_failure($username){ // check what page the login attempt is coming from global $current_error; $referrer = $_SERVER['HTTP_REFERER']; if ( !empty($referrer) && !strstr($referrer,'wp-login') && !strstr($referrer,'wp-admin') ) { wp_redirect(home_url() . '/?login=failed&errcode='.$current_error ); exit; } } if ( !function_exists('wp_authenticate') ) { function wp_authenticate($username, $password) { global $current_error; $username = sanitize_user($username); $password = trim($password); $user = apply_filters('authenticate', null, $username, $password); if ( $user == null ) { $user = new WP_Error('authentication_failed', __('ERROR: Invalid username or incorrect password.', 'realistic' )); } $ignore_codes = array('empty_username', 'empty_password', 'invalid_username', 'incorrect_password'); if (is_wp_error($user) && in_array($user->get_error_code(), $ignore_codes) ) { $current_error = $user->get_error_code(); do_action('wp_login_failed', $username); } return $user; } } ?>