Quantcast
Channel: Topic Tag: bug | WordPress.org
Viewing all articles
Browse latest Browse all 23376

Kneecoe on "[Plugin: User Status Manager] [resolved] Home redirect after failed login attempt"

$
0
0

This is awesome. This plugin does exactly what it says and friggin works like magic!
One lil detail thou, it kept bugging me that after a temporarily disabled user tried to login, an early redirect to main page kept him/her from seeing the error message, it still works because this "wtf happened" event pushes you to try to login a second time and BAM! the wp-login.php loads with the error message already.

Well all it needs is a lil fix in the plugin's "Start.php" file, look for this part of the code where redirects users with a status value of "1"

session_start();
	function check_user($user_login, $user) {
		global $wpdb;
		$user_id = $user->data->ID;
		$table = $wpdb->prefix . 'user_status_manager';
		$date_val = date('Y/m/d');
		$get_status = $wpdb->get_row('select status,status_from,status_to from '.$table.' where user_id='.$user_id);
		$status_from = $get_status->status_from;
		$status_to 	 = $get_status->status_to;
		if($get_status->status=="0"){
			if($status_from!="" && $status_to!=""){
				if($status_from <= $date_val){
					if($status_to >= $date_val){
						//The User Is Active
						$_SESSION['status_val']=0;
					}else{
						wp_redirect(get_option('siteurl') . '/wp-login.php?disabled=true');
						wp_logout();
						$_SESSION['status_val'] = 1;
					}
				}else{
					wp_redirect(get_option('siteurl') . '/wp-login.php?disabled=true');
					wp_logout();
					$_SESSION['status_val'] = 1;
				}
			}
		}else{
			if($status_from!="" && $status_to!=""){
				if($status_from <= $date_val){
					if($status_to >= $date_val){
						wp_redirect(get_option('siteurl') . '/wp-login.php?disabled=true');
						wp_logout();
						$_SESSION['status_val'] = 1;
					}
				}
			}else{
				wp_redirect(get_option('siteurl') . '/wp-login.php?disabled=true');
				wp_logout();
				$_SESSION['status_val'] = 1;
			}
		}

	}
	add_action('wp_login', 'check_user', 10, 2);

And just add " exit;" after every "$_SESSION['status_val'] = 1;" like this:

session_start();
	function check_user($user_login, $user) {
		global $wpdb;
		$user_id = $user->data->ID;
		$table = $wpdb->prefix . 'user_status_manager';
		$date_val = date('Y/m/d');
		$get_status = $wpdb->get_row('select status,status_from,status_to from '.$table.' where user_id='.$user_id);
		$status_from = $get_status->status_from;
		$status_to 	 = $get_status->status_to;
		if($get_status->status=="0"){
			if($status_from!="" && $status_to!=""){
				if($status_from <= $date_val){
					if($status_to >= $date_val){
						//The User Is Active
						$_SESSION['status_val']=0;
					}else{
						wp_redirect(get_option('siteurl') . '/wp-login.php?disabled=true');
						wp_logout();
						$_SESSION['status_val'] = 1; exit;
					}
				}else{
					wp_redirect(get_option('siteurl') . '/wp-login.php?disabled=true');
					wp_logout();
					$_SESSION['status_val'] = 1; exit;
				}
			}
		}else{
			if($status_from!="" && $status_to!=""){
				if($status_from <= $date_val){
					if($status_to >= $date_val){
						wp_redirect(get_option('siteurl') . '/wp-login.php?disabled=true');
						wp_logout();
						$_SESSION['status_val'] = 1; exit;
					}
				}
			}else{
				wp_redirect(get_option('siteurl') . '/wp-login.php?disabled=true');
				wp_logout();
				$_SESSION['status_val'] = 1; exit;
			}
		}

	}
	add_action('wp_login', 'check_user', 10, 2);

And voila!!! it doesnt redirects to main page anymore, and displays the message as it should

http://wordpress.org/extend/plugins/user-status-manager/


Viewing all articles
Browse latest Browse all 23376

Trending Articles