WordPress.org

Ready to get started?Download WordPress

Forums

User Status Manager
[resolved] [resolved] Home redirect after failed login attempt (5 posts)

  1. Kneecoe
    Member
    Posted 1 year ago #

    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/

  2. Rahul Balakrishna
    Member
    Plugin Author

    Posted 1 year ago #

    Hello Kneecoe,

    Thank you for your reply. Really appreciate it. I checked it on my site but was not redirected to the home page. May be the issue was related to some setting of login related plug-in is installed.

    Thank you though for your response will add your problem solution at the installation section

    Regards,
    Rahul

  3. Kneecoe
    Member
    Posted 1 year ago #

    No probs! Btw I don't have a clue why this plugin didn't go viral, It was EXACTLY what I wanted and was about to give up the 3 hours search when I finally found it, there's nothing like this out there, maybe spam control but still not a viable penalty system.

    Also I wrote a small addon to immediately end the user's session and log him out after the "Inactive" status is set (so you don't have to wait until he voluntarily logs out and back in) and it works great, thank you so much!

    Best regards,
    Nico

  4. Rahul Balakrishna
    Member
    Plugin Author

    Posted 1 year ago #

    Thank You Kneecoe. Sorry for late reply was busy with work

    I really appreciate it. I agree there is no plugin like this still its not so famous as it should be. If possible then please promote the plugin like telling it to friends and all, I would really appreciate it.

    Regards,
    Rahul

  5. entrepreblog
    Member
    Posted 1 year ago #

    I installed this in a 3.4.2 site, and followed the post-install 'save' step, and none of my userids can log in.

    Other plugins removed, and retested with the same result.

    So I picked one and made sure to set the flag to ACTIVE, and put the dates from 2013/01/17 to 2033/01/17, and saved - same result.

    After that I deactivated. Any suggestions?

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic